al_fixsub(3alleg5)

πŸ“¦
version 5.2.11.3 Β· 4 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– al_fixsub β€” Allegro 5 API πŸ’–

okay bestie, welcome to the Allegro 5 reference manual, page al_fixsub(3alleg5), and trust me when I say this one is a whole vibe. it's giving "safe subtraction for fixed point girlies" and honestly? we're obsessed. πŸŽ€


✨ SYNOPSIS ✨

#include <allegro5/allegro.h>

al_fixed al_fixsub(al_fixed x, al_fixed y);

🌸 DESCRIPTION 🌸

so like, yes, you could just subtract fixed point numbers with the normal - integer operator. it's fine. it works. it's lowkey the easy route. BUT β€” and this is the important part, no cap β€” that gives you zero protection against overflow. none. nada. πŸ’€

if overflow is a problem for you, this function is the one you want instead. it is slower than just using integer operators, that's just the truth and we're not gonna pretend otherwise, but here's the trade: if an overflow happens, it sets Allegro's errno and clamps the result, instead of just letting it wrap around and ruin your whole day. main character behaviour tbh. πŸ‘‘

Example, because seeing it is believing:

al_fixed result;

/* This will put 4965 into `result'. */
result = al_fixsub(al_itofix(5000), al_itofix(35));

/* Sets errno and puts -32768 into `result'. */
result = al_fixsub(al_itofix(-31000), al_itofix(3000));
assert(!al_get_errno()); /* This will fail. */

like... the second one sets errno and shoves -32768 into result, and then that assert is literally guaranteed to fail. she's dramatic, she's correct, she ate. πŸ’…


πŸ¦‹ RETURN VALUE πŸ¦‹

returns the clamped result of subtracting y from x, and sets Allegro's errno to ERANGE if there was an overflow. periodt. ⭐

ngl bestie, watch out for that ERANGE β€” if your numbers are spicy enough to overflow, that's your little alarm bell going off. 🚨

🌈 SEE ALSO 🌈


and that's the whole page, babe β€” this was the Allegro reference manual serving you al_fixsub(3alleg5), mwah, go clamp some numbers responsibly πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from