[nvfortran] Incorrect format specification of double variables

Using nvfortran 23.1 I tried to print 3 digits exponent variables with different format specifiactions. For these purposes I used double precision variable and function HUGE and print zero value.

None fmt                             huge(lv)               lv = 0.0_dp     
 None fmt                 1.7976931348623157E+308    0.000000000000000     
Use format es27.17E3     1.79769313486231571+308    0.00000000000000000E+00
Use format  d27.17       0.17976931348623157+309    0.00000000000000000D+00
Use format  G27.17E3    0.17976931348623157E+309    0.0000000000000000     
NOT allowed in NVF to use   DSw.d  
NOT allowed in NVF to use   Dw.dEe 

The format ES27.17E3 doesn’t print 3 digits in exponential part for double precision.
In case of Single Precision it also works weird.

Use format es27.17E3     1.79769313486231571+308    0.00000000000000000E+00
Use es27.17E3 SPrec      3.40282346638528860E+38    0.00000000000000000E+00

The source of the program is below

program test_format
  use iso_fortran_env, only: dp => real64, sp => real32

  real(sp), parameter ::sv = 0.0_sp
  real(dp), parameter ::lv = 0.0_dp

  write(*,'(a,2a27)')       "None fmt             ",  "huge(lv)    ", "lv = 0.0_dp     "
  write(*,*)                "None fmt             ",  huge(lv), lv
  write(*,'(a,2es27.17E3)') "Use format es27.17E3 ",  huge(lv), lv
  write(*,'(a,2d27.17)')    "Use format  d27.17   ",  huge(lv), lv
  write(*,'(a,2G27.17E3)')  "Use format  G27.17E3 ",  huge(lv), lv
  write(*,'(a)')            "NOT allowed in NVF to use   DSw.d  "         
  write(*,'(a)')            "NOT allowed in NVF to use   Dw.dEe "         
  write(*,'(a,2es27.17E3)') "Use es27.17E3 SPrec  ",  huge(sv), sv

end program test_format

Thanks for the report medvsn. I’ve filed a problem report, TPR #33643, and sent it to engineering for review.

The formatting has been this way for probably 35+ years now, i.e. the first Floating Point Systems Fortran compiler which became the basis for PGI HPF. Surprised no one noticed before now.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.