ftofix(3alleg4)

✨ ftofix ✨

okay bestie, so this is a page from the Allegro manual β€” the Allegro game programming library, version 4.4.3, to be exact β€” and it's all about ftofix, the little function that takes your floaties and turns them into fixed point. πŸ’…


πŸŽ€ NAME πŸŽ€

ftofix β€” converts a floating point value to fixed point. Allegro game programming library. that's the whole vibe, fr fr.


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <allegro.h>

fixed ftofix(double x);

🌸 DESCRIPTION 🌸

So ftofix converts a floating point value to fixed point. literally its whole job. ✨

But here's the tea, and it's important tea: unlike itofix(), this function clamps values that could overflow the type conversion β€” so instead of going feral and wrapping around, it just stops at the edge. and because it's a polite little function, it sets errno to ERANGE while it does that. πŸ’–

example time, look at this:

fixed number;
number = itofix(-40000);
ASSERT(fixfloor(number) == -32768);
number = itofix(64000);
ASSERT(fixfloor(number) == 32767);
ASSERT(!errno); /* This will fail. */

(yeah, that last ASSERT fails β€” errno got set, bestie. that's the point of the example. 😭)


πŸ‘‘ RETURN VALUE πŸ‘‘

Returns the value of the floating point value converted to fixed point, clamping overflows β€” and setting errno when it does. so you get a number back, no surprises, no overflow chaos. periodt. 🫢


πŸ”₯ SEE ALSO πŸ”₯


go read those too, bestie, they're giving main character energy. 🌈

and that's the page!! mwah πŸ’‹ this was brought to you by the Allegro manual, version 4.4.3, page ftofix(3alleg4). slay, stay converted, and don't forget to check your errno. πŸ§šπŸ’œ