public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/47742] New: Large Values Increment By 1 When Casting Long to Double
@ 2011-02-15  0:14 dogbreath69 at hotmail dot com
  2011-02-15  0:20 ` [Bug c/47742] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: dogbreath69 at hotmail dot com @ 2011-02-15  0:14 UTC (permalink / raw)
  To: gcc-bugs

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 <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <float.h>

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/47742] Large Values Increment By 1 When Casting Long to Double
  2011-02-15  0:14 [Bug c/47742] New: Large Values Increment By 1 When Casting Long to Double dogbreath69 at hotmail dot com
@ 2011-02-15  0:20 ` pinskia at gcc dot gnu.org
  2011-02-15 23:16 ` manu at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-02-15  0:20 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47742

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-02-15 00:14:37 UTC ---
This is correct as long is 64bits and the precision of a double is less than
64bits.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/47742] Large Values Increment By 1 When Casting Long to Double
  2011-02-15  0:14 [Bug c/47742] New: Large Values Increment By 1 When Casting Long to Double dogbreath69 at hotmail dot com
  2011-02-15  0:20 ` [Bug c/47742] " pinskia at gcc dot gnu.org
@ 2011-02-15 23:16 ` manu at gcc dot gnu.org
  2011-02-15 23:18 ` manu at gcc dot gnu.org
  2011-02-16  6:05 ` dogbreath69 at hotmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: manu at gcc dot gnu.org @ 2011-02-15 23:16 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47742

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu.org

--- Comment #2 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2011-02-15 23:15:03 UTC ---
I think GCC (>= 4.4) should catch this -Wconversion is you drop the forced
cast:

long infc = LONG_MAX;
double real_size = infc;


No?


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/47742] Large Values Increment By 1 When Casting Long to Double
  2011-02-15  0:14 [Bug c/47742] New: Large Values Increment By 1 When Casting Long to Double dogbreath69 at hotmail dot com
  2011-02-15  0:20 ` [Bug c/47742] " pinskia at gcc dot gnu.org
  2011-02-15 23:16 ` manu at gcc dot gnu.org
@ 2011-02-15 23:18 ` manu at gcc dot gnu.org
  2011-02-16  6:05 ` dogbreath69 at hotmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: manu at gcc dot gnu.org @ 2011-02-15 23:18 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47742

--- Comment #3 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2011-02-15 23:16:09 UTC ---
Let me try again:

I think GCC (>= 4.4) should catch this using -Wconversion if you drop the
explicit
cast like in:

long infc = LONG_MAX;
double real_size = infc;

Doesn't it?


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/47742] Large Values Increment By 1 When Casting Long to Double
  2011-02-15  0:14 [Bug c/47742] New: Large Values Increment By 1 When Casting Long to Double dogbreath69 at hotmail dot com
                   ` (2 preceding siblings ...)
  2011-02-15 23:18 ` manu at gcc dot gnu.org
@ 2011-02-16  6:05 ` dogbreath69 at hotmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: dogbreath69 at hotmail dot com @ 2011-02-16  6:05 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47742

--- Comment #4 from dogbreath69 at hotmail dot com 2011-02-16 05:08:06 UTC ---
I haven't tried it with anything greater than GCC 4.1.2. Therefore I do not
know the answer.

> From: gcc-bugzilla@gcc.gnu.org
> To: dogbreath69@hotmail.com
> Subject: [Bug c/47742] Large Values Increment By 1 When Casting Long to Double
> Date: Tue, 15 Feb 2011 23:16:17 +0000
> 
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47742
> 
> --- Comment #3 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2011-02-15 23:16:09 UTC ---
> Let me try again:
> 
> I think GCC (>= 4.4) should catch this using -Wconversion if you drop the
> explicit
> cast like in:
> 
> long infc = LONG_MAX;
> double real_size = infc;
> 
> Doesn't it?
> 
> -- 
> Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email
> ------- You are receiving this mail because: -------
> You reported the bug.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-02-16  5:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-15  0:14 [Bug c/47742] New: Large Values Increment By 1 When Casting Long to Double dogbreath69 at hotmail dot com
2011-02-15  0:20 ` [Bug c/47742] " pinskia at gcc dot gnu.org
2011-02-15 23:16 ` manu at gcc dot gnu.org
2011-02-15 23:18 ` manu at gcc dot gnu.org
2011-02-16  6:05 ` dogbreath69 at hotmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).