al_fixadd(3alleg5)

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

✨ 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 -32768 into your result πŸ’€ and that assert? 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