mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
Implement and test Float.#add
This commit is contained in:
parent
523282e7bc
commit
21e4eb505a
4 changed files with 32 additions and 1 deletions
|
@ -552,6 +552,13 @@ fn call_by_name<'a, B: Backend>(
|
|||
|
||||
builder.ins().iadd(a, b)
|
||||
}
|
||||
Symbol::FLOAT_ADD => {
|
||||
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().fadd(a, b)
|
||||
}
|
||||
Symbol::NUM_SUB => {
|
||||
debug_assert!(args.len() == 2);
|
||||
let a = build_arg(&args[0], env, scope, module, builder, procs);
|
||||
|
|
|
@ -547,6 +547,17 @@ fn call_with_args<'a, 'ctx, 'env>(
|
|||
|
||||
BasicValueEnum::IntValue(int_val)
|
||||
}
|
||||
Symbol::FLOAT_ADD => {
|
||||
debug_assert!(args.len() == 2);
|
||||
|
||||
let float_val = env.builder.build_float_add(
|
||||
args[0].into_float_value(),
|
||||
args[1].into_float_value(),
|
||||
"add_f64",
|
||||
);
|
||||
|
||||
BasicValueEnum::FloatValue(float_val)
|
||||
}
|
||||
Symbol::NUM_SUB => {
|
||||
debug_assert!(args.len() == 2);
|
||||
|
||||
|
|
|
@ -800,6 +800,19 @@ mod test_gen {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gen_add_f64() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
1.1 + 2.4 + 3
|
||||
"#
|
||||
),
|
||||
6.5,
|
||||
f64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gen_add_i64() {
|
||||
assert_evals_to!(
|
||||
|
|
|
@ -586,7 +586,7 @@ define_builtins! {
|
|||
5 FLOAT_SQRT: "sqrt"
|
||||
6 FLOAT_HIGHEST: "highest"
|
||||
7 FLOAT_LOWEST: "lowest"
|
||||
8 FLOAT_ADD: "add"
|
||||
8 FLOAT_ADD: "#add"
|
||||
}
|
||||
4 BOOL: "Bool" => {
|
||||
0 BOOL_BOOL: "Bool" imported // the Bool.Bool type alias
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue