1.0.41.47: (EXPT 0.0 0.0) and (EXPT 0 0.0) to signal an error
authorNikodemus Siivola <nikodemus@random-state.net>
Mon, 16 Aug 2010 12:53:42 +0000 (12:53 +0000)
committerNikodemus Siivola <nikodemus@random-state.net>
Mon, 16 Aug 2010 12:53:42 +0000 (12:53 +0000)
 https://bugs.launchpad.net/sbcl/+bug/571581

 From patch by Roman Marynchack.

NEWS
package-data-list.lisp-expr
src/code/condition.lisp
src/code/irrat.lisp
tests/arith.pure.lisp
version.lisp-expr

diff --git a/NEWS b/NEWS
index e70ebe7..0efbedc 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,8 @@ changes relative to sbcl-1.0.41
     by multithreaded code.  See documentation for details.
   * enhancement: Experimental support for threading on Linux/PPC.
   * bug fix: RENAME-PACKAGE returns the package.  (Thanks to Eric Marsden)
+  * bug fix: EXPT signals an error if first argument is a zero and second
+    argument is a floating point zero. (lp#571581, thanks to Roman Marynchak)
 
 changes in sbcl-1.0.41 relative to sbcl-1.0.40:
   * optimization: validity of observed keyword initargs to MAKE-INSTANCE is
index 7782f15..939d02b 100644 (file)
@@ -897,6 +897,7 @@ possibly temporariliy, because it might be used internally."
                "*SETF-FDEFINITION-HOOK*"
 
                ;; error-reporting facilities
+               "ARGUMENTS-OUT-OF-DOMAIN-ERROR"
                "CLOSED-STREAM-ERROR"
                "COMPILED-PROGRAM-ERROR"
                "ENCAPSULATED-CONDITION"
index ee00b04..d01dca2 100644 (file)
 (define-condition simple-reference-warning (reference-condition simple-warning)
   ())
 
+(define-condition arguments-out-of-domain-error
+    (arithmetic-error reference-condition)
+  ())
+
 (define-condition duplicate-definition (reference-condition warning)
   ((name :initarg :name :reader duplicate-definition-name))
   (:report (lambda (c s)
index 55dbb83..71619ee 100644 (file)
   #!+sb-doc
   "Return BASE raised to the POWER."
   (if (zerop power)
-      (let ((result (1+ (* base power))))
-        (if (and (floatp result) (float-nan-p result))
-            (float 1 result)
-            result))
+    (if (and (zerop base) (floatp power))
+        (error 'arguments-out-of-domain-error
+               :operands (list base power)
+               :operation 'expt
+               :references (list '(:ansi-cl :function expt)))
+        (let ((result (1+ (* base power))))
+          (if (and (floatp result) (float-nan-p result))
+              (float 1 result)
+              result)))
     (labels (;; determine if the double float is an integer.
              ;;  0 - not an integer
              ;;  1 - an odd int
index 6ca3aaa..746b88b 100644 (file)
 (with-test (:name :gcd)
   (assert (plusp (gcd 20286123923750474264166990598656
                       680564733841876926926749214863536422912))))
+
+(with-test (:name :expt-zero-zero)
+  ;; Check that (expt 0.0 0.0) and (expt 0 0.0) signal error, but (expt 0.0 0)
+  ;; returns 1.0
+  (assert (raises-error? (expt 0.0 0.0) sb-int:arguments-out-of-domain-error))
+  (assert (raises-error? (expt 0 0.0) sb-int:arguments-out-of-domain-error))
+  (assert (eql (expt 0.0 0) 1.0)))
index 2631a7b..a934320 100644 (file)
@@ -17,4 +17,4 @@
 ;;; checkins which aren't released. (And occasionally for internal
 ;;; versions, especially for internal versions off the main CVS
 ;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".)
-"1.0.41.46"
+"1.0.41.47"