al_fixmul(3alleg5)

πŸ“¦
version 5.2.11.3 Β· 4 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– al_fixmul β€” the Allegro 5 API page, bestie edition πŸ’–

okay so this is al_fixmul from the allegro5 manual (that's the manual name, in case you were wondering, and yes we're doing this whole thing together) πŸŽ€


✨ NAME ✨

al_fixmul β€” Allegro 5 API


🌸 SYNOPSIS 🌸

#include <allegro5/allegro.h>

al_fixed al_fixmul(al_fixed x, al_fixed y);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so here's the tea, bestie πŸ“ β€” a fixed point value can be multiplied or divided by an integer using the normal * and / operators. easy, right? no thoughts, head empty, just vibes.

BUT πŸ’€ β€” if you wanna multiply two fixed point values together? nope. you must use this function. there is no other way. this is the only way. periodt.

now for the part that will lowkey ruin your day if you ignore it πŸ™ˆ β€” if an overflow happens, Allegro's errno gets set, and the maximum possible value gets returned. cute, right? except here's the catch: errno is not cleared if the operation is successful. so if you're planning to actually test for overflow, you have to call al_set_errno(0) before you call al_fixmul(3alleg5). otherwise you're out here checking an errno from three functions ago and living a lie. do not do that to yourself πŸ’…

Example:

al_fixed result;

/* This will put 30000 into `result'. */
result = al_fixmul(al_itofix(10), al_itofix(3000));

/* But this overflows, and sets errno. */
result = al_fixmul(al_itofix(100), al_itofix(3000));
assert(!al_get_errno());

πŸ‘‘ RETURN VALUE πŸ‘‘

it returns the clamped result of multiplying x by y, and it sets Allegro's errno to ERANGE if there was an overflow. so like, no silent nonsense, it tells on itself, iconic behaviour honestly ✨


πŸ’œ SEE ALSO πŸ’œ


and that's the whole page, bestie 🫢 this came to you straight from the Allegro reference manual, page al_fixmul(3alleg5) β€” go forth and multiply your fixed point values responsibly πŸ’–βœ¨πŸŒˆ

πŸ“¦ where this page comes from