Approximate functions.

Tue 30 June 2015
By Bram

For game development, I often use function from the math library, as there are: sinf(), cosf(), atan2f(), acosf(), logf() and such. And these functions tend to be quite expensive in CPU cycles. However, in game development, low precision math functions will often suffice. Which means we can skip computing a precise answer, and use other functions that approximate the output of the expensive functions.

I've found a few resources for code that approximates expensive math functions with much cheaper approximations. There is SIMD Math prims by jhjourdan e.g. that comes with approximations for expf(), logf(), cosf() and sinf(). As a bonus, these simpler functions are also easier to vectorize.

But my favourite approximation is that of atan2f(), because I use it so often to convert direction vectors to angles. Here are Volkan Salma's approximations for the atan2f() function.