diff options
| -rw-r--r-- | lib/std/json.zig | 4 | ||||
| -rw-r--r-- | lib/std/json/write_stream.zig | 8 |
2 files changed, 7 insertions, 5 deletions
diff --git a/lib/std/json.zig b/lib/std/json.zig index 1784f44a4d..c4a5ec75d9 100644 --- a/lib/std/json.zig +++ b/lib/std/json.zig @@ -2194,7 +2194,7 @@ test "write json then parse it" { try jw.emitBool(true); try jw.objectField("int"); - try jw.emitNumber(@as(i32, 1234)); + try jw.emitNumber(1234); try jw.objectField("array"); try jw.beginArray(); @@ -2203,7 +2203,7 @@ test "write json then parse it" { try jw.emitNull(); try jw.arrayElem(); - try jw.emitNumber(@as(f64, 12.34)); + try jw.emitNumber(12.34); try jw.endArray(); diff --git a/lib/std/json/write_stream.zig b/lib/std/json/write_stream.zig index 11f0171996..6dd02a03cf 100644 --- a/lib/std/json/write_stream.zig +++ b/lib/std/json/write_stream.zig @@ -148,7 +148,6 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type { self.popState(); } - // TODO better handling of ComptimeInt and ComptimeFloat pub fn emitNumber( self: *Self, /// An integer, float, or `std.math.BigInt`. Emitted as a bare number if it fits losslessly @@ -169,8 +168,11 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type { return; } }, - .Float => if (@floatCast(f64, value) == value) { - try self.stream.print("{}", .{value}); + .ComptimeInt => { + return self.emitNumber(@as(std.math.IntFittingRange(value, value), value)); + }, + .Float, .ComptimeFloat => if (@floatCast(f64, value) == value) { + try self.stream.print("{}", .{@floatCast(f64, value)}); self.popState(); return; }, |
