Why does pow(n,2) return 24 when n=5, with my compiler and OS?

Here is what may be happening here. You should be able to confirm this by looking at your compiler’s implementation of the pow function: Assuming you have the correct #include’s, (all the previous answers and comments about this are correct — don’t take the #include files for granted), the prototype for the standard pow function … Read more

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 … Read more

Why do you have to link the math library in C?

The functions in stdlib.h and stdio.h have implementations in libc.so (or libc.a for static linking), which is linked into your executable by default (as if -lc were specified). GCC can be instructed to avoid this automatic link with the -nostdlib or -nodefaultlibs options. The math functions in math.h have implementations in libm.so (or libm.a for … Read more

Why do you have to link the math library in C?

The functions in stdlib.h and stdio.h have implementations in libc.so (or libc.a for static linking), which is linked into your executable by default (as if -lc were specified). GCC can be instructed to avoid this automatic link with the -nostdlib or -nodefaultlibs options. The math functions in math.h have implementations in libm.so (or libm.a for … Read more