Does calculating Sqrt(x) as x * InvSqrt(x) make any sense in the Doom 3 BFG code?

I can see two reasons for doing it this way: firstly, the “fast invSqrt” method (really Newton Raphson) is now the method used in a lot of hardware, so this approach leaves open the possibility of taking advantage of such hardware (and doing potentially four or more such operations at once). This article discusses it a little bit:

How slow (how many cycles) is calculating a square root?

The second reason is for compatibility. If you change the code path for calculating square roots, you may get different results (especially for zeroes, NaNs, etc.), and lose compatibility with code that depended on the old system.

Leave a Comment