This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
double to int64 loses 1 problem
- From: Tao Ma <tm334 at ece dot msstate dot edu>
- To: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Fri, 20 Oct 2006 20:20:35 -0600
- Subject: double to int64 loses 1 problem
Hi, everybody:
The following code will get different result in gcc3.2.3 and
gcc3.4 (or higher, like gcc4.0 or gcc4.1.0).
Anybody can give me some idea? Thank you in advance.
--
Kind Regards,
Tao Ma
-----------------------------------------
class Integral {
typedef long long int int64;
typedef unsigned long long int ullong;
public:
static const double TWO_EXP63 = ((ullong)1 << 63);
};
#include <iostream>
#include <math.h>
using namespace std;
int main() {
typedef long long int int64;
typedef unsigned long long int ullong;
int64 num_4 = (int64)pow((double)2, (double)63);
int64 num_5 = (int64)Integral::TWO_EXP63;
cout << "gcc3.2.3 will get: 0x8000000000000000" << endl;
cout << "gcc4.1.0 will get: 0x7fffffffffffffff" << endl;
cout << hex << num_4 << endl;
cout << hex << num_5 << endl;
}