[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
doubling your bits
Date: Tue, 24 Nov 87 14:16 EST
From: Bill Long <WJL@ZERMATT.LCS.MIT.EDU>
Having just noticed that:
(coerce .1 'double-float) = 0.10000000149011612d0
I was wondering...
1) How much slower would coerce be if it added decimal zeros?
eg., (coerce .1 'double-float) -> 0.1d0
2) How do other Commonlisp implementations handle this?
3) If I really want the additional digits to be zeros, is there any
faster way than something like:
(coerce (/ (round .1 .00000001) 100000000) 'double-float)
Happy Thanksgiving!
-Bill Long
what you really want is (coerce .1 'double-1decimal0-float)
The problem really lies in the fact that in binary the decimal fraction
1/10 can't be fully expressed (its an infinitely repeating fraction) so
what you see is what gets represented in the float. Chances are the
mantissa is just extended with zeros. What you really want is
(coerce 1/10 'double-float) -> 0.1d0. What your seeing is the reader
converting the .1 then doing the coerce on the single float...