| ... | @@ -35,7 +35,7 @@ pub const StringifyOptions = struct { | ... | @@ -35,7 +35,7 @@ pub const StringifyOptions = struct { |
| 35 | escape_unicode: bool = false, | 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 | emit_big_numbers_quoted: bool = false, | 38 | emit_nonportable_numbers_as_strings: bool = false, |
| 39 | }; | 39 | }; |
| 40 | | 40 | |
| 41 | /// Writes the given value to the `std.io.Writer` stream. | 41 | /// Writes the given value to the `std.io.Writer` stream. |
| ... | @@ -164,7 +164,7 @@ pub fn writeStreamArbitraryDepth( | ... | @@ -164,7 +164,7 @@ pub fn writeStreamArbitraryDepth( |
| 164 | /// * Zig `bool` -> JSON `true` or `false`. | 164 | /// * Zig `bool` -> JSON `true` or `false`. |
| 165 | /// * Zig `?T` -> `null` or the rendering of `T`. | 165 | /// * Zig `?T` -> `null` or the rendering of `T`. |
| 166 | /// * Zig `i32`, `u64`, etc. -> JSON number or string. | 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 | /// * When option `emit_nonportable_numbers_as_strings` is true, 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 | /// * Zig floats -> JSON number or string. | 168 | /// * Zig floats -> JSON number or string. |
| 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. | 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 | /// * TODO: Float rendering will likely change in the future, e.g. to remove the unnecessary "e+00". | 170 | /// * TODO: Float rendering will likely change in the future, e.g. to remove the unnecessary "e+00". |
| ... | @@ -404,12 +404,12 @@ pub fn WriteStream( | ... | @@ -404,12 +404,12 @@ pub fn WriteStream( |
| 404 | switch (@typeInfo(T)) { | 404 | switch (@typeInfo(T)) { |
| 405 | .Int => { | 405 | .Int => { |
| 406 | try self.valueStart(); | 406 | try self.valueStart(); |
| 407 | if (!self.options.emit_big_numbers_quoted or | 407 | if (self.options.emit_nonportable_numbers_as_strings and |
| 408 | (value > -(1 << 53) and value < (1 << 53))) | 408 | (value <= -(1 << 53) or value >= (1 << 53))) |
| 409 | { | 409 | { |
| 410 | try self.stream.print("{}", .{value}); | | |
| 411 | } else { | | |
| 412 | try self.stream.print("\"{}\"", .{value}); | 410 | try self.stream.print("\"{}\"", .{value}); |
| | 411 | } else { |
| | 412 | try self.stream.print("{}", .{value}); |
| 413 | } | 413 | } |
| 414 | self.valueDone(); | 414 | self.valueDone(); |
| 415 | return; | 415 | return; |