注意tan、atan等三角函数不能接受整数,如:tan(1)会报错“error C2668: 'tan' : ambiguous call to overloaded function” ,改为浮点型即可正确计算。
1、错误代码如下:
#include <iostream>
#include <cmath>
using namespace std;
#define PI 3.1415926
int main()
{
float tanValue = tan(1);
cout<<"tan(1) = "<<tanValue<<endl;
float atanValue = atan(1);
cout<<"atan(1) = "<<atanValue<<endl;
cin.get();
return 0;
}
报错信息如下:
2、修改后的正确代码如下:
#include <iostream>
#include <cmath>
using namespace std;
#define PI 3.1415926
int main()
{
float tanValue = tan(1.0f);
cout<<"tan(1) = "<<tanValue<<endl;
float atanValue = atan(1.0f);
cout<<"atan(1) = "<<atanValue<<endl;
cin.get();
return 0;
}
正确输出结果如下: