For a long time now people have mentioned fixed point arithmetic here and there, but I’ve always thought it’s a shame that it’s not something more accessible to less experienced users. Worse yet the amount of online explanation of fixed point arithmetic is few and far between, so it’s difficult for even experienced programmers to find a good level of information about it.
Hence for the last 2-3 months I’ve been secretly working (on and off) on a library that will help to make fixed point arithmetic more accessible.
I was originally intending to only announce the library today and to delay the release for a few more days until I could add more tutorials and demos, but I really need a break from working on it, so I’m releasing it now.
It isn’t yet available from the library manager, but I have requested that it be added so it should be available eventually. (It’s issue #6777.)
It has been accepted into the library manager, so including the library is just a matter of:
#include <FixedPoints.h> #include <FixedPointsCommon.h>
Note that the former header sets up the templates and the latter sets up type aliases. i.e. the former includes types like
SFixed<7, 8> etc and the latter includes types like
SQ7x8. Including the latter is recommended for people who aren’t used to using templates.
README.md is a reasonable introduction to the library, but for more information about fixed points I added this:
During the development of this library, a few select users (most of whom I had prior contact with) were informed about this library before its release.
One of these users was @filmote, who liked the idea enough that he ended up using the library in the game he was developing at the time, so it sort of turned into an ‘eat your own dogfood’ situation where @filmote was testing the library by using it in his game. This was a two way deal, @filmote got smooth movement and relatively quick bugfixes whilst I got a free source of actual road testing which helped bring up bugs to be squashed and feature requests.
@filmote’s game is the first game to use the FixedPoints library so I’m giving it a prominent placement here:
I’d be happy to list/link to any other games or programs that make use of this library in the future.
Special thanks to:
@filmote - head tester
@eried - early helper
Special mentions to:
And last but not least,
thanks to @noel_abercrombie, king of the ducks.