# infinite (fractional) precision

Ketil Z. Malde ketil@ii.uib.no
10 Oct 2002 11:56:43 +0200

```Ashley Yakeley <ashley@semantic.org> writes:

> At 2002-10-10 01:29, Ketil Z. Malde wrote:
>
> >I realize it's probably far from trivial, e.g. comparing two equal
> >numbers could easily not terminate, and memory exhaustion would
> >probably arise in many other cases.
>
> I considered doing something very like this for real (computable)
> numbers, but because I couldn't properly make the type an instance of Eq,

instance Eq InfPoint where
x (==) y == compareToPrecision epsilon x y
where epsilon = unsafePerformIO ...

A bit (perhaps not just a bit either) ugly, but comparable to using a
fixed point, no?

> I left it. Actually it was worse than that. Suppose I'm adding two
> numbers, both of which are actually 1, but I don't know that:
>
>  1.000000000.... +
>  0.999999999....

Could it be represented as

data InfPoint = IP Integer FractionalPart
data FractionalPart = FP Word8 | Repeat FractionalPart

Thus:

1.00.. -> IP 1 (Repeat (FP 0))
0.99.. -> IP 0 (Repeat (FP 9))

where the latter could be normalized to the former?

Okay, you still get the problem comparing

sqrt 2 == sqrt (sqrt 4)

But wait a second:

> The trouble is, as far as I know with a finite number of digits, the

>  1.9999999999937425

> or it might be

> 2.0000000000013565

> ...so I can't actually generate any digits at all.

But if you want to calcualte the sum for a finite number of digits, do
you really care if you calculate it as

1.999..9
or      2.000..0
?

-kzm
--
If I haven't seen further, it is by standing in the footprints of giants

```