Integer Trigonometry: trigint

This’ll be handy if you need to do some trigonometry on older hardware, especially when compiling non-thumb code:

trigint: An Integer-based Trigonometry Library

… Or, you could avoid floating point altogether. Thus, I wrote trigint, a 100% integer-based trigonometry library. It uses a 16-entry lookup table plus linear interpolation so it’s quite memory efficient, yet still accurate enough for most purposes. Since it’s written in ANSI C99, it can be used on 8-bit microcontrollers, like an Atmel AVR with avr-gcc. Here’s the code and the API documentation.

How fast is it? Take a look at the numbers on a 1st generation iPod Touch:

sin16_perf.png

In summary, trigint_sin16() is about 4.4 times faster than sinf() and 6.7 times faster than sin() in Thumb mode. Without Thumb mode, the gap closes a bit to 3.8 times faster and 6.2 times faster, respectively…

Yes, that certainly is a striking difference indeed. Probably not as striking with modern ARMv7 hardware, as you may recall from this ARM architecture discussion … but hey, sometimes every cycle counts!

Alex | August 19, 2010

Leave a Reply