Skip to content

Instantly share code, notes, and snippets.

@topokel
Created May 24, 2014 05:29
Show Gist options
  • Select an option

  • Save topokel/070e21799af58d41555e to your computer and use it in GitHub Desktop.

Select an option

Save topokel/070e21799af58d41555e to your computer and use it in GitHub Desktop.
func FastInvSqrt(x float32) float32 {
i := math.Float32frombits(0x5f3759df - math.Float32bits(x)>>1)
return i * (1.5 - (x * 0.5 * i * i))
}
func FastInvSqrt64(x float64) float64 {
i := math.Float64frombits(0x5fe6eb50c7b537a9 - math.Float64bits(x)>>1)
return i * (1.5 - (x * 0.5 * i * i))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment