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 π₯
fixtof(3alleg4)itofix(3alleg4)fixtoi(3alleg4)exfixed(3alleg4)exrotscl(3alleg4)exspline(3alleg4)exupdate(3alleg4)
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. π§π
π¦ where this page comes from
- debian bookworm: allegro4-doc 2:4.4.3.1-3 Β· Allegro-gift-ware
- debian trixie: allegro4-doc 2:4.4.3.1-5 Β· Allegro-gift-ware
- ubuntu jammy: allegro4-doc 2:4.4.3.1-2 Β· Allegro-gift-ware
- ubuntu noble: allegro4-doc 2:4.4.3.1-4.1build3 Β· Allegro-gift-ware
- ubuntu questing: allegro4-doc 2:4.4.3.1-6
- ubuntu resolute: allegro4-doc 2:4.4.3.1-7 Β· Allegro-gift-ware
- ubuntu stonking: allegro4-doc 2:4.4.3.1-9 Β· Allegro-gift-ware
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms