Add min and max for f32
and f64
This commit is contained in:
parent
b8362d9e66
commit
5463b48e63
@ -29,11 +29,16 @@ do
|
|||||||
local div = {}
|
local div = {}
|
||||||
local rem = {}
|
local rem = {}
|
||||||
local neg = {}
|
local neg = {}
|
||||||
|
local min = {}
|
||||||
|
local max = {}
|
||||||
local copysign = {}
|
local copysign = {}
|
||||||
local nearest = {}
|
local nearest = {}
|
||||||
|
|
||||||
local to_signed = bit.tobit
|
local to_signed = bit.tobit
|
||||||
|
|
||||||
local math_abs = math.abs
|
local math_abs = math.abs
|
||||||
|
local math_min = math.min
|
||||||
|
local math_max = math.max
|
||||||
|
|
||||||
local RE_INSTANCE = ffi.new([[union {
|
local RE_INSTANCE = ffi.new([[union {
|
||||||
double f64;
|
double f64;
|
||||||
@ -100,6 +105,26 @@ do
|
|||||||
return -num
|
return -num
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function min.f32(lhs, rhs)
|
||||||
|
if lhs ~= lhs then
|
||||||
|
return lhs
|
||||||
|
elseif rhs ~= rhs then
|
||||||
|
return rhs
|
||||||
|
else
|
||||||
|
return math_min(lhs, rhs)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function max.f32(lhs, rhs)
|
||||||
|
if lhs ~= lhs then
|
||||||
|
return lhs
|
||||||
|
elseif rhs ~= rhs then
|
||||||
|
return rhs
|
||||||
|
else
|
||||||
|
return math_max(lhs, rhs)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function copysign.f32(lhs, rhs)
|
function copysign.f32(lhs, rhs)
|
||||||
RE_INSTANCE.f64 = rhs
|
RE_INSTANCE.f64 = rhs
|
||||||
|
|
||||||
@ -121,6 +146,8 @@ do
|
|||||||
end
|
end
|
||||||
|
|
||||||
neg.f64 = neg.f32
|
neg.f64 = neg.f32
|
||||||
|
min.f64 = min.f32
|
||||||
|
max.f64 = max.f32
|
||||||
copysign.f64 = copysign.f32
|
copysign.f64 = copysign.f32
|
||||||
nearest.f64 = nearest.f32
|
nearest.f64 = nearest.f32
|
||||||
|
|
||||||
@ -129,6 +156,8 @@ do
|
|||||||
module.mul = mul
|
module.mul = mul
|
||||||
module.div = div
|
module.div = div
|
||||||
module.rem = rem
|
module.rem = rem
|
||||||
|
module.min = min
|
||||||
|
module.max = max
|
||||||
module.neg = neg
|
module.neg = neg
|
||||||
module.copysign = copysign
|
module.copysign = copysign
|
||||||
module.nearest = nearest
|
module.nearest = nearest
|
||||||
|
@ -219,7 +219,7 @@ fn write_local_operation(head: &str, tail: &str, w: &mut dyn Write) -> Result<()
|
|||||||
write!(w, "local {head}_{tail} = ")?;
|
write!(w, "local {head}_{tail} = ")?;
|
||||||
|
|
||||||
match (head, tail) {
|
match (head, tail) {
|
||||||
("abs" | "ceil" | "floor" | "sqrt" | "min" | "max", _) => write!(w, "math.{head} "),
|
("abs" | "ceil" | "floor" | "sqrt", _) => write!(w, "math.{head} "),
|
||||||
("rem", "i32") => write!(w, "math.fmod "),
|
("rem", "i32") => write!(w, "math.fmod "),
|
||||||
("band" | "bor" | "bxor" | "bnot", _) => write!(w, "bit.{head} "),
|
("band" | "bor" | "bxor" | "bnot", _) => write!(w, "bit.{head} "),
|
||||||
("shl", _) => write!(w, "bit.lshift "),
|
("shl", _) => write!(w, "bit.lshift "),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user