al_ftofix(3alleg5)

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

✨ al_ftofix ✨

okay bestie, welcome to the Allegro 5 API reference manual, and today's main character is al_ftofix πŸ’– she's a lil conversion girlie and she's SO good at her job, fr fr.


🌸 NAME 🌸

al_ftofix β€” the Allegro 5 API function that takes your float and turns it into a fixed point value πŸ¦‹


✨ SYNOPSIS ✨

#include <allegro5/allegro.h>

al_fixed al_ftofix(double x);

like yes that's the whole vibe. include the header, call the function, get a fixed. slay πŸ’…


πŸ’œ DESCRIPTION πŸ’œ

so basically she converts a floating point value into fixed point. that's it, that's the job πŸŽ€

BUT here's the tea, and it's important tea: unlike al_itofix(3alleg5), this function clamps values that would otherwise overflow the type conversion. no cap. and if that clamping actually happens, she sets Allegro's errno to ERANGE in the process. so she's polite about it, she tells you πŸ‘‘

Example, because we love a demo:

al_fixed number;

number = al_itofix(-40000);
assert(al_fixfloor(number) == -32768);

number = al_itofix(64000);
assert(al_fixfloor(number) == 32767);
assert(!al_get_errno()); /* This will fail. */
lowkey obsessed with how that last assert just gives up and dies πŸ’€ read it carefully bestie, the comment is telling you the truth.

🌈 RETURN VALUE 🌈

she returns the value of that floating point value, now converted to fixed point, with the overflows clamped β€” and yeah, she sets Allegro's errno while she's at it if clamping went down. periodt. πŸ’–


🫢 SEE ALSO 🫢

go read those too, they're all part of the same fixed point friend group 🧚✨


okay that's the whole page, mwah πŸ’œ this was the Allegro reference manual, al_ftofix(3alleg5), and yes she really is that iconic. go convert something. byeee πŸŽ€

πŸ“¦ where this page comes from