Function ludomath::num::inv_sqrt [] [src]

pub fn inv_sqrt(x: f32) -> f32

Quickly, but roughly, approximates 1/sqrt(x).

Uses a technique popularized, but not invented, by John Carmack in Quake 3 Arena, generally known as the fast inverse square root. Has a maximum error of about 0.175%.

Although 1.0/x.sqrt() likely won't be optimized by the compiler, any hardware implementation of 1/sqrt(x) will be both faster and more accurate, and should as such be preferred.

Returns nonsense for negative numbers, NaN and infinities.