al_fixmul(3)

๐Ÿ“ฆ
version 5.2.11.3 ยท 3 versions
, in arch rolling

๐Ÿ’… 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