fixsub(3)
β¨ fixsub(3) β¨
okay bestie, gather round, because this is a page from the Allegro manual and it's about a little function called fixsub π it's the safe way to subtract fixed point numbers, and it clamps underflow instead of letting everything go feral. it's giving "responsible subtraction" energy and honestly? we love that for us π«Ά
πΈ NAME πΈ
fixsub β the safe function to subtract fixed point numbers, clamping underflow. part of the Allegro game programming library π
π SYNOPSIS π
#include <allegro.h>
fixed fixsub(fixed x, fixed y);
π DESCRIPTION π
so here's the tea, bestie β fixed point numbers can be subtracted with the normal - integer operator, but the way that gives you zero protection against overflow? not iconic. not even a little bit. π
if overflow is a problem for you β and babes, it usually is β you should use this function instead. periodt.
it's slower than using integer operators, ngl, that's the tradeoff. but if an overflow happens, it will set errno and clamp the result, rather than just letting it wrap and ruining your whole day. no cap. β¨
example:
fixed result;
/* This will put 4965 into `result'. */
result = fixsub(itofix(5000), itofix(35));
/* Sets `errno' and puts -32768 into `result'. */
result = fixsub(itofix(-31000), itofix(3000));
ASSERT(!errno); /* This will fail. */
π not that last line failing on you. it literally tells you it will fail. the audacity. the honesty. i'm obsessed.
π RETURN VALUE π
returns the clamped result of subtracting y from x, and it sets errno to ERANGE if there was an overflow π¦
π SEE ALSO π
and that's the whole page, bestie π shoutout to Allegro, version 4.4.3 β this little fixsub(3) moment came straight from that source, so go be safe with your subtractions and don't let anything wrap on you ππ§ββοΈ
π¦ 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