home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / fortran / 4436 < prev    next >
Encoding:
Text File  |  1992-11-24  |  1.4 KB  |  32 lines

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