fixatan2(3)

πŸ“¦ version 4.4.3.1, in fedora 43, fedora 44

πŸŽ€ fixatan2 β€” the Allegro manual, bestie edition πŸŽ€

okay so you found your way into the Allegro manual, and specifically into fixatan2(3) from the Allegro game programming library. pull up a chair, we're doing trig but make it fixed point. ✨


✨ NAME ✨

fixatan2 β€” it's the fixed point version of the libc atan2() routine, living its best life inside the Allegro game programming library. πŸ¦‹


🌸 SYNOPSIS 🌸

#include <allegro.h>

fixed fixatan2(fixed y, fixed x);

πŸ’– DESCRIPTION πŸ’–

So. This is a fixed point version of the libc atan2() routine. No floats invited to this party. πŸ’…

What it does: it computes the arc tangent of y / x, BUT β€” and this is the part that eats β€” the signs of both arguments get used to figure out which quadrant the result should land in, and x is allowed to be zero (no div-by-zero meltdown, we love that for us 🫢).

It's genuinely useful for converting Cartesian coordinates into polar coordinates. iconic behaviour fr fr.

Example, and yes it's giving tutorial-core:

fixed result;

/* Sets `result' to binary angle 64. */
result = fixatan2(itofix(1), 0);
/* Sets `result' to binary angle -109. */
result = fixatan2(itofix(-1), itofix(-2));
/* Fails the assert. */
result = fixatan2(0, 0);
ASSERT(!errno);
⚠️ not me pointing at that third call β€” fixatan2(0, 0) sets errno, so that ASSERT(!errno) is going to fail. it says so right there in the comment. periodt. πŸ’€

🌈 RETURN VALUE 🌈

It returns the arc tangent of y / x as a fixed point binary format angle, ranging from -128 to 128. πŸ“

But bestie, listen β€” if both x and y are zero, it returns zero and sets errno to EDOM. that's the failure vibe check. no cap.


πŸ‘‘ SEE ALSO πŸ‘‘


and that's the whole page, bestie!! you ate. πŸ“πŸ’…

Allegro, version 4.4.3 β€” signed off with love from fixatan2(3), mwah πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from