fixadd(3)
๐ NAME ๐
okay so bestie, welcome to the Allegro manual โจ this page is all about fixadd โ the safe function to add fixed point numbers that clamps the overflow instead of letting it do something unhinged ๐
and yeah it's part of the Allegro game programming library, no cap ๐ฎ
๐ธ SYNOPSIS ๐ธ
#include <allegro.h>
fixed fixadd(fixed x, fixed y);
like literally that's it, that's the whole vibe ๐ซถ
๐ DESCRIPTION ๐
so here's the tea โ you can totally add fixed point numbers with the normal '+' integer operator, sure, but the way that it gives you zero protection against overflow?? it's giving risky ๐
so if overflow is a problem for you (and bestie, it usually is ๐ญ), you should use this function instead. she's slower than using integer operators, lowkey โ but if an overflow happens, she will set errno and clamp the result, rather than just letting it wrap like some feral little gremlin ๐
example time, look at this:
fixed result;
/* This will put 5035 into `result'. */
result = fixadd(itofix(5000), itofix(35));
/* Sets `errno' and puts -32768 into `result'. */
result = fixadd(itofix(-31000), itofix(-3000));
ASSERT(!errno); /* This will fail. */
see how the second one just calmly clamps and flags errno instead of wrapping around into chaos?? that's the whole point, she's the responsible one ๐
โญ RETURN VALUE โญ
returns the clamped result of adding x to y ๐ and if there was an overflow, she sets errno to ERANGE. that's it, that's the whole dealio โจ
๐ฆ SEE ALSO ๐ฆ
go read those too, they're the rest of the squad fr fr ๐ซถ
and that's a wrap, bestie!! this page is from the Allegro manual, specifically version 4.4.3, and it was last touched fixadd(3)-style ๐ mwah, go clamp something responsibly ๐ โจ
๐ฆ 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