bolt/stdlib/math.bolt

36 lines
463 B
Text
Raw Normal View History

2020-03-03 14:53:54 +01:00
pub struct i32;
pub struct i64;
pub struct isize;
pub struct u32;
pub struct u64;
pub struct usize;
2020-03-03 14:53:54 +01:00
trait Num;
fn (a: N) + (b: N) -> N where N: Num {
N::add(a, b)
}
fn (a: N) - (b: N) -> N where N: Num {
N::sub(a, b)
}
fn (a: N) / (b: N) -> N where N: Num {
N::div(a, b)
}
fn (a: N) * (b: N) -> N where N: Num {
N::mul(a, b)
}
// precedence a + b < a * b;
pub fn fac(n: I) -> I where I: int {
match n {
0 => 1,
i => i * fac(i-1),
2020-03-03 14:53:54 +01:00
}
}