[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 22.1.50; calc-math.el patch: fix non-termination
From: |
Markus Triska |
Subject: |
Re: 22.1.50; calc-math.el patch: fix non-termination |
Date: |
Thu, 27 Sep 2007 20:42:38 +0200 |
Jay Belanger <address@hidden> writes:
> There was talk about adjusting `expt' to give a range error for large
> x; if that doesn't happen then something like Markus's patch (I'll
> tweak it to take care of the 0 case, for example) will be needed.
The 0 case cannot arise for math-largest-emacs-expt, and it is handled
for math-smallest-emacs-expt. I have now tested on another OS and
suggest the following improved patch, which should work in all cases:
2007-09-27 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..1cfc582 100644
--- a/lisp/calc/calc-math.el
+++ b/lisp/calc/calc-math.el
@@ -53,14 +53,17 @@
;;; is an Emacs float, for acceptable d.dddd....
(defvar math-largest-emacs-expt
- (let ((x 1))
+ (let ((x 1)
+ err)
(while (condition-case nil
- (expt 10.0 x)
- (error nil))
+ (< (expt 10.0 x) (expt 10.0 (* 2 x)))
+ (error (setq err t)
+ nil))
(setq x (* 2 x)))
- (setq x (/ x 2))
+ (unless err
+ (setq x (/ x 2)))
(while (condition-case nil
- (expt 10.0 x)
+ (< (expt 10.0 x) (expt 10.0 (1+ x)))
(error nil))
(setq x (1+ x)))
(- x 2))
@@ -69,12 +72,12 @@
(defvar math-smallest-emacs-expt
(let ((x -1))
(while (condition-case nil
- (expt 10.0 x)
+ (> (expt 10.0 x) 0.0)
(error nil))
(setq x (* 2 x)))
(setq x (/ x 2))
(while (condition-case nil
- (expt 10.0 x)
+ (> (expt 10.0 x) 0.0)
(error nil))
(setq x (1- x)))
(+ x 2))