double SECTION __mpsin1(double x) { int p; int n; mp_no u,s,c; double y; p=32; n=__mpranred(x,&u,p); /* n is 0, 1, 2 or 3 */ __c32(&u,&c,&s,p); switch (n) { /* in which quarter of unit circle y is*/ case 0: __mp_dbl(&s,&y,p); return y; break; case 2: __mp_dbl(&s,&y,p); return -y; break; case 1: __mp_dbl(&c,&y,p); return y; break; case 3: __mp_dbl(&c,&y,p); return -y; break; } return 0; /* unreachable, to make the compiler happy */ }
/* Compute cos() of double-length number (X + DX) as Multi Precision number and return result as double. If REDUCE_RANGE is true, X is assumed to be the original input and DX is ignored. */ double SECTION __mpcos (double x, double dx, bool reduce_range) { double y; mp_no a, b, c, s; int n; int p = 32; if (reduce_range) { n = __mpranred (x, &a, p); /* n is 0, 1, 2 or 3. */ __c32 (&a, &c, &s, p); } else { n = -1; __dbl_mp (x, &b, p); __dbl_mp (dx, &c, p); __add (&b, &c, &a, p); if (x > 0.8) { __sub (&hp, &a, &b, p); __c32 (&b, &s, &c, p); } else __c32 (&a, &c, &s, p); /* a = cos(x+dx) */ } /* Convert result based on which quarter of unit circle y is in. */ switch (n) { case 1: __mp_dbl (&s, &y, p); y = -y; break; case 3: __mp_dbl (&s, &y, p); break; case 2: __mp_dbl (&c, &y, p); y = -y; break; /* Quadrant not set, so the result must be cos (X + DX), which is also stored in C. */ case 0: default: __mp_dbl (&c, &y, p); } LIBC_PROBE (slowcos, 3, &x, &dx, &y); return y; }
void SECTION __mptan (double x, mp_no *mpy, int p) { int n; mp_no mpw, mpc, mps; /* Negative or positive result. */ n = __mpranred (x, &mpw, p) & 0x00000001; /* Computing sin(x) and cos(x). */ __c32 (&mpw, &mpc, &mps, p); /* Second or fourth quarter of unit circle. */ if (n) { __dvd (&mpc, &mps, mpy, p); mpy->d[0] *= -1; } /* tan is negative in this area. */ else __dvd (&mps, &mpc, mpy, p); }