Re: error in simple loop !!
- From: nospam@xxxxxxxxxxxxx (Richard Maine)
- Date: Sun, 8 Apr 2007 10:38:16 -0700
nakisa <nakisa.nooraee@xxxxxxxxx> wrote:
i have another problem here . i wrote k=0.0001 in program ( i define
k as real variable ) ,and then
say fortran to wrie k , it writes : 9.9999997E-06 .
This is closely related to your DO loop problem and understanding it is
absolutely critical to doing anything much useful with scientific
programming.
Almost all numbers in computers today are stored as binary - not
decimal. There are exceptions, but they are rare and for your current
purposes, they can be ignored. (For example, there are no exceptions in
current Fortran compilers).
The number 0.0001 cannot be represented exactly in a finite binary
representation. I repeat the "cannot". Nothing you can do will change
that. Anything you code that depends on having this number exactly will
fail. The 0.0001 that you write is converted to the closest
approximation available in the particular binary representation being
used. When you write the number back out, the binary number is converted
to a decimal character representation for the printout. That conversion
will also be an approximation.
Let me repeat that understanding this is *CRITICAL* to scientific
programming. Floating point arithmetic involves approximations. You
cannot afford to sweep the matter aside. A large part of the study of
scientific computation involves analysis of those approximations and
their effects.
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
.
- Follow-Ups:
- Re: error in simple loop !!
- From: John Harper
- Re: error in simple loop !!
- From: nakisa
- Re: error in simple loop !!
- References:
- error in simple loop !!
- From: nakisa
- Re: error in simple loop !!
- From: Herman D . Knoble
- Re: error in simple loop !!
- From: Dr Ivan D. Reid
- Re: error in simple loop !!
- From: nakisa
- error in simple loop !!
- Prev by Date: Re: error in simple loop !!
- Next by Date: Re: Starting to doubt fortran
- Previous by thread: Re: error in simple loop !!
- Next by thread: Re: error in simple loop !!
- Index(es):
Relevant Pages
|