From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Toru TSUNEYOSHI Newsgroups: gmane.emacs.devel Subject: Re: macro FIXNUM_OVERFLOW_P in lisp.h is valid ? Date: Sun, 25 Oct 2009 03:45:39 +0900 Message-ID: References: <83vdi5f9gy.fsf@gnu.org> <83my3heylo.fsf@gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Sun_Oct_25_03_45_39_2009_298)--" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1256409969 9348 80.91.229.12 (24 Oct 2009 18:46:09 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 24 Oct 2009 18:46:09 +0000 (UTC) Cc: emacs-devel@gnu.org To: eliz@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Oct 24 20:46:02 2009 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 1N1lcm-000615-43 for ged-emacs-devel@m.gmane.org; Sat, 24 Oct 2009 20:46:00 +0200 Original-Received: from localhost ([127.0.0.1]:58620 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N1lcl-00076a-B3 for ged-emacs-devel@m.gmane.org; Sat, 24 Oct 2009 14:45:59 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N1lcf-00076L-K6 for emacs-devel@gnu.org; Sat, 24 Oct 2009 14:45:53 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N1lca-00075h-55 for emacs-devel@gnu.org; Sat, 24 Oct 2009 14:45:52 -0400 Original-Received: from [199.232.76.173] (port=38912 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N1lcZ-00075e-Um for emacs-devel@gnu.org; Sat, 24 Oct 2009 14:45:48 -0400 Original-Received: from blu0-omc2-s30.blu0.hotmail.com ([65.55.111.105]:47933) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N1lcY-0000Ob-64; Sat, 24 Oct 2009 14:45:46 -0400 Original-Received: from BLU0-SMTP84 ([65.55.111.72]) by blu0-omc2-s30.blu0.hotmail.com with Microsoft SMTPSVC(6.0.3790.3959); Sat, 24 Oct 2009 11:45:45 -0700 X-Originating-IP: [124.155.30.210] X-Originating-Email: [t_tuneyosi@hotmail.com] Original-Received: from localhost ([124.155.30.210]) by BLU0-SMTP84.blu0.hotmail.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.3959); Sat, 24 Oct 2009 11:45:44 -0700 In-Reply-To: <83my3heylo.fsf@gnu.org> X-Mailer: Mew version 6.2 on Emacs 23.1 / Mule 6.0 (HANACHIRUSATO) X-OriginalArrivalTime: 24 Oct 2009 18:45:44.0874 (UTC) FILETIME=[31CF18A0:01CA54DA] X-detected-operating-system: by monty-python.gnu.org: Windows 2000 SP4, XP SP1+ 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:116371 Archived-At: ----Next_Part(Sun_Oct_25_03_45_39_2009_298)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Thanks for your checking. From: Eli Zaretskii > OK, but please make your patch compare against MOST_POSITIVE_FIXNUM, > instead of using INT_MAX or LONG_MAX. Also, if you know that the > value does not overflow an EMACS_INT, you can simply call make_number, > instead of make_fixnum_or_float. I revised the patch as you wrote. Would you like to check it? ;; supplement ;; check list (with results on 32-bit platforms) (string-to-number "268435455") ; 2^28 - 1 => 268435455 (string-to-number "268435456") ; 2^28 => 268435456.0 (string-to-number "268435457") ; 2^28 + 1 => 268435457.0 (string-to-number "-268435456") ; - 2^28 => -268435456 (string-to-number "-268435457") ; - 2^28 - 1 => -268435457.0 (string-to-number "536870911") ; 2^29 - 1 => 536870911.0 (string-to-number "1073741822") ; 2^30 - 1 => 1073741822.0 (string-to-number "2147483647") ; 2^31 - 1 => 2147483647.0 (string-to-number "1152921504606846975") ; 2^60 - 1 => 1.1529215046068467e+018 (string-to-number "1152921504606846976") ; 2^60 => 1.1529215046068467e+018 (string-to-number "1152921504606846977") ; 2^60 + 1 => 1.1529215046068467e+018 (string-to-number "-1152921504606846976") ; - 2^60 => -1.1529215046068467e+018 (string-to-number "-1152921504606846977") ; - 2^60 - 1 => -1.1529215046068467e+018 (string-to-number "9223372036854775807") ; 2^63 - 1 => 9.223372036854778e+018 ----Next_Part(Sun_Oct_25_03_45_39_2009_298)-- Content-Type: Text/X-Patch; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="data.c.diff" --- data.c.orig 2009-06-21 13:38:14.000000000 +0900 +++ data.c 2009-10-25 03:35:54.414697700 +0900 @@ -2392,17 +2392,43 @@ val = make_float (sign * atof (p)); else { - double v = 0; + unsigned char *old_p = p; + EMACS_INT most_fixnum, chknum, v = 0; + int overflow = 0; /* most_fixnum overflow */ - while (1) + most_fixnum = sign > 0 ? MOST_POSITIVE_FIXNUM : MOST_NEGATIVE_FIXNUM * -1; + chknum = most_fixnum / b; + + while (v >= 0) { int digit = digit_to_number (*p++, b); if (digit < 0) break; + if (chknum < v / b) + { + overflow = 1; + break; + } v = v * b + digit; } - val = make_fixnum_or_float (sign * v); + if (!overflow && v <= most_fixnum && v >= 0) + val = make_number (sign * v); + else + { + double w = 0; + p = old_p; + + while (1) + { + int digit = digit_to_number (*p++, b); + if (digit < 0) + break; + w = w * b + digit; + } + + val = make_float (sign * w); + } } return val; ----Next_Part(Sun_Oct_25_03_45_39_2009_298)----