really fix float rounding on 32-bit platforms
authorChristophe Rhodes <csr21@cantab.net>
Fri, 7 Oct 2011 11:39:33 +0000 (12:39 +0100)
committerChristophe Rhodes <csr21@cantab.net>
Fri, 7 Oct 2011 19:35:35 +0000 (20:35 +0100)
Now, as well as not giving completely the wrong answer for most
larger-than-fixnum double floats, we additionally don't try to perform
arithmetic on NIL for larger-than-fixnum single-floats.

src/code/float.lisp
tests/float.pure.lisp

index 483a6cf..3b5690b 100644 (file)
                                  (cond
                                    ((> fractional-bits 0.5bits) (1+ shifted))
                                    ((< fractional-bits 0.5bits) shifted)
-                                   (t (if (oddp shifted) (1+ shifted) shifted)))))
-                    ))
+                                   (t (if (oddp shifted) (1+ shifted) shifted))))
+                               shifted)))
              (if (minusp number)
                  (- rounded)
                  rounded)))))))
index e2aed69..60b3a36 100644 (file)
   (assert (= (round 1073741823.3d0) 1073741823))
   (assert (= (round 1073741823.5d0) 1073741824))
   (assert (= (round 1073741823.7d0) 1073741824)))
+
+(with-test (:name :round-single-to-bignum)
+  (assert (= (round 1e14) 100000000376832))
+  (assert (= (round 1e19) 9999999980506447872)))