- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello all,
according to the "Intel Fortran Libraries Reference", the natural logarithm of a complex number should give complex values x+i*y with -pi < y <= pi. But:
write(*,*) log((-1d0,0d0)),log(-(1d0,0d0))
yields the following output
(0.000000000000000E+000,3.14159265358979)
(0.000000000000000E+000,-3.14159265358979)
although the results should be identical and the imaginary part should NOT be -pi. I see this with versions 12 and 15. (In the final version of the code, where several complex logarithms are added up, the compilers behave differently, however, leading to correct results with v12 and incorrect results with v15. This complexity is lost after simplifying it to the above example.)
Thank you.
Christoph
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Looking in my copy of the Intel Fortran documentation, it says:
If the arguments are complex, the result is the principal value with imaginary part omega in the range -pi <= omega <= pi.
If the real part of x < 0 and the imaginary part of x is a positive real zero, the imaginary part of the result is pi.
If the real part of x < 0 and the imaginary part of x is a negative real zero, the imaginary part of the result is -pi.
This matches the behavior you are seeing (and what I see.) "Intel Fortran Libraries Reference" seems to be a very old document (I was unfamiliar with it - a Google search turned up a PDF from 2003.) The behavior also matches the definition of complex logarithm I see on Wikipedia and elsewhere.
If you have a program that delivers incorrect results in the 15.0 compiler and correct with an earlier version, and it does not assume that the imaginary part of a complex log can be pi or -pi, please provide us with a test case.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The Fortran standard explicitly specifies "-π <= ω <= π", so Intel Fortran follows the standard. There are several places where the "correct" answer has multiple possibilities, depending on whom you ask. This appears to be one of them.
I also tried gfortran 4.8.2 and got the identical results.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'll look forward to seeing the test case.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page