From 04d1840d2d2a7666bf00d609ac943f32ec3387f5 Mon Sep 17 00:00:00 2001 From: Rerumu Date: Tue, 28 Jun 2022 02:03:29 -0400 Subject: [PATCH] Fix nearest `f32` and `f64` again --- codegen/luajit/runtime/runtime.lua | 8 ++++++-- codegen/luau/runtime/runtime.lua | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/codegen/luajit/runtime/runtime.lua b/codegen/luajit/runtime/runtime.lua index 5490847..4d36e44 100644 --- a/codegen/luajit/runtime/runtime.lua +++ b/codegen/luajit/runtime/runtime.lua @@ -138,8 +138,12 @@ do function nearest.f32(num) local result = round(num) - if math_abs(num) % 1 == 0.5 and result % 2 == 1 then - result = result - 1 + if (math_abs(num) + 0.5) % 2 == 1 then + if result >= 0 then + result = result - 1 + else + result = result + 1 + end end return result diff --git a/codegen/luau/runtime/runtime.lua b/codegen/luau/runtime/runtime.lua index 335db0a..fda863d 100644 --- a/codegen/luau/runtime/runtime.lua +++ b/codegen/luau/runtime/runtime.lua @@ -151,7 +151,7 @@ do function nearest.f32(num) local result = math_round(num) - if math_abs(num) % 1 == 0.5 and math_floor(math_abs(num) % 2) == 0 then + if (math_abs(num) + 0.5) % 2 == 1 then result = result - math_sign(result) end