123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- #include "cdefs-compat.h"
- #include <float.h>
- #include <openlibm_math.h>
- #include "math_private.h"
- static const double
- sc1pio2 = 1*M_PI_2,
- sc2pio2 = 2*M_PI_2,
- sc3pio2 = 3*M_PI_2,
- sc4pio2 = 4*M_PI_2,
- one = 1.0,
- S1 = -0x15555554cbac77.0p-55,
- S2 = 0x111110896efbb2.0p-59,
- S3 = -0x1a00f9e2cae774.0p-65,
- S4 = 0x16cd878c3b46a7.0p-71,
- C0 = -0x1ffffffd0c5e81.0p-54,
- C1 = 0x155553e1053a42.0p-57,
- C2 = -0x16c087e80f1e27.0p-62,
- C3 = 0x199342e0ee5069.0p-68;
- static void
- __kernel_sincosdf( double x, float * s, float * c )
- {
- double r, w, z, v;
- z = x*x;
- w = z*z;
-
- r = C2+z*C3;
- double k_c = ((one+z*C0) + w*C1) + (w*z)*r;
-
- r = S3+z*S4;
- v = z*x;
- double k_s = (x + v*(S1+z*S2)) + v*w*r;
- *c = k_c;
- *s = k_s;
- }
- OLM_DLLEXPORT void
- sincosf(float x, float * s, float * c) {
-
- *s = x;
- *c = x;
- double y;
- float k_c, k_s;
- int32_t n, hx, ix;
- GET_FLOAT_WORD(hx,x);
- ix = hx & 0x7fffffff;
- if(ix <= 0x3f490fda) {
- if(ix<0x39800000) {
-
- if(((int)x)==0) {
- *s = x;
- *c = 1.0f;
- return;
- }
- }
- __kernel_sincosdf(x, s, c);
- return;
- }
-
- if (ix<=0x407b53d1) {
-
- if(ix<=0x4016cbe3) {
- if(hx>0) {
- __kernel_sincosdf( sc1pio2 - x, c, s );
- }
- else {
- __kernel_sincosdf( sc1pio2 + x, c, &k_s );
- *s = -k_s;
- }
- } else {
- if(hx>0) {
- __kernel_sincosdf( sc2pio2 - x, s, &k_c );
- *c = -k_c;
- } else {
- __kernel_sincosdf( -sc2pio2 - x, s, &k_c );
- *c = -k_c;
- }
- }
- return;
- }
-
- if(ix<=0x40e231d5) {
-
- if(ix<=0x40afeddf) {
- if(hx>0) {
- __kernel_sincosdf( x - sc3pio2, c, &k_s );
- *s = -k_s;
- } else {
- __kernel_sincosdf( x + sc3pio2, &k_c, s );
- *c = -k_c;
- }
- }
- else {
- if( hx > 0 ) {
- __kernel_sincosdf( x - sc4pio2, s, c );
- } else {
- __kernel_sincosdf( x + sc4pio2, s, c );
- }
- }
- return;
- }
-
- else if(ix>=0x7f800000) {
- *c = *s = x-x;
- } else {
-
- n = __ieee754_rem_pio2f(x,&y);
- switch(n&3) {
- case 0:
- __kernel_sincosdf( y, s, c );
- break;
- case 1:
- __kernel_sincosdf( -y, c, s );
- break;
- case 2:
- __kernel_sincosdf( -y, s, &k_c);
- *c = -k_c;
- break;
- default:
- __kernel_sincosdf( -y, &k_c, &k_s );
- *c = -k_c;
- *s = -k_s;
- break;
- }
- }
- }
|