compiler-builtins-zynq/src/float/pow.rs

37 lines
677 B
Rust
Raw Normal View History

2017-06-24 12:31:54 +08:00
use int::Int;
/// Returns `a` raised to the power `b`
2016-10-01 06:15:44 +08:00
macro_rules! pow {
($a: expr, $b: expr) => ({
let (mut a, mut b) = ($a, $b);
let recip = b < 0;
let mut r = 1.0;
loop {
if (b & 1) != 0 {
r *= a;
2016-10-01 06:15:44 +08:00
}
2017-06-24 12:31:54 +08:00
b = b.aborting_div(2);
if b == 0 {
break;
2016-10-01 06:15:44 +08:00
}
a *= a;
2016-10-01 06:15:44 +08:00
}
if recip {
1.0 / r
} else {
r
}
})
2016-10-01 06:15:44 +08:00
}
intrinsics! {
pub extern "C" fn __powisf2(a: f32, b: i32) -> f32 {
pow!(a, b)
}
pub extern "C" fn __powidf2(a: f64, b: i32) -> f64 {
pow!(a, b)
}
}