Created
September 25, 2021 15:35
-
-
Save ChronoMonochrome/24be54d195315806b790abbfe479f401 to your computer and use it in GitHub Desktop.
Fast Inverse Square Root (Quake III) on Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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