Print this page
11175 libm should use signbit() correctly
11188 c99 math macros should return strictly backward compatible values


  33  * return the remainder of x rem pi/2 in y[0]+y[1] by calling __rem_pio2m
  34  */
  35 
  36 #ifndef FDLIBM_BASED
  37 #include "libm.h"
  38 extern int __rem_pio2m(double *, double *, int, int, int, const int *);
  39 #else                           /* FDLIBM_BASED */
  40 #include "fdlibm.h"
  41 #define __rem_pio2m     __kernel_rem_pio2
  42 #endif                          /* FDLIBM_BASED */
  43 
  44 #include "longdouble.h"
  45 
  46 extern const int _TBL_ipio2l_inf[];
  47 
  48 static const long double
  49         two24l = 16777216.0L,
  50         pio4   = 0.7853981633974483096156608458198757210495L;
  51 
  52 int
  53 __rem_pio2l(long double x, long double *y) {

  54         long double z, w;
  55         double t[5], v[5];
  56         int e0, i, nx, n, sign;
  57         const int *ipio2;
  58 
  59         sign = signbitl(x);
  60         z = fabsl(x);
  61         if (z <= pio4) {
  62                 y[0] = x;
  63                 y[1] = 0;
  64                 return (0);
  65         }
  66         e0 = ilogbl(z) - 23;
  67         z = scalbnl(z, -e0);
  68         for (i = 0; i < 5; i++) {
  69                 t[i] = (double) ((int) (z));
  70                 z = (z - (long double) t[i]) * two24l;
  71         }
  72         nx = 5;
  73         while (t[nx - 1] == 0.0)
  74                 nx--;           /* skip zero term */
  75         ipio2 = _TBL_ipio2l_inf;
  76         n = __rem_pio2m(t, v, e0, nx, 3, (const int *) ipio2);
  77         z = (long double) v[2] + (long double) v[1];
  78         w = (long double) v[0];
  79         y[0] = z + w;
  80         y[1] = z - (y[0] - w);
  81         if (sign == 1) {
  82                 y[0] = -y[0];
  83                 y[1] = -y[1];
  84                 return (-n);
  85         }
  86         return (n);
  87 }


  33  * return the remainder of x rem pi/2 in y[0]+y[1] by calling __rem_pio2m
  34  */
  35 
  36 #ifndef FDLIBM_BASED
  37 #include "libm.h"
  38 extern int __rem_pio2m(double *, double *, int, int, int, const int *);
  39 #else                           /* FDLIBM_BASED */
  40 #include "fdlibm.h"
  41 #define __rem_pio2m     __kernel_rem_pio2
  42 #endif                          /* FDLIBM_BASED */
  43 
  44 #include "longdouble.h"
  45 
  46 extern const int _TBL_ipio2l_inf[];
  47 
  48 static const long double
  49         two24l = 16777216.0L,
  50         pio4   = 0.7853981633974483096156608458198757210495L;
  51 
  52 int
  53 __rem_pio2l(long double x, long double *y)
  54 {
  55         long double z, w;
  56         double t[5], v[5];
  57         int e0, i, nx, n, sign;
  58         const int *ipio2;
  59 
  60         sign = signbitl(x);
  61         z = fabsl(x);
  62         if (z <= pio4) {
  63                 y[0] = x;
  64                 y[1] = 0;
  65                 return (0);
  66         }
  67         e0 = ilogbl(z) - 23;
  68         z = scalbnl(z, -e0);
  69         for (i = 0; i < 5; i++) {
  70                 t[i] = (double)((int)(z));
  71                 z = (z - (long double)t[i]) * two24l;
  72         }
  73         nx = 5;
  74         while (t[nx - 1] == 0.0)
  75                 nx--;           /* skip zero term */
  76         ipio2 = _TBL_ipio2l_inf;
  77         n = __rem_pio2m(t, v, e0, nx, 3, (const int *)ipio2);
  78         z = (long double)v[2] + (long double)v[1];
  79         w = (long double)v[0];
  80         y[0] = z + w;
  81         y[1] = z - (y[0] - w);
  82         if (sign != 0) {
  83                 y[0] = -y[0];
  84                 y[1] = -y[1];
  85                 return (-n);
  86         }
  87         return (n);
  88 }