al_fixsub(3)
β¨ 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