From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Helmut Eller Newsgroups: gmane.emacs.bugs Subject: bug#5114: 23.1.50; (string-to-number (number-to-string most-positive-fixnum)) Date: Sat, 05 Dec 2009 13:36:41 +0100 Message-ID: References: Reply-To: Helmut Eller , 5114@emacsbugs.donarmstrong.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1260017275 21473 80.91.229.12 (5 Dec 2009 12:47:55 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 5 Dec 2009 12:47:55 +0000 (UTC) Cc: 5114@emacsbugs.donarmstrong.com To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Dec 05 13:47:48 2009 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1NGu39-0003gS-HJ for geb-bug-gnu-emacs@m.gmane.org; Sat, 05 Dec 2009 13:47:47 +0100 Original-Received: from localhost ([127.0.0.1]:42993 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NGu39-0000ng-4G for geb-bug-gnu-emacs@m.gmane.org; Sat, 05 Dec 2009 07:47:47 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NGu2v-0000ml-FO for bug-gnu-emacs@gnu.org; Sat, 05 Dec 2009 07:47:33 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NGu2q-0000lJ-BO for bug-gnu-emacs@gnu.org; Sat, 05 Dec 2009 07:47:32 -0500 Original-Received: from [199.232.76.173] (port=47578 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NGu2p-0000l1-OH for bug-gnu-emacs@gnu.org; Sat, 05 Dec 2009 07:47:27 -0500 Original-Received: from rzlab.ucr.edu ([138.23.92.77]:37744) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NGu2p-0004Mf-8Z for bug-gnu-emacs@gnu.org; Sat, 05 Dec 2009 07:47:27 -0500 Original-Received: from rzlab.ucr.edu (rzlab.ucr.edu [127.0.0.1]) by rzlab.ucr.edu (8.14.3/8.14.3/Debian-5) with ESMTP id nB5ClO4t013548; Sat, 5 Dec 2009 04:47:25 -0800 Original-Received: (from debbugs@localhost) by rzlab.ucr.edu (8.14.3/8.14.3/Submit) id nB5Cj4lX013269; Sat, 5 Dec 2009 04:45:04 -0800 Resent-Date: Sat, 5 Dec 2009 04:45:04 -0800 X-Loop: owner@emacsbugs.donarmstrong.com Resent-From: Helmut Eller Resent-To: bug-submit-list@donarmstrong.com Resent-CC: Emacs Bugs 2Resent-Date: Sat, 05 Dec 2009 12:45:03 +0000 Resent-Message-ID: Resent-Sender: owner@emacsbugs.donarmstrong.com X-Emacs-PR-Message: followup 5114 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: Original-Received: via spool by 5114-submit@emacsbugs.donarmstrong.com id=B5114.126001661012816 (code B ref 5114); Sat, 05 Dec 2009 12:45:03 +0000 Original-Received: (at 5114) by emacsbugs.donarmstrong.com; 5 Dec 2009 12:36:50 +0000 X-Spam-Bayes: score:0.5 Bayes not run. spammytokens:Tokens not available. hammytokens:Tokens not available. Original-Received: from ix (dial-177248.pool.broadband44.net [212.46.177.248]) by rzlab.ucr.edu (8.14.3/8.14.3/Debian-5) with ESMTP id nB5CamQK012813 for <5114@emacsbugs.donarmstrong.com>; Sat, 5 Dec 2009 04:36:50 -0800 Original-Received: from helmut by ix with local (Exim 4.69) (envelope-from ) id 1NGtsP-0001AG-CX; Sat, 05 Dec 2009 13:36:41 +0100 In-Reply-To: (Stefan Monnier's message of "Thu, 03 Dec 2009 15:52:16 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Resent-Date: Sat, 05 Dec 2009 07:47:32 -0500 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:33249 Archived-At: --=-=-= * 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: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=string-to-number.patch --- 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); + } + } + } } --=-=-= Helmut --=-=-=--