Made (in)famous by the original implementation in the Quake 3 Arena source code, where fast inverse square roots are vital for perfoming vector operations for game physics, the Fast Inverse Square Root is an extremely clever bit/memory hack, that avoids using slow division instructions, and replaces everything with rapid bit-shifts to calculate an approximation to, f(x) = \frac{1}/{\sqrt{x}}.
- gcc
- conda/miniconda
conda install -c skailasa pyinvsqrt
import numpy as np
from pyinvsqrt import invsqrt
# Only 32 Bit compatible
x = np.float32(10)
# Compute inverse square root
y = invsqrt(x)
Compared with a pure Numpy (BLAS backend) inverse square root, pyinvqrt is almost 400% faster, and almost 25% compared to a Numba-fied implementation.