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


  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 /* __rem_pio2l(x,y)

  31  *
  32  * return the remainder of x rem pi/2 in y[0]+y[1]
  33  * by calling __rem_pio2m
  34  */
  35 
  36 #include "libm.h"
  37 #include "longdouble.h"
  38 
  39 extern const int _TBL_ipio2l_inf[];
  40 
  41 static const long double
  42     two24l = 16777216.0L,
  43     pio4   = 0.7853981633974483096156608458198757210495L;
  44 
  45 int
  46 __rem_pio2l(long double x, long double *y)
  47 {
  48         long double     z, w;
  49         double          t[3], v[5];
  50         int             e0, i, nx, n, sign;


  53         z = fabsl(x);
  54         if (z <= pio4) {
  55                 y[0] = x;
  56                 y[1] = 0;
  57                 return (0);
  58         }
  59         e0 = ilogbl(z) - 23;
  60         z = scalbnl(z, -e0);
  61         for (i = 0; i < 3; i++) {
  62                 t[i] = (double)((int)(z));
  63                 z = (z - (long double)t[i]) * two24l;
  64         }
  65         nx = 3;
  66         while (t[nx-1] == 0.0)
  67                 nx--;   /* omit trailing zeros */
  68         n = __rem_pio2m(t, v, e0, nx, 2, _TBL_ipio2l_inf);
  69         z = (long double)v[1];
  70         w = (long double)v[0];
  71         y[0] = z + w;
  72         y[1] = z - (y[0] - w);
  73         if (sign == 1) {
  74                 y[0] = -y[0];
  75                 y[1] = -y[1];
  76                 return (-n);
  77         }
  78         return (n);
  79 }


  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]
  34  * by calling __rem_pio2m
  35  */
  36 
  37 #include "libm.h"
  38 #include "longdouble.h"
  39 
  40 extern const int _TBL_ipio2l_inf[];
  41 
  42 static const long double
  43     two24l = 16777216.0L,
  44     pio4   = 0.7853981633974483096156608458198757210495L;
  45 
  46 int
  47 __rem_pio2l(long double x, long double *y)
  48 {
  49         long double     z, w;
  50         double          t[3], v[5];
  51         int             e0, i, nx, n, sign;


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