[info-mcl] Issue 32 FIX and Knock-on Effects of (float ) returning single rather than double-floats
wws2 new
ww.s2 at ukonline.co.uk
Sun Mar 28 15:34:12 CDT 2010
I recently discovered ISSUE 32 which at first appears to be a problem related to reading floats.
> Welcome to Macintosh Common Lisp Version 5.2.1!
> ? (read-from-string "0.6146281499692686 ")
> 0.61462814
> 19
>
> ? (setf *READ-DEFAULT-FLOAT-FORMAT* 'double-float)
> DOUBLE-FLOAT
>
> ? (read-from-string "0.6146281499692686 ")
> 0.6146281332167046 <<<<<< WHAT?
> 19
> ? (read-from-string "0.9847365829640571 ")
> 0.9847365829640571
> 19
> ?
Terje tracked this down as far as FIDE (which handles the two cases differently).
After further work, I have found that the underlying cause is that in RMCL 5.2 the float function defaults to single-floats, rather than double-flats as in recent versions of MCL. The knock on effect is that various source code locations need to be reverified. For the bug in question the problem is that the vector float-powers-of-5 needs to be filled with double-floats, as illustrated below. This fixes the above read-from-string case and makes the vector the same as in MCL.
I worry that there may be other locations in the source code where the float function needs to be modified so as to produce double floats. I have searched through the source code to see that most cases seem to have a second argument, but hopefully the math and source experts can have a further go.
> (setq float-powers-of-5 (make-array 23))
> (let ((array ccl::float-powers-of-5))
> (dotimes (i 23)
> ; was (setf (svref array i) (float (expt 5 i)))
> (setf (svref array i) (float (expt 5 i) 1.0d0)) ;;;<<< here is the change
> )
> )
More information about the info-mcl
mailing list