unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* 22.1.50; calc-math.el patch: fix non-termination
@ 2007-09-26 17:54 Markus Triska
  2007-09-27  0:06 ` Jay Belanger
  0 siblings, 1 reply; 4+ messages in thread
From: Markus Triska @ 2007-09-26 17:54 UTC (permalink / raw)
  To: emacs-pretest-bug


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  <markus.triska@gmx.at>

	* 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.")

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-09-27 18:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-09-26 17:54 22.1.50; calc-math.el patch: fix non-termination Markus Triska
2007-09-27  0:06 ` Jay Belanger
2007-09-27 18:00   ` Richard Stallman
2007-09-27 18:42   ` Markus Triska

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).