unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Markus Triska <markus.triska@gmx.at>
To: jay.p.belanger@gmail.com
Cc: emacs-pretest-bug@gnu.org
Subject: Re: 22.1.50; calc-math.el patch: fix non-termination
Date: Thu, 27 Sep 2007 20:42:38 +0200	[thread overview]
Message-ID: <m18x6sgdb5.fsf@gmx.at> (raw)
In-Reply-To: <m33ax1dlac.fsf@gmail.com> (Jay Belanger's message of "Wed\, 26 Sep 2007 19\:06\:19 -0500")

Jay Belanger <jay.p.belanger@gmail.com> 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  <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..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))

      parent reply	other threads:[~2007-09-27 18:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

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=m18x6sgdb5.fsf@gmx.at \
    --to=markus.triska@gmx.at \
    --cc=emacs-pretest-bug@gnu.org \
    --cc=jay.p.belanger@gmail.com \
    /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).