fixdiv(3)
π 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,errnogets set and the maximum possible value gets returned. BUT β and this is the sneaky bit βerrnois not cleared if the operation is successful. so if you're tryna test for division by zero, you gotta seterrno=0before callingfixdiv(). 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
- fedora 43: allegro-devel 4.4.3.1-18.fc43 Β· Giftware
- fedora 43: allegro-devel 4.4.3.1-18.fc43 Β· Giftware
- fedora 44: allegro-devel 4.4.3.1-20.fc44 Β· Giftware
- fedora 44: allegro-devel 4.4.3.1-20.fc44 Β· Giftware
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms