Skip to content

Instantly share code, notes, and snippets.

@ChronoMonochrome
Created September 25, 2021 15:35
Show Gist options
  • Save ChronoMonochrome/24be54d195315806b790abbfe479f401 to your computer and use it in GitHub Desktop.
Save ChronoMonochrome/24be54d195315806b790abbfe479f401 to your computer and use it in GitHub Desktop.
Fast Inverse Square Root (Quake III) on Python
import struct
def q_rsqrt(number):
i = 0
x2 = 0.
y = 0.
threehalfs = 1.5
x2 = number * 0.5
y = number
i = struct.unpack("I", struct.pack("f", y))[0]
i = 0x5f3759df - (i >> 1)
y = struct.unpack("f", struct.pack("I", i))[0]
y = y * (threehalfs - (x2 * y * y))
return y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment