also looking at this
fix(interpreter): keep 2^63 as a float in floor, ceil and round
#932
2 files
+22
-3
| @@ -3464,8 +3464,10 @@ pub const Interpreter = struct { | ||
| 3464 | 3464 | if (val == .Float) { |
| 3465 | 3465 | const floored = @floor(val.Float); |
| 3466 | 3466 | // If the result fits in i64, return Int; otherwise Float. |
| 3467 | // maxInt(i64) rounds up to 2^63 as an f64, which does not fit, | |
| 3468 | // so the upper bound is exclusive. | |
| 3467 | 3469 | if (floored >= @as(f64, @floatFromInt(std.math.minInt(i64))) and |
| 3468 | floored <= @as(f64, @floatFromInt(std.math.maxInt(i64)))) | |
| 3470 | floored < @as(f64, @floatFromInt(std.math.maxInt(i64)))) | |
| 3469 | 3471 | { |
| 3470 | 3472 | return Value{ .Int = @intFromFloat(floored) }; |
| 3471 | 3473 | } |
| @@ -3481,7 +3483,7 @@ pub const Interpreter = struct { | ||
| 3481 | 3483 | if (val == .Float) { |
| 3482 | 3484 | const ceiled = @ceil(val.Float); |
| 3483 | 3485 | if (ceiled >= @as(f64, @floatFromInt(std.math.minInt(i64))) and |
| 3484 | ceiled <= @as(f64, @floatFromInt(std.math.maxInt(i64)))) | |
| 3486 | ceiled < @as(f64, @floatFromInt(std.math.maxInt(i64)))) | |
| 3485 | 3487 | { |
| 3486 | 3488 | return Value{ .Int = @intFromFloat(ceiled) }; |
| 3487 | 3489 | } |
| @@ -3497,7 +3499,7 @@ pub const Interpreter = struct { | ||
| 3497 | 3499 | if (val == .Float) { |
| 3498 | 3500 | const rounded = @round(val.Float); |
| 3499 | 3501 | if (rounded >= @as(f64, @floatFromInt(std.math.minInt(i64))) and |
| 3500 | rounded <= @as(f64, @floatFromInt(std.math.maxInt(i64)))) | |
| 3502 | rounded < @as(f64, @floatFromInt(std.math.maxInt(i64)))) | |
| 3501 | 3503 | { |
| 3502 | 3504 | return Value{ .Int = @intFromFloat(rounded) }; |
| 3503 | 3505 | } |