Lisp HUG Maillist Archive

Double precision Floor bug?

I noticed this at work in LispWorks 5.1, but I get the same result in 
LispWorks 6.1 when I just tried it at home:

(let ((x 0.59d0)
       (d 0.01d0))
   (multiple-value-bind (div rem) (floor x d)
     (format t "floor(~A ~A) => ~A ~A~%" x d div rem)
     (multiple-value-bind (div2 rem2) (floor rem d)
       (format t "floor(~A ~A) => ~A ~A~%" rem d div2 rem2))))

floor(0.59D0 0.01D0) => 58 0.010000000000000009D0
floor(0.010000000000000009D0 0.01D0) => 1 8.673617379884036D-18

I would have expected the first result to be 59 0.000000000000000009D0

At first I thought it might some kind of floating-point 
rounding/precision issue, but I don't think that would explain the 
second value returned by floor being greater than the second argument 
given to floor.

Regards
Guy Footring

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Re: Double precision Floor bug?

Neither .59 nor .01 have exact double precision representation, so these
are rounded (at read time) to 
.59 ->  5314247560297185/9007199254740992
.01 ->  5764607523034235/576460752303423488

everything is working correctly, it's just not working on the numbers you
thought it was working on.

On Fri, Jun 1, 2012 at 1:30 PM, Guy Footring <Guy@footring.net> wrote:

I noticed this at work in LispWorks 5.1, but I get the same result in LispWorks 6.1 when I just tried it at home:

(let ((x 0.59d0)
     (d 0.01d0))
 (multiple-value-bind (div rem) (floor x d)
   (format t "floor(~A ~A) => ~A ~A~%" x d div rem)
   (multiple-value-bind (div2 rem2) (floor rem d)
     (format t "floor(~A ~A) => ~A ~A~%" rem d div2 rem2))))

floor(0.59D0 0.01D0) => 58 0.010000000000000009D0
floor(0.010000000000000009D0 0.01D0) => 1 8.673617379884036D-18

I would have expected the first result to be 59 0.000000000000000009D0

At first I thought it might some kind of floating-point rounding/precision issue, but I don't think that would explain the second value returned by floor being greater than the second argument given to floor.

Regards
Guy Footring

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html




--
~jrm
Updated at: 2020-12-10 08:36 UTC