Unexpected NaN value

Luca Donatini lucadonatini.k@gmail.com
Thu Oct 4 20:26:00 GMT 2018


Dear all,

I noticed a strange behaviour of the gfortran compiler.

In the source file below, when the real variable b has an "integer-like"
value (e.g. "2", "2.", "2.0" ...) the code correctly writes out a numerical
result. But when a "real-like" value is assigned to b (e.g. "2.1",
"2.0000009", "2.83" ...) , the code writes a NaN value.
This does not occurr when the sample code is compiled with an Intel
compiler (I tested version 2018a).

I have the NaN value problem with both:

   - gfortran 8.2.1 20180831 (Arch Linux package)
   - gfortran 6.3.0 20170516 (Debian Stretch package).


Is this a bug? A known one?

Many thanks in advance for all the clarifications,


Luca Donatini

*** example source file ***

program test
    implicit none

    real :: a = -1.57079637
    real :: b = 2.1

    write(*,*) cos(a)
    write(*,*) cos(a) **(2*b)

end program



More information about the Fortran mailing list