]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - sysdeps/ieee754/dbl-64/s_sin.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / ieee754 / dbl-64 / s_sin.c
index 9ecba05db29dc7b595f5e2418ff9c62af79d5fbb..8c589cbd4ab7451a5889e9a474bf4bd36c49d498 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * IBM Accurate Mathematical Library
  * written by International Business Machines Corp.
- * Copyright (C) 2001-2016 Free Software Foundation, Inc.
+ * Copyright (C) 2001-2018 Free Software Foundation, Inc.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -52,6 +52,7 @@
 #include "MathLib.h"
 #include <math.h>
 #include <math_private.h>
+#include <libm-alias-double.h>
 #include <fenv.h>
 
 /* Helper macros to compute sin of the input values.  */
@@ -132,8 +133,8 @@ double __mpcos (double x, double dx, bool reduce_range);
 static double slow (double x);
 static double slow1 (double x);
 static double slow2 (double x);
-static double sloww (double x, double dx, double orig, int n);
-static double sloww1 (double x, double dx, double orig, int n);
+static double sloww (double x, double dx, double orig, bool shift_quadrant);
+static double sloww1 (double x, double dx, double orig, bool shift_quadrant);
 static double sloww2 (double x, double dx, double orig, int n);
 static double bsloww (double x, double dx, double orig, int n);
 static double bsloww1 (double x, double dx, double orig, int n);
@@ -141,14 +142,22 @@ static double bsloww2 (double x, double dx, double orig, int n);
 int __branred (double x, double *a, double *aa);
 static double cslow2 (double x);
 
-/* Given a number partitioned into U and X such that U is an index into the
-   sin/cos table, this macro computes the cosine of the number by combining
-   the sin and cos of X (as computed by a variation of the Taylor series) with
-   the values looked up from the sin/cos table to get the result in RES and a
-   correction value in COR.  */
-static double
-do_cos (mynumber u, double x, double *corp)
+/* Given a number partitioned into X and DX, this function computes the cosine
+   of the number by combining the sin and cos of X (as computed by a variation
+   of the Taylor series) with the values looked up from the sin/cos table to
+   get the result in RES and a correction value in COR.  */
+static inline double
+__always_inline
+do_cos (double x, double dx, double *corp)
 {
+  mynumber u;
+
+  if (x < 0)
+    dx = -dx;
+
+  u.x = big + fabs (x);
+  x = fabs (x) - (u.x - big) + dx;
+
   double xx, s, sn, ssn, c, cs, ccs, res, cor;
   xx = x * x;
   s = x + x * xx * (sn3 + xx * sn5);
@@ -161,11 +170,20 @@ do_cos (mynumber u, double x, double *corp)
   return res;
 }
 
-/* A more precise variant of DO_COS where the number is partitioned into U, X
-   and DX.  EPS is the adjustment to the correction COR.  */
-static double
-do_cos_slow (mynumber u, double x, double dx, double eps, double *corp)
+/* A more precise variant of DO_COS.  EPS is the adjustment to the correction
+   COR.  */
+static inline double
+__always_inline
+do_cos_slow (double x, double dx, double eps, double *corp)
 {
+  mynumber u;
+
+  if (x <= 0)
+    dx = -dx;
+
+  u.x = big + fabs (x);
+  x = fabs (x) - (u.x - big);
+
   double xx, y, x1, x2, e1, e2, res, cor;
   double s, sn, ssn, c, cs, ccs;
   xx = x * x;
@@ -181,19 +199,26 @@ do_cos_slow (mynumber u, double x, double dx, double eps, double *corp)
   cor = cor + ((cs - y) - e1 * x1);
   res = y + cor;
   cor = (y - res) + cor;
-  cor = 1.0005 * cor + ((cor > 0) ? eps : -eps);
+  cor = 1.0005 * cor + __copysign (eps, cor);
   *corp = cor;
   return res;
 }
 
-/* Given a number partitioned into U and X and DX such that U is an index into
-   the sin/cos table, this macro computes the sine of the number by combining
-   the sin and cos of X (as computed by a variation of the Taylor series) with
-   the values looked up from the sin/cos table to get the result in RES and a
-   correction value in COR.  */
-static double
-do_sin (mynumber u, double x, double dx, double *corp)
+/* Given a number partitioned into X and DX, this function computes the sine of
+   the number by combining the sin and cos of X (as computed by a variation of
+   the Taylor series) with the values looked up from the sin/cos table to get
+   the result in RES and a correction value in COR.  */
+static inline double
+__always_inline
+do_sin (double x, double dx, double *corp)
 {
+  mynumber u;
+
+  if (x <= 0)
+    dx = -dx;
+  u.x = big + fabs (x);
+  x = fabs (x) - (u.x - big);
+
   double xx, s, sn, ssn, c, cs, ccs, cor, res;
   xx = x * x;
   s = x + (dx + x * xx * (sn3 + xx * sn5));
@@ -206,11 +231,19 @@ do_sin (mynumber u, double x, double dx, double *corp)
   return res;
 }
 
-/* A more precise variant of res = do_sin where the number is partitioned into U, X
-   and DX.  EPS is the adjustment to the correction COR.  */
-static double
-do_sin_slow (mynumber u, double x, double dx, double eps, double *corp)
+/* A more precise variant of DO_SIN.  EPS is the adjustment to the correction
+   COR.  */
+static inline double
+__always_inline
+do_sin_slow (double x, double dx, double eps, double *corp)
 {
+  mynumber u;
+
+  if (x <= 0)
+    dx = -dx;
+  u.x = big + fabs (x);
+  x = fabs (x) - (u.x - big);
+
   double xx, y, x1, x2, c1, c2, res, cor;
   double s, sn, ssn, c, cs, ccs;
   xx = x * x;
@@ -226,21 +259,21 @@ do_sin_slow (mynumber u, double x, double dx, double eps, double *corp)
   cor = cor + ((sn - y) + c1 * x1);
   res = y + cor;
   cor = (y - res) + cor;
-  cor = 1.0005 * cor + ((cor > 0) ? eps : -eps);
+  cor = 1.0005 * cor + __copysign (eps, cor);
   *corp = cor;
   return res;
 }
 
-/* Reduce range of X and compute sin of a + da.  K is the amount by which to
-   rotate the quadrants.  This allows us to use the same routine to compute cos
-   by simply rotating the quadrants by 1.  */
+/* Reduce range of X and compute sin of a + da. When SHIFT_QUADRANT is true,
+   the routine returns the cosine of a + da by rotating the quadrant once and
+   computing the sine of the result.  */
 static inline double
 __always_inline
-reduce_and_compute (double x, unsigned int k)
+reduce_and_compute (double x, bool shift_quadrant)
 {
   double retval = 0, a, da;
   unsigned int n = __branred (x, &a, &da);
-  k = (n + k) % 4;
+  int4 k = (n + shift_quadrant) % 4;
   switch (k)
     {
     case 2:
@@ -283,17 +316,16 @@ reduce_sincos_1 (double x, double *a, double *da)
   return n;
 }
 
-/* Compute sin (A + DA).  cos can be computed by shifting the quadrant N
-   clockwise.  */
+/* Compute sin (A + DA).  cos can be computed by passing SHIFT_QUADRANT as
+   true, which results in shifting the quadrant N clockwise.  */
 static double
 __always_inline
-do_sincos_1 (double a, double da, double x, int4 n, int4 k)
+do_sincos_1 (double a, double da, double x, int4 n, bool shift_quadrant)
 {
-  double xx, retval, res, cor, y;
-  mynumber u;
+  double xx, retval, res, cor;
   double eps = fabs (x) * 1.2e-30;
 
-  int k1 = (n + k) & 3;
+  int k1 = (n + shift_quadrant) & 3;
   switch (k1)
     {                  /* quarter of unit circle */
     case 2:
@@ -306,33 +338,25 @@ do_sincos_1 (double a, double da, double x, int4 n, int4 k)
        {
          /* Taylor series.  */
          res = TAYLOR_SIN (xx, a, da, cor);
-         cor = (cor > 0) ? 1.02 * cor + eps : 1.02 * cor - eps;
-         retval = (res == res + cor) ? res : sloww (a, da, x, k);
+         cor = 1.02 * cor + __copysign (eps, cor);
+         retval = (res == res + cor) ? res : sloww (a, da, x, shift_quadrant);
        }
       else
        {
-         double db = (a > 0 ? da : -da);
-         u.x = big + fabs (a);
-         y = fabs (a) - (u.x - big);
-         res = do_sin (u, y, db, &cor);
-         cor = (cor > 0) ? 1.035 * cor + eps : 1.035 * cor - eps;
-         retval = ((res == res + cor) ? ((a > 0) ? res : -res)
-                   : sloww1 (a, da, x, k));
+         res = do_sin (a, da, &cor);
+         cor = 1.035 * cor + __copysign (eps, cor);
+         retval = ((res == res + cor) ? __copysign (res, a)
+                   : sloww1 (a, da, x, shift_quadrant));
        }
       break;
 
     case 1:
     case 3:
-       {
-         double db = (a > 0 ? da : -da);
-         u.x = big + fabs (a);
-         y = fabs (a) - (u.x - big) + db;
-         res = do_cos (u, y, &cor);
-         cor = (cor > 0) ? 1.025 * cor + eps : 1.025 * cor - eps;
-         retval = ((res == res + cor) ? ((k1 & 2) ? -res : res)
-                   : sloww2 (a, da, x, n));
-         break;
-       }
+      res = do_cos (a, da, &cor);
+      cor = 1.025 * cor + __copysign (eps, cor);
+      retval = ((res == res + cor) ? ((n & 2) ? -res : res)
+               : sloww2 (a, da, x, n));
+      break;
     }
 
   return retval;
@@ -364,18 +388,17 @@ reduce_sincos_2 (double x, double *a, double *da)
   return n;
 }
 
-/* Compute sin (A + DA).  cos can be computed by shifting the quadrant N
-   clockwise.  */
+/* Compute sin (A + DA).  cos can be computed by passing SHIFT_QUADRANT as
+   true, which results in shifting the quadrant N clockwise.  */
 static double
 __always_inline
-do_sincos_2 (double a, double da, double x, int4 n, int4 k)
+do_sincos_2 (double a, double da, double x, int4 n, bool shift_quadrant)
 {
   double res, retval, cor, xx;
-  mynumber u;
 
   double eps = 1.0e-24;
 
-  k = (n + k) & 3;
+  int4 k = (n + shift_quadrant) & 3;
 
   switch (k)
     {
@@ -389,33 +412,25 @@ do_sincos_2 (double a, double da, double x, int4 n, int4 k)
        {
          /* Taylor series.  */
          res = TAYLOR_SIN (xx, a, da, cor);
-         cor = (cor > 0) ? 1.02 * cor + eps : 1.02 * cor - eps;
+         cor = 1.02 * cor + __copysign (eps, cor);
          retval = (res == res + cor) ? res : bsloww (a, da, x, n);
        }
       else
        {
-         double db = (a > 0 ? da : -da);
-         u.x = big + fabs (a);
-         double y = fabs (a) - (u.x - big);
-         res = do_sin (u, y, db, &cor);
-         cor = (cor > 0) ? 1.035 * cor + eps : 1.035 * cor - eps;
-         retval = ((res == res + cor) ? ((a > 0) ? res : -res)
+         res = do_sin (a, da, &cor);
+         cor = 1.035 * cor + __copysign (eps, cor);
+         retval = ((res == res + cor) ? __copysign (res, a)
                    : bsloww1 (a, da, x, n));
        }
       break;
 
     case 1:
     case 3:
-       {
-         double db = (a > 0 ? da : -da);
-         u.x = big + fabs (a);
-         double y = fabs (a) - (u.x - big) + db;
-         res = do_cos (u, y, &cor);
-         cor = (cor > 0) ? 1.025 * cor + eps : 1.025 * cor - eps;
-         retval = ((res == res + cor) ? ((n & 2) ? -res : res)
-                   : bsloww2 (a, da, x, n));
-         break;
-       }
+      res = do_cos (a, da, &cor);
+      cor = 1.025 * cor + __copysign (eps, cor);
+      retval = ((res == res + cor) ? ((n & 2) ? -res : res)
+               : bsloww2 (a, da, x, n));
+      break;
     }
 
   return retval;
@@ -433,7 +448,7 @@ SECTION
 #endif
 __sin (double x)
 {
-  double xx, res, t, cor, y, s, c, sn, ssn, cs, ccs;
+  double xx, res, t, cor;
   mynumber u;
   int4 k, m;
   double retval = 0;
@@ -463,23 +478,9 @@ __sin (double x)
 /*---------------------------- 0.25<|x|< 0.855469---------------------- */
   else if (k < 0x3feb6000)
     {
-      u.x = big + fabs (x);
-      y = fabs (x) - (u.x - big);
-      y = (x > 0 ? y : -y);
-
-      xx = y * y;
-      s = y + y * xx * (sn3 + xx * sn5);
-      c = xx * (cs2 + xx * (cs4 + xx * cs6));
-      SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs);
-      if (m <= 0)
-        {
-          sn = -sn;
-         ssn = -ssn;
-       }
-      cor = (ssn + s * ccs - sn * c) + cs * s;
-      res = sn + cor;
-      cor = (sn - res) + cor;
+      res = do_sin (x, 0, &cor);
       retval = (res == res + 1.096 * cor) ? res : slow1 (x);
+      retval = __copysign (retval, x);
     }                          /*   else  if (k < 0x3feb6000)    */
 
 /*----------------------- 0.855469  <|x|<2.426265  ----------------------*/
@@ -487,12 +488,9 @@ __sin (double x)
     {
 
       t = hp0 - fabs (x);
-      u.x = big + fabs (t);
-      y = fabs (t) - (u.x - big);
-      y = ((t >= 0) ? hp1 : -hp1) + y;
-
-      res = do_cos (u, y, &cor);
-      retval = (res == res + 1.020 * cor) ? ((m > 0) ? res : -res) : slow2 (x);
+      res = do_cos (t, hp1, &cor);
+      retval = (res == res + 1.020 * cor) ? res : slow2 (x);
+      retval = __copysign (retval, x);
     }                          /*   else  if (k < 0x400368fd)    */
 
 #ifndef IN_SINCOS
@@ -501,7 +499,7 @@ __sin (double x)
     {
       double a, da;
       int4 n = reduce_sincos_1 (x, &a, &da);
-      retval = do_sincos_1 (a, da, x, n, 0);
+      retval = do_sincos_1 (a, da, x, n, false);
     }                          /*   else  if (k <  0x419921FB )    */
 
 /*---------------------105414350 <|x|< 281474976710656 --------------------*/
@@ -510,12 +508,12 @@ __sin (double x)
       double a, da;
 
       int4 n = reduce_sincos_2 (x, &a, &da);
-      retval = do_sincos_2 (a, da, x, n, 0);
+      retval = do_sincos_2 (a, da, x, n, false);
     }                          /*   else  if (k <  0x42F00000 )   */
 
 /* -----------------281474976710656 <|x| <2^1024----------------------------*/
   else if (k < 0x7ff00000)
-    retval = reduce_and_compute (x, 0);
+    retval = reduce_and_compute (x, false);
 
 /*--------------------- |x| > 2^1024 ----------------------------------*/
   else
@@ -563,10 +561,7 @@ __cos (double x)
 
   else if (k < 0x3feb6000)
     {                          /* 2^-27 < |x| < 0.855469 */
-      y = fabs (x);
-      u.x = big + y;
-      y = y - (u.x - big);
-      res = do_cos (u, y, &cor);
+      res = do_cos (x, 0, &cor);
       retval = (res == res + 1.020 * cor) ? res : cslow2 (x);
     }                          /*   else  if (k < 0x3feb6000)    */
 
@@ -579,18 +574,15 @@ __cos (double x)
       if (xx < 0.01588)
        {
          res = TAYLOR_SIN (xx, a, da, cor);
-         cor = (cor > 0) ? 1.02 * cor + 1.0e-31 : 1.02 * cor - 1.0e-31;
-         retval = (res == res + cor) ? res : sloww (a, da, x, 1);
+         cor = 1.02 * cor + __copysign (1.0e-31, cor);
+         retval = (res == res + cor) ? res : sloww (a, da, x, true);
        }
       else
        {
-         double db = (a > 0 ? da : -da);
-         u.x = big + fabs (a);
-         y = fabs (a) - (u.x - big);
-         res = do_sin (u, y, db, &cor);
-         cor = (cor > 0) ? 1.035 * cor + 1.0e-31 : 1.035 * cor - 1.0e-31;
-         retval = ((res == res + cor) ? ((a > 0) ? res : -res)
-                   : sloww1 (a, da, x, 1));
+         res = do_sin (a, da, &cor);
+         cor = 1.035 * cor + __copysign (1.0e-31, cor);
+         retval = ((res == res + cor) ? __copysign (res, a)
+                   : sloww1 (a, da, x, true));
        }
 
     }                          /*   else  if (k < 0x400368fd)    */
@@ -601,7 +593,7 @@ __cos (double x)
     {                          /* 2.426265<|x|< 105414350 */
       double a, da;
       int4 n = reduce_sincos_1 (x, &a, &da);
-      retval = do_sincos_1 (a, da, x, n, 1);
+      retval = do_sincos_1 (a, da, x, n, true);
     }                          /*   else  if (k <  0x419921FB )    */
 
   else if (k < 0x42F00000)
@@ -609,12 +601,12 @@ __cos (double x)
       double a, da;
 
       int4 n = reduce_sincos_2 (x, &a, &da);
-      retval = do_sincos_2 (a, da, x, n, 1);
+      retval = do_sincos_2 (a, da, x, n, true);
     }                          /*   else  if (k <  0x42F00000 )    */
 
   /* 281474976710656 <|x| <2^1024 */
   else if (k < 0x7ff00000)
-    retval = reduce_and_compute (x, 1);
+    retval = reduce_and_compute (x, true);
 
   else
     {
@@ -632,8 +624,8 @@ __cos (double x)
 /* precision  and if still doesn't accurate enough by mpsin   or dubsin */
 /************************************************************************/
 
-static double
-SECTION
+static inline double
+__always_inline
 slow (double x)
 {
   double res, cor, w[2];
@@ -643,9 +635,9 @@ slow (double x)
 
   __dubsin (fabs (x), 0, w);
   if (w[0] == w[0] + 1.000000001 * w[1])
-    return (x > 0) ? w[0] : -w[0];
+    return __copysign (w[0], x);
 
-  return (x > 0) ? __mpsin (x, 0, false) : -__mpsin (-x, 0, false);
+  return __copysign (__mpsin (fabs (x), 0, false), x);
 }
 
 /*******************************************************************************/
@@ -653,67 +645,56 @@ slow (double x)
 /* and if result still doesn't accurate enough by mpsin   or dubsin            */
 /*******************************************************************************/
 
-static double
-SECTION
+static inline double
+__always_inline
 slow1 (double x)
 {
-  mynumber u;
-  double w[2], y, cor, res;
-  y = fabs (x);
-  u.x = big + y;
-  y = y - (u.x - big);
-  res = do_sin_slow (u, y, 0, 0, &cor);
+  double w[2], cor, res;
+
+  res = do_sin_slow (x, 0, 0, &cor);
   if (res == res + cor)
-    return (x > 0) ? res : -res;
+    return res;
 
   __dubsin (fabs (x), 0, w);
   if (w[0] == w[0] + 1.000000005 * w[1])
-    return (x > 0) ? w[0] : -w[0];
+    return w[0];
 
-  return (x > 0) ? __mpsin (x, 0, false) : -__mpsin (-x, 0, false);
+  return __mpsin (fabs (x), 0, false);
 }
 
 /**************************************************************************/
 /*  Routine compute sin(x) for   0.855469  <|x|<2.426265  by  __sincostab.tbl  */
 /* and if result still doesn't accurate enough by mpsin   or dubsin       */
 /**************************************************************************/
-static double
-SECTION
+static inline double
+__always_inline
 slow2 (double x)
 {
-  mynumber u;
-  double w[2], y, y1, y2, cor, res, del;
+  double w[2], y, y1, y2, cor, res;
 
   double t = hp0 - fabs (x);
-  u.x = big + fabs (t);
-  y = fabs (t) - (u.x - big);
-  del = (t >= 0) ? hp1 : -hp1;
-
-  res = do_cos_slow (u, y, del, 0, &cor);
+  res = do_cos_slow (t, hp1, 0, &cor);
   if (res == res + cor)
-    return (x > 0) ? res : -res;
+    return res;
 
   y = fabs (x) - hp0;
   y1 = y - hp1;
   y2 = (y - y1) - hp1;
   __docos (y1, y2, w);
   if (w[0] == w[0] + 1.000000005 * w[1])
-    return (x > 0) ? w[0] : -w[0];
+    return w[0];
 
-  return (x > 0) ? __mpsin (x, 0, false) : -__mpsin (-x, 0, false);
+  return __mpsin (fabs (x), 0, false);
 }
 
-/***************************************************************************/
-/*  Routine compute sin(x+dx) (Double-Length number) where x is small enough*/
-/* to use Taylor series around zero and   (x+dx)                            */
-/* in first or third quarter of unit circle.Routine receive also            */
-/* (right argument) the  original   value of x for computing error of      */
-/* result.And if result not accurate enough routine calls mpsin1 or dubsin */
-/***************************************************************************/
-
-static double
-SECTION
-sloww (double x, double dx, double orig, int k)
+/* Compute sin(x + dx) where X is small enough to use Taylor series around zero
+   and (x + dx) in the first or third quarter of the unit circle.  ORIG is the
+   original value of X for computing error of the result.  If the result is not
+   accurate enough, the routine calls mpsin or dubsin.  SHIFT_QUADRANT rotates
+   the unit circle by 1 to compute the cosine instead of sine.  */
+static inline double
+__always_inline
+sloww (double x, double dx, double orig, bool shift_quadrant)
 {
   double y, t, res, cor, w[2], a, da, xn;
   mynumber v;
@@ -722,7 +703,7 @@ sloww (double x, double dx, double orig, int k)
 
   double eps = fabs (orig) * 3.1e-30;
 
-  cor = 1.0005 * cor + ((cor > 0) ? eps : -eps);
+  cor = 1.0005 * cor + __copysign (eps, cor);
 
   if (res == res + cor)
     return res;
@@ -731,16 +712,16 @@ sloww (double x, double dx, double orig, int k)
   da = (x > 0) ? dx : -dx;
   __dubsin (a, da, w);
   eps = fabs (orig) * 1.1e-30;
-  cor = 1.000000001 * w[1] + ((w[1] > 0) ? eps : -eps);
+  cor = 1.000000001 * w[1] + __copysign (eps, w[1]);
 
   if (w[0] == w[0] + cor)
-    return (x > 0) ? w[0] : -w[0];
+    return __copysign (w[0], x);
 
   t = (orig * hpinv + toint);
   xn = t - toint;
   v.x = t;
   y = (orig - xn * mp1) - xn * mp2;
-  n = (v.i[LOW_HALF] + k) & 3;
+  n = (v.i[LOW_HALF] + shift_quadrant) & 3;
   da = xn * pp3;
   t = y - da;
   da = (y - t) - da;
@@ -757,45 +738,40 @@ sloww (double x, double dx, double orig, int k)
   dx = (a > 0) ? da : -da;
   __dubsin (x, dx, w);
   eps = fabs (orig) * 1.1e-40;
-  cor = 1.000000001 * w[1] + ((w[1] > 0) ? eps : -eps);
+  cor = 1.000000001 * w[1] + __copysign (eps, w[1]);
 
   if (w[0] == w[0] + cor)
-    return (a > 0) ? w[0] : -w[0];
+    return __copysign (w[0], a);
 
-  return k ? __mpcos (orig, 0, true) : __mpsin (orig, 0, true);
+  return shift_quadrant ? __mpcos (orig, 0, true) : __mpsin (orig, 0, true);
 }
 
-/***************************************************************************/
-/*  Routine compute sin(x+dx)   (Double-Length number) where x in first or  */
-/*  third quarter of unit circle.Routine receive also (right argument) the  */
-/*  original   value of x for computing error of result.And if result not  */
-/* accurate enough routine calls  mpsin1   or dubsin                       */
-/***************************************************************************/
-
-static double
-SECTION
-sloww1 (double x, double dx, double orig, int k)
+/* Compute sin(x + dx) where X is in the first or third quarter of the unit
+   circle.  ORIG is the original value of X for computing error of the result.
+   If the result is not accurate enough, the routine calls mpsin or dubsin.
+   SHIFT_QUADRANT rotates the unit circle by 1 to compute the cosine instead of
+   sine.  */
+static inline double
+__always_inline
+sloww1 (double x, double dx, double orig, bool shift_quadrant)
 {
-  mynumber u;
-  double w[2], y, cor, res;
+  double w[2], cor, res;
 
-  u.x = big + fabs (x);
-  y = fabs (x) - (u.x - big);
-  dx = (x > 0 ? dx : -dx);
-  res = do_sin_slow (u, y, dx, 3.1e-30 * fabs (orig), &cor);
+  res = do_sin_slow (x, dx, 3.1e-30 * fabs (orig), &cor);
 
   if (res == res + cor)
-    return (x > 0) ? res : -res;
+    return __copysign (res, x);
 
+  dx = (x > 0 ? dx : -dx);
   __dubsin (fabs (x), dx, w);
 
   double eps = 1.1e-30 * fabs (orig);
-  cor = 1.000000005 * w[1] + ((w[1] > 0) ? eps : -eps);
+  cor = 1.000000005 * w[1] + __copysign (eps, w[1]);
 
   if (w[0] == w[0] + cor)
-    return (x > 0) ? w[0] : -w[0];
+    return __copysign (w[0], x);
 
-  return (k == 1) ? __mpcos (orig, 0, true) : __mpsin (orig, 0, true);
+  return shift_quadrant ? __mpcos (orig, 0, true) : __mpsin (orig, 0, true);
 }
 
 /***************************************************************************/
@@ -805,25 +781,22 @@ sloww1 (double x, double dx, double orig, int k)
 /* accurate enough routine calls  mpsin1   or dubsin                       */
 /***************************************************************************/
 
-static double
-SECTION
+static inline double
+__always_inline
 sloww2 (double x, double dx, double orig, int n)
 {
-  mynumber u;
-  double w[2], y, cor, res;
+  double w[2], cor, res;
 
-  u.x = big + fabs (x);
-  y = fabs (x) - (u.x - big);
-  dx = (x > 0 ? dx : -dx);
-  res = do_cos_slow (u, y, dx, 3.1e-30 * fabs (orig), &cor);
+  res = do_cos_slow (x, dx, 3.1e-30 * fabs (orig), &cor);
 
   if (res == res + cor)
     return (n & 2) ? -res : res;
 
+  dx = x > 0 ? dx : -dx;
   __docos (fabs (x), dx, w);
 
   double eps = 1.1e-30 * fabs (orig);
-  cor = 1.000000005 * w[1] + ((w[1] > 0) ? eps : -eps);
+  cor = 1.000000005 * w[1] + __copysign (eps, w[1]);
 
   if (w[0] == w[0] + cor)
     return (n & 2) ? -w[0] : w[0];
@@ -839,24 +812,24 @@ sloww2 (double x, double dx, double orig, int n)
 /* result.And if result not accurate enough routine calls other routines    */
 /***************************************************************************/
 
-static double
-SECTION
+static inline double
+__always_inline
 bsloww (double x, double dx, double orig, int n)
 {
   double res, cor, w[2], a, da;
 
   res = TAYLOR_SLOW (x, dx, cor);
-  cor = 1.0005 * cor + ((cor > 0) ? 1.1e-24 : -1.1e-24);
+  cor = 1.0005 * cor + __copysign (1.1e-24, cor);
   if (res == res + cor)
     return res;
 
   a = fabs (x);
   da = (x > 0) ? dx : -dx;
   __dubsin (a, da, w);
-  cor = 1.000000001 * w[1] + ((w[1] > 0) ? 1.1e-24 : -1.1e-24);
+  cor = 1.000000001 * w[1] + __copysign (1.1e-24, w[1]);
 
   if (w[0] == w[0] + cor)
-    return (x > 0) ? w[0] : -w[0];
+    return __copysign (w[0], x);
 
   return (n & 1) ? __mpcos (orig, 0, true) : __mpsin (orig, 0, true);
 }
@@ -868,27 +841,23 @@ bsloww (double x, double dx, double orig, int n)
 /* And if result not  accurate enough routine calls  other routines         */
 /***************************************************************************/
 
-static double
-SECTION
+static inline double
+__always_inline
 bsloww1 (double x, double dx, double orig, int n)
 {
-  mynumber u;
-  double w[2], y, cor, res;
+  double w[2], cor, res;
 
-  y = fabs (x);
-  u.x = big + y;
-  y = y - (u.x - big);
-  dx = (x > 0) ? dx : -dx;
-  res = do_sin_slow (u, y, dx, 1.1e-24, &cor);
+  res = do_sin_slow (x, dx, 1.1e-24, &cor);
   if (res == res + cor)
     return (x > 0) ? res : -res;
 
+  dx = (x > 0) ? dx : -dx;
   __dubsin (fabs (x), dx, w);
 
-  cor = 1.000000005 * w[1] + ((w[1] > 0) ? 1.1e-24 : -1.1e-24);
+  cor = 1.000000005 * w[1] + __copysign (1.1e-24, w[1]);
 
   if (w[0] == w[0] + cor)
-    return (x > 0) ? w[0] : -w[0];
+    return __copysign (w[0], x);
 
   return (n & 1) ? __mpcos (orig, 0, true) : __mpsin (orig, 0, true);
 }
@@ -900,24 +869,20 @@ bsloww1 (double x, double dx, double orig, int n)
 /* And if result not accurate enough routine calls  other routines          */
 /***************************************************************************/
 
-static double
-SECTION
+static inline double
+__always_inline
 bsloww2 (double x, double dx, double orig, int n)
 {
-  mynumber u;
-  double w[2], y, cor, res;
+  double w[2], cor, res;
 
-  y = fabs (x);
-  u.x = big + y;
-  y = y - (u.x - big);
-  dx = (x > 0) ? dx : -dx;
-  res = do_cos_slow (u, y, dx, 1.1e-24, &cor);
+  res = do_cos_slow (x, dx, 1.1e-24, &cor);
   if (res == res + cor)
     return (n & 2) ? -res : res;
 
+  dx = (x > 0) ? dx : -dx;
   __docos (fabs (x), dx, w);
 
-  cor = 1.000000005 * w[1] + ((w[1] > 0) ? 1.1e-24 : -1.1e-24);
+  cor = 1.000000005 * w[1] + __copysign (1.1e-24, w[1]);
 
   if (w[0] == w[0] + cor)
     return (n & 2) ? -w[0] : w[0];
@@ -930,22 +895,17 @@ bsloww2 (double x, double dx, double orig, int n)
 /* precision  and if still doesn't accurate enough by mpcos   or docos  */
 /************************************************************************/
 
-static double
-SECTION
+static inline double
+__always_inline
 cslow2 (double x)
 {
-  mynumber u;
-  double w[2], y, cor, res;
+  double w[2], cor, res;
 
-  y = fabs (x);
-  u.x = big + y;
-  y = y - (u.x - big);
-  res = do_cos_slow (u, y, 0, 0, &cor);
+  res = do_cos_slow (x, 0, 0, &cor);
   if (res == res + cor)
     return res;
 
-  y = fabs (x);
-  __docos (y, 0, w);
+  __docos (fabs (x), 0, w);
   if (w[0] == w[0] + 1.000000005 * w[1])
     return w[0];
 
@@ -953,16 +913,8 @@ cslow2 (double x)
 }
 
 #ifndef __cos
-weak_alias (__cos, cos)
-# ifdef NO_LONG_DOUBLE
-strong_alias (__cos, __cosl)
-weak_alias (__cos, cosl)
-# endif
+libm_alias_double (__cos, cos)
 #endif
 #ifndef __sin
-weak_alias (__sin, sin)
-# ifdef NO_LONG_DOUBLE
-strong_alias (__sin, __sinl)
-weak_alias (__sin, sinl)
-# endif
+libm_alias_double (__sin, sin)
 #endif