Add copysign
and nearest
to runtimes
This commit is contained in:
parent
8d671b99e4
commit
830727d8d4
@ -25,8 +25,19 @@ do
|
|||||||
local mul = {}
|
local mul = {}
|
||||||
local div = {}
|
local div = {}
|
||||||
local neg = {}
|
local neg = {}
|
||||||
|
local copysign = {}
|
||||||
|
local nearest = {}
|
||||||
|
|
||||||
local to_signed = bit.tobit
|
local to_signed = bit.tobit
|
||||||
|
local math_abs = math.abs
|
||||||
|
|
||||||
|
local function round(num)
|
||||||
|
if num >= 0 then
|
||||||
|
return (math_floor(num + 0.5))
|
||||||
|
else
|
||||||
|
return (math_ceil(num - 0.5))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function add.i32(a, b)
|
function add.i32(a, b)
|
||||||
return (to_signed(a + b))
|
return (to_signed(a + b))
|
||||||
@ -65,11 +76,31 @@ do
|
|||||||
return -num
|
return -num
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function copysign.num(lhs, rhs)
|
||||||
|
if rhs >= 0 then
|
||||||
|
return (math_abs(lhs))
|
||||||
|
else
|
||||||
|
return -math_abs(lhs)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function nearest.num(num)
|
||||||
|
local result = round(num)
|
||||||
|
|
||||||
|
if math_abs(num) % 1 == 0.5 and temp_2 % 2 == 1 then
|
||||||
|
result = result - 1
|
||||||
|
end
|
||||||
|
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
module.add = add
|
module.add = add
|
||||||
module.sub = sub
|
module.sub = sub
|
||||||
module.mul = mul
|
module.mul = mul
|
||||||
module.div = div
|
module.div = div
|
||||||
module.neg = neg
|
module.neg = neg
|
||||||
|
module.copysign = copysign
|
||||||
|
module.nearest = nearest
|
||||||
end
|
end
|
||||||
|
|
||||||
do
|
do
|
||||||
|
@ -37,8 +37,12 @@ do
|
|||||||
local mul = {}
|
local mul = {}
|
||||||
local div = {}
|
local div = {}
|
||||||
local neg = {}
|
local neg = {}
|
||||||
|
local copysign = {}
|
||||||
|
local nearest = {}
|
||||||
|
|
||||||
local assert = assert
|
local assert = assert
|
||||||
|
local math_abs = math.abs
|
||||||
|
local math_round = math.round
|
||||||
|
|
||||||
function add.i32(a, b)
|
function add.i32(a, b)
|
||||||
return to_u32(a + b)
|
return to_u32(a + b)
|
||||||
@ -81,11 +85,31 @@ do
|
|||||||
return -num
|
return -num
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function copysign.num(lhs, rhs)
|
||||||
|
if rhs >= 0 then
|
||||||
|
return (math_abs(lhs))
|
||||||
|
else
|
||||||
|
return -math_abs(lhs)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function nearest.num(num)
|
||||||
|
local result = math_round(num)
|
||||||
|
|
||||||
|
if math_abs(num) % 1 == 0.5 and temp_2 % 2 == 1 then
|
||||||
|
result = result - 1
|
||||||
|
end
|
||||||
|
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
module.add = add
|
module.add = add
|
||||||
module.sub = sub
|
module.sub = sub
|
||||||
module.mul = mul
|
module.mul = mul
|
||||||
module.div = div
|
module.div = div
|
||||||
module.neg = neg
|
module.neg = neg
|
||||||
|
module.copysign = copysign
|
||||||
|
module.nearest = nearest
|
||||||
end
|
end
|
||||||
|
|
||||||
do
|
do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user