The unified diff between revisions [4cc7246c..] and [dc88787e..] is displayed below. It can also be downloaded as a raw diff.
This diff has been restricted to the following files: 'fisqrt.c'
# # old_revision [4cc7246c1b6c809c9dc15997798f6deed15b3631] # new_revision [dc88787ecd1d574feba045763baed2a7651ff33d] # # add_file "fisqrt.c" # content [4fb1fdd34c6fc3f9e172991f3149c9c4057eb68e] # ============================================================ --- /dev/null +++ fisqrt.c 4fb1fdd34c6fc3f9e172991f3149c9c4057eb68e @@ -0,0 +1,26 @@ +/* Implementation of fast inverse square root. + * See http://en.wikipedia.org/wiki/Fast_inverse_square_root + */ + +float fisqrt(float n) +{ + long i; + float x2, y; + union { + float f; + long l; + } u; + + x2 = n * 0.5f; + y = n; +/* i = *(long *)&y; */ + u.f = y; + i = u.l; + i = 0x5f3759df - (i>>1); +/* y = *(float *)&i; */ + u.l = i; + y = u.f; + y = y * (1.5f - (x2*y*y)); + + return y; +}