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§

source

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());
source

fn approx_inv_sqrt_unchecked<const NEWTON: usize>(self) -> Self

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl ApproxInvSqrt for f32

source§

fn approx_inv_sqrt<const NEWTON: usize>(self) -> Self

source§

fn approx_inv_sqrt_unchecked<const NEWTON: usize>(self) -> Self

source§

impl ApproxInvSqrt for f64

source§

fn approx_inv_sqrt<const NEWTON: usize>(self) -> Self

source§

fn approx_inv_sqrt_unchecked<const NEWTON: usize>(self) -> Self

Implementors§