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: Sat, 24 Oct 2009 16:46:55 +0900 Message-ID: References: <83y6n1gb14.fsf@gnu.org> <20091024.105033.100383844.t_tuneyosi@hotmail.com> <20091024.150744.186061320.t_tuneyosi@hotmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Sat_Oct_24_16_46_55_2009_232)--" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1256370452 7714 80.91.229.12 (24 Oct 2009 07:47:32 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 24 Oct 2009 07:47:32 +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 09:47:24 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 1N1bLQ-00019Q-G1 for ged-emacs-devel@m.gmane.org; Sat, 24 Oct 2009 09:47:24 +0200 Original-Received: from localhost ([127.0.0.1]:48444 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N1bLP-0007YU-Sg for ged-emacs-devel@m.gmane.org; Sat, 24 Oct 2009 03:47:23 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N1bLL-0007YH-1U for emacs-devel@gnu.org; Sat, 24 Oct 2009 03:47:19 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N1bLF-0007Xm-Aq for emacs-devel@gnu.org; Sat, 24 Oct 2009 03:47:17 -0400 Original-Received: from [199.232.76.173] (port=36109 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N1bLE-0007Xi-WA for emacs-devel@gnu.org; Sat, 24 Oct 2009 03:47:13 -0400 Original-Received: from blu0-omc2-s32.blu0.hotmail.com ([65.55.111.107]:42531) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N1bLD-0000VL-JO; Sat, 24 Oct 2009 03:47:11 -0400 Original-Received: from BLU0-SMTP5 ([65.55.111.73]) by blu0-omc2-s32.blu0.hotmail.com with Microsoft SMTPSVC(6.0.3790.3959); Sat, 24 Oct 2009 00:47:11 -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-SMTP5.blu0.hotmail.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.3959); Sat, 24 Oct 2009 00:47:10 -0700 In-Reply-To: <20091024.150744.186061320.t_tuneyosi@hotmail.com> X-Mailer: Mew version 6.2 on Emacs 23.1 / Mule 6.0 (HANACHIRUSATO) X-OriginalArrivalTime: 24 Oct 2009 07:47:10.0359 (UTC) FILETIME=[31529A70:01CA547E] 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:116352 Archived-At: ----Next_Part(Sat_Oct_24_16_46_55_2009_232)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit >> So in 64-bit platforms, casting `double' to `int' causes lack of >> precision already (because a double does not have 64 bits in the >> mantissa), doesn't it? > > So I make a patch for keep the precision. > It tries to deal with the number in type `int' possibly, otherwise it > deals with the number in type `double'. > > Would you like to check it ? I revised the patch. ----Next_Part(Sat_Oct_24_16_46_55_2009_232)-- Content-Type: Text/X-Patch; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="data.c.diff" --- data.c.original 2009-06-21 13:38:14.000000000 +0900 +++ data.c 2009-10-24 16:32:17.805194400 +0900 @@ -22,6 +22,7 @@ #include #include #include +#include #include "lisp.h" #include "puresize.h" #include "character.h" @@ -2392,17 +2393,46 @@ val = make_float (sign * atof (p)); else { - double v = 0; + unsigned char *old_p = p; + EMACS_INT v = 0; + int overflow = 0; - while (1) + while (v >= 0) { int digit = digit_to_number (*p++, b); if (digit < 0) break; +#ifdef _LP64 + if (v > LONG_MAX / b) +#else + if (v > INT_MAX / b) +#endif + { + overflow = 1; + break; + } v = v * b + digit; } - val = make_fixnum_or_float (sign * v); + if (!overflow && v >= 0) + { + val = make_fixnum_or_float (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_fixnum_or_float (sign * w); + } } return val; ----Next_Part(Sat_Oct_24_16_46_55_2009_232)----