Code highlight without JavaScript

⚓ Dev    📅 2022-10-11    👤 freedit    👁️ 140      

freedit

Wikipedia: Fast_inverse_square_root

Paper: FAST INVERSE SQUARE ROOT

1x
fn main() {
    let test = inv_sqrt(0.015);
    println!("{}", test);
}

/// [Fast_inverse_square_root](https://en.wikipedia.org/wiki/Fast_inverse_square_root)
fn inv_sqrt(flote: f32) -> f32 {
    let i = flote.to_bits() >> 1;
    let y = 0x5f3759df - i;
    let mut y = f32::from_bits(y.to_le());
    y = y * (1.5 - (flote * 0.5 * y * y));
    y = y * (1.5 - (flote * 0.5 * y * y)); // second iter, can be removed
    y
}
🏷️ highlight 🏷️ rust 🏷️ math
👍 󠁮󠁮󠁮󠁮 2 👎 󠁮󠁮󠁮󠁮