Print this page
11210 libm should be cstyle(1ONBLD) clean


   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
  24  */

  25 /*
  26  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  27  * Use is subject to license terms.
  28  */
  29 
  30 /*
  31  * __rem_pio2l(x,y)
  32  *
  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 }


   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
  24  */
  25 
  26 /*
  27  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  28  * Use is subject to license terms.
  29  */
  30 
  31 /*
  32  * __rem_pio2l(x,y)
  33  *
  34  * return the remainder of x rem pi/2 in y[0]+y[1] by calling __rem_pio2m
  35  */
  36 
  37 #ifndef FDLIBM_BASED
  38 #include "libm.h"
  39 
  40 extern int __rem_pio2m(double *, double *, int, int, int, const int *);
  41 #else /* FDLIBM_BASED */
  42 #include "fdlibm.h"
  43 #define __rem_pio2m     __kernel_rem_pio2
  44 #endif /* FDLIBM_BASED */
  45 
  46 #include "longdouble.h"
  47 
  48 extern const int _TBL_ipio2l_inf[];
  49 static const long double 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 
  63         if (z <= pio4) {
  64                 y[0] = x;
  65                 y[1] = 0;
  66                 return (0);
  67         }
  68 
  69         e0 = ilogbl(z) - 23;
  70         z = scalbnl(z, -e0);
  71 
  72         for (i = 0; i < 5; i++) {
  73                 t[i] = (double)((int)(z));
  74                 z = (z - (long double)t[i]) * two24l;
  75         }
  76 
  77         nx = 5;
  78 
  79         while (t[nx - 1] == 0.0)
  80                 nx--;                   /* skip zero term */
  81 
  82         ipio2 = _TBL_ipio2l_inf;
  83         n = __rem_pio2m(t, v, e0, nx, 3, (const int *)ipio2);
  84         z = (long double)v[2] + (long double)v[1];
  85         w = (long double)v[0];
  86         y[0] = z + w;
  87         y[1] = z - (y[0] - w);
  88 
  89         if (sign != 0) {
  90                 y[0] = -y[0];
  91                 y[1] = -y[1];
  92                 return (-n);
  93         }
  94 
  95         return (n);
  96 }