我調試我的代碼時感到驚訝。在這裏,我提供了示例代碼不完全從雙轉換爲int - 似乎問題是在CPU指令
#include<QMessageBox>
#include<iostream>
#include<math.h>
#include<QApplication>
using namespace std;
class MyMessageBox: public QMessageBox
{
public:
MyMessageBox(string message,QWidget *parent=0) :
QMessageBox(
QMessageBox::NoIcon,
QString("ErrorMessage"),
QString(message.c_str()),
QMessageBox::Ok,
parent,
Qt::Widget)
{
}
};
void Hai()
{
int tempi = 4;
double a = pow(10,tempi);
int temp = int(pow(10,tempi));
//int temp=a;
MyMessageBox mb1((QString::number(pow(10,tempi))+
" *** "+
QString::number(temp)).toStdString());
mb1.exec();
}
int main(int argc, char * argv[])
{
QApplication app(argc,argv);
Hai();
return app.exec();
}
,其結果是,
10000 *** 9999
而主要的一點是,這個事情發生僅用於電源4(= POW(X,4),不爲任何其它權力
編輯:
我試圖使用Visual Studio最少的代碼,但它產生萬正好但是,它從來沒有編譯,直到我做了C型。明確地反轉。下面的代碼給出
#include<iostream>
#include<math.h>
using namespace std;
void Hai()
{
int tempi = 4;
double a=pow(10.0,tempi);
int temp=pow(10.0,tempi);
cout << " a " << a << " temp " << temp << endl ;
}
int main(int argc, char * argv[])
{
Hai();
return 1;
}
請儘量舉例說明。你的例子包含一堆與任何東西無關的QT cruft - 一個使用printf()的10行程序也會顯示問題。 – 2010-11-29 06:51:40
@j_random_hacker請參閱編輯 – prabhakaran 2010-11-29 07:35:25