al_fixatan2(3)

πŸ“¦
version 5.2.11.3 Β· 3 versions
, in arch rolling

✨ al_fixatan2(3) ✨

okay bestie, welcome to the Allegro 5 API corner of the universe πŸ’– this little icon is al_fixatan2, and she's here to do trigonometry for you in fixed point. no floats, no drama, just vibes and angles πŸŽ€


🌸 SYNOPSIS 🌸

#include <allegro5/allegro.h>

al_fixed al_fixatan2(al_fixed y, al_fixed x)

like, that's it. two fixed point numbers in, one angle out. slay πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so bestie, this is literally the fixed point version of the libc atan2() routine. same energy, but without any of that floating point nonsense πŸ’€

what she does: computes the arc tangent of y / x. but here's the iconic part β€” the signs of both arguments get used to determine the quadrant of the result, and x is permitted to be zero. so she's not just blindly dividing, she's actually paying attention to where you are on the plane πŸ‘‘ iykyk

this function is useful to convert Cartesian coordinates to polar coordinates. literally her whole purpose in life ✨

πŸ“ Example πŸ“

al_fixed result;

/* Sets `result' to binary angle 64. */
result = al_fixatan2(al_itofix(1), 0);

/* Sets `result' to binary angle -109. */
result = al_fixatan2(al_itofix(-1), al_itofix(-2));

/* Fails the assert. */
result = al_fixatan2(0, 0);
assert(!al_get_errno());

look at her go 😭 note that last one β€” when both are zero she sets errno and the assert fails, which is the whole point of the example. read it carefully bestie, don't come for me 🫢


🌈 RETURN VALUE 🌈

returns the arc tangent of y / x in fixed point binary format angle, from -128 to 128. that range is not a suggestion, it's the whole map πŸ—ΊοΈ

but if both x and y are zero? returns zero and sets Allegro's errno to EDOM. that's the error case, no cap πŸ’€


⚠️ heads up gorgeous β€” the (0, 0) case is the one that gives you EDOM, so if you're checking for it, al_get_errno() after the call is your bestie πŸŽ€

and that's the tea πŸ’œ this page came from the Allegro reference manual, manual name al_fixatan2(3) β€” big fan honestly β€” and the version/date on the tin is the Allegro reference manual, al_fixatan2(3). mwah, go write some polar coordinates, queen πŸ‘‘πŸŒΈ

πŸ“¦ where this page comes from
  • arch rolling: allegro 5.2.11.3-2 Β· Zlib AND BSD-3-Clause AND OFL-1.1 AND LicenseRef-Custom
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms