diff --git a/compiler/gen/src/crane/build.rs b/compiler/gen/src/crane/build.rs index cb45836e22..a4abd0baf7 100644 --- a/compiler/gen/src/crane/build.rs +++ b/compiler/gen/src/crane/build.rs @@ -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); diff --git a/compiler/gen/src/llvm/build.rs b/compiler/gen/src/llvm/build.rs index 6dbfc17981..0e703d15db 100644 --- a/compiler/gen/src/llvm/build.rs +++ b/compiler/gen/src/llvm/build.rs @@ -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); diff --git a/compiler/gen/tests/test_gen.rs b/compiler/gen/tests/test_gen.rs index a97102854f..044da1892a 100644 --- a/compiler/gen/tests/test_gen.rs +++ b/compiler/gen/tests/test_gen.rs @@ -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 ); } diff --git a/compiler/load/tests/fixtures/build/interface_with_deps/WithBuiltins.roc b/compiler/load/tests/fixtures/build/interface_with_deps/WithBuiltins.roc index fd64d478fa..fb37ddaf1a 100644 --- a/compiler/load/tests/fixtures/build/interface_with_deps/WithBuiltins.roc +++ b/compiler/load/tests/fixtures/build/interface_with_deps/WithBuiltins.roc @@ -5,15 +5,15 @@ interface WithBuiltins floatTest = Float.highest divisionFn = Float.div - + x = 5.0 -divisionTest = Float.highest / x +divisionTest = Float.highest / x intTest = Int.highest constantInt = 5 - + fromDep2 = Dep2.two divDep1ByDep2 = Dep1.three / fromDep2