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 15:07:44 +0900 Message-ID: References: <83y6n1gb14.fsf@gnu.org> <20091024.105033.100383844.t_tuneyosi@hotmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Sat_Oct_24_15_07_44_2009_188)--" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1256364496 29143 80.91.229.12 (24 Oct 2009 06:08:16 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 24 Oct 2009 06:08:16 +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 08:08:09 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 1N1ZnM-0002EY-Ol for ged-emacs-devel@m.gmane.org; Sat, 24 Oct 2009 08:08:09 +0200 Original-Received: from localhost ([127.0.0.1]:36809 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N1ZnM-0000KM-5z for ged-emacs-devel@m.gmane.org; Sat, 24 Oct 2009 02:08:08 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N1ZnD-0000Ig-CC for emacs-devel@gnu.org; Sat, 24 Oct 2009 02:07:59 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N1Zn8-0000FO-9U for emacs-devel@gnu.org; Sat, 24 Oct 2009 02:07:58 -0400 Original-Received: from [199.232.76.173] (port=42013 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N1Zn7-0000F3-Mq for emacs-devel@gnu.org; Sat, 24 Oct 2009 02:07:53 -0400 Original-Received: from blu0-omc2-s1.blu0.hotmail.com ([65.55.111.76]:51207) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N1Zn5-0004ze-HE; Sat, 24 Oct 2009 02:07:51 -0400 Original-Received: from BLU0-SMTP46 ([65.55.111.73]) by blu0-omc2-s1.blu0.hotmail.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 23 Oct 2009 23:07:50 -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-SMTP46.blu0.hotmail.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.3959); Fri, 23 Oct 2009 23:07:50 -0700 In-Reply-To: <20091024.105033.100383844.t_tuneyosi@hotmail.com> X-Mailer: Mew version 6.2 on Emacs 23.1 / Mule 6.0 (HANACHIRUSATO) X-OriginalArrivalTime: 24 Oct 2009 06:07:50.0625 (UTC) FILETIME=[510B5D10:01CA5470] 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:116349 Archived-At: ----Next_Part(Sat_Oct_24_15_07_44_2009_188)-- 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 ? ----Next_Part(Sat_Oct_24_15_07_44_2009_188)-- 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 14:31:43.356164300 +0900 @@ -22,6 +22,7 @@ #include #include #include +#include #include "lisp.h" #include "puresize.h" #include "character.h" @@ -2392,17 +2393,42 @@ val = make_float (sign * atof (p)); else { - double v = 0; + unsigned char *old_p = p; + int v = 0; + int overflow = 0; - while (1) + while (v >= 0) { int digit = digit_to_number (*p++, b); if (digit < 0) break; + if (v > INT_MAX / b) + { + 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_15_07_44_2009_188)----