0

I decied to post here since I'm facing a very weird trouble with my fortran90 code. Indeed, I declared double precision variables such that :

double precision, dimension(-1:20,-1:20) :: a,b,c

Then I initialize all variables to zero,

a(:,:) = 0.d0
b(:,:) = 0.d0
c(:,:) = 0.d0

And finally I do my computations,

a(1:17,2:18) = a(1:17,2:18) + b(1:17,2:18) + 0.5d0*c(1:17,2:18)

I checked each variable and they are all equal to zero before this computations but then I obtain,

abs(maxval(a(1:17,2)) - minval(a(1:17,2))) = 4.336808689942018E-019

This makes no sense but I have no idea where the problem comes from, could someone help me out on this ?

Regards

P.S : I'm using ifort with the following options : "-O3 -xHost -vec-report0 -implicitnone -warn truncated_source -warn argument_checking -warn unused -warn declarations -warn alignments -warn ignore_loc -warn usage -check nobounds -ftz"

Amzocks
  • 123
  • 4
  • possible duplicate of [Is floating point math broken?](http://stackoverflow.com/questions/588004/is-floating-point-math-broken) – Alexander Vogt Dec 03 '14 at 11:02
  • Or: https://stackoverflow.com/questions/21895756/why-are-floating-point-numbers-inaccurate – Alexander Vogt Dec 03 '14 at 11:03
  • 3
    If you could convert this into a copy/paste compilable example which exhibits the problem, that would be useful. But I can't replicate using an inferred program. – francescalus Dec 03 '14 at 11:41

1 Answers1

0

I ran your snippet on MS Visual Studio 2005 (Intel Fortran 11.0.3452.2005) and got 0.000000000000000E+000. Same results on GNU Fortran 4.9.0.

Not sure if it makes a difference in your case, but may I suggest you to use DABS instead of ABS, though.

Fausto

  • 2
    Always best to use the generic intrinsic functions and then let the compiler decide how to handle the operations. – Joel DeWitt Dec 03 '14 at 19:00
  • Agree with Joel, the generic `abs` is better style. – Vladimir F Героям слава Dec 03 '14 at 19:20
  • I think that that's a matter of personal policy/taste, but I _never_ let the compiler to decide whatever is better for the program statements I write. It's sometimes a good idea, also: if I use a double-precision intrinsic function and get an error, that's an indication that I'm screwing up somewhere, and that my code needs some mending. – Fausto Arinos Barbuto Dec 03 '14 at 20:18
  • That is no free decision of the compiler in regards what is better! The generic resolution of the intrinsics follows the rules of the language as defined in the standard. I argue that the error catching argument is dubious, inexact assignments can be mostly caught by compiler warnings and using the generic names is regarded as better style not only by me but also by authorities, such as the great style guide by Clerman and Spector. – Vladimir F Героям слава Dec 04 '14 at 20:10