Arbitrary precision reals?

Alastair Reid alastair@reid-consulting-uk.ltd.uk
Wed, 26 Mar 2003 08:34:27 +0000


Tom Pledger <Tom.Pledger@peace.com> wrote:
>>  The floating point part of the GNU mp library looks difficult to
>> fit into Haskell's numeric classes, because the type signatures in
>> class Floating don't include a how-much-precision-do-you-want
>> parameter.

Fergus Henderson <fjh@cs.mu.OZ.AU> writes:
> How about using a function type which takes a precision and gives
> you back an answer to that many digits, and making this function
> type an instance of the numeric type classes?

That's pretty neat.

But it seems that this will suffer from the same loss of sharing problem
as we get with overloaded CAFs.  That is, if I calculate:

   let
     a :: ARBITRARY_PRECISION_REAL
     a = 1
     b = a+a
     c = b+b
     d = c+c
     e = d+d
   in 
   e

then, instead of doing just 4 additions, I will do 15.

So I think we need to add in a memo table.


More seriously though, can we make an Eq instance?  Presumably the GNU
MP equality test doesn't test for equality but equality over the first
'n' bits for some user-specified 'n'?


--
Alastair Reid                 alastair@reid-consulting-uk.ltd.uk  
Reid Consulting (UK) Limited  http://www.reid-consulting-uk.ltd.uk/alastair/