这个三角参数约简中有什么 "discontinuities in the error"?

What "discontinuities in the error" are present in this trigonometric argument reduction?

我一直在阅读 C99 Rationale,在那里我找到了这段神秘的摘录(重点是我的):

7.12.4 Trigonometric functions

Implementation note: trignometric argument reduction should be performed by a method that causes no catastrophic discontinuities in the error of the computed result. In particular, methods based solely on naive application of a calculation like

x - (2*pi) * (int)(x/(2*pi))

are ill-advised.

这个减少公式究竟有什么问题?看来,根据属性的周期,间隔2*pi.

,看起来还不错

π 是一个无理数,无法用有限的浮点值精确表示 - 都是有理数。

各种实现支持像 M_PI 这样的常量,它接近但不完全是 π。所以下面引入error。 (x/(2*pi)超出int范围当然是个问题。

double pi = M_PI;
double x;  // radians
double y;  // reduced radians.
y  = x - (2*pi) * (int)(x/(2*pi))

如果此错误对特定于应用程序的代码很重要。典型的问题是 tan(x),其中 x 接近 π*(n +1/2),x 的微小变化将产生 + 或 - 无穷大/DBL_MAX

一些平台提供减少 π 的函数。

这个问题的一个很好的参考是ARGUMENT REDUCTION FOR HUGE ARGUMENTS: Good to Last Bit K. C. Ng和SunPro的FP组成员


减少度数:

度数的范围缩小是 fmod(x,360.0),预计会将 x 缩小到范围 -360.0 < x < +360.0 正好 。最好使用 remquo