aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2019-11-04 23:19:36 -0800
committerPaul Eggert2019-11-04 23:39:55 -0800
commit3843711abd8d599206acbcc0aa97dae708285416 (patch)
tree07a65df17454880f4ab3b7a28c49bde8da95bd9d
parent799d738bc7404b5bda4fe3c544a4fc24e6580f46 (diff)
downloademacs-3843711abd8d599206acbcc0aa97dae708285416.tar.gz
emacs-3843711abd8d599206acbcc0aa97dae708285416.zip
Simplify calculator-expt
* lisp/calculator.el (calculator-expt): Simplify, now that expt does the right thing if the first arg is -1, 0, or 1.
-rw-r--r--lisp/calculator.el28
1 files changed, 4 insertions, 24 deletions
diff --git a/lisp/calculator.el b/lisp/calculator.el
index 281151c7c25..fab365d5f28 100644
--- a/lisp/calculator.el
+++ b/lisp/calculator.el
@@ -1619,30 +1619,10 @@ To use this, apply a binary operator (evaluate it), then call this."
1619 "Compute X^Y, dealing with errors appropriately." 1619 "Compute X^Y, dealing with errors appropriately."
1620 (condition-case nil 1620 (condition-case nil
1621 (expt x y) 1621 (expt x y)
1622 (domain-error 0.0e+NaN) 1622 (overflow-error
1623 (range-error 1623 (if (or (natnump x) (cl-evenp y))
1624 (cond ((and (< x 1.0) (> x -1.0)) 1624 1.0e+INF
1625 ;; For small x, the range error comes from large y. 1625 -1.0e+INF))))
1626 0.0)
1627 ((and (> x 0.0) (< y 0.0))
1628 ;; For large positive x and negative y, the range error
1629 ;; comes from large negative y.
1630 0.0)
1631 ((and (> x 0.0) (> y 0.0))
1632 ;; For large positive x and positive y, the range error
1633 ;; comes from large y.
1634 1.0e+INF)
1635 ;; For the rest, x must be large and negative.
1636 ;; The range errors come from large integer y.
1637 ((< y 0.0)
1638 0.0)
1639 ((eq (logand (truncate y) 1) 1) ; expansion of cl `oddp'
1640 ;; If y is odd
1641 -1.0e+INF)
1642 (t
1643 ;;
1644 1.0e+INF)))
1645 (error 0.0e+NaN)))
1646 1626
1647(defun calculator-fact (x) 1627(defun calculator-fact (x)
1648 "Simple factorial of X." 1628 "Simple factorial of X."