public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* Multiplication with double produces wrong result
@ 2004-11-02 15:23 Christoph Rabel
0 siblings, 0 replies; only message in thread
From: Christoph Rabel @ 2004-11-02 15:23 UTC (permalink / raw)
To: gcc-bugs
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2004-11-02 15:23 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-02 15:23 Multiplication with double produces wrong result Christoph Rabel
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).