Re: Help! I'm new to Fortran 77
- From: nospam@xxxxxxxxxxxxx (Richard E Maine)
- Date: Tue, 8 Nov 2005 09:38:42 -0800
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
.
- Follow-Ups:
- Re: Help! I'm new to Fortran 77
- From: glen herrmannsfeldt
- Re: Help! I'm new to Fortran 77
- References:
- Help! I'm new to Fortran 77
- From: J. Jennings
- Re: Help! I'm new to Fortran 77
- From: Duane Bozarth
- Help! I'm new to Fortran 77
- Prev by Date: Re: Help! I'm new to Fortran 77
- Next by Date: writing to binary
- Previous by thread: Re: Help! I'm new to Fortran 77
- Next by thread: Re: Help! I'm new to Fortran 77
- Index(es):
Relevant Pages
|