mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-21 15:59:20 +03:00
Add Num.round to dev backend
This commit is contained in:
parent
b25862a93b
commit
1c6ac84f2f
@ -79,6 +79,7 @@ comptime {
|
||||
exportNumFn(num.powInt, "pow_int");
|
||||
exportNumFn(num.acos, "acos");
|
||||
exportNumFn(num.asin, "asin");
|
||||
exportNumFn(num.round, "round");
|
||||
}
|
||||
|
||||
// Str Module
|
||||
|
@ -21,3 +21,7 @@ pub fn acos(num: f64) callconv(.C) f64 {
|
||||
pub fn asin(num: f64) callconv(.C) f64 {
|
||||
return @call(.{ .modifier = always_inline }, math.asin, .{num});
|
||||
}
|
||||
|
||||
pub fn round(num: f64) callconv(.C) i64 {
|
||||
return @floatToInt(i32, (@round(num)));
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ pub const NUM_ACOS: &str = "roc_builtins.num.acos";
|
||||
pub const NUM_ATAN: &str = "roc_builtins.num.atan";
|
||||
pub const NUM_IS_FINITE: &str = "roc_builtins.num.is_finite";
|
||||
pub const NUM_POW_INT: &str = "roc_builtins.num.pow_int";
|
||||
pub const NUM_ROUND: &str = "roc_builtins.num.round";
|
||||
|
||||
pub const STR_INIT: &str = "roc_builtins.str.init";
|
||||
pub const STR_COUNT_SEGMENTS: &str = "roc_builtins.str.count_segments";
|
||||
|
@ -201,6 +201,9 @@ where
|
||||
Symbol::NUM_SUB => {
|
||||
self.build_run_low_level(sym, &LowLevel::NumSub, arguments, layout)
|
||||
}
|
||||
Symbol::NUM_ROUND => {
|
||||
self.build_run_low_level(sym, &LowLevel::NumRound, arguments, layout)
|
||||
}
|
||||
Symbol::BOOL_EQ => {
|
||||
self.build_run_low_level(sym, &LowLevel::Eq, arguments, layout)
|
||||
}
|
||||
@ -300,7 +303,13 @@ where
|
||||
// Should we panic?
|
||||
x => Err(format!("wrong layout, {:?}, for LowLevel::Eq", x)),
|
||||
},
|
||||
|
||||
LowLevel::NumRound => self.build_fn_call(
|
||||
sym,
|
||||
bitcode::NUM_ROUND.to_string(),
|
||||
args,
|
||||
&[Layout::Builtin(Builtin::Float64)],
|
||||
layout,
|
||||
),
|
||||
x => Err(format!("low level, {:?}. is not yet implemented", x)),
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -73,19 +73,22 @@ pub fn helper<'a>(
|
||||
procedures.insert(key, proc);
|
||||
}
|
||||
|
||||
/*
|
||||
println!("=========== Procedures ==========");
|
||||
println!("{:?}", procedures);
|
||||
println!("=================================\n");
|
||||
// You can comment and uncomment this block out to get more useful information
|
||||
// while you're working on the dev backend!
|
||||
{
|
||||
println!("=========== Procedures ==========");
|
||||
println!("{:?}", procedures);
|
||||
println!("=================================\n");
|
||||
|
||||
println!("=========== Interns ==========");
|
||||
println!("{:?}", interns);
|
||||
println!("=================================\n");
|
||||
// println!("=========== Interns ==========");
|
||||
// println!("{:?}", interns);
|
||||
// println!("=================================\n");
|
||||
|
||||
// println!("=========== Exposed ==========");
|
||||
// println!("{:?}", exposed_to_host);
|
||||
// println!("=================================\n");
|
||||
}
|
||||
|
||||
println!("=========== Exposed ==========");
|
||||
println!("{:?}", exposed_to_host);
|
||||
println!("=================================\n");
|
||||
*/
|
||||
debug_assert_eq!(exposed_to_host.len(), 1);
|
||||
let main_fn_symbol = loaded.entry_point.symbol;
|
||||
let main_fn_layout = loaded.entry_point.layout;
|
||||
|
@ -481,8 +481,12 @@ mod gen_num {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn f64_round_old() {
|
||||
fn f64_round() {
|
||||
assert_evals_to!("Num.round 3.6", 4, i64);
|
||||
assert_evals_to!("Num.round 3.4", 3, i64);
|
||||
assert_evals_to!("Num.round 2.5", 3, i64);
|
||||
assert_evals_to!("Num.round -2.3", -2, i64);
|
||||
assert_evals_to!("Num.round -2.5", -3, i64);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user