chicken-users
[Top][All Lists]

## Re: [Chicken-users] Possible numbers bug

 From: Matt Welland Subject: Re: [Chicken-users] Possible numbers bug Date: Sat, 28 May 2011 11:03:41 -0700

```What was the final word on this? Is it a real issue on some platforms?

Anyhow, I found this whole exercise pretty interesting and played with
it a bit more and observed a couple curious things:

1. Performance (see below) of guile was better than the compiled
chicken-4.6.5 for my code. It looked like it might be due to string
operations based on profile (I wasn't exactly trying to be efficient).

2. Taking the inverse exponent (i.e. result^(1/n) ) runs into trouble
at n=144. Anyone care to explain why that is and is there a numerical
methods trick to work around it?

3. Why do guile, scm and STk put out +inf.0 and chicken puts out +inf
(gauche gives #i1/0)? My hazy understanding is that +inf.0 is not the
same as +inf.

The code I used is below.
==============================
Chicken 3.4:

1000368...(2987 hidden digits)...0846700
Inverse of 144th expt is +inf
==============================
Chicken 4.6.5:

Note: re-importing already imported identifier: magnitude
/nfs/ch/disks/ch_umg_disk0003/mrwellan/tools/4/lib/chicken/6/numbers.so
...
...
1000368...(2987 hidden digits)...0846700
Inverse of 144th expt is +inf
==============================
1000368...(2987 hidden digits)...0846700
Inverse of 144th expt is inf.0
==============================
guile -s test.scm
~
1000368...(2987 hidden digits)...0846700
Inverse of 144th expt is +inf.0
==============================
scm -f test.scm
~
1000368...(2987 hidden digits)...0846700
Inverse of 144th expt is +inf.0
==============================
gosh -b -q test.scm
~
1000368...(2987 hidden digits)...0846700
Inverse of 144th expt is #i1/0
==============================
Speed (on Atom n550)

Chicken 4.6.5, compiled:   0.46s
Chicken 3.4, compiled:     37s
stk -f test.scm                  2.9s
guile -s test.scm:              0.16s
scm -f test.scm:               1.49s
gosh  -b -q test.scm:         0.46s
==============================

;(use numbers)

(define vals #f)

(define (print . strs)
(map display strs)
(display "\n"))

(define (sum-of-exponents n lim)
(if (> n lim) 0 (+ (expt n n)
(sum-of-exponents (+ n 1) lim))))
(define (pp-bignum num)
(let* ((str (number->string num))
(len (string-length str)))
(if (> len 45)
(string-append (substring str 0 7) "...(" (number->string (- len 14))
" hidden digits)..." (substring str (- len 7) len))
str)))

(define (cmpit lim)
(set! vals (make-vector (+ 2 lim)))
(let loop ((n   1)
(sum 0))
(vector-set! vals n (expt n n))
(if (> n lim)
(print (pp-bignum sum))
(loop (+ n 1)(+ sum (vector-ref vals n)))))
(let loop ((n 1))
(let ((invexpt (expt (vector-ref vals n)(/ 1.0 n))))
(if (> (abs (- invexpt n)) 0.0001)
(print "Inverse of " n "th expt is " (pp-bignum invexpt))
(if (> n lim)
(print "Done")
(loop (+ n 1)))))))

;; (print (message-digest-string (md5-primitive) (number->string
(sum-of-exponents 1 1000))))'

(cmpit 1000)
(exit)

On Fri, May 27, 2011 at 2:00 PM, David N Murray <address@hidden> wrote:
> On May 27, Kon Lovett scribed:
>
>>
>> Chicken x86:
>>
> sauron:chicken-4.7.0 dnm\$ csi -v
>
> CHICKEN
> (c)2008-2011 The Chicken Team
> (c)2000-2007 Felix L. Winkelmann
> Version 4.7.0
> macosx-unix-gnu-x86-64 [ 64bit manyargs dload ptables ]
> compiled 2011-05-26 on sauron.local (Darwin)
>
> sauron:chicken-4.7.0 dnm\$ csi -b -n -q -e '(use md5 message-digest
> numbers) (define (sum-of-exponents n lim) (if (> n lim) 0 (+ (expt n n)
> (sum-of-exponents (+ n 1) lim)))) (print (message-digest-string
> (md5-primitive) (number->string (sum-of-exponents 1 1000))))'
> 89f880d1887706b3d1a2263b177f3352
>
> Yup, that doesn't match.  I have a debug build of x64-64 (macosx)
> available if someone wants to give me an idea on where to look.
>
> Dave
>
> _______________________________________________
> Chicken-users mailing list