al_fixdiv(3alleg5)

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

al_fixdiv(3alleg5) πŸ’–

okay bestie, welcome to the al_fixdiv page from the Allegro 5 API ✨ this is the diva that handles your fixed point division, and she is very particular about how you talk to her πŸ’…


✨ SYNOPSIS ✨

#include <allegro5/allegro.h>

al_fixed al_fixdiv(al_fixed x, al_fixed y);

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea, bestie πŸ«– a fixed point value can be divided by an integer with the normal / operator, easy peasy, no drama, she ate πŸ’…

but the moment you wanna divide two fixed point values? nope, the / operator is not the move, you must use this function. it's giving "only I can do this" main character energy, and honestly? iconic πŸ‘‘

now the serious part, and I need you locked in fr fr 😭 β€” if a division by zero occurs, Allegro's errno gets set and the maximum possible value gets returned. BUT (and this is the sneaky bit) errno is not cleared if the operation is successful. so if you're gonna test for division by zero, you should call al_set_errno(0) before calling al_fixdiv(3alleg5). that's the vibe check you cannot skip, no cap πŸ™ˆ

lowkey crucial: errno staying dirty from a previous call is exactly how you end up debugging at 3am. set it to 0 first, bestie, please 😭

Example β€” here's the receipts 🧾:

al_fixed result;

/* This will put 0.06060 `result'. */
result = al_fixdiv(al_itofix(2), al_itofix(33));

/* This will put 0 into `result'. */
result = al_fixdiv(0, al_itofix(-30));

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

🌸 RETURN VALUE 🌸

returns the result of dividing x by y ✨ and if y is zero? she returns the maximum possible fixed point value and sets Allegro's errno to ERANGE πŸ’€ that's it, that's the whole personality.


πŸŽ€ SEE ALSO πŸŽ€


and that's the page, bestie πŸ’œ this was al_fixdiv(3alleg5) from the Allegro reference manual β€” mwah, go divide responsibly, ily, bye 🫢✨

πŸ“¦ where this page comes from