fixmul(3alleg4)

πŸ’– fixmul β€” the fixed-point girlie's multiplication era πŸ’–

okay bestie, so this is a page from the Allegro manual, and it's about fixmul, the Allegro game programming library's very own fixed-point multiplier. no cap. πŸŽ€


✨ NAME ✨

fixmul β€” multiplies two fixed point values together, and it lives in the Allegro game programming library. that's the whole vibe. πŸ¦‹


✨ SYNOPSIS ✨

#include <allegro.h>

fixed fixmul(fixed x, fixed y);

like. it's giving two fixed values walk into a function. 🫢


✨ DESCRIPTION ✨

okay so here's the tea, and it's actually kind of important. πŸ“

a fixed point value can be multiplied or divided by an integer with the normal * and / operators. easy, right? slay. but the moment you want to multiply two fixed point values together?? nope, the operators are NOT going to save you, bestie. you must use this function. fixmul is literally the main character here. πŸ‘‘

and now for the part where we get a little serious. 😭 if an overflow occurs, errno will be set and the maximum possible value will be returned. BUT β€” and this is the sneaky bit β€” errno is not cleared if the operation is successful. so if you're planning to test for overflow, you have to set errno=0 before you call fixmul(). otherwise you're doing a vibe check on stale data and that's not the move. πŸ’€

example, verbatim, no notes:

fixed result;

/* This will put 30000 into `result'. */
result = fixmul(itofix(10), itofix(3000));
/* But this overflows, and sets `errno'. */
result = fixmul(itofix(100), itofix(3000));
ASSERT(!errno);

see how the second one is out here causing chaos? yeah. that's the overflow. 🫠


✨ RETURN VALUE ✨

returns the clamped result of multiplying x by y, and sets errno to ERANGE if there was an overflow. that's it, that's the deal. ⭐


✨ SEE ALSO ✨

go read these next, they're all part of the same friend group fr fr:


and that's the page, bestie!! 🌈✨ this lil masterpiece comes to you from Allegro, version 4.4.3, and its whole fixmul(3alleg4) self is dated accordingly β€” mwah πŸ’…πŸ«ΆπŸ’–