From efc5c9354f36e164f614299a770f2ea2b21d11bd Mon Sep 17 00:00:00 2001 From: Rerumu Date: Sat, 25 Jun 2022 22:51:45 -0400 Subject: [PATCH] Fix copysign --- codegen/luau/runtime/runtime.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/codegen/luau/runtime/runtime.lua b/codegen/luau/runtime/runtime.lua index d1dc423..5812e1f 100644 --- a/codegen/luau/runtime/runtime.lua +++ b/codegen/luau/runtime/runtime.lua @@ -43,6 +43,7 @@ do local nearest = {} local assert = assert + local math_abs = math.abs local math_floor = math.floor local math_round = math.round @@ -50,6 +51,9 @@ do local math_max = math.max local math_min = math.min + local string_byte = string.byte + local string_pack = string.pack + function add.i32(a, b) return to_u32(a + b) end @@ -108,8 +112,11 @@ do end function copysign.f32(lhs, rhs) - if rhs >= 0 then - return (math_abs(lhs)) + local packed = string_pack("d", rhs) + local sign = string_byte(packed, 8) + + if sign < 0x80 then + return math_abs(lhs) else return -math_abs(lhs) end