这是我的简单代码:
int main() {
double d1 = 10000000000.0;
const double d2 = 10000000000.0;
cout << static_cast<int>(d1) << endl;
cout << static_cast<int>(d2) << endl;
cout << static_cast<int>(10000000000.0) << endl;
}
Run Code Online (Sandbox Code Playgroud)
输出是:
-2147483648
2147483647
2147483647
Run Code Online (Sandbox Code Playgroud)
这令我感到惊讶.为什么一个正面的双重有时会被转换为负数?
我正在使用g++:GCC版本4.4.3(Ubuntu 4.4.3-4ubuntu5).