From b5696612c774dac57abff3b5abe3f04ebe0ce2c7 Mon Sep 17 00:00:00 2001 From: Nikodemus Siivola Date: Mon, 16 Aug 2010 12:53:42 +0000 Subject: [PATCH] 1.0.41.47: (EXPT 0.0 0.0) and (EXPT 0 0.0) to signal an error https://bugs.launchpad.net/sbcl/+bug/571581 From patch by Roman Marynchack. --- NEWS | 2 ++ package-data-list.lisp-expr | 1 + src/code/condition.lisp | 4 ++++ src/code/irrat.lisp | 13 +++++++++---- tests/arith.pure.lisp | 7 +++++++ version.lisp-expr | 2 +- 6 files changed, 24 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index e70ebe7..0efbedc 100644 --- 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 diff --git a/package-data-list.lisp-expr b/package-data-list.lisp-expr index 7782f15..939d02b 100644 --- a/package-data-list.lisp-expr +++ b/package-data-list.lisp-expr @@ -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" diff --git a/src/code/condition.lisp b/src/code/condition.lisp index ee00b04..d01dca2 100644 --- a/src/code/condition.lisp +++ b/src/code/condition.lisp @@ -900,6 +900,10 @@ (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) diff --git a/src/code/irrat.lisp b/src/code/irrat.lisp index 55dbb83..71619ee 100644 --- a/src/code/irrat.lisp +++ b/src/code/irrat.lisp @@ -178,10 +178,15 @@ #!+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 diff --git a/tests/arith.pure.lisp b/tests/arith.pure.lisp index 6ca3aaa..746b88b 100644 --- a/tests/arith.pure.lisp +++ b/tests/arith.pure.lisp @@ -365,3 +365,10 @@ (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))) diff --git a/version.lisp-expr b/version.lisp-expr index 2631a7b..a934320 100644 --- a/version.lisp-expr +++ b/version.lisp-expr @@ -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" -- 1.7.10.4