authorgravatar for marc@tiehu.isMarc Tiehuis <marc@tiehu.is> 2024-03-09 22:22:55+13:00
committergravatar for marc@tiehu.isMarc Tiehuis <marc@tiehu.is> 2024-03-09 22:23:14+13:00
logda4acf9a485bf1658194c8cb8593dd142677138d
tree0588fca38068dcc6a366150e6105dc23170b7cda
parent2e60d4d06400eef07ff05d5552b69961fa9e63f9

std.fmt: fix std-cases and perform round-trip check in ryu unit tests


3 files changed, 19 insertions(+), 1 deletions(-)

lib/std/fmt.zig+4
......@@ -784,6 +784,10 @@ fn formatFloatValue(
784784 }
785785}
786786
787test {
788 _ = &ryu128;
789}
790
787791pub const Case = enum { lower, upper };
788792
789793fn formatSliceHexImpl(comptime case: Case) type {
lib/std/fmt/ryu128.zig+14
......@@ -959,9 +959,23 @@ const POW5_INV_ERRORS: [154]u64 = .{
959959// zig fmt: on
960960
961961fn check(comptime T: type, value: T, comptime expected: []const u8) !void {
962 const I = @Type(.{ .Int = .{ .signedness = .unsigned, .bits = @bitSizeOf(T) } });
963
962964 var buf: [6000]u8 = undefined;
965 const value_bits: I = @bitCast(value);
963966 const s = try format(&buf, value, .{});
964967 try std.testing.expectEqualStrings(expected, s);
968
969 if (@bitSizeOf(T) != 80) {
970 const o = try std.fmt.parseFloat(T, s);
971 const o_bits: I = @bitCast(o);
972
973 if (std.math.isNan(value)) {
974 try std.testing.expect(std.math.isNan(o));
975 } else {
976 try std.testing.expectEqual(value_bits, o_bits);
977 }
978 }
965979}
966980
967981test "format f32" {
test/cases/safety/slice sentinel mismatch - floats.zig +1-1
......@@ -2,7 +2,7 @@ const std = @import("std");
22
33pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
44 _ = stack_trace;
5 if (std.mem.eql(u8, message, "sentinel mismatch: expected 1.20000004e+00, found 4.0e+00")) {
5 if (std.mem.eql(u8, message, "sentinel mismatch: expected 1.2e0, found 4e0")) {
66 std.process.exit(0);
77 }
88 std.process.exit(1);