division with huge numbers

Hannah Schroeter uk1o@rz.uni-karlsruhe.de
Wed, 21 Mar 2001 11:56:38 +0100


Hello!

On Wed, Mar 21, 2001 at 04:56:21PM +0900, Satoru Takabayashi wrote:
> Hi,

> I got an unexpected result with division with huge numbers.

>   % hugs
>   Prelude> :version
>   -- Hugs Version February 2001 
>   Prelude> 21099067259124990080755354669061414400 / 708801874985091845381344307009569161216
>   0.0

> Is it a bug or just a limitation? I think it should be something like:

>   % guile  # a scheme interpreter
>   guile> (/ 21099067259124990080755354669061414400 708801874985091845381344307009569161216)
>   0.0297672283380582

I just tested it. At least my installation of hugs seems to treat
Double equally as Float (single precision IEEE).

And in single precision float, your divisor is already too large and
thus is converted to infinity.

The scheme interpreter you tested seems to treat both numbers as bigint,
divides them and *then* converts the result to double float.

You can do this in Haskell, too:
let a = 21099067259124990080755354669061414400
    b = 708801874985091845381344307009569161216
in fromRational (a/b :: Rational) :: Double

However, scheme48 yields:

> (define a 21099067259124990080755354669061414400)
> (define b 708801874985091845381344307009569161216)
> (/ a b)
169584838438183112145988897481525/5697031531194475351894806994354176

And clisp (a Common Lisp implementation):

[1]> (defconstant *a* 21099067259124990080755354669061414400)
*A*
[2]> (defconstant *b* 708801874985091845381344307009569161216)
*B*
[3]> (/ *a* *b*)
169584838438183112145988897481525/5697031531194475351894806994354176

Kind regards,

Hannah.