Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fast Inverse Square Root on x64

Tags:

c++

algorithm

I found on net Fast Inverse Square Root on http://en.wikipedia.org/wiki/Fast_inverse_square_root . Does it work properly on x64 ? Did anyone use and serious test ?

like image 914
Damir Avatar asked Jul 25 '12 07:07

Damir


People also ask

How much faster is fast inverse square root?

The algorithm was approximately four times faster than computing the square root with another method and calculating the reciprocal via floating-point division.

How accurate is fast inverse square root?

A single Newton-Raphson iteration is performed to calculate a more accurate approximation of the inverse square root of the input. The result of the Newton-Raphson iteration is the return value of the function. The result is extremely accurate with a maximum error of 0.175%.

Is fast inverse square root copyrighted?

The algorithm is not copyrighted, but the source code of the function is copyrighted. You could learn how the algorithm works by reading the function, and then write your own function that implements the same algorithm.


1 Answers

Originally Fast Inverse Square Root was written for a 32-bit float, so as long as you operate on IEEE-754 floating point representation, there is no way x64 architecture will affect the result.

Note that for "double" precision floating point (64-bit) you should use another constant:

...the "magic number" for 64 bit IEEE754 size type double ... was shown to be exactly 0x5fe6eb50c7b537a9

like image 190
Lyth Avatar answered Oct 03 '22 02:10

Lyth