Function 的回答不正确
Answer from Function is incorrect
这个函数的答案返回到程序的主函数中,运行良好。问题是余弦应该为 0 的任何值,结果都会给出一个奇怪的无理数(类似于 1.30431912*10^-13)。所以,90、450等等,都是非理性的答案。怎么了?
float cosineDegrees() {
string i;
double iDouble;
cout << "Give me a number to find the value of degrees in. ";
getline(cin, i);
iDouble = stod(i);
double PI = 3.14159265359;
float answer = cos((PI/180)*iDouble);
return answer;
}
浮点数学的精度有限。您的 (PI/180)*iDouble
值约为 90 度角 1.30E-13 弧度。
如果您将 Pi 锁定到有限的精度,您就不能指望 'answer' 更精确。 10^-13其实基本为零,并不是'irrational.'计算机里一切都是有理数
这个函数的答案返回到程序的主函数中,运行良好。问题是余弦应该为 0 的任何值,结果都会给出一个奇怪的无理数(类似于 1.30431912*10^-13)。所以,90、450等等,都是非理性的答案。怎么了?
float cosineDegrees() {
string i;
double iDouble;
cout << "Give me a number to find the value of degrees in. ";
getline(cin, i);
iDouble = stod(i);
double PI = 3.14159265359;
float answer = cos((PI/180)*iDouble);
return answer;
}
浮点数学的精度有限。您的 (PI/180)*iDouble
值约为 90 度角 1.30E-13 弧度。
如果您将 Pi 锁定到有限的精度,您就不能指望 'answer' 更精确。 10^-13其实基本为零,并不是'irrational.'计算机里一切都是有理数