Fix copysign

This commit is contained in:
Rerumu 2022-06-25 22:51:45 -04:00
parent 27c05550e4
commit efc5c9354f

View File

@ -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