srctree

Marc Tiehuis parent 2e60d4d0 da4acf9a
std.fmt: fix std-cases and perform round-trip check in ryu unit tests

inlinesplit
lib/std/fmt.zig added: 22, removed: 4, total 18
@@ -784,6 +784,10 @@ fn formatFloatValue(
}
}
 
test {
_ = &ryu128;
}
 
pub const Case = enum { lower, upper };
 
fn formatSliceHexImpl(comptime case: Case) type {
 
lib/std/fmt/ryu128.zig added: 22, removed: 4, total 18
@@ -959,9 +959,23 @@ const POW5_INV_ERRORS: [154]u64 = .{
// zig fmt: on
 
fn check(comptime T: type, value: T, comptime expected: []const u8) !void {
const I = @Type(.{ .Int = .{ .signedness = .unsigned, .bits = @bitSizeOf(T) } });
 
var buf: [6000]u8 = undefined;
const value_bits: I = @bitCast(value);
const s = try format(&buf, value, .{});
try std.testing.expectEqualStrings(expected, s);
 
if (@bitSizeOf(T) != 80) {
const o = try std.fmt.parseFloat(T, s);
const o_bits: I = @bitCast(o);
 
if (std.math.isNan(value)) {
try std.testing.expect(std.math.isNan(o));
} else {
try std.testing.expectEqual(value_bits, o_bits);
}
}
}
 
test "format f32" {
 
test/cases/safety/slice sentinel mismatch - floats.zig added: 22, removed: 4, total 18
@@ -2,7 +2,7 @@ const std = @import("std");
 
pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
_ = stack_trace;
if (std.mem.eql(u8, message, "sentinel mismatch: expected 1.20000004e+00, found 4.0e+00")) {
if (std.mem.eql(u8, message, "sentinel mismatch: expected 1.2e0, found 4e0")) {
std.process.exit(0);
}
std.process.exit(1);