Re: error in simple loop !!



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
.



Relevant Pages

  • Re: This calculation is just wrong / computer cant count!
    ... is accurate and CORRECT as a representation of 25/30. ... No it isn't, it is an approximation and the approximation (conversion from bin to dec) has introduced a level of error, rendering the number incorrect. ...
    (microsoft.public.vc.mfc)
  • Re: question regarding java puzzlers #2
    ... it seems a little wrong-headed to me to use an exact representation ... for something that I think is better thought of as an approximation. ... want to convert doubles to BigDecimals using different rules (which is not in ... reason to assume that the true value has a short decimal representation. ...
    (comp.lang.java.programmer)
  • Re: Switch for floating !!
    ... It's an approximation of a range of real numbers near 2.0. ... Can you explain what base ten math has to do with this? ... any real value whose closest representation is that double value, ... If I recall correctly, stock prices used ...
    (comp.lang.c)
  • Particles and Group Representations
    ... My goal is to have a clear conceptual understanding of what it means ... I understand the basics of group theory, representation theory ... I understand how various Lie groups act on the state spaces ...
    (sci.physics.research)
  • Re: question regarding java puzzlers #2
    ... it seems a little wrong-headed to me to use an exact representation ... for something that I think is better thought of as an approximation. ... sensible choice other than the one made by the BigDecimal constructor. ... There is a sense in which floating point computation can be considered to be ...
    (comp.lang.java.programmer)