itofix(3)
π itofix(3) β the Allegro manual, but make it make sense π
okay bestie, so this is a page from the Allegro manual, the game programming library, and it's about one tiny little function that does so much heavy lifting. itofix β int to fixed. say it with me. int. to. fixed. β¨
β¨ SYNOPSIS β¨
#include <allegro.h>
fixed itofix(int x);
like. that's it. that's the whole signature. one int goes in, one fixed comes out. we love a low-effort king π
π¦ DESCRIPTION π¦
okay so what it does: it converts an integer to fixed point. literally. that's the job.
and if you're sitting there like "bestie what does that even mean" β it's the same thing as x<<16. that's the whole trick. shift left sixteen bits and boom, you're in fixed-point land. no cap. π
β οΈ THE PART YOU NEED TO HEAR, FR FR: overflows and underflows are not detected. not even in debug builds. like, the debug build is not gonna save you here. it's not gonna warn you. it's not gonna hold your hand. the values simply "wrap around". trying to convert an integer greater than32767? overflow. trying to convert an integer lesser than-32768? underflow. both of them just wrap. silently. iconic behaviour honestly but also terrifying π
here's the example, and pls look at it because it is literally demonstrating the crime:
fixed number;
/* This conversion is OK. */
number = itofix(100);
ASSERT(fixtoi(number) == 100);
number = itofix(64000);
/* This check will fail in debug builds. */
ASSERT(fixtoi(number) == 64000);
see how itofix(100) is fine and ASSERT(fixtoi(number) == 100) passes? cute. and then itofix(64000) happens and the assert below it will fail in debug builds. the conversion is "OK" in the sense that it compiles and runs, but 64000 is bigger than 32767, so. yeah. wrap city. π
π RETURN VALUE π
it returns the value of the integer converted to fixed point, ignoring overflows. ignoring them!! like they didn't even happen!! the overflow is not being handled, it's being ignored, which is a whole mood but also a whole footgun. π«Ά
πΈ SEE ALSO πΈ
go read these next, bestie, they're the whole friend group:
fixtoi(3)ftofix(3)fixtof(3)ex12bit(3)ex3buf(3)ex3d(3)exblend(3)excustom(3)exfixed(3)exlights(3)exspline(3)exsprite(3)exstars(3)
and that's the page!! sending u off with all the love in the world from Allegro version 4.4.3 πβ¨ stay safe out there and maybe don't pass 64000 to itofix unless u want chaos. mwah. ππ¦π
π¦ where this page comes from
- fedora 43: allegro-devel 4.4.3.1-18.fc43 Β· Giftware
- fedora 43: allegro-devel 4.4.3.1-18.fc43 Β· Giftware
- fedora 44: allegro-devel 4.4.3.1-20.fc44 Β· Giftware
- fedora 44: allegro-devel 4.4.3.1-20.fc44 Β· Giftware
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms