Re: Help! I'm new to Fortran 77



Duane Bozarth <dpbozarth@xxxxxxxxxxxx> wrote:

> "J. Jennings" wrote:

> > 1111.7 5
....
> > why does A read as 1111.699951171875, and N reads as 0 (zero) ??
>
> First is representation of value in floating point.

To elaborate just slightly (a full elaboration would take too long and
is best left to references), this is fundamental to pretty much all
technical computing - not just Fortran. It is absolutely critical to
understand that most computations with real numbers involve
approximations rather than exact results. In practice, real numbers are
stored in a binary floating point form. This means that even reading or
writing a value requires computations and approximations.

In particular, there is no finite binary value that exactly equals th
decimal 1111.7 that you are reading. There are binary values that
closely approximate it, but there are none that exactly equal it. If the
approximation is not close enough for your purposes, you can specify
that more precision be used (namely double precision). But that will
just get you a closer approximation; it still won't be exact.

This is one of the most important fundamentals to learn about technical
computing; you pretty much can't write programs that can be counted on
to give correct results unless you understand this. Heck, you probably
can't do a good job of using most scientific analysis programs, even if
someone else writes them, unless you understand this.

An excellent reference is Goldberg's "What Every Computer Scientist
Should Know About Floating-Point Arithmetic", a copy of which can be
found at <http://docs.sun.com/source/806-3568/ncg_goldberg.html>. Note
that the "computer scientist" referred to is basically anyone who works
with scientific computing; this is not restricted to those specializing
in the field of computer science.

--
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: fpga custom cpu VS. cuda
    ... We published some papers with GPU - FPGA comparison. ... needs about 200 64-bit floating point operations. ... that makes 18e9 computing cycles/s. ...
    (comp.arch.fpga)
  • Re: Sine code for ANSI C
    ... >representation arose. ... >that there's a corresponding sine that is worth computing ... Floating point numbers *are* fuzzy. ... Dan Pop ...
    (comp.lang.c)
  • Re: Adding floating point numbers
    ... I use it when I'm feeling lazy, such as for computing the correct font height ... certainly see floating point being handy for all kinds of graphical ... precision is necessary. ...
    (microsoft.public.vc.mfc)
  • Re: Precision issue with Float and Double (C++)
    ... If you are having problems with "decimal precision", ... You can download my Floating Point Explorer from my MVP Tips site and prove that it is not ... One of the first things we teach students in computing is that you ... My first programming exercise in the course I took in numeric programming in the summer of ...
    (microsoft.public.vc.mfc)
  • Re: Dealing with Degrees and Radians
    ... And the tan and other trigonometric functions are just approximations as ... it would have to simply convert to radians using the same ... there are formulas for computing things like tangent using an angle ... This is a power series ...
    (comp.lang.java.help)