0.8.2.14:
[sbcl.git] / src / code / float.lisp
index ee9dacd..14c1a79 100644 (file)
@@ -34,7 +34,8 @@
   (declare (type bit sign) (type (unsigned-byte 53) sig)
           (type (unsigned-byte 11) exp))
   (make-double-float (dpb exp sb!vm:double-float-exponent-byte
-                         (dpb (ash sig -32) sb!vm:double-float-significand-byte
+                         (dpb (ash sig -32)
+                              sb!vm:double-float-significand-byte
                               (if (zerop sign) 0 -1)))
                     (ldb (byte 32 0) sig)))
 #!+(and long-float x86)
@@ -44,7 +45,7 @@
   (make-long-float (logior (ash sign 15) exp)
                   (ldb (byte 32 32) sig)
                   (ldb (byte 32 0) sig)))
-                                       
+
 ) ; EVAL-WHEN
 \f
 ;;;; float parameters
 (defconstant least-negative-short-float least-negative-single-float)
 (defconstant least-positive-double-float (double-from-bits 0 0 1))
 #!-long-float
-(defconstant least-positive-long-float least-positive-double-float)
+(defconstant least-positive-long-float (double-from-bits 0 0 1))
 #!+(and long-float x86)
 (defconstant least-positive-long-float (long-from-bits 0 0 1))
 (defconstant least-negative-double-float (double-from-bits 1 0 1))
 #!-long-float
-(defconstant least-negative-long-float least-negative-double-float)
+(defconstant least-negative-long-float (double-from-bits 1 0 1))
 #!+(and long-float x86)
 (defconstant least-negative-long-float (long-from-bits 1 0 1))
 
      (and (zerop (ldb sb!vm:long-float-exponent-byte (long-float-exp-bits x)))
          (not (zerop x))))))
 
-(macrolet ((def (name doc single double #!+(and long-float x86) long)
-            `(defun ,name (x)
-               ,doc
-               (number-dispatch ((x float))
-                 ((single-float)
-                  (let ((bits (single-float-bits x)))
-                    (and (> (ldb sb!vm:single-float-exponent-byte bits)
-                            sb!vm:single-float-normal-exponent-max)
-                         ,single)))
-                 ((double-float)
-                  (let ((hi (double-float-high-bits x))
-                        (lo (double-float-low-bits x)))
-                    (declare (ignorable lo))
-                    (and (> (ldb sb!vm:double-float-exponent-byte hi)
-                            sb!vm:double-float-normal-exponent-max)
-                         ,double)))
-                 #!+(and long-float x86)
-                 ((long-float)
-                  (let ((exp (long-float-exp-bits x))
-                        (hi (long-float-high-bits x))
-                        (lo (long-float-low-bits x)))
-                    (declare (ignorable lo))
-                    (and (> (ldb sb!vm:long-float-exponent-byte exp)
-                            sb!vm:long-float-normal-exponent-max)
-                         ,long)))))))
-
-  (def float-infinity-p
-    "Return true if the float X is an infinity (+ or -)."
-    (zerop (ldb sb!vm:single-float-significand-byte bits))
-    (and (zerop (ldb sb!vm:double-float-significand-byte hi))
-        (zerop lo))
-    #!+(and long-float x86)
-    (and (zerop (ldb sb!vm:long-float-significand-byte hi))
-        (zerop lo)))
-
-  (def float-nan-p
-    "Return true if the float X is a NaN (Not a Number)."
-    (not (zerop (ldb sb!vm:single-float-significand-byte bits)))
-    (or (not (zerop (ldb sb!vm:double-float-significand-byte hi)))
-       (not (zerop lo)))
-    #!+(and long-float x86)
-    (or (not (zerop (ldb sb!vm:long-float-significand-byte hi)))
-       (not (zerop lo))))
-
-  (def float-trapping-nan-p
-    "Return true if the float X is a trapping NaN (Not a Number)."
-    (zerop (logand (ldb sb!vm:single-float-significand-byte bits)
-                  sb!vm:single-float-trapping-nan-bit))
-    (zerop (logand (ldb sb!vm:double-float-significand-byte hi)
-                  sb!vm:double-float-trapping-nan-bit))
-    #!+(and long-float x86)
-    (zerop (logand (ldb sb!vm:long-float-significand-byte hi)
-                  sb!vm:long-float-trapping-nan-bit))))
+(defmacro !define-float-dispatching-function
+    (name doc single double #!+(and long-float x86) long)
+  `(defun ,name (x)
+    ,doc
+    (number-dispatch ((x float))
+     ((single-float)
+      (let ((bits (single-float-bits x)))
+       (and (> (ldb sb!vm:single-float-exponent-byte bits)
+               sb!vm:single-float-normal-exponent-max)
+            ,single)))
+     ((double-float)
+      (let ((hi (double-float-high-bits x))
+           (lo (double-float-low-bits x)))
+       (declare (ignorable lo))
+       (and (> (ldb sb!vm:double-float-exponent-byte hi)
+               sb!vm:double-float-normal-exponent-max)
+            ,double)))
+     #!+(and long-float x86)
+     ((long-float)
+      (let ((exp (long-float-exp-bits x))
+           (hi (long-float-high-bits x))
+           (lo (long-float-low-bits x)))
+       (declare (ignorable lo))
+       (and (> (ldb sb!vm:long-float-exponent-byte exp)
+               sb!vm:long-float-normal-exponent-max)
+            ,long))))))
+
+(!define-float-dispatching-function float-infinity-p
+  "Return true if the float X is an infinity (+ or -)."
+  (zerop (ldb sb!vm:single-float-significand-byte bits))
+  (and (zerop (ldb sb!vm:double-float-significand-byte hi))
+       (zerop lo))
+  #!+(and long-float x86)
+  (and (zerop (ldb sb!vm:long-float-significand-byte hi))
+       (zerop lo)))
+
+(!define-float-dispatching-function float-nan-p
+  "Return true if the float X is a NaN (Not a Number)."
+  (not (zerop (ldb sb!vm:single-float-significand-byte bits)))
+  (or (not (zerop (ldb sb!vm:double-float-significand-byte hi)))
+      (not (zerop lo)))
+  #!+(and long-float x86)
+  (or (not (zerop (ldb sb!vm:long-float-significand-byte hi)))
+      (not (zerop lo))))
+
+(!define-float-dispatching-function float-trapping-nan-p
+  "Return true if the float X is a trapping NaN (Not a Number)."
+  (zerop (logand (ldb sb!vm:single-float-significand-byte bits)
+                sb!vm:single-float-trapping-nan-bit))
+  (zerop (logand (ldb sb!vm:double-float-significand-byte hi)
+                sb!vm:double-float-trapping-nan-bit))
+  #!+(and long-float x86)
+  (zerop (logand (ldb sb!vm:long-float-significand-byte hi)
+                sb!vm:long-float-trapping-nan-bit)))
 
 ;;; If denormalized, use a subfunction from INTEGER-DECODE-FLOAT to find the
 ;;; actual exponent (and hence how denormalized it is), otherwise we just
 (defun float-sign (float1 &optional (float2 (float 1 float1)))
   #!+sb-doc
   "Return a floating-point number that has the same sign as
-   float1 and, if float2 is given, has the same absolute value
-   as float2."
+   FLOAT1 and, if FLOAT2 is given, has the same absolute value
+   as FLOAT2."
   (declare (float float1 float2))
   (* (if (etypecase float1
           (single-float (minusp (single-float-bits float1)))
 (defun float-radix (x)
   #!+sb-doc
   "Return (as an integer) the radix b of its floating-point argument."
-  ;; ANSI says this function "should signal an error if [..] argument
-  ;; is not a float". Since X is otherwise ignored, Python doesn't
-  ;; check the type by default, so we have to do it ourself:
-  (unless (floatp x)
-    (error 'type-error :datum x :expected-type 'float))
   2)
 \f
 ;;;; INTEGER-DECODE-FLOAT and DECODE-FLOAT
          (t
           (values (logior sig sb!vm:single-float-hidden-bit) biased sign)))))
 
-;;; Like INTEGER-DECODE-SINGLE-DENORM, only doubly so.
+;;; like INTEGER-DECODE-SINGLE-DENORM, only doubly so
 (defun integer-decode-double-denorm (x)
   (declare (type double-float x))
   (let* ((high-bits (double-float-high-bits (abs x)))
                  (truly-the fixnum (- biased extra-bias))
                  sign)))))
 
-;;; Like INTEGER-DECODE-SINGLE-FLOAT, only doubly so.
+;;; like INTEGER-DECODE-SINGLE-FLOAT, only doubly so
 (defun integer-decode-double-float (x)
   (declare (double-float x))
   (let* ((abs (abs x))
                         bits))
                   biased sign)))))
 
-;;; Like DECODE-SINGLE-DENORM, only doubly so.
+;;; like DECODE-SINGLE-DENORM, only doubly so
 (defun decode-double-denorm (x)
   (declare (double-float x))
   (multiple-value-bind (sig exp sign) (integer-decode-double-denorm x)
            (truly-the fixnum (+ exp sb!vm:double-float-digits))
            (float sign x))))
 
-;;; Like DECODE-SINGLE-FLOAT, only doubly so.
+;;; like DECODE-SINGLE-FLOAT, only doubly so
 (defun decode-double-float (x)
   (declare (double-float x))
   (let* ((abs (abs x))