| ... | ... | @@ -1555,6 +1555,7 @@ fn parseInternal(comptime T: type, token: Token, tokens: *TokenStream, options: |
| 1555 | 1555 | return try std.fmt.parseInt(T, numberToken.slice(tokens.slice, tokens.i - 1), 10); |
| 1556 | 1556 | const float = try std.fmt.parseFloat(f128, numberToken.slice(tokens.slice, tokens.i - 1)); |
| 1557 | 1557 | if (std.math.round(float) != float) return error.InvalidNumber; |
| 1558 | if (float > std.math.maxInt(T) or float < std.math.minInt(T)) return error.Overflow; |
| 1558 | 1559 | return @floatToInt(T, float); |
| 1559 | 1560 | }, |
| 1560 | 1561 | .Optional => |optionalInfo| { |
| ... | ... | @@ -2617,6 +2618,7 @@ test "parse exponential into int" { |
| 2617 | 2618 | const r = try parse(T, &TokenStream.init("{ \"int\": 4.2e2 }"), ParseOptions{}); |
| 2618 | 2619 | try testing.expectEqual(@as(i64, 420), r.int); |
| 2619 | 2620 | try testing.expectError(error.InvalidNumber, parse(T, &TokenStream.init("{ \"int\": 0.042e2 }"), ParseOptions{})); |
| 2621 | try testing.expectError(error.Overflow, parse(T, &TokenStream.init("{ \"int\": 18446744073709551616.0 }"), ParseOptions{})); |
| 2620 | 2622 | } |
| 2621 | 2623 | |
| 2622 | 2624 | test "escaped characters" { |