Mercurial > emacs
changeset 84994:39018b7044de
calc-math.el (math-largest-emacs-expt): Handle the cases when expt
doesn't give range errors.
author | Jay Belanger <jay.p.belanger@gmail.com> |
---|---|
date | Mon, 01 Oct 2007 03:15:01 +0000 |
parents | 3788dd19e020 |
children | e452faef14e5 |
files | lisp/calc/calc-math.el |
diffstat | 1 files changed, 27 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/calc/calc-math.el Mon Oct 01 02:53:29 2007 +0000 +++ b/lisp/calc/calc-math.el Mon Oct 01 03:15:01 2007 +0000 @@ -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