unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: calc: E command hangs Emacs.
       [not found]           ` <42b562540709201741s28d34896h9c6a69b8db676794@mail.gmail.com>
@ 2007-09-21  9:25             ` Michaël Cadilhac
       [not found]               ` <E1IYgkh-000069-ME@fencepost.gnu.org>
       [not found]               ` <42b562540709232026s650e98ebgbeb780881565c0fa@mail.gmail.com>
  0 siblings, 2 replies; 4+ messages in thread
From: Michaël Cadilhac @ 2007-09-21  9:25 UTC (permalink / raw)
  To: yu jie; +Cc: emacs-devel


[-- Attachment #1.1.1: Type: text/plain, Size: 885 bytes --]

"yu jie" <yujie052@gmail.com> writes:

>> (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.

Can you please try the following patch?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.1.2: floatfns.patch --]
[-- Type: text/x-patch, Size: 753 bytes --]

--- 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,

[-- Attachment #1.1.3: Type: text/plain, Size: 344 bytes --]


Thanks again.

-- 
 |   Michaël `Micha' Cadilhac       |  Would someone please DTRT with this,  |
 |   http://michael.cadilhac.name   |        then ACK?                       |
 |   JID/MSN:                       |          -- Richard Stallman           |
 `----  michael.cadilhac@gmail.com  |                                   -  --'

[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --]

[-- Attachment #2: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

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

* Possible bug in `expt'. (was: calc: E command hangs Emacs.)
       [not found]               ` <E1IYgkh-000069-ME@fencepost.gnu.org>
@ 2007-09-21 11:49                 ` Michaël Cadilhac
  0 siblings, 0 replies; 4+ messages in thread
From: Michaël Cadilhac @ 2007-09-21 11:49 UTC (permalink / raw)
  To: bob; +Cc: emacs-devel


[-- Attachment #1.1: Type: text/plain, Size: 1965 bytes --]

"Robert J. Chassell" <bob@rattlesnake.com> writes:

> Please don't confuse us even when the original title is wrong!
> As a first sentence in the body of your message please write
>
>     The following is Emacs Lisp, not Emacs Calc mode even though the
>     title talks about Emacs Calc mode

Well, you know, the `References' field of my previous message is here if
you need context.  The body of the text was all you needed, and it was
just pointing out a bug in the (expt) function, but sorry for the
misleading subject.

> In the body of your message, you attributed the Emacs Lisp to Yu Jie,
> which I think is correct:

Why, not quite.  Yu Jie is quoted with `>', not `>>'.

>     "yu jie" <yujie052@gmail.com> writes:
>
>     >> (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))

That expression leads to a weird behavior on Yu's computer.  In fact, it
never gets out the first loop, and `x' reaches 0 without any error.

> That expression is for Emacs Lisp, not Emacs Calc.

> In Emacs Calc mode, E computes the exponential, i.e., `e' raised to the
> power of a number you have given it.

And this function uses (expt), which is buggy.

Hope everybody understands the matter now.

-- 
 |   Michaël `Micha' Cadilhac       |  21 seems like a good value: half of   |
 |   http://michael.cadilhac.name   |  of 42 and just old enough to drink!   |
 |   JID/MSN:                       |   Why would you want to change it?     |
 `----  michael.cadilhac@gmail.com  |          -- Stefan Monnier        -  --'

[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --]

[-- Attachment #2: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

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

* Re: calc: E command hangs Emacs.
       [not found]               ` <42b562540709232026s650e98ebgbeb780881565c0fa@mail.gmail.com>
@ 2007-09-24  6:49                 ` Michaël Cadilhac
  2007-10-01  9:17                   ` Michaël Cadilhac
  0 siblings, 1 reply; 4+ messages in thread
From: Michaël Cadilhac @ 2007-09-24  6:49 UTC (permalink / raw)
  To: emacs-devel


[-- Attachment #1.1.1: Type: text/plain, Size: 1264 bytes --]

"yu jie" <yujie052@gmail.com> writes:

> On 9/21/07, Michaël Cadilhac <michael@cadilhac.name> 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).


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.1.2: floatfns.patch --]
[-- Type: text/x-patch, Size: 753 bytes --]

--- 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,

[-- Attachment #1.1.3: Type: text/plain, Size: 327 bytes --]


-- 
 |   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.            |
 `----  michael.cadilhac@gmail.com  |                                   -  --'

[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --]

[-- Attachment #2: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

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

* Re: calc: E command hangs Emacs.
  2007-09-24  6:49                 ` calc: E command hangs Emacs Michaël Cadilhac
@ 2007-10-01  9:17                   ` Michaël Cadilhac
  0 siblings, 0 replies; 4+ messages in thread
From: Michaël Cadilhac @ 2007-10-01  9:17 UTC (permalink / raw)
  To: emacs-devel


[-- Attachment #1.1: Type: text/plain, Size: 960 bytes --]

michael@cadilhac.name (Michaël Cadilhac) writes:

> 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
                                      Read -256.
> 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	

> +  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);

Installed.

-- 
 |   Michaël `Micha' Cadilhac       |  Perhaps we should start               |
 |   http://michael.cadilhac.name   |     making protest releases            |
 |   JID/MSN:                       |   before doing a fall release.         |
 `----  michael.cadilhac@gmail.com  |          -- David Kastrup         -  --'

[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --]

[-- Attachment #2: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

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

end of thread, other threads:[~2007-10-01  9:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <42b562540709171814v3257a1adic5202f42911aad37@mail.gmail.com>
     [not found] ` <873axcrrcv.fsf@cadilhac.name>
     [not found]   ` <42b562540709181923t54c3876of89a0c3322b459cc@mail.gmail.com>
     [not found]     ` <876426n1hu.fsf@cadilhac.name>
     [not found]       ` <42b562540709191805tdbc3da4xf0f8d0cc2456cada@mail.gmail.com>
     [not found]         ` <876425n5gg.fsf@cadilhac.name>
     [not found]           ` <42b562540709201741s28d34896h9c6a69b8db676794@mail.gmail.com>
2007-09-21  9:25             ` calc: E command hangs Emacs Michaël Cadilhac
     [not found]               ` <E1IYgkh-000069-ME@fencepost.gnu.org>
2007-09-21 11:49                 ` Possible bug in `expt'. (was: calc: E command hangs Emacs.) Michaël Cadilhac
     [not found]               ` <42b562540709232026s650e98ebgbeb780881565c0fa@mail.gmail.com>
2007-09-24  6:49                 ` calc: E command hangs Emacs Michaël Cadilhac
2007-10-01  9:17                   ` Michaël Cadilhac

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