public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/24387] New: int-float cast fails for large int values
@ 2005-10-15 18:32 neff dot kevin at mayo dot edu
2005-10-15 18:34 ` [Bug c/24387] " pinskia at gcc dot gnu dot org
2005-10-20 14:01 ` neff dot kevin at mayo dot edu
0 siblings, 2 replies; 3+ messages in thread
From: neff dot kevin at mayo dot edu @ 2005-10-15 18:32 UTC (permalink / raw)
To: gcc-bugs
Seems that there is an error when casting an int to a float, at least for
certain values of the integer. The first integer to fail is 2^24... Note
also that it's only odd integer values that are a problem.
At least one other version (2.3.2) of gcc did not have this problem.
-bash-2.05b$ gcc main_cast.c && ./a.out | head
Size of integers: 4
Failed: 16777216.000000 != 16777217.000000
Failed: 16777220.000000 != 16777219.000000
Failed: 16777220.000000 != 16777221.000000
Failed: 16777224.000000 != 16777223.000000
Failed: 16777224.000000 != 16777225.000000
Failed: 16777228.000000 != 16777227.000000
Failed: 16777228.000000 != 16777229.000000
Failed: 16777232.000000 != 16777231.000000
Failed: 16777232.000000 != 16777233.000000
-bash-2.05b$
--- main_cast.c ---
#include <stdio.h>
#include <limits.h>
int main()
{
int i;
float f;
printf( "Size of integers: %i\n", sizeof(int) );
for( i = 0; i < INT_MAX; i += 1 )
{
f = (float)i;
if( f != ((float)i) )
printf( "Failed: %f != %f\n", f, (float)i );
}
return 0;
}
--
Summary: int-float cast fails for large int values
Product: gcc
Version: 4.0.1
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: neff dot kevin at mayo dot edu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24387
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/24387] int-float cast fails for large int values
2005-10-15 18:32 [Bug c/24387] New: int-float cast fails for large int values neff dot kevin at mayo dot edu
@ 2005-10-15 18:34 ` pinskia at gcc dot gnu dot org
2005-10-20 14:01 ` neff dot kevin at mayo dot edu
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-10-15 18:34 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gcc dot gnu dot org 2005-10-15 18:34 -------
*** This bug has been marked as a duplicate of 323 ***
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |DUPLICATE
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24387
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/24387] int-float cast fails for large int values
2005-10-15 18:32 [Bug c/24387] New: int-float cast fails for large int values neff dot kevin at mayo dot edu
2005-10-15 18:34 ` [Bug c/24387] " pinskia at gcc dot gnu dot org
@ 2005-10-20 14:01 ` neff dot kevin at mayo dot edu
1 sibling, 0 replies; 3+ messages in thread
From: neff dot kevin at mayo dot edu @ 2005-10-20 14:01 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from neff dot kevin at mayo dot edu 2005-10-20 14:01 -------
Oops. floats only store 23 or 24 bits of mantissa.
I guess it's a feature...
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24387
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-10-20 14:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-15 18:32 [Bug c/24387] New: int-float cast fails for large int values neff dot kevin at mayo dot edu
2005-10-15 18:34 ` [Bug c/24387] " pinskia at gcc dot gnu dot org
2005-10-20 14:01 ` neff dot kevin at mayo dot edu
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).