al_itofix(3alleg5)

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

πŸ’– al_itofix β€” Allegro 5 API πŸ’–

okay bestie, welcome to the al_itofix(3alleg5) page, aka the manual page where we turn boring whole numbers into fancy fixed-point ones ✨ no cap, it's short but it's important, so let's get into it 🫢


✨ SYNOPSIS ✨

#include <allegro5/allegro.h>

al_fixed al_itofix(int x);

like… look at it. one function. one argument. it's giving minimalism πŸ’…


🌸 DESCRIPTION 🌸

So what does it do? It converts an integer to fixed point πŸ’– that's it, that's the whole vibe. Lowkey it's literally the same thing as x<<16 β€” same energy, different font πŸŽ€

⚠️ okay but listen up, this part is the main character and you cannot skip it ⚠️

Overflows (when you try to convert an integer greater than 32767) and underflows (when you try to convert an integer lesser than -32768) are NOT detected β€” not even in debug builds!! 😭 like, no warning, no error, no nothing. The values simply β€œwrap around” πŸ’€ bestie that's a silent bug waiting to happen, fr fr.

πŸ¦‹ Example πŸ¦‹

al_fixed number;

/* This conversion is OK. */
number = al_itofix(100);
assert(al_fixtoi(number) == 100);

number = al_itofix(64000);

/* This check will fail in debug builds. */
assert(al_fixtoi(number) == 64000);

see how the first one slays and the second one… does not? 100 is fine, 64000 is out here living dangerously πŸ™ˆ that's the wrap-around in action, periodt.


πŸ’œ RETURN VALUE πŸ’œ

Returns the value of the integer converted to fixed point, ignoring overflows 🌈 (yes, ignoring. it just does the thing and pretends nothing went wrong. iconic behaviour honestly πŸ‘‘)


πŸ”₯ SEE ALSO πŸ”₯


and that's the whole page bestie!! 🌟 it's from the Allegro reference manual, dated around the al_itofix(3alleg5) era, and you just read the whole thing πŸ’– go forth and convert responsibly, and remember: 32767 is the limit, don't be weird about it πŸ’…βœ¨πŸ§š

πŸ“¦ where this page comes from