Created
August 4, 2016 12:58
-
-
Save merryhime/dd860e89c100d443ec31e13b63f2e540 to your computer and use it in GitHub Desktop.
This file contains 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
// Superfast trig, x = [0.0, 1.0] only. | |
// Breaks for negative x. | |
// A circle is from x = 0 (0º) to x = 1 (360º). x = 0.5 is the same as 180º. | |
func sinCos(x float32) (float32, float32) { | |
cos := x - 0.25 - float32(int(x+0.25)) | |
sin := x - float32(int(x+0.5)) | |
cos *= 16.0 * (abs(cos) - 0.5) | |
sin *= 16.0 * (0.5 - abs(sin)) | |
return sin, cos | |
} | |
// Superfast sqrt | |
// Seriously inaccurate. | |
// Works by halving exponent. | |
func sqrt(x float32) float32 { | |
return math.Float32frombits((math.Float32bits(x) + (127 << 23)) >> 1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment