fixadd(3)

๐Ÿ“ฆ version 4.4.3.1, in fedora 43, fedora 44

๐ŸŽ€ 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