diff options
author | Jay Belanger <jay.p.belanger@gmail.com> | 2007-10-01 03:18:00 +0000 |
---|---|---|
committer | Jay Belanger <jay.p.belanger@gmail.com> | 2007-10-01 03:18:00 +0000 |
commit | 86e405cfcbd467a812f6d4c4366477e6d6e0a430 (patch) | |
tree | 238d16928b06bce23b794ca7d6097a7a12972de5 | |
parent | f1640784ad5617487a3820e2c4f24c44193e1694 (diff) | |
download | emacs-86e405cfcbd467a812f6d4c4366477e6d6e0a430.tar.gz |
calc-math.el (math-largest-emacs-expt): Handle the cases when expt
doesn't give range errors.
-rw-r--r-- | lisp/ChangeLog | 10 | ||||
-rw-r--r-- | lisp/calc/calc-math.el | 38 |
2 files changed, 37 insertions, 11 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index ac151a50bf0..b8546373c97 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,13 @@ +2007-10-01 Jay Belanger <jay.p.belanger@gmail.com> + + * calc/calc-math.el (math-largest-emacs-expt): Handle the cases + when `expt' doesn't give range errors. + +2007-10-01 Markus Triska <markus.triska@gmx.at> + + * calc/calc-math.el (math-smallest-emacs-expt): Make the + computation more robust. + 2007-09-30 David Kastrup <dak@gnu.org> * startup.el (argv): Alias for `command-line-args-left' to use as diff --git a/lisp/calc/calc-math.el b/lisp/calc/calc-math.el index 0b4c82d1292..1aab53524f8 100644 --- a/lisp/calc/calc-math.el +++ b/lisp/calc/calc-math.el @@ -53,17 +53,33 @@ ;;; is an Emacs float, for acceptable d.dddd.... (defvar math-largest-emacs-expt - (let ((x 1)) - (while (condition-case nil - (expt 10.0 x) - (error nil)) - (setq x (* 2 x))) - (setq x (/ x 2)) - (while (condition-case nil - (expt 10.0 x) - (error nil)) - (setq x (1+ x))) - (- x 2)) + (let ((x 1) + (pow 1e2)) + ;; The following loop is for efficiency; it should stop when + ;; 10^(2x) is too large. This could be indicated by a range + ;; error when computing 10^(2x), an infinite value for 10^(2x), + ;; or (!) a zero value for 10^(2x). + (while (and + pow + (< pow 1.0e+INF) + (> pow 0.0)) + (setq x (* 2 x)) + (setq pow (condition-case nil + (expt 10.0 (* 2 x)) + (error nil)))) + ;; The following loop should stop when 10^(x+1) is too large. + (setq pow (condition-case nil + (expt 10.0 (1+ x)) + (error nil))) + (while (and + pow + (< pow 1.0e+INF) + (> pow 0.0)) + (setq x (1+ x)) + (setq pow (condition-case nil + (expt 10.0 (1+ x)) + (error nil)))) + (1- x)) "The largest exponent which Calc will convert to an Emacs float.") (defvar math-smallest-emacs-expt |