Re: Need Help with Precision!!

From: Richard Maine (nospam_at_see.signature)
Date: 02/11/04


Date: 11 Feb 2004 12:12:49 -0800

vihang@iucaa.ernet.in (Vihang) writes:

> I am doing a simulation involving very low values like 10^-108.
> Fortran 77 is not able to recognize the value.
> I am using DOUBLE PRECISION. What can be done to stop this?

Fortran 90 provides more control and flexibility in such matters.
In Fortran 77, your options are very limited. However....

Double precision ought to be adequate for values of that magnitude on
most current machines. It typically goes down to around 10^-300 or
so. Exceptions exist, so it could help to mention your specific
machine and compiler.

Mostly, I'll give the same advice as seems to be appropriate
to a large fraction of the posts asking questions. You need
to be a lot more specific. *EXACTLY* what does your code say
and *EXACTLY* what does the compiler say about it. As it
happens, I think I can guess on this one, but the advice is
still applicable to the future.

For my guess...

Somehow I doubt that your code literally has 10^-108 in it. That
doesn't look like Fortran to me. It matters. What are the odds that
your code actually has something more like 1.E-108? If that's
what you have, then I can answer the question. A constant
like 1.E-108 is single precision. Always. It doesn't matter what
context it is in. Really. No, really. If you are about to say,
but... then you can stop. Whatever was going to follow the "but"
is irrelevant. You'll probably say it anyway (well, maybe you
won't, but lots of people do), so I'll give one of the specific
cases where the "but" doesn't matter; the other cases are all the
same

  double precision x
  x = 1.E-108

It doesn't matter that x is double precision. The 1.E-108 is
still single precision (just like it always is). The above
assignment says to take the single precision value 1.e-108,
convert it to double, and then assign it to x. So yes, x does
end up with a double precision value, but the 1.e-108 is still
single. (Some compilers might "help" you by figuring out what
you actually intended, but counting on such help is nonportable
and dangerous).

To write 10^-108 as a double precision constant, use D instead
of E in Fortran 77. That is, write 1.D-108. Again, Fortran 90
provides other options, but you asked about Fortran 77, so I'm
sticking to that in my answer.

If I guess wrong and that isn't your problem, we are back to
needing more specifics. What machine, what compiler, what
exact code and what exact message?

-- 
Richard Maine                       |  Good judgment comes from experience;
email: my first.last at org.domain  |  experience comes from bad judgment.
org: nasa, domain: gov              |        -- Mark Twain


Relevant Pages

  • Re: BLAS: dgemm
    ... to a procedure requiring double precision data, ... be 'single precision correct' instead of 'double precision correct'. ... Where is the compiler supposed to get ...
    (comp.lang.fortran)
  • Object Oriented Optimization
    ... I have the following problem with re-using a fortran 77 optimization ... double precision, dimension, intent:: co ... several objectives and constraints. ...
    (comp.lang.fortran)
  • Re: help about ARPACK solver
    ... Fortran uses single precision variables by default. ... Fortran program, that is *single* precision. ... I still dont know what kind of criteria Matlab adopts to form ...
    (sci.math.num-analysis)
  • Re: Unexpected 15 digits precision from "REAL"
    ... Fortran required double precision, it is about ... Every few days a question like "why doesn't Fortran ... improved versions much more often than most compiler developers do, ... It is much easier in modern fortran to support several different ...
    (comp.lang.fortran)
  • Re: help about ARPACK solver
    ... Fortran uses single precision variables by default. ... Fortran program, that is *single* precision. ...
    (sci.math.num-analysis)