From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13199 invoked by alias); 15 Feb 2011 00:13:06 -0000 Received: (qmail 13187 invoked by uid 22791); 15 Feb 2011 00:13:03 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_CX,TW_GC X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 15 Feb 2011 00:12:59 +0000 From: "dogbreath69 at hotmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/47742] New: Large Values Increment By 1 When Casting Long to Double X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: dogbreath69 at hotmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Tue, 15 Feb 2011 00:14:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-02/txt/msg01751.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47742 Summary: Large Values Increment By 1 When Casting Long to Double Product: gcc Version: 4.1.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned@gcc.gnu.org ReportedBy: dogbreath69@hotmail.com When casting some large long values to a double the resultant double values is 1 larger than the long. This can easily be seen with the value for LONG_MAX, but will even appear with long values as low as 23372036854775807 (and possibly lower). It is not consistent and does not affect all large longs, but does appear in a great number of them. ratscat> gcc -v Using built-in specs. Target: x86_64-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=x86_64-redhat-linux Thread model: posix gcc version 4.1.2 20080704 (Red Hat 4.1.2-48) Program is: #include #include #include #include int main( int argc, char **argv ) { long infc = LONG_MAX; double real_size = (double) infc; printf( "infc %ld\nreal_size %lf\n", infc, real_size ); exit( 0 ); } ratscat> gcc -Wall truncfc.c ratscat> a.out infc 9223372036854775807 real_size 9223372036854775808.000000