| author | |
| committer | |
| log | b1ebaba40811a6131152b9fc2eb8fb533e9fe5f3 |
| tree | 9bc8cd0e095ce28bbc1fa46f9a76f9c719fddd8a |
| parent | ebbd137a0e90a8e78655d2a5f74cf87120b5a5a1 |
| signature | Commit is signed but in an unrecognized format. |
2 files changed, 7 insertions(+), 5 deletions(-)
lib/std/json.zig+2-2| ... | @@ -2194,7 +2194,7 @@ test "write json then parse it" { | ... | @@ -2194,7 +2194,7 @@ test "write json then parse it" { |
| 2194 | try jw.emitBool(true); | 2194 | try jw.emitBool(true); |
| 2195 | 2195 | ||
| 2196 | try jw.objectField("int"); | 2196 | try jw.objectField("int"); |
| 2197 | try jw.emitNumber(@as(i32, 1234)); | 2197 | try jw.emitNumber(1234); |
| 2198 | 2198 | ||
| 2199 | try jw.objectField("array"); | 2199 | try jw.objectField("array"); |
| 2200 | try jw.beginArray(); | 2200 | try jw.beginArray(); |
| ... | @@ -2203,7 +2203,7 @@ test "write json then parse it" { | ... | @@ -2203,7 +2203,7 @@ test "write json then parse it" { |
| 2203 | try jw.emitNull(); | 2203 | try jw.emitNull(); |
| 2204 | 2204 | ||
| 2205 | try jw.arrayElem(); | 2205 | try jw.arrayElem(); |
| 2206 | try jw.emitNumber(@as(f64, 12.34)); | 2206 | try jw.emitNumber(12.34); |
| 2207 | 2207 | ||
| 2208 | try jw.endArray(); | 2208 | try jw.endArray(); |
| 2209 | 2209 |
lib/std/json/write_stream.zig+5-3| ... | @@ -148,7 +148,6 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type { | ... | @@ -148,7 +148,6 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type { |
| 148 | self.popState(); | 148 | self.popState(); |
| 149 | } | 149 | } |
| 150 | 150 | ||
| 151 | // TODO better handling of ComptimeInt and ComptimeFloat | ||
| 152 | pub fn emitNumber( | 151 | pub fn emitNumber( |
| 153 | self: *Self, | 152 | self: *Self, |
| 154 | /// An integer, float, or `std.math.BigInt`. Emitted as a bare number if it fits losslessly | 153 | /// 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 { | ... | @@ -169,8 +168,11 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type { |
| 169 | return; | 168 | return; |
| 170 | } | 169 | } |
| 171 | }, | 170 | }, |
| 172 | .Float => if (@floatCast(f64, value) == value) { | 171 | .ComptimeInt => { |
| 173 | try self.stream.print("{}", .{value}); | 172 | return self.emitNumber(@as(std.math.IntFittingRange(value, value), value)); |
| 173 | }, | ||
| 174 | .Float, .ComptimeFloat => if (@floatCast(f64, value) == value) { | ||
| 175 | try self.stream.print("{}", .{@floatCast(f64, value)}); | ||
| 174 | self.popState(); | 176 | self.popState(); |
| 175 | return; | 177 | return; |
| 176 | }, | 178 | }, |