Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!sun-barr!cs.utexas.edu!usc!bloom-beacon!bu-cs!purdue!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: atan2() Message-ID: <10730@smoke.BRL.MIL> Date: 14 Aug 89 19:37:03 GMT References:Reply-To: gwyn@brl.arpa (Doug Gwyn) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 21 In article tg1e+@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 . 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.