(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))
;;; 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)
(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
#!-sb-fluid (declaim (maybe-inline float-precision))
(defun float-precision (f)
#!+sb-doc
- "Returns a non-negative number of significant digits in its float argument.
+ "Return a non-negative number of significant digits in its float argument.
Will be less than FLOAT-DIGITS if denormalized or zero."
(macrolet ((frob (digits bias decode)
`(cond ((zerop f) 0)
(defun float-sign (float1 &optional (float2 (float 1 float1)))
#!+sb-doc
- "Returns a floating-point number that has the same sign as
+ "Return a floating-point number that has the same sign as
float1 and, if float2 is given, has the same absolute value
as float2."
(declare (float float1 float2))
(defun float-radix (x)
#!+sb-doc
"Return (as an integer) the radix b of its floating-point argument."
- (declare (type float x))
;; 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:
;;; Dispatch to the correct type-specific i-d-f function.
(defun integer-decode-float (x)
#!+sb-doc
- "Returns three values:
+ "Return three values:
1) an integer representation of the significand.
2) the exponent for the power of 2 that the significand must be multiplied
by to get the actual value. This differs from the DECODE-FLOAT exponent
;;; Dispatch to the appropriate type-specific function.
(defun decode-float (f)
#!+sb-doc
- "Returns three values:
+ "Return three values:
1) a floating-point number representing the significand. This is always
between 0.5 (inclusive) and 1.0 (exclusive).
2) an integer representing the exponent.
;;; Dispatch to the correct type-specific scale-float function.
(defun scale-float (f ex)
#!+sb-doc
- "Returns the value (* f (expt (float 2 f) ex)), but with no unnecessary loss
+ "Return the value (* f (expt (float 2 f) ex)), but with no unnecessary loss
of precision or overflow."
(number-dispatch ((f float))
((single-float)
(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