mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 07:14:46 +00:00
Float.div implemented, Int.div WIP-ish
This commit is contained in:
parent
17e9f0b8c3
commit
a5c2844f54
4 changed files with 69 additions and 7 deletions
|
@ -574,6 +574,20 @@ fn call_by_name<'a, B: Backend>(
|
|||
|
||||
builder.ins().ineg(num)
|
||||
}
|
||||
Symbol::FLOAT_DIV => {
|
||||
debug_assert!(args.len() == 2);
|
||||
let a = build_arg(&args[0], env, scope, module, builder, procs);
|
||||
let b = build_arg(&args[1], env, scope, module, builder, procs);
|
||||
|
||||
builder.ins().fdiv(a, b)
|
||||
}
|
||||
// Symbol::INT_DIV => {
|
||||
// debug_assert!(args.len() == 2);
|
||||
// let a = build_arg(&args[0], env, scope, module, builder, procs);
|
||||
// let b = build_arg(&args[1], env, scope, module, builder, procs);
|
||||
//
|
||||
// builder.ins().sdiv(a, b)
|
||||
// }
|
||||
Symbol::LIST_GET_UNSAFE => {
|
||||
debug_assert!(args.len() == 2);
|
||||
|
||||
|
|
|
@ -578,6 +578,28 @@ fn call_with_args<'a, 'ctx, 'env>(
|
|||
|
||||
BasicValueEnum::IntValue(int_val)
|
||||
}
|
||||
Symbol::FLOAT_DIV => {
|
||||
debug_assert!(args.len() == 2);
|
||||
|
||||
let float_val = env.builder.build_float_div(
|
||||
args[0].into_float_value(),
|
||||
args[1].into_float_value(),
|
||||
"DIV_F64",
|
||||
);
|
||||
|
||||
BasicValueEnum::FloatValue(float_val)
|
||||
}
|
||||
// Symbol::INT_DIV => {
|
||||
// debug_assert!(args.len() == 2);
|
||||
//
|
||||
// let int_val = env.builder.build_int_signed_div(
|
||||
// args[0].into_int_value(),
|
||||
// args[1].into_int_value(),
|
||||
// "DIV_I64",
|
||||
// );
|
||||
//
|
||||
// BasicValueEnum::IntValue(int_val)
|
||||
// }
|
||||
Symbol::LIST_GET_UNSAFE => {
|
||||
debug_assert!(args.len() == 2);
|
||||
|
||||
|
|
|
@ -838,6 +838,19 @@ mod test_gen {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gen_div_f64() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
48.0 / 2.0
|
||||
"#
|
||||
),
|
||||
24.0,
|
||||
f64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gen_order_of_arithmetic_ops() {
|
||||
assert_evals_to!(
|
||||
|
@ -853,15 +866,28 @@ mod test_gen {
|
|||
|
||||
#[test]
|
||||
// https://math.berkeley.edu/~gbergman/misc/numbers/ord_ops.html
|
||||
fn gen_order_of_arithmetic_ops_complex() {
|
||||
// fn gen_order_of_arithmetic_ops_complex() {
|
||||
// assert_evals_to!(
|
||||
// indoc!(
|
||||
// r#"
|
||||
// 48 / 2 * (9 + 3)
|
||||
// "#
|
||||
// ),
|
||||
// 288,
|
||||
// i64
|
||||
// );
|
||||
// }
|
||||
|
||||
#[test]
|
||||
fn gen_order_of_arithmetic_ops_complex_float() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
48 / 2 * (9 + 3)
|
||||
48.0 / 2.0 + 3.0
|
||||
"#
|
||||
),
|
||||
288,
|
||||
i64
|
||||
24.0,
|
||||
f64
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue