Skip to content

Instantly share code, notes, and snippets.

@8-bit-pixel
8-bit-pixel / Quake2_InvSqrt.h
Last active August 9, 2025 10:01
A simple implementation of the Quake 2 inverse square root algorithm.
#ifndef QUAKE2_INVSQRT_HPP
#define QUAKE2_INVSQRT_HPP
// Fast inverse square root algorithm
// Credit: Quake III Arena
// (Obsolete now due to native CPU support)
float invsqrt (float num) {
long i = *(long*) &y; // Read the bits of the float as an integer