From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: macro FIXNUM_OVERFLOW_P in lisp.h is valid ? Date: Fri, 23 Oct 2009 21:33:59 +0200 Message-ID: <83y6n1gb14.fsf@gnu.org> References: Reply-To: Eli Zaretskii NNTP-Posting-Host: lo.gmane.org X-Trace: ger.gmane.org 1256326555 10530 80.91.229.12 (23 Oct 2009 19:35:55 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 23 Oct 2009 19:35:55 +0000 (UTC) Cc: emacs-devel@gnu.org To: Toru TSUNEYOSHI Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Oct 23 21:35:48 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 1N1PvL-0008Or-NE for ged-emacs-devel@m.gmane.org; Fri, 23 Oct 2009 21:35:43 +0200 Original-Received: from localhost ([127.0.0.1]:33224 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N1PvL-0002Z6-79 for ged-emacs-devel@m.gmane.org; Fri, 23 Oct 2009 15:35:43 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N1Pts-0001Wr-HY for emacs-devel@gnu.org; Fri, 23 Oct 2009 15:34:12 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N1Ptn-0001RG-Ml for emacs-devel@gnu.org; Fri, 23 Oct 2009 15:34:12 -0400 Original-Received: from [199.232.76.173] (port=52535 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N1Ptn-0001R3-H7 for emacs-devel@gnu.org; Fri, 23 Oct 2009 15:34:07 -0400 Original-Received: from mtaout23.012.net.il ([80.179.55.175]:37558) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N1Ptn-0004XO-4m for emacs-devel@gnu.org; Fri, 23 Oct 2009 15:34:07 -0400 Original-Received: from conversion-daemon.a-mtaout23.012.net.il by a-mtaout23.012.net.il (HyperSendmail v2007.08) id <0KRZ00J00FIGPY00@a-mtaout23.012.net.il> for emacs-devel@gnu.org; Fri, 23 Oct 2009 21:34:05 +0200 (IST) Original-Received: from HOME-C4E4A596F7 ([87.70.77.20]) by a-mtaout23.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0KRZ00GAAFON7FD0@a-mtaout23.012.net.il>; Fri, 23 Oct 2009 21:33:59 +0200 (IST) In-reply-to: X-012-Sender: halo1@inter.net.il X-detected-operating-system: by monty-python.gnu.org: Solaris 10 (beta) 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:116341 Archived-At: > Date: Sat, 24 Oct 2009 02:51:47 +0900 > From: Toru TSUNEYOSHI > > /* Value is non-zero if C integer I doesn't fit into a Lisp fixnum. */ > > #define FIXNUM_OVERFLOW_P(i) \ > ((EMACS_INT)(i) > MOST_POSITIVE_FIXNUM \ > || (EMACS_INT) (i) < MOST_NEGATIVE_FIXNUM) > > I think FIXNUM_OVERFLOW_P is problematic. > > The reason is that > in case `i' is 4294967296.0 (2^32), (EMACS_INT)(i) returns 0 > with a executable program by some compiler This is a known problem, but I'm not sure what would be the right solution. FIXNUM_OVERFLOW_P fails like that for any unsigned integer that is large enough, because EMACS_INT is a signed type, so large unsigned values become small negative values, and pass the test. > In conclusion, it needs casting to double, I think. > > #define FIXNUM_OVERFLOW_P(i) \ > ((double)(i) > (double)MOST_POSITIVE_FIXNUM \ > || (double)(i) < (double)MOST_NEGATIVE_FIXNUM) > > What do you think about it ? This will not work on 64-bit platforms (where EMACS_INT is a 64-bit type), because a double does not have 64 bits in the mantissa, and so you will lose significant digits by that cast. An alternative would be to have a separate test for unsigned values.