This is the mail archive of the guile@cygnus.com mailing list for the guile project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Someone reported a bug a while ago in the bignum support: a factorial procedure wasn't giving the right answer. e.g.,: (define (factiter x tot) (if (= x 1) tot (factiter (- x 1) (* x tot)))) (define (fact x) (factiter x 1)) (define bad (fact 7350)) (define str (number->string bad)) (define len (string-length str)) (define last (substring str (- len 40) len)) (display last) should print a string of zeros. sometimes it works, but you still get the wrong answer if you type "bad" a few times. it's probably system-specific: i get the bug on i586/linux; gcc 2.7.2 and gcc 2.8.1, but only if numbers.c is optimised: -O will do. the problem seems to be in the bignum -> string conversion. this is a work-around: i don't know why it helps. --- numbers.c.orig Wed Oct 7 22:31:18 1998 +++ numbers.c Wed Oct 7 22:28:56 1998 @@ -1387,7 +1387,8 @@ SCM b; register unsigned int radix; { - SCM t = scm_copybig(b, 0); /* sign of temp doesn't matter */ + /* volatile to avoid the (fact 7350) bug. */ + volatile SCM t = scm_copybig(b, 0); /* sign of temp doesn't matter */ register SCM_BIGDIG *ds = SCM_BDIGITS(t); scm_sizet i = SCM_NUMDIGS(t); scm_sizet j = radix==16 ? (SCM_BITSPERDIG*i)/4+2