comp.lang.ada
 help / color / mirror / Atom feed
From: "Frank J. Lhota" <NOSPAM.FrankLho@rcn.com>
Subject: Re: float problem
Date: Sun, 7 Jul 2002 10:08:01 -0400
Date: 2002-07-07T14:07:52+00:00	[thread overview]
Message-ID: <ag9hvo$ro2$1@bob.news.rcn.net> (raw)
In-Reply-To: pan.2002.07.07.14.03.50.890537.1744@gmx.net

The problem is that 0.1 cannot be represented exactly as a floating point
number. When you add 5 copies of 0.1 to 1.0, the error in the representation
of 0.1 is multiplied by 5. The error is small enough to not affect the
printed output, where things are rounded to six significant digits, but it
does result in a value of f that is slightly more than -0.5. You can confirm
this by adding the following statement right before the statement where f
gets incremented by 0.1:

    if f > -0.5 then
        Put_Line ( "f > -0.5, that's the problem!" );
    end if;






  reply	other threads:[~2002-07-07 14:08 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-07 15:06 gnat: float problem Jan Prazak
2002-07-07 14:08 ` Frank J. Lhota [this message]
2002-07-08 20:20   ` Jan Prazak
2002-07-08 18:10     ` David C. Hoos
2002-07-09  1:05       ` Robert A Duff
2002-07-09  2:14         ` David C. Hoos, Sr.
2002-07-08 18:19     ` Frank J. Lhota
2002-07-08 19:12     ` tmoran
2002-07-08 19:28     ` achrist
2002-07-08 23:00     ` Jan Prazak
2002-07-08 23:00     ` Jan Prazak
2002-07-08 20:34       ` David C. Hoos
2002-07-09 13:36       ` Ted Dennison
2002-07-09 19:03         ` Jeffrey Carter
2002-07-09 20:07         ` Robert Dewar
2002-07-07 21:04 ` gnat: " achrist
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox