Discussion:
Unexpected NaN value
Luca Donatini
2018-10-04 20:26:14 UTC
Permalink
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
Thomas Koenig
2018-10-04 20:29:59 UTC
Permalink
Hi Luca,
Post by Luca Donatini
program test
implicit none
real :: a = -1.57079637
real :: b = 2.1
write(*,*) cos(a)
write(*,*) cos(a) **(2*b)
end program
cos(a) happens to be negative, so cos(a)**(2*b) is undefined,
because 2*b is real. And yes, this is expected.

Regards

Thomas
Luca Donatini
2018-10-04 21:16:58 UTC
Permalink
Dear Thomas,

Many thanks for the clarification!


Best regards,


Luca
Post by Thomas Koenig
Hi Luca,
Post by Luca Donatini
program test
implicit none
real :: a = -1.57079637
real :: b = 2.1
write(*,*) cos(a)
write(*,*) cos(a) **(2*b)
end program
cos(a) happens to be negative, so cos(a)**(2*b) is undefined,
because 2*b is real. And yes, this is expected.
Regards
Thomas
Loading...