Re: how to compute

"Pierpaolo BERNARDI" <[email protected]> Wed, 17 May 2006 02:26:33 +0200
Newsgroups gmane.lisp.allegro
Message-ID <op.s9n56jdr8t8izc@eraora>
On Tue, 16 May 2006 20:14:18 +0200, Yaling Zheng <[email protected]> wrote:

>
> Does any one know how to calculate the exact value of the ratio (such
> as 6042715942219502152353483497843569525253244555916134 over 200)?
>
> CL-USER(68): (float (/ 6042715942219502152353483497843569525253244555916134 200))
> #.EXCL::*INFINITY-SINGLE*

In case you just want to *see* the result as a decimal number,
the following should work for positive rationals (to work also
for negative rationals it must be tweaked a little):

(defun as-decimal (r)
   (multiple-value-bind (int dec) (truncate r)
     (format nil "~a~a"
             int
             (subseq (write-to-string (float dec)) 1))))

CL-USER(146): (as-decimal (/ 6042715942219502152353483497843569525253244555916134 200))
"30213579711097510761767417489217847626266222779580.67"


BTW, I think the following is a small bug in acl:

CL-USER(153): 6042715942219502152353483497843569525253244555916134.0
Error: This integer is too large to be converted to single float:
        343488630960564478300511837005615234375
   [condition type: SIMPLE-ERROR]

(there's no integer in my code, and the value printed is bogus)

Cheers
P.