al_fixsub(3)

πŸ“¦
version 5.2.11.3 Β· 3 versions
, in arch rolling

✨ NAME ✨

okay bestie, this is al_fixsub β€” Allegro 5 API β€” from the Library Functions Manual. She’s the fixed point subtraction function who does not let overflow just vibe into chaos. πŸ’…

🌸 SYNOPSIS 🌸

#include <allegro5/allegro.h>

al_fixed al_fixsub(al_fixed x, al_fixed y);

πŸ¦‹ DESCRIPTION πŸ¦‹

so yes, fixed point numbers can be subtracted with the normal - integer operator β€” iconic β€” but that does not give you any protection against overflow. no cap. If overflow is a problem, you should use this function instead. She’s slower than using integer operators, but if an overflow occurs she will set Allegro’s errno and clamp the result, rather than just letting it wrap. periodt. πŸ’–

Example time, bestie:

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. */

that last assert is literally not joking around β€” the comment says it will fail, and she means it. 😭


πŸ’œ RETURN VALUE πŸ’œ

Returns the clamped result of subtracting y from x, and sets Allegro’s errno to ERANGE if there was an overflow. that’s the whole tea. ✨

πŸŽ€ SEE ALSO πŸŽ€


okay bye bestie 🫢 this has been al_fixsub(3) from the Allegro reference manual β€” go protect your fixed point math, mwah πŸ’–πŸ¦‹

πŸ“¦ where this page comes from
  • arch rolling: allegro 5.2.11.3-2 Β· Zlib AND BSD-3-Clause AND OFL-1.1 AND LicenseRef-Custom
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms