Skip to content

Instantly share code, notes, and snippets.

@hcarver
Created May 3, 2018 13:30
Show Gist options
  • Save hcarver/634b18e4fc66fdb1360f50c271323349 to your computer and use it in GitHub Desktop.
Save hcarver/634b18e4fc66fdb1360f50c271323349 to your computer and use it in GitHub Desktop.
from ctypes import c_float, c_int32, cast, byref, POINTER
def a(number):
threehalfs = 1.5
x2 = number * 0.5
y = c_float(number)
i = cast(byref(y), POINTER(c_int32)).contents.value
i = c_int32(0x5f3759df - (i >> 1))
y = cast(byref(i), POINTER(c_float)).contents.value
y = y * (1.5 - (x2 * y * y))
return y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment