Re: how to compute
Steve Haflich <[email protected]> Tue, 16 May 2006 12:13:26 -0700
| Newsgroups | gmane.lisp.allegro |
|---|---|
| Message-ID | <13807.1147806806@bach> |
From: Yaling Zheng <[email protected]> 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* From: "Bob Giansiracusa" <[email protected]> Sure. Use bignums: (/ 6042715942219502152353483497843569525253244555916134 200) This is indeed the "exact" answer. But if your intended meaning of "exact" was really "a floating-point approximation" (:-) then you must first realize that the numeric value is outside the range of single-float. But if the ratio it is still within the range of double-float you might compute a double-float approximation this way: cl-user(11): (let* ((rat (/ 6042715942219502152353483497843569525253244555916134 200)) (num (coerce (numerator rat) 'double-float)) (den (coerce (denominator rat) 'double-float))) (/ num den)) 3.0213579711097513d+49