fixdiv(3alleg4)
fixdiv π
okay so bestie, welcome to the Allegro manual β this little cutie lives in the Allegro game programming library, and today we're talking about fixed point division. yes. division. for fixed points. it's giving math but make it gamer β¨
β¨ NAME β¨
fixdiv β Fixed point division. Allegro game programming library. π
πΈ SYNOPSIS πΈ
#include <allegro.h>
fixed fixdiv(fixed x, fixed y);
π DESCRIPTION π
okay so here's the tea π« β if you wanna divide a fixed point value by a regular integer, you can just use the normal / operator, no big deal, she's easy like that.
BUT. if you need to divide two fixed point values by each other? bestie you cannot just use /. you gotta call this function. this one. right here. fixdiv(). periodt. π
and now the scary part π β if a division by zero happens, errno gets set and the maximum possible value gets returned. but here's the sneaky lil detail that gets people every time: errno is not cleared if the operation is successful. so if you're planning to test for division by zero, you better set errno=0 before you call fixdiv(), or you're gonna be out here debugging a ghost π» fr fr.
Example time, slay:
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. */
π not the ASSERT failing... yeah bestie that last line will fail, that's the whole point of the example. iykyk.
π RETURN VALUE π
she returns the result of dividing x by y. simple. iconic. π
but if y is zero? π¨ she returns the maximum possible fixed point value and sets errno to ERANGE. so like, she tried her best, but dividing by zero is not it. π
π¦ SEE ALSO π¦
and that's the whole vibe, bestie β this page came to you straight from Allegro, version 4.4.3, dated the same as always, living under the name fixdiv(3alleg4). go forth and divide responsibly πβ¨
π¦ where this page comes from
- debian bookworm: allegro4-doc 2:4.4.3.1-3 Β· Allegro-gift-ware
- debian trixie: allegro4-doc 2:4.4.3.1-5 Β· Allegro-gift-ware
- ubuntu jammy: allegro4-doc 2:4.4.3.1-2 Β· Allegro-gift-ware
- ubuntu noble: allegro4-doc 2:4.4.3.1-4.1build3 Β· Allegro-gift-ware
- ubuntu questing: allegro4-doc 2:4.4.3.1-6
- ubuntu resolute: allegro4-doc 2:4.4.3.1-7 Β· Allegro-gift-ware
- ubuntu stonking: allegro4-doc 2:4.4.3.1-9 Β· Allegro-gift-ware
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms