GNU bug report logs - #5114
23.1.50; (string-to-number (number-to-string most-positive-fixnum))

Previous Next

Package: emacs;

Reported by: Helmut Eller <eller.helmut <at> gmail.com>

Date: Thu, 3 Dec 2009 15:05:07 UTC

Severity: normal

Tags: fixed

Fixed in version 24.1

Done: Lars Magne Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 5114 in the body.
You can then email your comments to 5114 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#5114; Package emacs. (Thu, 03 Dec 2009 15:05:08 GMT) Full text and rfc822 format available.

Acknowledgement sent to Helmut Eller <eller.helmut <at> gmail.com>:
New bug report received and forwarded. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Thu, 03 Dec 2009 15:05:08 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Helmut Eller <eller.helmut <at> gmail.com>
To: emacs-pretest-bug <at> gnu.org
Subject: 23.1.50; (string-to-number (number-to-string most-positive-fixnum))
Date: Thu, 03 Dec 2009 15:36:27 +0100
(setq x (string-to-number (number-to-string most-positive-fixnum)))
(= most-positive-fixnum x) => nil
   
x is 2305843009213693440 but it should be most-positive-fixnum
which is 2305843009213693951.

The test
(= most-positive-fixnum 
   (string-to-number (number-to-string most-positive-fixnum)))
seems to work as expected on 32-bit machines but not so on 64 bit.

Helmut.

In GNU Emacs 23.1.50.1 (x86_64-unknown-linux-gnu)
 of 2009-12-03
configured using `configure  '--without-x''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: nil
  locale-coding-system: utf-8-unix
  default enable-multibyte-characters: t




Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#5114; Package emacs. (Thu, 03 Dec 2009 21:00:04 GMT) Full text and rfc822 format available.

Acknowledgement sent to Stefan Monnier <monnier <at> IRO.UMontreal.CA>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Thu, 03 Dec 2009 21:00:04 GMT) Full text and rfc822 format available.

Message #10 received at 5114 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Helmut Eller <eller.helmut <at> gmail.com>
Cc: 5114 <at> debbugs.gnu.org
Subject: Re: bug#5114: 23.1.50; (string-to-number (number-to-string most-positive-fixnum))
Date: Thu, 03 Dec 2009 15:52:16 -0500
> (setq x (string-to-number (number-to-string most-positive-fixnum)))
> (= most-positive-fixnum x) => nil
   
> x is 2305843009213693440 but it should be most-positive-fixnum
> which is 2305843009213693951.

> The test
> (= most-positive-fixnum 
>    (string-to-number (number-to-string most-positive-fixnum)))
> seems to work as expected on 32-bit machines but not so on 64 bit.

Indeed, it passes through a floating point conversion, so there's only
abour 52 bit of precesion.


        Stefan



Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#5114; Package emacs. (Sat, 05 Dec 2009 12:45:04 GMT) Full text and rfc822 format available.

Acknowledgement sent to Helmut Eller <eller.helmut <at> gmail.com>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Sat, 05 Dec 2009 12:45:04 GMT) Full text and rfc822 format available.

Message #15 received at 5114 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Helmut Eller <eller.helmut <at> gmail.com>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: 5114 <at> debbugs.gnu.org
Subject: Re: bug#5114: 23.1.50; (string-to-number (number-to-string most-positive-fixnum))
Date: Sat, 05 Dec 2009 13:36:41 +0100
[Message part 1 (text/plain, inline)]
* Stefan Monnier [2009-12-03 21:52+0100] writes:

>> (setq x (string-to-number (number-to-string most-positive-fixnum)))
>> (= most-positive-fixnum x) => nil
>    
>> x is 2305843009213693440 but it should be most-positive-fixnum
>> which is 2305843009213693951.
>
>> The test
>> (= most-positive-fixnum 
>>    (string-to-number (number-to-string most-positive-fixnum)))
>> seems to work as expected on 32-bit machines but not so on 64 bit.
>
> Indeed, it passes through a floating point conversion, so there's only
> abour 52 bit of precesion.

Here is a patch for string-to-number to use the full fixnum range:

[string-to-number.patch (text/x-diff, inline)]
--- data.c.~1.308.~	2009-12-05 08:07:48.000000000 +0100
+++ data.c	2009-12-05 13:27:33.000000000 +0100
@@ -2393,23 +2393,26 @@
     p++;
 
   if (isfloat_string (p, 1) && b == 10)
-    val = make_float (sign * atof (p));
-  else
-    {
-      double v = 0;
-
-      while (1)
-	{
-	  int digit = digit_to_number (*p++, b);
-	  if (digit < 0)
-	    break;
-	  v = v * b + digit;
-	}
-
-      val = make_fixnum_or_float (sign * v);
-    }
-
-  return val;
+    return make_float (sign * atof (p));
+  else {
+    unsigned long u = 0;
+    while (1)
+      {
+	int digit = digit_to_number (*p++, b);
+	if (digit < 0)
+	  return make_number (sign * u);
+	else if (u <= (MOST_POSITIVE_FIXNUM - digit) / b)
+	  u = u * b + digit;
+	else
+	  {
+	    /* overflow to flonums */
+	    double f = ((double)u) * b + digit;
+	    while (digit = digit_to_number (*p++, b), digit >= 0)
+	      f = f * b + digit;
+	    return make_float (sign * f);
+	  }
+      }
+  }
 }
 
 
[Message part 3 (text/plain, inline)]
Helmut

Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#5114; Package emacs. (Sat, 05 Dec 2009 14:35:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Eli Zaretskii <eliz <at> gnu.org>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Sat, 05 Dec 2009 14:35:04 GMT) Full text and rfc822 format available.

Message #20 received at 5114 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Helmut Eller <eller.helmut <at> gmail.com>, 5114 <at> debbugs.gnu.org
Cc: monnier <at> IRO.UMontreal.CA
Subject: Re: bug#5114: 23.1.50;	(string-to-number (number-to-string most-positive-fixnum))
Date: Sat, 05 Dec 2009 16:25:57 +0200
> From: Helmut Eller <eller.helmut <at> gmail.com>
> Date: Sat, 05 Dec 2009 13:36:41 +0100
> Cc: 5114 <at> emacsbugs.donarmstrong.com
> 
> +  else {
> +    unsigned long u = 0;

This assumes that `unsigned long' is the same width as EMACS_INT.
This could be false, e.g., with 64-bit MS-Windows.  Isn't it better to
use EMACS_INT instead?



Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#5114; Package emacs. (Sat, 05 Dec 2009 15:25:05 GMT) Full text and rfc822 format available.

Acknowledgement sent to Helmut Eller <eller.helmut <at> gmail.com>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Sat, 05 Dec 2009 15:25:05 GMT) Full text and rfc822 format available.

Message #25 received at submit <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Helmut Eller <eller.helmut <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#5114: 23.1.50; (string-to-number (number-to-string most-positive-fixnum))
Date: Sat, 05 Dec 2009 16:18:13 +0100
* Eli Zaretskii [2009-12-05 15:25+0100] writes:

>> From: Helmut Eller <eller.helmut <at> gmail.com>
>> Date: Sat, 05 Dec 2009 13:36:41 +0100
>> Cc: 5114 <at> emacsbugs.donarmstrong.com
>> 
>> +  else {
>> +    unsigned long u = 0;
>
> This assumes that `unsigned long' is the same width as EMACS_INT.
> This could be false, e.g., with 64-bit MS-Windows.  Isn't it better to
> use EMACS_INT instead?

Using EMACS_UINT wouldn't hurt.  Does MOST_POSITIVE_FIXNUM not fit in a
unsigned long on Windows?  I assumed that longs are supposed to be as
wide as pointers.

Helmut





Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#5114; Package emacs. (Sat, 05 Dec 2009 16:55:05 GMT) Full text and rfc822 format available.

Acknowledgement sent to Eli Zaretskii <eliz <at> gnu.org>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Sat, 05 Dec 2009 16:55:06 GMT) Full text and rfc822 format available.

Message #30 received at 5114 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Helmut Eller <eller.helmut <at> gmail.com>, 5114 <at> debbugs.gnu.org
Subject: Re: bug#5114: 23.1.50;	(string-to-number (number-to-string most-positive-fixnum))
Date: Sat, 05 Dec 2009 18:44:42 +0200
> From: Helmut Eller <eller.helmut <at> gmail.com>
> Date: Sat, 05 Dec 2009 16:18:13 +0100
> Cc: 
> 
> * Eli Zaretskii [2009-12-05 15:25+0100] writes:
> 
> >> From: Helmut Eller <eller.helmut <at> gmail.com>
> >> Date: Sat, 05 Dec 2009 13:36:41 +0100
> >> Cc: 5114 <at> emacsbugs.donarmstrong.com
> >> 
> >> +  else {
> >> +    unsigned long u = 0;
> >
> > This assumes that `unsigned long' is the same width as EMACS_INT.
> > This could be false, e.g., with 64-bit MS-Windows.  Isn't it better to
> > use EMACS_INT instead?
> 
> Using EMACS_UINT wouldn't hurt.  Does MOST_POSITIVE_FIXNUM not fit in a
> unsigned long on Windows?

In the 32-bit Windows build, it does.  In the 64-bit Windows build
(which does not yet exist, since we don't yet support it), it will
not, because MS in their infinite wisdom (probably because backward
compatibility considerations wrt existing source code and headers)
decided to use the LLP64 programming model.

> I assumed that longs are supposed to be as wide as pointers.

Not on 64-bit Windows, they don't.



Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#5114; Package emacs. (Sun, 18 Sep 2011 09:57:02 GMT) Full text and rfc822 format available.

Message #33 received at 5114 <at> debbugs.gnu.org (full text, mbox):

From: Lars Magne Ingebrigtsen <larsi <at> gnus.org>
To: Helmut Eller <eller.helmut <at> gmail.com>
Cc: 5114 <at> debbugs.gnu.org
Subject: Re: 23.1.50;
	(string-to-number (number-to-string most-positive-fixnum))
Date: Sun, 18 Sep 2011 11:47:58 +0200
Helmut Eller <eller.helmut <at> gmail.com> writes:

> (setq x (string-to-number (number-to-string most-positive-fixnum)))
> (= most-positive-fixnum x) => nil
>
> x is 2305843009213693440 but it should be most-positive-fixnum
> which is 2305843009213693951.
>
> The test
> (= most-positive-fixnum 
>    (string-to-number (number-to-string most-positive-fixnum)))
> seems to work as expected on 32-bit machines but not so on 64 bit.

I'm unable to reproduce this on Emacs 24, so I think it's likely that
this has been fixed by all the numerical fixes that have been applied
the last year.

-- 
(domestic pets only, the antidote for overdose, milk.)
  bloggy blog http://lars.ingebrigtsen.no/




Added tag(s) fixed. Request was from Lars Magne Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sun, 18 Sep 2011 09:57:02 GMT) Full text and rfc822 format available.

bug marked as fixed in version 24.1, send any further explanations to 5114 <at> debbugs.gnu.org and Helmut Eller <eller.helmut <at> gmail.com> Request was from Lars Magne Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sun, 18 Sep 2011 09:57:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#5114; Package emacs. (Sun, 18 Sep 2011 11:09:02 GMT) Full text and rfc822 format available.

Message #40 received at 5114 <at> debbugs.gnu.org (full text, mbox):

From: Leo <sdl.web <at> gmail.com>
To: Lars Magne Ingebrigtsen <larsi <at> gnus.org>
Cc: 5114 <at> debbugs.gnu.org, Helmut Eller <eller.helmut <at> gmail.com>
Subject: Re: bug#5114: 23.1.50;
	(string-to-number (number-to-string most-positive-fixnum))
Date: Sun, 18 Sep 2011 18:57:53 +0800
On 2011-09-18 17:47 +0800, Lars Magne Ingebrigtsen wrote:
> I'm unable to reproduce this on Emacs 24, so I think it's likely that
> this has been fixed by all the numerical fixes that have been applied
> the last year.

Indeed fixed in 24.x but present in emacs-23.

Leo




bug marked as fixed in version 24.1, send any further explanations to 5114 <at> debbugs.gnu.org and Helmut Eller <eller.helmut <at> gmail.com> Request was from Lars Magne Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sun, 18 Sep 2011 11:48:01 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 17 Oct 2011 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 13 years and 245 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.