sincospi()
, . sinpi
cospi
-, . (. fenv.h
) , errno
, .
. , , 2π, . [-¼, + ¼] . . , .
( -0, NaN) , IEEE-754. x*0.0
0.0
( -0, NaN), 0.0-x
-x
, - 5.5.1 IEEE-754 ( NaN). , "" , . -fp-model=precise
Intel C/++.
nearbyint
. rint
, . fenv.h
, " ". , , . round
, " , ", . , .
: C99 fma()
, fused multiply-add, . , - FMA.
#include <math.h>
#include <stdint.h>
void my_sincospi (double a, double *sp, double *cp)
{
double c, r, s, t, az;
int64_t i;
az = a * 0.0;
a = (fabs (a) < 9.0071992547409920e+15) ? a : az;
r = nearbyint (a + a);
i = (int64_t)r;
t = fma (-0.5, r, a);
s = t * t;
r = -1.0369917389758117e-4;
r = fma (r, s, 1.9294935641298806e-3);
r = fma (r, s, -2.5806887942825395e-2);
r = fma (r, s, 2.3533063028328211e-1);
r = fma (r, s, -1.3352627688538006e+0);
r = fma (r, s, 4.0587121264167623e+0);
r = fma (r, s, -4.9348022005446790e+0);
c = fma (r, s, 1.0000000000000000e+0);
r = 4.6151442520157035e-4;
r = fma (r, s, -7.3700183130883555e-3);
r = fma (r, s, 8.2145868949323936e-2);
r = fma (r, s, -5.9926452893214921e-1);
r = fma (r, s, 2.5501640398732688e+0);
r = fma (r, s, -5.1677127800499516e+0);
s = s * t;
r = r * s;
s = fma (t, 3.1415926535897931e+0, r);
if (i & 2) {
s = 0.0 - s;
c = 0.0 - c;
}
if (i & 1) {
t = 0.0 - s;
s = c;
c = t;
}
if (a == floor (a)) s = az;
*sp = s;
*cp = c;
}
. .
#include <math.h>
#include <stdint.h>
void my_sincospif (float a, float *sp, float *cp)
{
float az, t, c, r, s;
int32_t i;
az = a * 0.0f;
a = (fabsf (a) < 0x1.0p24f) ? a : az;
r = nearbyintf (a + a);
i = (int32_t)r;
t = fmaf (-0.5f, r, a);
s = t * t;
r = 0x1.d9e000p-3f;
r = fmaf (r, s, -0x1.55c400p+0f);
r = fmaf (r, s, 0x1.03c1cep+2f);
r = fmaf (r, s, -0x1.3bd3ccp+2f);
c = fmaf (r, s, 0x1.000000p+0f);
r = -0x1.310000p-1f;
r = fmaf (r, s, 0x1.46737ep+1f);
r = fmaf (r, s, -0x1.4abbfep+2f);
r = (t * s) * r;
s = fmaf (t, 0x1.921fb6p+1f, r);
if (i & 2) {
s = 0.0f - s;
c = 0.0f - c;
}
if (i & 1) {
t = 0.0f - s;
s = c;
c = t;
}
if (a == floorf (a)) s = az;
*sp = s;
*cp = c;
}