[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
This is right, of course. We get so many complaints about this from
people who are not familiar with floating point numbers, that in 7.2 we
have added extensions so that you can see the precise value of the
floating point number you are using. For example,
(write .1 :exact-float-value t) ==> 0.100000001490116119384765625
which is the closest IEEE floating point number to 1/10. When you asked
for the closest double-precision number to that, you got it.
If you still don't understand this, you should consult a textbook on
floating point.
I was wondering...
1) How much slower would coerce be if it added decimal zeros?
eg., (coerce .1 'double-float) -> 0.1d0
It would be wrong.
2) How do other Commonlisp implementations handle this?
It depends on what floating-point format they support. Any
implementation of IEEE floating point in any language will do 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)
How about (coerce 1/10 'double-float)?
Happy Thanksgiving!
-Bill Long