diff --git a/src/compiler/float-tran.lisp b/src/compiler/float-tran.lisp index 4aecd5cd2760f2b5715ce730c09e5bd819093b85..ff094749e76c3a8955c0fca4a12c44fdff365926 100644 --- a/src/compiler/float-tran.lisp +++ b/src/compiler/float-tran.lisp @@ -2057,13 +2057,13 @@ (when x (nth-value 1 (decode-float x)))) (min-exp () - ;; Use decode-float on 0 of the appropriate type to find - ;; the min exponent. If we don't know the actual number - ;; format, use double, which has the widest range - ;; (including double-double-float). - (if (numeric-type-format arg) - (nth-value 1 (decode-float (coerce 0 (numeric-type-format arg)))) - (nth-value 1 (decode-float (coerce 0 'double-float))))) + ;; Use decode-float on the least positive float of the + ;; appropriate type to find the min exponent. If we don't + ;; know the actual number format, use double, which has the + ;; widest range (including double-double-float). + (nth-value 1 (decode-float (if (eq 'single-float (numeric-type-format arg)) + least-positive-single-float + least-positive-double-float)))) (max-exp () ;; Use decode-float on the most postive number of the ;; appropriate type to find the max exponent. If we don't diff --git a/tests/float-tran.lisp b/tests/float-tran.lisp index 9c818824ba70bab59e5c942e385475f36c5647a6..713d3992964db4ee64207b082e24ec337c18bbcc 100644 --- a/tests/float-tran.lisp +++ b/tests/float-tran.lisp @@ -1,3 +1,4 @@ + ;; Tests for various float transformations. (defpackage :float-tran-tests @@ -14,4 +15,18 @@ (assert-equalp (c::make-member-type :members (list 1f0)) (c::decode-float-sign-derive-type-aux (c::specifier-type '(single-float (0f0)))))) - \ No newline at end of file +(define-test decode-float-exp + "Test type derivation of the exponent from decode-float" + (assert-equalp (c::specifier-type '(integer -148 128)) + (c::decode-float-exp-derive-type-aux + (c::specifier-type 'single-float))) + (assert-equalp (c::specifier-type '(integer -1073 1024)) + (c::decode-float-exp-derive-type-aux + (c::specifier-type 'double-float))) + #+double-double + (assert-equalp (c::specifier-type '(integer -1073 1024)) + (c::decode-float-exp-derive-type-aux + (c::specifier-type 'double-double-float))) + (assert-equalp (c::specifier-type '(integer 2 8)) + (c::decode-float-exp-derive-type-aux + (c::specifier-type '(double-float 2d0 128d0)))))