int main() {
double inf = INFINITY;
double pi = acos(-1.0);
printf("[1]: %f %f\n", atan(inf) / pi, atan(-inf) / pi);
printf("[2]: %f %f\n", tan(inf) / pi, tan(-inf) / pi);
return 0;
}
输出
[1]: 0.500000 -0.500000
[2]: -nan -nan
标准是否定义了这种行为? [2]
是未定义的行为吗?未指定?
我想确定至少 [1]
是有保证的结果。
最佳答案
两者都是明确定义的行为。 引自 http://en.cppreference.com
棕褐色
If the argument is ±0, it is returned unmodified.
If the argument is ±∞, NaN is returned and FE_INVALID is raised.
If the argument is NaN, NaN is returned.阿坦
If the argument is ±0, it is returned unmodified.
If the argument is +∞, +π/2 is returned.
If the argument is -∞, -π/2 is returned.
If the argument is NaN, NaN is returned.
关于c++ - 标准数学函数能否正确处理无穷大?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30696923/