diff options
author | 2023-05-08 23:07:14 -0700 | |
---|---|---|
committer | 2023-05-08 23:07:14 -0700 | |
commit | e74207650bb70ab1bdc0670296b2a79808bd0179 (patch) | |
tree | eadcfb50dd1cbcb0daa2d14e7c1b15302f954ef7 | |
parent | aa85d7af92fc4f1e48bc38f9db8124243c99fd3d (diff) | |
download | bun-e74207650bb70ab1bdc0670296b2a79808bd0179.tar.gz bun-e74207650bb70ab1bdc0670296b2a79808bd0179.tar.zst bun-e74207650bb70ab1bdc0670296b2a79808bd0179.zip |
Fix bug with float minification
-rw-r--r-- | src/js_ast.zig | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/src/js_ast.zig b/src/js_ast.zig index bf02ab7fe..cf432e9f2 100644 --- a/src/js_ast.zig +++ b/src/js_ast.zig @@ -1710,8 +1710,8 @@ pub const E = struct { } pub fn toStringFromF64Safe(value: f64, allocator: std.mem.Allocator) ?string { - const int_value = @floatToInt(i64, value); - if (value == @intToFloat(f64, int_value)) { + if (value == @trunc(value) and (value < std.math.maxInt(i32) and value > std.math.minInt(i32))) { + const int_value = @floatToInt(i64, value); const abs = @intCast(u64, std.math.absInt(int_value) catch return null); if (abs < double_digit.len) { return if (int_value < 0) @@ -1720,9 +1720,7 @@ pub const E = struct { double_digit[abs]; } - if (abs <= std.math.maxInt(i32)) { - return std.fmt.allocPrint(allocator, "{d}", .{@intCast(i32, int_value)}) catch return null; - } + return std.fmt.allocPrint(allocator, "{d}", .{@intCast(i32, int_value)}) catch return null; } if (std.math.isNan(value)) { |