fixatan2(3alleg4)

πŸŽ€ NAME πŸŽ€

bestie, meet fixatan2 β€” she's the fixed point version of the libc atan2() routine, and she lives in the Allegro game programming library. manual name? fixatan2(3alleg4), periodt. πŸ’…


✨ SYNOPSIS ✨

#include <allegro.h>

fixed fixatan2(fixed y, fixed x);

πŸ’– DESCRIPTION πŸ’–

okay so. this is literally just a fixed point version of the libc atan2() routine. no cap.

what she does is compute the arc tangent of y / x, BUT β€” and this is the iconic part β€” the signs of both arguments get used to figure out which quadrant the result lands in, and x is allowed to be zero. yes, zero. she said i contain multitudes. πŸ¦‹

so when would you even need her? when you're converting Cartesian coordinates to polar coordinates. that's the vibe. that's the assignment. that's the whole point. 🌈

example time, and look at this gorgeous thing:

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);
🚨 heads up bestie: that last one fails the assert. like, it's in the example. the assert does not survive. iykyk. πŸ’€

πŸ‘‘ RETURN VALUE πŸ‘‘

she returns the arc tangent of y / x in fixed point binary format angle, and the range is from -128 to 128. locked in. πŸ”₯

but if both x and y are zero? she returns zero and sets errno to EDOM. that's the deal. no drama, just math. πŸ™ˆ


🌸 SEE ALSO 🌸

(and yeah, the original list opens with a little stray comma. she's quirky like that. we love her.) πŸŽ€


anyway that's the whole page, you ate it, mwah πŸ’–

this was brought to you by Allegro, version 4.4.3, and the letter fixatan2(3alleg4) β€” go forth and convert your coordinates, bestie, you've got this 🫢✨