Xref: utzoo comp.lang.scheme:1440 comp.sys.ibm.pc.misc:232 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!hp4nl!dutrun!duteca!dutepp1!alfred From: alfred@dutepp1.tudelft.nl (Alfred Kayser) Newsgroups: comp.lang.scheme,comp.sys.ibm.pc.misc Subject: Re: IBM PC XScheme numbers representation? Message-ID: <.648809664@dutepp1> Date: 24 Jul 90 08:54:24 GMT References: <1990Jul23.075719.8352@agate.berkeley.edu> Sender: news@duteca Lines: 34 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 --