itofix(3alleg4)

πŸ’– itofix πŸ’–

okay bestie, welcome to the Allegro manual, page itofix(3alleg4) πŸŽ€ β€” yeah it's a whole section-3 library function, not a command, we're doing C today, slay.


✨ NAME ✨

itofix β€” converts an integer to fixed point. it's part of the Allegro game programming library, iykyk πŸ¦‹


🌸 SYNOPSIS 🌸

#include <allegro.h>

fixed itofix(int x);

that's it. one include, one function, no drama πŸ’…


🧚 DESCRIPTION 🧚

so like, itofix takes your regular boring integer and turns it into a fixed point value. literally the exact same thing as writing x<<16. that's the whole vibe, no cap ✨

⚠️ but bestie, listen, this is the important part: overflows (aka trying to convert an integer greater than 32767) and underflows (aka trying to convert an integer lesser than -32768) are NOT detected, not even in debug builds!! 😭 the values just simply "wrap around". no warning, no error, no nothing. she just does it and moves on, main character energy fr fr.

here's the example so you can see it with your own eyes πŸ‘€:

fixed number;
/* This conversion is OK. */
number = itofix(100);
ASSERT(fixtoi(number) == 100);
number = itofix(64000);
/* This check will fail in debug builds. */
ASSERT(fixtoi(number) == 64000);

see how the second one is giving chaos? 64000 is way over 32767 so that ASSERT goes down in flames even in debug builds πŸ’€ wrap-around moment.


🫢 RETURN VALUE 🫢

returns the value of the integer converted to fixed point, ignoring overflows. she said "i'm not checking that" and honestly? respect πŸ’…


🌈 SEE ALSO 🌈

the whole friend group, go say hi:


and that's the page, bestie!! πŸŽ€ this was Allegro, version 4.4.3, page itofix(3alleg4) β€” go forth and convert your integers, but please, for the love of everything, keep them between -32768 and 32767 πŸ™ˆπŸ’– mwah, bye!! βœ¨πŸ¦‹πŸ‘‘