Skip to content

Instantly share code, notes, and snippets.

@alco
Forked from james4k/gist:3730918
Created September 16, 2012 07:03
Show Gist options
  • Save alco/3731366 to your computer and use it in GitHub Desktop.
Save alco/3731366 to your computer and use it in GitHub Desktop.
package main
import "fmt"
import "math"
func FastInvSqrt(x float32) float32 {
xhalf := float32(0.5) * x
i := math.Float32bits(x)
i = 0x5f3759df - i>>1
x = math.Float32frombits(i)
x = x * (1.5 - (xhalf * x * x))
return x
}
func main() {
fmt.Printf("inv sqrt: %f\n", FastInvSqrt(4))
}
@bazhenovc
Copy link

Reminds me q3 sources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment