al_fixadd(3alleg5)
β¨ NAME β¨
al_fixadd β it's the Allegro 5 API function that adds two fixed point numbers together safely π«Ά (like, it's the manual page for al_fixadd, from section 3alleg5, bestie π
)
πΈ SYNOPSIS πΈ
#include <allegro5/allegro.h>
al_fixed al_fixadd(al_fixed x, al_fixed y);
π DESCRIPTION π
okay so here's the tea β β yes, you can just add fixed point numbers with the normal + integer operator, and honestly that's giving effortless β¨. But bestie, that way has zero protection against overflow. None. Nada. She will just let it happen π
So if overflow is a problem for you (and it might be!!), you should use this function instead. Lowkey it's slower than using integer operators β that's the tradeoff, no cap β but the glow-up is that if an overflow occurs, it will set Allegro's errno and clamp the result, rather than just letting it wrap. Clamp > wrap, fr fr π
Example:
al_fixed result;
/* This will put 5035 into `result'. */
result = al_fixadd(al_itofix(5000), al_itofix(35));
/* Sets errno and puts -32768 into `result'. */
result = al_fixadd(al_itofix(-31000), al_itofix(-3000));
assert(!al_get_errno()); /* This will fail. */
not the second one setting errno AND slamming-32768into your result π and thatassert? yeah she's failing. main character energy, but for errors π
π¦ RETURN VALUE π¦
Returns the clamped result of adding x to y β and it sets Allegro's errno to ERANGE if there was an overflow. That's the whole vibe check π
π SEE ALSO π
k that's the page!! this was the Allegro reference manual, al_fixadd(3alleg5) β go forth and add your fixed point numbers responsibly, ily, slay π
β¨π
π¦ where this page comes from
- debian trixie: allegro5-doc 2:5.2.10.1+dfsg-1 Β· Zlib
- ubuntu questing: allegro5-doc 2:5.2.10.1+dfsg-1build1
- ubuntu resolute: allegro5-doc 2:5.2.11.3+dfsg-1 Β· Zlib
- ubuntu stonking: allegro5-doc 2:5.2.11.3+dfsg-1 Β· Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms