1

I am performing some calculations in Fortran 90. A particular variable (declared as implicit double precision) is taking the value of something like -1.0420437349566899E-318. At first, I ignored it assuming that it was probably just zero (the value that the variable is supposed to take is also zero). But now I am wondering if E-318 indicates an error in my code. I am also asking this since this variable takes such values at various points in a loop and on occasions the variable also takes NaN as its value. This indicates that there is most certainly an error in my code but I have a different question. In general What is the maximum and minimum value that such variables can take in Fortran 90?

Ian Bush
  • 6,996
  • 1
  • 21
  • 27
Babaji
  • 398
  • 1
  • 4
  • 18
  • 1
    Please use tag [tag:fortran]. You should show your code. It can be the right answer and it can be an error, how could we know without your code and the math you are solving? Even `NaN` might be the right answer, sometimes. We have other questions about minumum and maximum values. See the `tiny()` and `huge()` intrinsic functions. – Vladimir F Героям слава Feb 23 '22 at 07:30
  • See also the table at https://en.wikipedia.org/wiki/IEEE_754#Basic_and_interchange_formats for the possible values and more. – Vladimir F Героям слава Feb 23 '22 at 07:52
  • 3
    10^-318 is obviously very small (too small for anything appearing in physics, for example) and close to the lower limit of binary64. However, we cannot say whether your code has an error or whether it is the correct result of your algorithm. Try enabling floating point exceptions (FPE) including underflow. Check your program for undefined (uninitialized) values. – Vladimir F Героям слава Feb 23 '22 at 07:58
  • 1
    *In general What is the maximum and minimum value that such variables can take in Fortran 90?* Have a look at the `huge` and `tiny` intrinsic functions. – High Performance Mark Feb 23 '22 at 08:04
  • 1
    See also [Is floating point math broken?](https://stackoverflow.com/questions/588004/is-floating-point-math-broken). – veryreverie Feb 23 '22 at 08:39
  • 1
    If you get values which could not occur numerically, it may be an indication of unitialized variables. I.e., you just get whatever bit-pattern was at that memory location before, but interpreted as a `double`. Maybe your compiler has some options to warn about this. – chtz Feb 23 '22 at 15:42

1 Answers1

3

-1.0420437349566899E-318 means −1.0420437349566899 • 10−318, that is, approximately −1 times ten to the power of −318. “E” stands for the Exponent of ten.

This is a very small number. Its magnitude is below the smallest normal number in the IEEE-754 “double precision” floating-point format (binary64), 2−1022, which is about −1.11254•10−308. The magnitude is above the small representable number, the subnormal number 2−1074, about 4.94•10−324. When a number this small appears in results, it may be because repeated multiplications by a number smaller than one have been performed. For example, in an audio filter designed to produce an echo, with each repetition at a lower volume than the previous one, the magnitudes of previous sounds will eventually reach the subnormal range if there is no new incoming sound overriding them. It can also occur when a variable is not initialized or the bytes representing a different type of data are reinterpreted as a floating-point type.

Eric Postpischil
  • 195,579
  • 13
  • 168
  • 312