[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Bug in the numbers egg?
From: |
Alex Shinn |
Subject: |
Re: [Chicken-users] Bug in the numbers egg? |
Date: |
Wed, 10 Aug 2005 20:37:21 -0500 |
User-agent: |
Wanderlust/2.10.1 (Watching The Wheels) SEMI/1.14.6 (Maruoka) FLIM/1.14.6 (Marutamachi) APEL/10.6 Emacs/21.3 (i386-pc-linux-gnu) MULE/5.0 (SAKAKI) |
At Wed, 10 Aug 2005 23:05:06 +0200, Thomas Chust wrote:
>
> #;2> (expt 10 100)
> 10000000000000110891155767964156222877689497504522960006971153529700550125477736178357726682741211136
The docs already note that expt gives incorrect results for exact
numbers. In the meantime you can use something like this:
(define (power base e) ; like expt but e must be an integer
(define (square x) (* x x))
(if (negative? e)
(/ 1 (power base (- e)))
(let lp ((res 1) (e e))
(cond
((zero? e) res)
((even? e) (* res (square (lp 1 (quotient e 2)))))
(else (lp (* res base) (- e 1)))))))
#;5> (power 10 100)
1000000000000000000000000000000000000000000000000000000000000000000000000000000\0000000000000000000000
--
Alex