fixdiv(3)

πŸ“¦ version 4.4.3.1, in fedora 43, fedora 44

πŸ’– fixdiv(3) β€” the Allegro manual, but make it make sense πŸ’–

ok so bestie, welcome to the Allegro manual page for fixdiv. yes that Allegro. the game programming library. we're doing fixed point math today and honestly? it's giving ✨precision✨


🌸 SYNOPSIS 🌸

#include <allegro.h>

fixed fixdiv(fixed x, fixed y);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so here's the tea. πŸ«–

A fixed point value can be divided by an integer using the normal / operator. easy. no drama.

But dividing two fixed point values?? nope, that's not a vibe. for that you must use this function. fixdiv is the main character here. πŸ‘‘

πŸ’€ the scary part: if a division by zero happens, 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 tryna test for division by zero, you gotta set errno=0 before calling fixdiv(). no cap.

Example, because seeing it is believing:

fixed result;
/* This will put 0.06060 `result'. */
result = fixdiv(itofix(2), itofix(33));
/* This will put 0 into `result'. */
result = fixdiv(0, itofix(-30));
/* Sets `errno' and puts -32768 into `result'. */
result = fixdiv(itofix(-100), itofix(0));
ASSERT(!errno); /* This will fail. */

✨ RETURN VALUE ✨

Returns the result of dividing x by y. simple. slay. πŸ’…

But if y is zero? it returns the maximum possible fixed point value and sets errno to ERANGE. so like, it doesn't crash on you, it just hands you the biggest number it has and a little note about it. iconic behaviour honestly πŸŽ€


πŸŽ€ SEE ALSO πŸŽ€

the whole fixed-point friend group fr fr 🫢


and that's the page!! this was the Allegro manual, version 4.4.3 β€” shoutout to the Allegro girlies who wrote it, mwah, go divide something responsibly bestie, and remember: set errno=0 first or you WILL be confused. πŸ˜­βœ¨πŸ’–

πŸ“¦ where this page comes from