emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: calc: E command hangs Emacs.


From: Michaël Cadilhac
Subject: Re: calc: E command hangs Emacs.
Date: Mon, 24 Sep 2007 08:49:56 +0200
User-agent: Gnus/5.110007 (No Gnus v0.7) Emacs/23.0.50 (gnu/linux)

"yu jie" <address@hidden> writes:

> On 9/21/07, Michaël Cadilhac <address@hidden> wrote:
>>
>> >> (let ((x -1))
>> >>   (while (condition-case nil
>> >>           (message "1.Expt is %e" (expt 10.0 x))
>> >>         (error nil))
>> >>     (message "1.`x' is now %d" (setq x (* 2 x))))
>> >>   (message "2.`x' is now %d" (setq x (/ x 2)))
>> >>   (while (condition-case nil
>> >>           (message "3.Expt is %e" (expt 10.0 x))
>> >>         (error nil))
>> >>     (message "3.`x' is now %d" (setq x (1- x))))
>> >>   (+ x 2))
>>
>> > *Message*:
>> > 1.Expt is 1.000000e+000
>> > 1.`x' is now 0
>> > 1.Expt is 1.000000e+000
>> > 1.`x' is now 0
>> > 1.Expt is 1.000000e+000
>> > 1.`x' is now 0
>> > 1.Expt is 1.000000e+000
>> > Loading debug...done
>> > Entering debugger...
>>
>> Thanks a lot.  As I read the pow(3) man page, the fact that it triggers
>> a ERANGE error is not documented, so it doesn't seem standard.
>>
>> IMO, we should check by hand if an (under|over)flow is triggered.

> Hi,
> it works.:)

We can then consider installing the following patch which fixes an
overflow of expt (namely that (expt 10.0 256) yields 0) on some system
that implement pow(3) without an ERANGE error (e.g., Cygwin).

--- floatfns.c  26 Jul 2007 07:27:51 +0200      1.94
+++ floatfns.c  21 Sep 2007 11:22:16 +0200      
@@ -454,7 +454,7 @@
      (arg1, arg2)
      register Lisp_Object arg1, arg2;
 {
-  double f1, f2;
+  double f1, f2, f3;
 
   CHECK_NUMBER_OR_FLOAT (arg1);
   CHECK_NUMBER_OR_FLOAT (arg2);
@@ -500,8 +500,11 @@
   else if ((f1 == 0.0 && f2 < 0.0) || (f1 < 0 && f2 != floor(f2)))
     domain_error2 ("expt", arg1, arg2);
 #endif
-  IN_FLOAT2 (f1 = pow (f1, f2), "expt", arg1, arg2);
-  return make_float (f1);
+  IN_FLOAT2 (f3 = pow (f1, f2), "expt", arg1, arg2);
+  /* Check for overflow in the result.  */
+  if (f1 != 0.0 && f3 == 0.0)
+    range_error ("expt", arg1);
+  return make_float (f3);
 }
 
 DEFUN ("log", Flog, Slog, 1, 2, 0,
-- 
 |   Michaël `Micha' Cadilhac       |  Le docteur : Je panse donc j'essuie,  |
 |   http://michael.cadilhac.name   |  Le voleur aillant trop avoué :        |
 |   JID/MSN:                       |     J'épenche donc je fuis.            |
 `----  address@hidden  |                                   -  --'

Attachment: pgpwPmaw2ae1U.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]