From: Robert Maas, http://tinyurl.com/uh3t
Subject: Likely bug in PowerLisp parse-integer
Date:
Message-ID: <REM-2009feb21-001@Yahoo.Com>
Comparison between CMUCL and PowerLisp, where PowerLisp seems to have a bug:
(format nil "~20r" (expt 10 100))
PWL: "D4DJ27751E811E02JC8J525841500000000000000000000000000000000000000000000000000"
CMU: "D4DJ27751E811E02JC8J525841500000000000000000000000000000000000000000000000000"
;Correct so-far.
(parse-integer * :radix 20)
PWL: 10000000000000000000000403522526612396441600000000000000000000000000000000000000000000000000000000000 77
CMU: 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
;Wrong answer in PowerLisp.
CLISP on teh.intarweb.org agrees with CMUCL.
Does anybody know of a patch to fix parse-integer in PowerLisp 2.01 68k?
I can manually do the string-to-bigInteger conversion in a LOOP,
so this bug might not be a show-stapper,
but does anybody know of a deeper bug in BIGNUM arithmetic in PowerLisp?
From: Pascal J. Bourguignon
Subject: Re: Likely bug in PowerLisp parse-integer
Date:
Message-ID: <87iqn3dz0u.fsf@galatea.local>
·············@rem.intarweb.org (Robert Maas, http://tinyurl.com/uh3t) writes:
> Comparison between CMUCL and PowerLisp, where PowerLisp seems to have a bug:
>
> (format nil "~20r" (expt 10 100))
> PWL: "D4DJ27751E811E02JC8J525841500000000000000000000000000000000000000000000000000"
> CMU: "D4DJ27751E811E02JC8J525841500000000000000000000000000000000000000000000000000"
> ;Correct so-far.
>
> (parse-integer * :radix 20)
> PWL: 10000000000000000000000403522526612396441600000000000000000000000000000000000000000000000000000000000 77
> CMU: 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
> ;Wrong answer in PowerLisp.
>
> CLISP on teh.intarweb.org agrees with CMUCL.
>
> Does anybody know of a patch to fix parse-integer in PowerLisp 2.01 68k?
Why do you want to fix parse-integer?
You don't know whether the problem is in parse-integer, or in bignum arithmetic.
(progn
(terpri)
(loop
:named :check-position
:for ch :in '(#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9 #\A #\B #\C #\D #\E #\F #\G #\H #\I #\J)
:for i :from 0 :below 20
:do (assert (= i (position ch "0123456789ABCDEFGHIJ"))))
(format t "~&POSITION seems to work~%")
(let ((digits (loop
:named :get-the-digits
:for ch :across "D4DJ27751E811E02JC8J525841500000000000000000000000000000000000000000000000000"
:collect (position ch "0123456789ABCDEFGHIJ"))))
(assert (equal digits '(13 4 13 19 2 7 7 5 1 14 8 1 1 14 0 2 19 12 8 19 5 2 5 8 4 1 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)))
(format t "~&LOOP :ACROSS :COLLECT seems to work~%")
(print digits)
(let ((big (loop
:named :compute-the-big-num
:for d :in digits
:for p = 0 :then n
:for n = d :then (+ (* n 20) d)
:do (multiple-value-bind (q r) (floor n 20)
(assert (= q p))
(assert (= r d)))
:finally (assert (= n 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000))
(format t "~&BIGNUM +, *, FLOOR, and = seem to work~%")
(return-from :compute-the-big-num n))))
(assert (equal (prin1-to-string big) "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"))
(format t "~&PRIN1-TO-STRING of bignums seems to work~%")
(terpri) (princ (prin1-to-string big))
(print big)
(assert (equal digits
(print (reverse (loop
:named :print-number
:with q :with r
:for n = big :then q
:while (plusp n)
:do (multiple-value-setq (q r) (floor n 20))
:collect r)))))
(format t "~&Bignum PLUSP and FLOOR seem to work~%")))
:success)
> I can manually do the string-to-bigInteger conversion in a LOOP,
> so this bug might not be a show-stapper,
> but does anybody know of a deeper bug in BIGNUM arithmetic in PowerLisp?
You are probably the most expert person on PowerLisp remaining in
function. What do you think?
--
__Pascal Bourguignon__