summaryrefslogtreecommitdiff
path: root/src/utils/fastsqrt.h
diff options
context:
space:
mode:
authorPhilipp Sehmisch <tmw@crushnet.org>2007-05-04 13:09:25 +0000
committerPhilipp Sehmisch <tmw@crushnet.org>2007-05-04 13:09:25 +0000
commit00fb4bde7974a20aacfc1c52e48fff2faee2d385 (patch)
tree2097ef003495d7e6b4a8cf697ad7896039aac113 /src/utils/fastsqrt.h
parentb3376bfe4e26591e1dc1066d8f2270baf4f9f759 (diff)
downloadmana-00fb4bde7974a20aacfc1c52e48fff2faee2d385.tar.gz
mana-00fb4bde7974a20aacfc1c52e48fff2faee2d385.tar.bz2
mana-00fb4bde7974a20aacfc1c52e48fff2faee2d385.tar.xz
mana-00fb4bde7974a20aacfc1c52e48fff2faee2d385.zip
Merged particle engine into main eAthena branch.
Diffstat (limited to 'src/utils/fastsqrt.h')
-rw-r--r--src/utils/fastsqrt.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/utils/fastsqrt.h b/src/utils/fastsqrt.h
new file mode 100644
index 00000000..8ba6f8ce
--- /dev/null
+++ b/src/utils/fastsqrt.h
@@ -0,0 +1,23 @@
+/* A very fast function to calculate the approximate inverse square root of a
+ * floating point value and a helper function that uses it for getting the
+ * normal squareroot. For an explanation of the inverse squareroot function
+ * read:
+ * http://www.math.purdue.edu/~clomont/Math/Papers/2003/InvSqrt.pdf
+ *
+ * Unfortunately the original creator of this function seems to be unknown.
+ */
+
+float fastInvSqrt(float x)
+{
+ float xhalf = 0.5f*x;
+ int i = *(int*)&x;
+ i = 0x5f375a86- (i>>1);
+ x = *(float*)&i;
+ x = x*(1.5f-xhalf*x*x);
+ return x;
+}
+
+float fastSqrt(float x)
+{
+ return 1.0f/fastInvSqrt(x);
+}