home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.fortran
- Path: sparky!uunet!cs.utexas.edu!swrinde!sdd.hp.com!saimiri.primate.wisc.edu!caen!hellgate.utah.edu!lanl!cochiti.lanl.gov!jlg
- From: jlg@cochiti.lanl.gov (J. Giles)
- Subject: Re: a question on ATAN function
- Message-ID: <1992Nov24.003507.6422@newshost.lanl.gov>
- Sender: news@newshost.lanl.gov
- Organization: Los Alamos National Laboratory
- References: <dedmunds.722548228@sfu.ca>
- Date: Tue, 24 Nov 1992 00:35:07 GMT
- Lines: 20
-
- In article <dedmunds.722548228@sfu.ca>, dedmunds@selkirk.sfu.ca (Darran Edmundson) writes:
- |> I'd like to pose a neophyte question on using the arctan function to
- |> calculate the phase angle of a complex variable (i.e. \theta = atan(v/u)
- |> where u and v are the real and complex parts of my imaginary number
- |> respectively). Is it sufficient to test for u=0 (i.e. \theta = \pm \pi)
- |> to avoid problems? What happens if the ratio exceeds range allowed
- |> for doubles or reals? How do you avoid this problem?
- |>
- |> (Now that I think about it, is it better to use arcsin or arccos?)
-
- What you should use is ATAN2(AIMAG(Z), REAL(Z)). You needn't even
- test for the real part being zero. If the second argument is zero
- and the first argument is not, the answer will have absolute value
- equal to PI/2 (the sign depending on the sign of the imaginary
- part of Z). In fact, this function should work for any pair of
- floating point numbers provided they aren't *both* zero and neither
- is out of range.
-
- --
- J. Giles
-