Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Complex logarithm

Christoph_F_
Beginner
1,280 Views

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

 

0 Kudos
4 Replies
Steven_L_Intel1
Employee
1,280 Views

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.

0 Kudos
Steven_L_Intel1
Employee
1,280 Views

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.

0 Kudos
Steven_L_Intel1
Employee
1,280 Views

This change was made by paper 03-155r1, approved at standards meeting 164.

0 Kudos
Steven_L_Intel1
Employee
1,280 Views

I'll look forward to seeing the test case.

0 Kudos
Reply