Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

strange number

Status
Not open for further replies.

Pfor

Technical User
Aug 11, 2010
22
IT
Hallo All,
I am using Fortran 90 (as a compiler I use gfortran), my code uses complex numbers and during a check on the output I found that the imaginary part of two numbers instead of being 0 as expected are:
3.60739284587612705E-313
2.56963542402032328E-320

I performed a -fbound-checks searching for any error but I found none.

Do you have any idea which kind of error in the code might lead to such numbers?
cheers,
thank you
Paolo
 
That is more or less zero. It is a common problem with digital computers and floating point numbers. The normal solution is to nominate an almost zero value, say -1E-99..1E-99. Anything inside the range is zero.
 
I disagree with xwb. These numbers are not zero !

If your code implements convergence loops, then these values might be due to a convergence toward zero. But I suspect that this is not the case because the exponent is too negative (a convergence criteria is normally much greater than E-300).

Another cause could be, for instance, the use the function EXP with a negative argument : this is the situation explained by xwb. But unfortunately, this is not the only one and even not the most frequent.

Possibly, you never initialized these values or you override them because of a programming mistake. Notice also that -fbounds-check cannot check everything, especially array arguments declared (*) for instance.

I suggest also the use of valgrind to verify that you don't use a memory zone which has never been allocated.

Anyway, you have to detect precisely the instruction generating these strange numbers and to judge if this is normal or not.

Do not leave a strange behavior without explanation! Never!

Use the debugger (in hoping that the behavior may be repeated with a version compiled with -g). If not, then you have a complicated bug : you will have to introduce print statements at strategical points in your code, again in expecting to reproduce the behavior with the modified version.

If the behavior cannot be reproduced when you modify the code, then you have a bug very complicated to locate...

 
Hallo,
thank you for your replies,
the "strange numbers" are strange since they should be exactly 0.

Moreover the non zero entries are parts of functions and all the other entries of the same function are exactly zero as expected.
For example I have a function of a "x" coordinate where the x coordinate is divided in 120 points, but at point 2 and 4 the very little numbers appear while elsewhere the function is zero.

I have never used neither vangrid (at first I was thinking it was an option of gfortran, then I searched on the net) or the -g option, thank you for giving me that hint.
cheers
Paolo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top