half and quad

Janice Caron caron800 at googlemail.com
Mon Oct 15 02:00:58 PDT 2007


On 10/15/07, Don Clugston <dac at nospam.com.au> wrote:
> Janice Caron wrote:
> > You could certainly argue that all floats are rational, but they don't
> > store all rational numbers exactly either. As soon as an operation
> > requires it, they start rounding. A float actually represents a kind
> > of "fuzzy real" - that is, the true real that it tries to represent
> > exists somewhere within plus or minus some error bound of the rational
> > value, and it tries to keep that error bound as small as possible.
>
> That's not right. There's nothing fuzzy about floats. They're just a mapping
> from the infinite set of real numbers into a small subset. A float always
> represents a single true real, and it represents it exactly. It's just that not
> many reals are representable. (The roundoff error exists in the operations, not
> the representation).

If you take the point of view that floats are an /exact/
representation of something, then obviously you're right and no one's
going to argue with you.

But I've always taken the view that floats are an /approximate/
representation of stuff. For example, the constant PI. We all know
that the real pi is a transcendental number which /cannot/ be
represented as a rational, but nonetheless float math libraries never
name their constant APPROXIMATELY_PI - we just take that for granted.

You can look at it either way. Yes, a float can be considered as the
set of exactly 2^N reals and special values representable by all
possible float bit patterns. But I don't believe that's a particularly
useful way of looking at it. (With that interpretation, you can't even
represent 1/3). A more useful interpretation, and the one actually
used in real programs, is that floats let us play with real numbers,
so long as we remember that they're only ever going to be approximate.

Everyone's right! :-)



More information about the Digitalmars-d mailing list