Added some additional fast math functions.

This commit is contained in:
Nathan Vegdahl 2017-07-22 13:34:16 -07:00
parent 1bb02f6604
commit 3cb684514a

View File

@ -142,10 +142,24 @@ pub fn fast_pow2(p: f32) -> f32 {
unsafe { transmute_copy::<u32, f32>(&i) }
}
pub fn fast_log2(x: f32) -> f32 {
use std::mem::transmute_copy;
let xi = unsafe { transmute_copy::<f32, u32>(&x) };
let y = xi as f32 * 1.1920928955078125e-7;
let mx = unsafe { transmute_copy::<u32, f32>(&((xi & 0x007FFFFF) | 0x3f000000)) };
return y - 124.22551499 - 1.498030302 * mx - 1.72587999 / (0.3520887068 + mx);
}
pub fn fast_exp(p: f32) -> f32 {
fast_pow2(1.442695040 * p)
}
pub fn fast_pow(x: f32, p: f32) -> f32 {
fast_pow2(p * fast_log2(x))
}
pub fn faster_pow2(p: f32) -> f32 {
use std::mem::transmute_copy;
@ -159,6 +173,7 @@ pub fn faster_exp(p: f32) -> f32 {
faster_pow2(1.442695040 * p)
}
// End of adapted code
//----------------------------------------------------------------