Hugs Humor

Jon Fairbairn
Mon, 07 Jul 2003 11:57:47 +0100

On 2003-07-07 at 12:01+0200 Jerzy Karczmarczuk wrote:
> Jon Fairbairn comments //Steffen Mazanek//:
> >>Prelude> 0.1::Rational
> >>13421773 % 134217728
> >>Prelude> 13421773/134217728
> >>0.1
> >>
> >>I do not know how this fraction is calculated, but
> >>it does not fit my expectations :-)
> >  
> > Remember that internally arithmetic is binary, and that 0.1
> > can't be expressed exactly as a floating point number. I
> > think that's the explanation.
> I don't understand the remark that the internal arithmetic is
> binary. Sure, it is, so what?

My comment was perhaps too brief. As far as I am concerned,
a constant with a decimal point in it should go like this:


becomes fromRational (CCCCCDD...DD % 100...00)

and there's no problem in getting an accurate Rational (what
you say about conversions applies if the desired result is
some kind of float). However, if the conversion goes via
float, and I think doing that is a bug, the fact that 1/5
has an infinite expansion in binary explains the peculiar
numbers that Hugs produces in its Rational. It's an
explanation of what happens, not what should be!

During the revision of the report I said something to the
effect that Int, Float and Double do not belong in the
language proper. The suggestion was rejected for (I think)
sociological reasons, but I still stand by it. While they
should of course be provided in the standard libraries, they
only serve to confuse things as far as the language design
is concerned.


Jón Fairbairn                       
31 Chalmers Road                               
Cambridge CB1 3SZ            +44 1223 570179 (after 14:00 only, please!)