2006-08-07

The Neglected Art of Fixed Point Arithmetic (2006)


Even if floating point is nowadays the typical way to do your math, there is still situations where fixed point math is still relevant. I held a seminar about this topic at the Assembly‘2006 event.

Note that the link below points now to a revised version of the slides. I noticed that in slide 26 I had inadvertently written “b > 0” and “b < 0” when it should read “|b| > 1.0” and “|b| < 1.0”, respectively.

I have also been asked why there’s rounding when converting fixed point numbers from real numbers, but not when converting to integer numbers. Conversion to and from integers is typically best left at simple shift operation, as then the operation is lossless so you can freely convert them back and forth. Convert from a real number typically loses accuracy, so in typical case you probably want to minimize the error. The need to round also varies case by case, so you should think if you want to do it or not.

Note also that the included square root code is actually the version from the Graphics Gems V, not the one from the mentioned Apple Technical Report (there’s minor difference). If you didn’t notice, the quoted form of code copes with 2.30 fixed point numbers, so you probably need to adjust the FRACBITS value to match with your code.

Revised PDF slides

Update 2019-08:
Please fill out this form if you’re potentially interested in a new resource about fixed-point math:

SeminarsRSS feed for responses (closed) — Trackbacks disabled.