Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Hyperbolic perplexity

mecej4
Honored Contributor III
1,370 Views

The intrinsic function ACOSH with complex argument was added to Fortran in Fortran 2008. Since this function is multi-valued for complex arguments, a convention is needed for what the return value should be. The F2008 (13.7.5) and F2018 (16.9.5) standards state:

5 Result Value. The result has a value equal to a processor-dependent approximation to the inverse hyperbolic cosine function of X. If the result is complex the imaginary part is expressed in radians and lies in the range 0 ≤ AIMAG (ACOSH (X)) ≤ π

In contrast, the Intel Fortran Development Reference Guide says:

If the result is complex, the real part is non-negative, and the imaginary part is expressed in radians and lies in the range -pi <= AIMAG (ACOSH (x)) <= pi.

The following program outputs a result with the imaginary part negative:

 

program xacosh
   implicit none
   complex :: z = (-0.01, -0.01)
   print 10, 'z', z, 'acosh(z)', acosh(z)
10 format(1x,A,T10,'( ',ES11.3,' , ',ES11.3,' )')
end

 

The result:

 

S:\LANG\ftn95>acosh
 z       (  -1.000E-02 ,  -1.000E-02 )
 acosh(z)(   1.000E-02 ,  -1.581E+00 )

 

Please clarify if the deviations ( w.r.t. (a) sign of the real part and (b) range of the imaginary part) from the standard are deliberately intended, and any reasons for the choices, if available. Thank you in advance.

0 Kudos
1 Solution
Steve_Lionel
Honored Contributor III
1,288 Views
D:\Projects>nagfor -o t.exe t.f90
NAG Fortran Compiler Release 7.1(Hanzomon) Build 7114
[NAG Fortran Compiler normal termination]

D:\Projects>t.exe
 z       (  -1.000E-02 ,  -1.000E-02 )
 acosh(z)(   1.000E-02 ,  -1.581E+00 )

It's an error in the F2018 standard, corrected by interpretation request F18/0001. The corrected text says, "If the result is complex the real part is nonnegative, and the imaginary part is expressed in radians and lies in the range −π ≤ AIMAG (ACOSH (X)) ≤ π"

View solution in original post

4 Replies
JohnNichols
Valued Contributor III
1,309 Views

This is really fascinating,  the https://www.geeksforgeeks.org/acosh-function-for-complex-number-in-c/  site seems to agree with your Intel observations.  They provide a couple of quick samples.  

Running their sample but with the -0.000 I get -pi. 

 

Screenshot 2023-03-06 110945.png

 

-1.58 is just 335 degrees in the -PI to PI system.  

0 Kudos
Ron_Green
Moderator
1,297 Views

This is an interesting one.  gfortran 12.0.1 is in agreement in values with ifort/ifx.   I will ask advice from someone more familiar with this function, and the F08 Standard.  I don't have the NAG compiler myself but I'll ask someone to try it with NAG.  

0 Kudos
Steve_Lionel
Honored Contributor III
1,289 Views
D:\Projects>nagfor -o t.exe t.f90
NAG Fortran Compiler Release 7.1(Hanzomon) Build 7114
[NAG Fortran Compiler normal termination]

D:\Projects>t.exe
 z       (  -1.000E-02 ,  -1.000E-02 )
 acosh(z)(   1.000E-02 ,  -1.581E+00 )

It's an error in the F2018 standard, corrected by interpretation request F18/0001. The corrected text says, "If the result is complex the real part is nonnegative, and the imaginary part is expressed in radians and lies in the range −π ≤ AIMAG (ACOSH (X)) ≤ π"

mecej4
Honored Contributor III
1,264 Views

The portion "the imaginary part is expressed in radians" strikes me as odd, since the imaginary part (with the i removed) does not represent an angle -- it is just a real number.

If one wishes to think about the Argand Diagram, the real part is the x-coordinate and the imaginary part is the y-coordinate.  It is only after the point (x, y), where z = x + i y, is plotted and a line drawn to it from the origin that we may speak of angles.

0 Kudos
Reply