al_fixed(3alleg5)

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

πŸ’– al_fixed πŸ’–

okay bestie, welcome to the Allegro 5 API page for al_fixed, bestie. yes this is the manual page, no I'm not gonna make it boring, sit down, grab a strawberry πŸ“


✨ NAME ✨

al_fixed β€” literally the Allegro 5 API, that's it, that's the name, periodt πŸ’…


🌸 SYNOPSIS 🌸

#include <allegro5/allegro.h>

typedef int32_t al_fixed;

πŸ¦‹ DESCRIPTION πŸ¦‹

So. al_fixed is a fixed point number. that's the whole vibe.

Allegro ships some routines for working with fixed point numbers, and it defines the type al_fixed to be a signed 32-bit integer. The high word is the integer part and the low word is the fraction, which gives you a range of -32768 to 32767 and an accuracy of about four or five decimal places. no cap. πŸŽ€

The way that fixed point numbers are lowkey just normal ints: you can assign, compare, add, subtract, negate and shift them (shifting is how you multiply or divide by powers of two) using the normal integer operators. but bestie. listen. 🫢 you have to take care to use the appropriate conversion routines whenever you're mixing fixed point with integer or floating point values. Writing fixed_point_1 + fixed_point_2 is OK, but fixed_point + integer is not. do not do it. I'm watching. πŸ‘€

⚠️ fr fr: fixed_point + integer is not the move. convert first, or perish.

okay so why does this exist at all? the only advantage of the fixed point math routines is that you don't require a floating point coprocessor to use them. that was iconic back in the i386 and i486 era, but it stopped being so useful with the coming of the Pentium class of processors. from Pentium onwards, CPUs leveled up their floating point game, equaling or even surpassing integer math performance. the more you know ✨

but wait, don't write it off yet β€” many embedded processors have no FPUs at all, so fixed point maths can still be super useful there. πŸ’œ

and one last thing, depending on the type of operations your program may need, using floating point types may actually be faster than fixed types if you are targeting a specific machine class. so know your target, bestie. vibe check your hardware first. 🌈


Allegro reference manual β€’ al_fixed(3alleg5) β€” that's a wrap, babe πŸŽ€ thanks for reading the whole thing, you ate that. mwah πŸ’–βœ¨

πŸ“¦ where this page comes from