| ... | ... | @@ -34,7 +34,7 @@ pub const StringifyOptions = struct { |
| 34 | 34 | /// Should unicode characters be escaped in strings? |
| 35 | 35 | escape_unicode: bool = false, |
| 36 | 36 | |
| 37 | | /// When true, renders numbers outside the range `±1<<53` (the precise integer range of f64) as JSON strings in base 10. |
| 37 | /// When true, renders numbers outside the range `+-1<<53` (the precise integer range of f64) as JSON strings in base 10. |
| 38 | 38 | emit_big_numbers_quoted: bool = false, |
| 39 | 39 | }; |
| 40 | 40 | |
| ... | ... | @@ -164,7 +164,7 @@ pub fn writeStreamArbitraryDepth( |
| 164 | 164 | /// * Zig `bool` -> JSON `true` or `false`. |
| 165 | 165 | /// * Zig `?T` -> `null` or the rendering of `T`. |
| 166 | 166 | /// * Zig `i32`, `u64`, etc. -> JSON number or string. |
| 167 | | /// * If the value is outside the range `±1<<53` (the precise integer range of f64), it is rendered as a JSON string in base 10. Otherwise, it is rendered as JSON number. |
| 167 | /// * If the value is outside the range `+-1<<53` (the precise integer range of f64), it is rendered as a JSON string in base 10. Otherwise, it is rendered as JSON number. |
| 168 | 168 | /// * Zig floats -> JSON number or string. |
| 169 | 169 | /// * If the value cannot be precisely represented by an f64, it is rendered as a JSON string. Otherwise, it is rendered as JSON number. |
| 170 | 170 | /// * TODO: Float rendering will likely change in the future, e.g. to remove the unnecessary "e+00". |
| ... | ... | @@ -402,13 +402,11 @@ pub fn WriteStream( |
| 402 | 402 | pub fn write(self: *Self, value: anytype) Error!void { |
| 403 | 403 | const T = @TypeOf(value); |
| 404 | 404 | switch (@typeInfo(T)) { |
| 405 | | .Int => |info| { |
| 406 | | const emit_unquoted = |
| 407 | | if (!self.options.emit_big_numbers_quoted) true |
| 408 | | else if (info.bits < 53) true |
| 409 | | else (value < 4503599627370496 and (info.signedness == .unsigned or value > -4503599627370496)); |
| 405 | .Int => { |
| 410 | 406 | try self.valueStart(); |
| 411 | | if (emit_unquoted) { |
| 407 | if (!self.options.emit_big_numbers_quoted or |
| 408 | (value > -(1 << 53) and value < (1 << 53))) |
| 409 | { |
| 412 | 410 | try self.stream.print("{}", .{value}); |
| 413 | 411 | } else { |
| 414 | 412 | try self.stream.print("\"{}\"", .{value}); |