Quantcast
Channel: Intel® Fortran Composer XE
Viewing all articles
Browse latest Browse all 1424

unexpected SUM() output

$
0
0

I am getting unexpected behavior in the following simple test program.  I am expecting the output values of n and s to be identical.  When the program is compiled in Release mode, they are identical:

 n =  20000000,   s =  20000000

However, when the program is compiled in Debug mode, they are different:

 n =  20000000,   s =  16777216

From what I have read, integers greater than 2**24=16777216, cannot be expressed accurately with single precision variables.  Is this what is happening in the code?  It is interesting that the Release code can still calculate the correct value.

program test_sum
implicit none

real,allocatable:: a(:)
integer n, s

n = 20000000
allocate( a(n) )
a = 1.0
s = nint(SUM(a))  ! Expect s == n

write(*,*) 'n =', n
write(*,*) 's =', s

stop
end program test_sum

 


Viewing all articles
Browse latest Browse all 1424

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>