[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
22.1.50; calc-math.el patch: fix non-termination
From: |
Markus Triska |
Subject: |
22.1.50; calc-math.el patch: fix non-termination |
Date: |
Wed, 26 Sep 2007 19:54:30 +0200 |
With the OS I'm currently working on, the result of (expt 10.0 x) is
1.0e+INF for x >= 309, i.e., no range error is triggered. This patch
to calc-math.el prevents non-termination when loading the file.
2007-09-26 Markus Triska <address@hidden>
* calc/calc-math.el (math-largest-emacs-expt)
(math-smallest-emacs-expt): more robust computation
diff --git a/lisp/calc/calc-math.el b/lisp/calc/calc-math.el
index 3e4743d..44ccbcc 100644
--- a/lisp/calc/calc-math.el
+++ b/lisp/calc/calc-math.el
@@ -54,28 +54,32 @@
(defvar math-largest-emacs-expt
(let ((x 1))
- (while (condition-case nil
- (expt 10.0 x)
- (error nil))
+ (while (and (condition-case nil
+ (expt 10.0 x)
+ (error nil))
+ (< (expt 10.0 x) (expt 10.0 (* 2 x))))
(setq x (* 2 x)))
(setq x (/ x 2))
- (while (condition-case nil
- (expt 10.0 x)
- (error nil))
+ (while (and (condition-case nil
+ (expt 10.0 x)
+ (error nil))
+ (< (expt 10.0 x) (expt 10.0 (* 2 x))))
(setq x (1+ x)))
(- x 2))
"The largest exponent which Calc will convert to an Emacs float.")
(defvar math-smallest-emacs-expt
(let ((x -1))
- (while (condition-case nil
- (expt 10.0 x)
- (error nil))
+ (while (and (condition-case nil
+ (expt 10.0 x)
+ (error nil))
+ (> (expt 10.0 x) 0.0))
(setq x (* 2 x)))
(setq x (/ x 2))
- (while (condition-case nil
- (expt 10.0 x)
- (error nil))
+ (while (and (condition-case nil
+ (expt 10.0 x)
+ (error nil))
+ (> (expt 10.0 x) 0.0))
(setq x (1- x)))
(+ x 2))
"The smallest exponent which Calc will convert to an Emacs float.")
- 22.1.50; calc-math.el patch: fix non-termination,
Markus Triska <=