Trait float_approx_math::ApproxInvSqrt
source · pub trait ApproxInvSqrt {
// Required methods
fn approx_inv_sqrt<const NEWTON: usize>(self) -> Self;
fn approx_inv_sqrt_unchecked<const NEWTON: usize>(self) -> Self;
}Required Methods§
sourcefn approx_inv_sqrt<const NEWTON: usize>(self) -> Self
fn approx_inv_sqrt<const NEWTON: usize>(self) -> Self
Calculates an approximation of 1/sqrt(x).
The result gets iterated through the Newton-Raphson method with a given amount of iterations.
At 5 or less iterations, it is generally faster than x.sqrt().recip() in release build.
1 iteration was good enough for quake.
Example
#![feature(const_trait_impl)]
use float_approx_math::ApproxInvSqrt;
const X: f32 = 2.0;
let y: f32 = X.approx_inv_sqrt::<4>(); // Three iterations
assert_eq!(y, X.sqrt().recip());fn approx_inv_sqrt_unchecked<const NEWTON: usize>(self) -> Self
Object Safety§
This trait is not object safe.