summaryrefslogtreecommitdiff
path: root/lisp/calculator.el
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2019-11-04 23:19:36 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2019-11-04 23:39:55 -0800
commit3843711abd8d599206acbcc0aa97dae708285416 (patch)
tree07a65df17454880f4ab3b7a28c49bde8da95bd9d /lisp/calculator.el
parent799d738bc7404b5bda4fe3c544a4fc24e6580f46 (diff)
downloademacs-3843711abd8d599206acbcc0aa97dae708285416.tar.gz
emacs-3843711abd8d599206acbcc0aa97dae708285416.tar.bz2
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.
Diffstat (limited to 'lisp/calculator.el')
-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."
"Compute X^Y, dealing with errors appropriately."
(condition-case nil
(expt x y)
- (domain-error 0.0e+NaN)
- (range-error
- (cond ((and (< x 1.0) (> x -1.0))
- ;; For small x, the range error comes from large y.
- 0.0)
- ((and (> x 0.0) (< y 0.0))
- ;; For large positive x and negative y, the range error
- ;; comes from large negative y.
- 0.0)
- ((and (> x 0.0) (> y 0.0))
- ;; For large positive x and positive y, the range error
- ;; comes from large y.
- 1.0e+INF)
- ;; For the rest, x must be large and negative.
- ;; The range errors come from large integer y.
- ((< y 0.0)
- 0.0)
- ((eq (logand (truncate y) 1) 1) ; expansion of cl `oddp'
- ;; If y is odd
- -1.0e+INF)
- (t
- ;;
- 1.0e+INF)))
- (error 0.0e+NaN)))
+ (overflow-error
+ (if (or (natnump x) (cl-evenp y))
+ 1.0e+INF
+ -1.0e+INF))))
(defun calculator-fact (x)
"Simple factorial of X."