From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Markus Triska Newsgroups: gmane.emacs.devel,gmane.emacs.pretest.bugs Subject: Re: 22.1.50; calc-math.el patch: fix non-termination Date: Thu, 27 Sep 2007 20:42:38 +0200 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1190918888 15799 80.91.229.12 (27 Sep 2007 18:48:08 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 27 Sep 2007 18:48:08 +0000 (UTC) Cc: emacs-pretest-bug@gnu.org To: jay.p.belanger@gmail.com Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Sep 27 20:48:02 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1IayP2-0001UQ-1a for ged-emacs-devel@m.gmane.org; Thu, 27 Sep 2007 20:48:00 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IayOy-0003fD-So for ged-emacs-devel@m.gmane.org; Thu, 27 Sep 2007 14:47:56 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IayOg-0003Si-Gp for emacs-devel@gnu.org; Thu, 27 Sep 2007 14:47:38 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IayOc-0003Qf-J0 for emacs-devel@gnu.org; Thu, 27 Sep 2007 14:47:37 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IayOc-0003QX-Fk for emacs-devel@gnu.org; Thu, 27 Sep 2007 14:47:34 -0400 Original-Received: from fencepost.gnu.org ([140.186.70.10]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IayOc-0000EG-4l for emacs-devel@gnu.org; Thu, 27 Sep 2007 14:47:34 -0400 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by fencepost.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IayNt-0003Bu-OS for emacs-pretest-bug@gnu.org; Thu, 27 Sep 2007 14:46:49 -0400 Original-Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1IayOX-0000DL-DB for emacs-pretest-bug@gnu.org; Thu, 27 Sep 2007 14:47:33 -0400 Original-Received: from mail.gmx.net ([213.165.64.20]) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1IayOW-0000Ct-Vn for emacs-pretest-bug@gnu.org; Thu, 27 Sep 2007 14:47:29 -0400 Original-Received: (qmail invoked by alias); 27 Sep 2007 18:47:27 -0000 Original-Received: from chello062178240212.3.14.tuwien.teleweb.at (EHLO mt-computer.local) [62.178.240.212] by mail.gmx.net (mp054) with SMTP; 27 Sep 2007 20:47:27 +0200 X-Authenticated: #4064391 X-Provags-ID: V01U2FsdGVkX1+TqqNm6rST0iXRiT63h0cLmpJcjYTa1x9aiJfpkN j9QybaKpZfwXlT In-Reply-To: (Jay Belanger's message of "Wed\, 26 Sep 2007 19\:06\:19 -0500") X-Y-GMX-Trusted: 0 X-Detected-Kernel: Linux 2.6, seldom 2.4 (older, 4) X-Detected-Kernel: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:79962 gmane.emacs.pretest.bugs:20022 Archived-At: Jay Belanger 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 * 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))