Use liblumen_otp erlang:div/2 for __lumen_builtin_math.div
Adds badarith handling missing from other implementation.
@@ -21,6 +21,8 @@ extern "C" {
fn erlang_bsr_2(integer: Term, shift: Term) -> Term;
#[link_name = "erlang:bxor/2"]
fn erlang_bxor_2(left: Term, right: Term) -> Term;
+ #[link_name = "erlang:div/2"]
+ fn erlang_div_2(dividend: Term, divisor: Term) -> Term;
}
#[export_name = "__lumen_builtin_bigint_from_cstr"]
@@ -224,7 +226,11 @@ math_builtin!("__lumen_builtin_math.sub", builtin_math_sub, Sub, sub);
math_builtin!("__lumen_builtin_math.mul", builtin_math_mul, Mul, mul);
math_builtin!("__lumen_builtin_math.fdiv", builtin_math_fdiv, Div, div);
-integer_math_builtin!("__lumen_builtin_math.div", builtin_math_div, div);
+#[export_name = "__lumen_builtin_math.div"]
+pub extern "C" fn builtin_math_div(dividend: Term, divisor: Term) -> Term {
+ unsafe { erlang_div_2(dividend, divisor) }
+}
+
integer_math_builtin!("__lumen_builtin_math.rem", builtin_math_rem, rem);
#[export_name = "__lumen_builtin_math.bsl"]
