Multiplication with double produces wrong result
Christoph Rabel
odie@hal9000.vc-graz.ac.at
Tue Nov 2 15:23:00 GMT 2004
Hi!
The following program compiled with gcc 3.3.3
#include <iostream>
using namespace std;
int main() {
double x = 0.55;
int v1 = (int) (x * UINT_MAX);
int v2 = (int) (0.55 * UINT_MAX);
cout << dec << v1 << "\t" << hex << v1 << endl;
cout << dec << v2 << "\t" << hex << v2 << endl;
}
produces the output:
-2147483648 80000000
-1932735284 8ccccccc
This is obviously a bug.
Changing "double x = 0.55;" to "const double x = 0.55;" produces
expected results.
Christoph
More information about the Gcc-bugs
mailing list