From bc6ac45059fac211caed370da101e6010f4d9437 Mon Sep 17 00:00:00 2001 From: Rerumu Date: Thu, 16 Jun 2022 00:44:12 -0400 Subject: [PATCH] Fix `copysign` --- codegen-luajit/runtime/runtime.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/codegen-luajit/runtime/runtime.lua b/codegen-luajit/runtime/runtime.lua index 7fe2f18..078bb33 100644 --- a/codegen-luajit/runtime/runtime.lua +++ b/codegen-luajit/runtime/runtime.lua @@ -31,6 +31,11 @@ do local to_signed = bit.tobit local math_abs = math.abs + local RE_INSTANCE = ffi.new([[union { + double f64; + struct { int32_t a32, b32; }; + }]]) + local function round(num) if num >= 0 then return (math_floor(num + 0.5)) @@ -77,7 +82,9 @@ do end function copysign.num(lhs, rhs) - if rhs >= 0 then + RE_INSTANCE.f64 = rhs + + if RE_INSTANCE.b32 >= 0 then return (math_abs(lhs)) else return -math_abs(lhs)