al_ftofix(3alleg5)
β¨ 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
- debian trixie: allegro5-doc 2:5.2.10.1+dfsg-1 Β· Zlib
- ubuntu questing: allegro5-doc 2:5.2.10.1+dfsg-1build1
- ubuntu resolute: allegro5-doc 2:5.2.11.3+dfsg-1 Β· Zlib
- ubuntu stonking: allegro5-doc 2:5.2.11.3+dfsg-1 Β· Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms