atan2()

Doug Gwyn gwyn at smoke.BRL.MIL
Tue Aug 15 05:37:03 AEST 1989


In article <oYtS4Cy00WB984HWR7 at andrew.cmu.edu> tg1e+ at andrew.cmu.edu (Timothy R. Gottschalk) writes:
>     I need to calculate that arctan of y over x, where x,y are declared as
>float.  Using the proper type-casting, I can get the atan() function to
>work properly i.e.
>     float result = (float)atan((double)(y/x);

Missing ")" in the above.

>However, if I use atan2() I get garbage values:
>     float result = (float)atan2((double)y, (double)x);

Be sure you've previously #included <math.h>.  The (float) cast is
unnecessary, but harmless.  In fact, so are the (double) casts.

Without more information about the system software you're using,
we cannot tell if your atan2() implementation is actually broken.

Generally, you should always use atan2() instead of atan().  I've
never seen a case where atan() was preferable.

Warning: many implementations consider atan2(0.0,0.0) to be an error.



More information about the Comp.lang.c mailing list