| ... | @@ -567,8 +567,8 @@ pub fn innerParseFromValue( | ... | @@ -567,8 +567,8 @@ pub fn innerParseFromValue( |
| 567 | switch (source) { | 567 | switch (source) { |
| 568 | .float => |f| { | 568 | .float => |f| { |
| 569 | if (@round(f) != f) return error.InvalidNumber; | 569 | if (@round(f) != f) return error.InvalidNumber; |
| 570 | if (f > std.math.maxInt(T)) return error.Overflow; | 570 | if (f > @as(@TypeOf(f), @floatFromInt(std.math.maxInt(T)))) return error.Overflow; |
| 571 | if (f < std.math.minInt(T)) return error.Overflow; | 571 | if (f < @as(@TypeOf(f), @floatFromInt(std.math.minInt(T)))) return error.Overflow; |
| 572 | return @as(T, @intFromFloat(f)); | 572 | return @as(T, @intFromFloat(f)); |
| 573 | }, | 573 | }, |
| 574 | .integer => |i| { | 574 | .integer => |i| { |
| ... | @@ -770,7 +770,7 @@ fn sliceToInt(comptime T: type, slice: []const u8) !T { | ... | @@ -770,7 +770,7 @@ fn sliceToInt(comptime T: type, slice: []const u8) !T { |
| 770 | // Try to coerce a float to an integer. | 770 | // Try to coerce a float to an integer. |
| 771 | const float = try std.fmt.parseFloat(f128, slice); | 771 | const float = try std.fmt.parseFloat(f128, slice); |
| 772 | if (@round(float) != float) return error.InvalidNumber; | 772 | if (@round(float) != float) return error.InvalidNumber; |
| 773 | if (float > std.math.maxInt(T) or float < std.math.minInt(T)) return error.Overflow; | 773 | if (float > @as(f128, @floatFromInt(std.math.maxInt(T))) or float < @as(f128, @floatFromInt(std.math.minInt(T)))) return error.Overflow; |
| 774 | return @as(T, @intCast(@as(i128, @intFromFloat(float)))); | 774 | return @as(T, @intCast(@as(i128, @intFromFloat(float)))); |
| 775 | } | 775 | } |
| 776 | | 776 | |