[comp.sys.ibm.pc.misc] IBM PC XScheme numbers representation?

alfred@dutepp1.tudelft.nl (Alfred Kayser) (07/24/90)

Byron c go writes:
>I got XScheme for the PC today and am relatively pleased with the following
>exception...
>     (fib 9) => 2432
>     (fib 10) => -8448
>(where fib is defined as (lambda (x) (if (= x 1) 1 (* x (fib (-1+ x))))))
        ^^^ I know that fib and fac (faculty) are both used for testing the
number system of Scheme implementations, but that is no reason to swap them.
It should be:
	(define (fac n) (if (< n 2) 1 (* n (fac (- n 1)))))
and     (define (fib n) (if (< n 2) 1 (+ (fib (- n 1)) (fib (- n 2)))))
Note the subtle difference.

But returning to the original question: XScheme uses long integers (32 bits)
and therefore will (fac 9) and (fac 10) overflow and return invalid results.
They should be: 362880 and 3628800.

>it would seem that there is some kind of overflow error going on here.
Indeed.
>does anybody know of a patch to the source code that fixes this?  perhaps
>a change in the representation of integers?
This is not very simple. Big integers (unlimited length) are not simple 
to implement.

>"Help... I've become the anti-Dan_Kogai!  (I've started writing Scheme code
> and translating it to C for my programming projects!)"		- me
The bignumber system as supported by most Scheme implementations (except
XScheme) doesn't exist in C.

                      Hope this helps. Alfred
--
-- Ir. Alfred Kayser. PACS, OS/2, TCP/IP. --- Email: AKayser@et.tudelft.nl --
-- CARDIT, Delft University of Technology ------------ Tel: (31)-15-786179 --
-- P.O.Box 5031, 2600 GA Delft, The Netherlands ------ Fax: (31)-15-784898 --

grunwald@foobar.colorado.edu (Dirk Grunwald) (07/26/90)

>>>>> On 24 Jul 90 08:54:24 GMT, alfred@dutepp1.tudelft.nl (Alfred Kayser) said:
AK> The bignumber system as supported by most Scheme implementations (except
AK> XScheme) doesn't exist in C.
--

not true. libg++ for the Gnu G++ compiler provides classes Integer
(basically a bignum) and Rational. They're fast too.

alfred@dutepp1.tudelft.nl (Alfred Kayser) (07/27/90)

grunwald@foobar.colorado.edu (Dirk Grunwald) writes:
>>>>>> On 24 Jul 90 08:54:24 GMT, alfred@dutepp1.tudelft.nl (Alfred Kayser) said:
>AK> The bignumber system as supported by most Scheme implementations (except
>AK> XScheme) doesn't exist in C.
>not true. libg++ for the Gnu G++ compiler provides classes Integer
>(basically a bignum) and Rational. They're fast too.
So it may be, but to my understanding is C++ not equal to C.
No flames intended.
--
-- Ir. Alfred Kayser. PACS, OS/2, TCP/IP. --- Email: AKayser@et.tudelft.nl --
-- CARDIT, Delft University of Technology ------------ Tel: (31)-15-786179 --
-- P.O.Box 5031, 2600 GA Delft, The Netherlands ------ Fax: (31)-15-784898 --