1.1.13: will be tagged as "sbcl-1.1.13"
[sbcl.git] / src / code / toplevel.lisp
index 1c00f03..2ce86e7 100644 (file)
@@ -164,16 +164,16 @@ means to wait indefinitely.")
 
 (defun split-seconds-for-sleep (seconds)
   (declare (optimize speed))
+  ;; KLUDGE: This whole thing to avoid consing floats
   (flet ((split-float ()
-           ;; KLUDGE: This whole thing to avoid consing floats
            (let ((whole-seconds (truly-the fixnum (%unary-truncate seconds))))
              (values whole-seconds
-                     (truly-the fixnum
-                                (%unary-truncate (* (- seconds whole-seconds)
-                                                    (load-time-value 1s9 t))))))))
+                     (truly-the (integer 0 #.(expt 10 9))
+                                (%unary-truncate (* (- seconds (float whole-seconds))
+                                                    (load-time-value 1f9 t))))))))
     (declare (inline split-float))
     (typecase seconds
-      ((single-float 0s0 #.(float most-positive-fixnum 1s0))
+      ((single-float 0f0 #.(float most-positive-fixnum 1f0))
        (split-float))
       ((double-float 0d0 #.(float most-positive-fixnum 1d0))
        (split-float))
@@ -181,11 +181,15 @@ means to wait indefinitely.")
        (multiple-value-bind (quot rem) (truncate (numerator seconds)
                                                  (denominator seconds))
          (values quot
-                 (truncate (* rem (/ 1000000000 (denominator seconds)))))))
+                 (* rem
+                    (if (typep 1000000000 'fixnum)
+                        (truncate 1000000000 (denominator seconds))
+                        ;; Can't truncate a bignum by a fixnum without consing
+                        (* 10 (truncate 100000000 (denominator seconds))))))))
       (t
        (multiple-value-bind (sec frac)
            (truncate seconds)
-         (values sec (truncate frac (load-time-value 1s-9 t))))))))
+         (values sec (truncate frac (load-time-value 1f-9 t))))))))
 
 (defun sleep (seconds)
   #!+sb-doc