Fix copysign

This commit is contained in:
Rerumu 2022-06-16 00:44:12 -04:00
parent e6f1f7469f
commit bc6ac45059

View File

@ -31,6 +31,11 @@ do
local to_signed = bit.tobit local to_signed = bit.tobit
local math_abs = math.abs local math_abs = math.abs
local RE_INSTANCE = ffi.new([[union {
double f64;
struct { int32_t a32, b32; };
}]])
local function round(num) local function round(num)
if num >= 0 then if num >= 0 then
return (math_floor(num + 0.5)) return (math_floor(num + 0.5))
@ -77,7 +82,9 @@ do
end end
function copysign.num(lhs, rhs) function copysign.num(lhs, rhs)
if rhs >= 0 then RE_INSTANCE.f64 = rhs
if RE_INSTANCE.b32 >= 0 then
return (math_abs(lhs)) return (math_abs(lhs))
else else
return -math_abs(lhs) return -math_abs(lhs)