casting bug

flatmax flatmax@cse.unsw.EDU.AU
Thu May 13 05:12:00 GMT 1999


GCC version:
Reading specs from 
/usr/local/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)

System type :
libc: libc.so.5.4.44
Linux 2.2.4 pentium II (slackware)

I have compiled the following in both C++ and gcc :
_________________ error.cc ___________________
#define CPLUSPLUS

#ifdef CPLUSPLUS
#include <iomanip.h>
#else
#include <stdio.h>
#endif

main(){
  int steps=10;
  double fact, factor;
  factor=1.0/(double)steps;
  fact = 1.0;
  while (fact >= 0.0){
#ifdef CPLUSPLUS
    cout <<fact/factor<<' ';
    cout <<(int)(fact/factor)<<endl;
#else
    printf("%d %d\n", fact/factor, (int)(fact/factor));
#endif
    fact-=factor;
  }
}
____________________________________________________________

It output the following: (with errors highlighted by me)
C++:
10 9
9 8   <-error should both be 9
8 8
7 7
6 6
5 5
4 4
3 3
2 2
1 1
1.38778e-15 0 <- error should both be 0

C: (big worries --- should all be numbers ranging 9 to 0 !!)
0 1076101120 
0 1075970048
0 1075838976
0 1075576832
1 1075314688
1 1075052544
1 1074790400
3 1074266112
3 1073741824
6 1072693248
0 1020854272

I believe it is a casting bug

Please help me to help myself and your group ... if it is a compiler bug
!!

thanks
Matt
__________
reverse ...
backwards needs forwards
want backwards - first go forwards
viva



More information about the Gcc-bugs mailing list