aboutsummaryrefslogtreecommitdiffstats
path: root/src/gmisc
diff options
context:
space:
mode:
authorinmarket <andrewh@inmarket.com.au>2013-09-24 16:11:29 +1000
committerinmarket <andrewh@inmarket.com.au>2013-09-24 16:11:29 +1000
commitd704c2f6d05ecaffa644213f728ed2d0182eeaee (patch)
tree896cd0067546963fe32e8ec97dfdb9c892038f42 /src/gmisc
parent973e34089e33f06cfd9ed560db968870e22c2b8a (diff)
downloaduGFX-d704c2f6d05ecaffa644213f728ed2d0182eeaee.tar.gz
uGFX-d704c2f6d05ecaffa644213f728ed2d0182eeaee.tar.bz2
uGFX-d704c2f6d05ecaffa644213f728ed2d0182eeaee.zip
New inverse square root accelerated math function
Diffstat (limited to 'src/gmisc')
-rw-r--r--src/gmisc/trig.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/gmisc/trig.c b/src/gmisc/trig.c
index 510ee597..00b6365a 100644
--- a/src/gmisc/trig.c
+++ b/src/gmisc/trig.c
@@ -142,5 +142,23 @@
#endif
+#if GMISC_NEED_INVSQRT
+ // Algorithm based on Quake code
+ float invsqrt(float n) {
+ long i;
+ float x2, y;
+ const float threehalfs = 1.5F;
+
+ x2 = n * 0.5F;
+ y = n;
+ i = * ( long * ) &y; // evil floating point bit level hacking
+ i = 0x5f3759df - ( i >> 1 ); // what the?
+ y = * ( float * ) &i;
+ y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration
+ //y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration for extra precision, this can be removed
+ return y;
+ }
+#endif
+
#endif /* GFX_USE_GMISC */
/** @} */