Fix signed i32 remainder

This commit is contained in:
Rerumu 2022-06-26 01:51:52 -04:00
parent 62f41eac17
commit 5d4aa97cd5
2 changed files with 13 additions and 1 deletions

View File

@ -43,6 +43,7 @@ do
local sub = {} local sub = {}
local mul = {} local mul = {}
local div = {} local div = {}
local rem = {}
local neg = {} local neg = {}
local min = {} local min = {}
local max = {} local max = {}
@ -52,6 +53,7 @@ do
local assert = assert local assert = assert
local math_abs = math.abs local math_abs = math.abs
local math_fmod = math.fmod
local math_floor = math.floor local math_floor = math.floor
local math_round = math.round local math_round = math.round
local math_sign = math.sign local math_sign = math.sign
@ -110,6 +112,15 @@ do
div.u64 = I64.divide_unsigned div.u64 = I64.divide_unsigned
function rem.i32(lhs, rhs)
assert(rhs ~= 0, "division by zero")
lhs = to_i32(lhs)
rhs = to_i32(rhs)
return to_u32(math_fmod(lhs, rhs))
end
function neg.f32(num) function neg.f32(num)
return -num return -num
end end
@ -161,6 +172,7 @@ do
module.sub = sub module.sub = sub
module.mul = mul module.mul = mul
module.div = div module.div = div
module.rem = rem
module.neg = neg module.neg = neg
module.min = min module.min = min
module.max = max module.max = max

View File

@ -11,7 +11,7 @@ impl AsSymbol for BinOpType {
Self::Sub_F32 | Self::Sub_F64 => "-", Self::Sub_F32 | Self::Sub_F64 => "-",
Self::Mul_F32 | Self::Mul_F64 => "*", Self::Mul_F32 | Self::Mul_F64 => "*",
Self::Div_F32 | Self::Div_F64 => "/", Self::Div_F32 | Self::Div_F64 => "/",
Self::RemS_I32 | Self::RemU_I32 => "%", Self::RemU_I32 => "%",
_ => return None, _ => return None,
}; };