powl.c revision 1ec68d336ba97cd53f46053ac10401d16014d075
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include "libm.h"
#include "xpg6.h" /* __xpg6 */
#if defined(__sparc)
#define i0 0
#define i1 1
#define i2 2
#define i3 3
extern const long double _TBL_logl_hi[], _TBL_logl_lo[];
static const long double
two113 = 10384593717069655257060992658440192.0L,
ln2hi = 6.931471805599453094172319547495844850203e-0001L,
ln2lo = 1.667085920830552208890449330400379754169e-0025L,
A2 = 6.666666666666666666666666666666091393804e-0001L,
A3 = 4.000000000000000000000000407167070220671e-0001L,
A4 = 2.857142857142857142730077490612903681164e-0001L,
A5 = 2.222222222222242577702836920812882605099e-0001L,
A6 = 1.818181816435493395985912667105885828356e-0001L,
A7 = 1.538537835211839751112067512805496931725e-0001L,
B1 = 6.666666666666666666666666666666666667787e-0001L,
B2 = 3.999999999999999999999999999999848524411e-0001L,
B3 = 2.857142857142857142857142865084581075070e-0001L,
B4 = 2.222222222222222222222010781800643808497e-0001L,
B5 = 1.818181818181818185051442171337036403674e-0001L,
B6 = 1.538461538461508363540720286292008207673e-0001L,
B7 = 1.333333333506731842033180638329317108428e-0001L,
B8 = 1.176469984587418890634302788283946761670e-0001L,
B9 = 1.053794891561452331722969901564862497132e-0001L;
static long double
logl_x(long double x, long double *w) {
int *px = (int *) &x;
int *pz = (int *) &z;
int i, j, ix, n;
n = 0;
f = x - one;
z = f * f;
*w = zero;
return (zero); /* log(1)= +0 */
}
s = f * qn; /* |s|<2**-6 */
v = s * s;
h = (long double) (2.0 * (double) s);
f1 = (long double) ((double) f);
s = (long double) ((double) (h + t));
*w = t - (s - h);
return (s);
}
x *= two113;
n = -113;
}
/* LARGE_N */
i = ix + 0x200;
f = x - z;
s = f * qn;
f1 = (long double) ((double) f);
h = (long double) (2.0 * (double) s);
j = (i >> 10) & 0x3f;
v = s * s;
qn = (long double) n;
v * A7))))));
s = h + v;
t += (h - (s - v));
z = (long double) ((double) (s + t));
*w = t - (z - s);
return (z);
}
extern const long double _TBL_expl_hi[], _TBL_expl_lo[];
static const long double
invln2_32 = 4.616624130844682903551758979206054839765e+1L,
ln2_32hi = 2.166084939249829091928849858592451515688e-2L,
ln2_32lo = 5.209643502595475652782654157501186731779e-27L,
ln2_64 = 1.083042469624914545964425189778400898568e-2L;
long double
powl(long double x, long double y) {
long double z, ax;
int *pz = (int *) &z;
int *px = (int *) &x;
int *py = (int *) &y;
return (one); /* x**+-0 = 1 */
(__xpg6 & _C99SUSv3_pow) != 0)
return (one); /* C99: 1**anything = 1 */
return (x + y); /* +-NaN return x+y */
/* includes Sun: 1**NaN = NaN */
/*
* determine if y is an odd int when x < 0
* yisint = 0 ... y is not an integer
* yisint = 1 ... y is an odd int
* yisint = 2 ... y is an even int
*/
yisint = 0;
if (sbx) {
else if (ahy >= 0x3fff0000) {
if (k > 80) {
} else if (k > 48) {
} else if (k > 16) {
} else if (ly == 0) {
j = ahy >> (16 - k);
if ((j << (16 - k)) == ahy)
}
}
}
/* special value of y */
if (ly == 0) {
if ((__xpg6 & _C99SUSv3_pow) != 0)
return (one);
/* C99: (-1)**+-inf = 1 */
else
return (y - y);
/* Sun: (+-1)**+-inf = NaN */
} else if (ahx >= 0x3fff0000)
/* (|x|>1)**+,-inf = inf,0 */
else /* (|x|<1)**-,+inf = inf,0 */
if (sby != 0)
return (one / x);
else
return (x);
return (x * x);
0))
return (sqrtl(x));
}
}
/* special value of x */
if (lx == 0) {
/* x is +-0,+-inf,+-1 */
z = ax;
if (sby == 1)
z = one / z; /* z = 1/|x| if y is negative */
if (sbx == 1) {
/* (-1)**non-int is NaN */
else if (yisint == 1)
z = -z; /* (x<0)**odd = -(|x|**odd) */
}
return (z);
}
}
/* (x<0)**(non-int) is NaN */
/* Now ax is finite, y is finite */
/* first compute log(ax) = w1+w2, with 53 bits w1 */
/* split up y into y1+y2 and compute (y1+y2)*(w1+w2) */
} else {
y1 = (long double) ((double) y);
}
if ((unsigned) j >= 0xffff0000) { /* NaN or -inf */
return (one / z);
else
return (-one / z);
} else if ((j & ~0x80000000) < 0x3fc30000) { /* |x|<2^-60 */
return (-one - z);
else
return (one + z);
} else if (j > 0) {
if (j > 0x400d0000) {
else
}
} else {
if ((unsigned) j > 0xc00d0000) {
else
}
}
j = k & 0x1f;
m = k >> 5;
{
/* rational approximation coeffs for [-(ln2)/64,(ln2)/64] */
long double
t1 = 1.666666666666666666666666666660876387437e-1L,
t2 = -2.777777777777777777777707812093173478756e-3L,
t3 = 6.613756613756613482074280932874221202424e-5L,
t4 = -1.653439153392139954169609822742235851120e-6L,
t5 = 4.175314851769539751387852116610973796053e-8L;
long double t = (long double) k;
two;
_TBL_expl_lo[j]);
}
if (j && (unsigned) j < 0x7fff)
else
z = scalbnl(z, m);
z = -z; /* (-ve)**(odd int) */
return (z);
}
#else
#endif /* defined(__sparc) */