X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcode%2Ffloat.lisp;h=a3a0114a7f752f74f4a94239572b150d64baef9a;hb=82cd148d729c241e79c8df04b700beec1b7c55de;hp=88ffb3784ef85c8737a076e77b8001f28ce238e6;hpb=b049b6c0e09815ca01f79090dd8343efcaac72a1;p=sbcl.git diff --git a/src/code/float.lisp b/src/code/float.lisp index 88ffb37..a3a0114 100644 --- a/src/code/float.lisp +++ b/src/code/float.lisp @@ -170,7 +170,7 @@ (defun float-radix (x) #!+sb-doc "Return (as an integer) the radix b of its floating-point argument." - (declare (ignore x)) + (declare (ignore x) (type float x)) 2) ;;;; INTEGER-DECODE-FLOAT and DECODE-FLOAT @@ -630,7 +630,7 @@ (frob %long-float long-float)) ;;; Convert a ratio to a float. We avoid any rounding error by doing an -;;; integer division. Accuracy is important to preserve read/print +;;; integer division. Accuracy is important to preserve print-read ;;; consistency, since this is ultimately how the reader reads a float. We ;;; scale the numerator by a power of two until the division results in the ;;; desired number of fraction bits, then do round-to-nearest. @@ -810,12 +810,13 @@ (truly-the fixnum (%unary-round number)) (multiple-value-bind (bits exp) (integer-decode-float number) (let* ((shifted (ash bits exp)) - (rounded (if (and (minusp exp) - (oddp shifted) - (eql (logand bits - (lognot (ash -1 (- exp)))) - (ash 1 (- -1 exp)))) - (1+ shifted) + (rounded (if (minusp exp) + (let ((fractional-bits (logand bits (lognot (ash -1 (- exp))))) + (0.5bits (ash 1 (- -1 exp)))) + (cond + ((> fractional-bits 0.5bits) (1+ shifted)) + ((< fractional-bits 0.5bits) shifted) + (t (if (oddp shifted) (1+ shifted) shifted)))) shifted))) (if (minusp number) (- rounded)