X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcode%2Ffloat.lisp;h=ffd5f5b4ed7098925d849f04f313e82effeeb9ca;hb=872175cd9cb5b4966a36d4bd92421cc407a0355b;hp=6e71f91d4382bac1e030f738385bbb60fe8c8469;hpb=c8af15e61b030c8d4b0e950bc9b7618530044618;p=sbcl.git diff --git a/src/code/float.lisp b/src/code/float.lisp index 6e71f91..ffd5f5b 100644 --- a/src/code/float.lisp +++ b/src/code/float.lisp @@ -19,9 +19,10 @@ (eval-when (:compile-toplevel :load-toplevel :execute) -;;; These functions let us create floats from bits with the significand -;;; uniformly represented as an integer. This is less efficient for double -;;; floats, but is more convenient when making special values, etc. +;;; These functions let us create floats from bits with the +;;; significand uniformly represented as an integer. This is less +;;; efficient for double floats, but is more convenient when making +;;; special values, etc. (defun single-from-bits (sign exp sig) (declare (type bit sign) (type (unsigned-byte 24) sig) (type (unsigned-byte 8) exp)) @@ -119,8 +120,10 @@ ;;; We don't want to do these DEFCONSTANTs at cross-compilation time, ;;; because the cross-compilation host might not support floating -;;; point infinities. -(eval-when (:load-toplevel :execute) +;;; point infinities. Putting them inside a LET remove +;;; top-level-formness, so that any EVAL-WHEN trickiness in the +;;; DEFCONSTANT forms is suppressed. +(let () (defconstant single-float-positive-infinity (single-from-bits 0 (1+ sb!vm:single-float-normal-exponent-max) 0)) (defconstant short-float-positive-infinity single-float-positive-infinity) @@ -143,7 +146,7 @@ (defconstant long-float-negative-infinity (long-from-bits 1 (1+ sb!vm:long-float-normal-exponent-max) (ash sb!vm:long-float-hidden-bit 32))) -) ; EVAL-WHEN +) ; LET-to-suppress-possible-EVAL-WHENs (defconstant single-float-epsilon (single-from-bits 0 (- sb!vm:single-float-bias @@ -308,9 +311,12 @@ (defun float-radix (x) #!+sb-doc - "Returns (as an integer) the radix b of its floating-point - argument." - (declare (type float x) (ignore x)) + "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) ;;;; INTEGER-DECODE-FLOAT and DECODE-FLOAT @@ -824,9 +830,9 @@ (incf scale))))))) #| -These might be useful if we ever have a machine w/o float/integer conversion -hardware. For now, we'll use special ops that uninterruptibly frob the -rounding modes & do ieee round-to-integer. +These might be useful if we ever have a machine without float/integer +conversion hardware. For now, we'll use special ops that +uninterruptibly frob the rounding modes & do ieee round-to-integer. ;;; The compiler compiles a call to this when we are doing %UNARY-TRUNCATE ;;; and the result is known to be a fixnum. We can avoid some generic