comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: float problem
Date: Tue, 9 Jul 2002 01:05:48 GMT
Date: 2002-07-09T01:05:48+00:00	[thread overview]
Message-ID: <wcceled1zir.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: mailman.1026151863.24481.comp.lang.ada@ada.eu.org

"David C. Hoos" <david.c.hoos.sr@ada95.com> writes:

> It is impossible for _any_ computer language or compiler to _not_
> round when converting to machine representation to decimal
> representation, unless the machine representation is decimal --
> something that no modern machine does.  This is because only certain
> decimal values are _exactly_ representable in binary.  For example
> 0.1 is not exactly representable in binary, but values like 0.125, 0.375,
> etc. are exactly representable.

I think you have it backwards.

Every binary value is representable exactly in decimal, so it *is*
possible to display floating point values (whose radix is 2, as is
usual) in decimal without rounding (or truncation or whatever).  You
just need to display enough digits (which will be a finite number).

Your comments apply to the other way 'round (e.g., 'Value of 0.1 cannot
produce an exact floating-point representation of 0.1 -- assuming the
radix is 2).

I just got done reading Volume 2 of Knuth, which I've put off for years,
because I'm much more interested in (say) storage allocation than
numerics stuff.  Anyway, he discusses this issue in problem 4 of section
4.4 (a whole section on "Radix Conversion"!).

- Bob



  reply	other threads:[~2002-07-09  1:05 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
2002-07-08 20:20   ` Jan Prazak
2002-07-08 18:10     ` David C. Hoos
2002-07-09  1:05       ` Robert A Duff [this message]
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