From: Markus Triska <markus.triska@gmx.at>
To: emacs-pretest-bug@gnu.org
Subject: 22.1.50; calc-math.el patch: fix non-termination
Date: Wed, 26 Sep 2007 19:54:30 +0200 [thread overview]
Message-ID: <m1fy115n3d.fsf@pnsgw3-client154.demo.tuwien.ac.at> (raw)
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.")
next reply other threads:[~2007-09-26 17:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-26 17:54 Markus Triska [this message]
2007-09-27 0:06 ` 22.1.50; calc-math.el patch: fix non-termination Jay Belanger
2007-09-27 18:00 ` Richard Stallman
2007-09-27 18:42 ` Markus Triska
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m1fy115n3d.fsf@pnsgw3-client154.demo.tuwien.ac.at \
--to=markus.triska@gmx.at \
--cc=emacs-pretest-bug@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).