Fix copysign
This commit is contained in:
parent
27c05550e4
commit
efc5c9354f
@ -43,6 +43,7 @@ do
|
|||||||
local nearest = {}
|
local nearest = {}
|
||||||
|
|
||||||
local assert = assert
|
local assert = assert
|
||||||
|
|
||||||
local math_abs = math.abs
|
local math_abs = math.abs
|
||||||
local math_floor = math.floor
|
local math_floor = math.floor
|
||||||
local math_round = math.round
|
local math_round = math.round
|
||||||
@ -50,6 +51,9 @@ do
|
|||||||
local math_max = math.max
|
local math_max = math.max
|
||||||
local math_min = math.min
|
local math_min = math.min
|
||||||
|
|
||||||
|
local string_byte = string.byte
|
||||||
|
local string_pack = string.pack
|
||||||
|
|
||||||
function add.i32(a, b)
|
function add.i32(a, b)
|
||||||
return to_u32(a + b)
|
return to_u32(a + b)
|
||||||
end
|
end
|
||||||
@ -108,8 +112,11 @@ do
|
|||||||
end
|
end
|
||||||
|
|
||||||
function copysign.f32(lhs, rhs)
|
function copysign.f32(lhs, rhs)
|
||||||
if rhs >= 0 then
|
local packed = string_pack("d", rhs)
|
||||||
return (math_abs(lhs))
|
local sign = string_byte(packed, 8)
|
||||||
|
|
||||||
|
if sign < 0x80 then
|
||||||
|
return math_abs(lhs)
|
||||||
else
|
else
|
||||||
return -math_abs(lhs)
|
return -math_abs(lhs)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user