al_fixmul(3)
๐ al_fixmul(3) โ Allegro 5 API โจ
okay bestie, so this one lives in the Library Functions Manual and it's part of the Allegro 5 API โ yes, that Allegro, the game library one, she's iconic ๐ฎ๐
๐ธ SYNOPSIS ๐ธ
#include <allegro5/allegro.h>
al_fixed al_fixmul(al_fixed x, al_fixed y);
๐ฆ DESCRIPTION ๐ฆ
So here's the tea ๐ต โ a fixed point value can be multiplied or divided by a plain old integer using the normal * and / operators, no drama, no special function needed, she's lowkey self-sufficient like that.
But โ and this is the main character plot twist โ if you wanna multiply two fixed point values together? Nope. You literally cannot just slam a * between them. You must use this function. That's the whole vibe. al_fixmul is the only way. periodt. ๐
Now for the serious part, bestie, don't skip this ๐ซถ: if an overflow happens, Allegro's errno gets set, and the maximum possible value gets returned instead. Cool cool cool โ however ๐, errno is not cleared if the operation succeeds. So if you're planning to actually test for overflow, you gotta call al_set_errno(0) before you call al_fixmul(3). Otherwise you're just out here checking stale errno energy and that's not giving what you think it's giving. ๐ญ
โ ๏ธ seriously, al_set_errno(0) first, or your overflow check is fake news fr fr
โจ 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());
see how the first one is all innocent and gives you a clean 30000, and the second one is out here overflowing and setting errno like it owns the place? that's the whole point of the example, bestie ๐
๐ RETURN VALUE ๐
Returns the clamped result of multiplying x by y โ and it sets Allegro's errno to ERANGE if there was an overflow. so if you see ERANGE, you know exactly what went down. no cap. ๐ฅ
๐ SEE ALSO ๐
go read al_get_errno(3) if you're gonna be doing that overflow-checking thing, iykyk ๐
later bestie โ this page came to you straight from the Allegro reference manual, page al_fixmul(3) ๐ stay fixed-point fabulous โจ
๐ฆ where this page comes from
- arch rolling: allegro 5.2.11.3-2 ยท Zlib AND BSD-3-Clause AND OFL-1.1 AND LicenseRef-Custom
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms