fixmul(3)

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

πŸ’– fixmul β€” the Allegro manual, but make it cute πŸ’–

okay bestie, we're in the Allegro manual today and the function on the menu is fixmul(3) πŸŽ€ she multiplies two fixed point values together, and honestly? she's iconic for it. Allegro game programming library, let's GO πŸ¦‹


✨ NAME ✨

fixmul β€” multiplies two fixed point values together. Allegro game programming library. no cap, that's the whole job description πŸ’…


🌸 SYNOPSIS 🌸

#include <allegro.h>

fixed fixmul(fixed x, fixed y);

πŸ’œ DESCRIPTION πŸ’œ

so here's the tea πŸ“ a fixed point value can be multiplied or divided by an integer using the normal * and / operators, easy peasy, love that for you.

BUT. if you wanna multiply two fixed point values together? you literally have to use this function. the operators will not save you here, bestie 😭

if an overflow happens, errno gets set and the maximum possible value gets returned. and here's the sneaky part β€” errno is not cleared if the operation is successful πŸ™ˆ so if you're planning to actually test for overflow, you should set errno=0 before calling fixmul(). it's giving "set the vibe before you walk in the room." example time:

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 first one's just chilling and the second one is spiraling? yeah. that's the whole bit πŸ’€


⭐ RETURN VALUE ⭐

she returns the clamped result of multiplying x by y, and she sets errno to ERANGE if there was an overflow. so if you see ERANGE, you know exactly what happened, no mystery, no drama πŸ‘‘


🫢 SEE ALSO 🫢

go read those next, they're all part of the same lil fixed point family 🌈


and that's the page, bestie!! this was Allegro version 4.4.3, page fixmul(3), and yes you read all of it which means you're lowkey a fixed point girlie now πŸ’–βœ¨ slay, periodt, go multiply responsibly πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from