log1pl.c revision ddc0e0b53c661f6e439e3b7072b3ef353eadb4af
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis/*
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * CDDL HEADER START
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis *
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * The contents of this file are subject to the terms of the
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Common Development and Distribution License (the "License").
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * You may not use this file except in compliance with the License.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis *
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * or http://www.opensolaris.org/os/licensing.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * See the License for the specific language governing permissions
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * and limitations under the License.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis *
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * When distributing Covered Code, include this CDDL HEADER in each
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * If applicable, add the following below this CDDL HEADER, with the
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * fields enclosed by brackets "[]" replaced with your own identifying
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * information: Portions Copyright [yyyy] [name of copyright owner]
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis *
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * CDDL HEADER END
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis/*
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis/*
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Use is subject to license terms.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis#ifdef __LITTLE_ENDIAN
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis#define H0(x) *(3 + (int *) &x)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis#define H1(x) *(2 + (int *) &x)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis#define H2(x) *(1 + (int *) &x)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis#define H3(x) *(int *) &x
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis#else
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis#define H0(x) *(int *) &x
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis#define H1(x) *(1 + (int *) &x)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis#define H2(x) *(2 + (int *) &x)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis#define H3(x) *(3 + (int *) &x)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis#endif
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis/*
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * log1pl(x)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Table look-up algorithm by modifying logl.c
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * By K.C. Ng, July 6, 1995
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis *
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * (a). For 1+x in [31/33,33/31], using a special approximation:
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * s = x/(2.0+x); ... here |s| <= 0.03125
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * z = s*s;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * return x-s*(x-z*(B1+z*(B2+z*(B3+z*(B4+...+z*B9)...))));
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * (i.e., x is in [-2/33,2/31])
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis *
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * (b). Otherwise, normalize 1+x = 2^n * 1.f.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Here we may need a correction term for 1+x rounded.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Use a 6-bit table look-up: find a 6 bit g that match f to 6.5 bits,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * then
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * log(1+x) = n*ln2 + log(1.g) + log(1.f/1.g).
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Here the leading and trailing values of log(1.g) are obtained from
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * a size-64 table.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * For log(1.f/1.g), let s = (1.f-1.g)/(1.f+1.g). Note that
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * 1.f = 2^-n(1+x)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis *
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * then
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * log(1.f/1.g) = log((1+s)/(1-s)) = 2s + 2/3 s^3 + 2/5 s^5 +...
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Note that |s|<2**-8=0.00390625. We use an odd s-polynomial
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * approximation to compute log(1.f/1.g):
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * s*(A1+s^2*(A2+s^2*(A3+s^2*(A4+s^2*(A5+s^2*(A6+s^2*A7))))))
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * (Precision is 2**-136.91 bits, absolute error)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis *
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * CAUTION:
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * For x>=1, compute 1+x will lost one bit (OK).
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * For x in [-0.5,-1), 1+x is exact.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * For x in (-0.5,-2/33]U[2/31,1), up to 4 last bits of x will be lost
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * in 1+x. Therefore, to recover the lost bits, one need to compute
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * 1.f-1.g accurately.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis *
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Let hx = HI(x), m = (hx>>16)-0x3fff (=ilogbl(x)), note that
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * -2/33 = -0.0606...= 2^-5 * 1.939...,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * 2/31 = 0.09375 = 2^-4 * 1.500...,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * so for x in (-0.5,-2/33], -5<=m<=-2, n= -1, 1+f=2*(1+x)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * for x in [2/33,1), -4<=m<=-1, n= 0, f=x
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis *
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * In short:
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * if x>0, let g: hg= ((hx + (0x200<<(-m)))>>(10-m))<<(10-m)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * then 1.f-1.g = x-g
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * if x<0, let g': hg' =((ix-(0x200)<<(-m-1))>>(9-m))<<(9-m)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * (ix=hx&0x7fffffff)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * then 1.f-1.g = 2*(g'+x),
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis *
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * (c). The final result is computed by
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * (n*ln2_hi+_TBL_logl_hi[j]) +
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * ( (n*ln2_lo+_TBL_logl_lo[j]) + s*(A1+...) )
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis *
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Note.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * For ln2_hi and _TBL_logl_hi[j], we force their last 32 bit to be zero
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * so that n*ln2_hi + _TBL_logl_hi[j] is exact. Here
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * _TBL_logl_hi[j] + _TBL_logl_lo[j] match log(1+j*2**-6) to 194 bits
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis *
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis *
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Special cases:
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * log(x) is NaN with signal if x < 0 (including -INF) ;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * log(+INF) is +INF; log(0) is -INF with signal;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * log(NaN) is that NaN with no signal.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis *
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Constants:
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * The hexadecimal values are the intended ones for the following constants.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * The decimal values may be used, provided that the compiler will convert
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * from decimal to binary accurately enough to produce the hexadecimal values
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * shown.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis
ddc0e0b53c661f6e439e3b7072b3ef353eadb4afRichard Lowe#pragma weak __log1pl = log1pl
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis#include "libm.h"
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtisextern const long double _TBL_logl_hi[], _TBL_logl_lo[];
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtisstatic const long double
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtiszero = 0.0L,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtisone = 1.0L,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtistwo = 2.0L,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtisln2hi = 6.931471805599453094172319547495844850203e-0001L,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtisln2lo = 1.667085920830552208890449330400379754169e-0025L,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr JasiukajtisA1 = 2.000000000000000000000000000000000000024e+0000L,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr JasiukajtisA2 = 6.666666666666666666666666666666091393804e-0001L,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr JasiukajtisA3 = 4.000000000000000000000000407167070220671e-0001L,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr JasiukajtisA4 = 2.857142857142857142730077490612903681164e-0001L,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr JasiukajtisA5 = 2.222222222222242577702836920812882605099e-0001L,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr JasiukajtisA6 = 1.818181816435493395985912667105885828356e-0001L,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr JasiukajtisA7 = 1.538537835211839751112067512805496931725e-0001L,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr JasiukajtisB1 = 6.666666666666666666666666666666961498329e-0001L,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr JasiukajtisB2 = 3.999999999999999999999999990037655042358e-0001L,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr JasiukajtisB3 = 2.857142857142857142857273426428347457918e-0001L,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr JasiukajtisB4 = 2.222222222222222221353229049747910109566e-0001L,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr JasiukajtisB5 = 1.818181818181821503532559306309070138046e-0001L,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr JasiukajtisB6 = 1.538461538453809210486356084587356788556e-0001L,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr JasiukajtisB7 = 1.333333344463358756121456892645178795480e-0001L,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr JasiukajtisB8 = 1.176460904783899064854645174603360383792e-0001L,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr JasiukajtisB9 = 1.057293869956598995326368602518056990746e-0001L;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtislong double
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtislog1pl(long double x) {
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis long double f, s, z, qn, h, t, y, g;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis int i, j, ix, iy, n, hx, m;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis hx = H0(x);
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis ix = hx & 0x7fffffff;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis if (ix < 0x3ffaf07c) { /* |x|<2/33 */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis if (ix <= 0x3f8d0000) { /* x <= 2**-114, return x */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis if ((int) x == 0)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis return (x);
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis }
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis s = x / (two + x); /* |s|<2**-8 */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis z = s * s;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis return (x - s * (x - z * (B1 + z * (B2 + z * (B3 + z * (B4 +
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis z * (B5 + z * (B6 + z * (B7 + z * (B8 + z * B9))))))))));
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis }
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis if (ix >= 0x7fff0000) { /* x is +inf or NaN */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis return (x + fabsl(x));
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis }
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis if (hx < 0 && ix >= 0x3fff0000) {
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis if (ix > 0x3fff0000 || (H1(x) | H2(x) | H3(x)) != 0)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis x = zero;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis return (x / zero); /* log1p(x) is NaN if x<-1 */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /* log1p(-1) is -inf */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis }
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis if (ix >= 0x7ffeffff)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis y = x; /* avoid spurious overflow */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis else
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis y = one + x;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis iy = H0(y);
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis n = ((iy + 0x200) >> 16) - 0x3fff;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis iy = (iy & 0x0000ffff) | 0x3fff0000; /* scale 1+x to [1,2] */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis H0(y) = iy;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis z = zero;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis m = (ix >> 16) - 0x3fff;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /* HI(1+x) = (((hx&0xffff)|0x10000)>>(-m))|0x3fff0000 */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis if (n == 0) { /* x in [2/33,1) */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis g = zero;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis H0(g) = ((hx + (0x200 << (-m))) >> (10 - m)) << (10 - m);
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis t = x - g;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis i = (((((hx & 0xffff) | 0x10000) >> (-m)) | 0x3fff0000) +
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis 0x200) >> 10;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis H0(z) = i << 10;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis } else if ((1 + n) == 0 && (ix < 0x3ffe0000)) { /* x in (-0.5,-2/33] */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis g = zero;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis H0(g) = ((ix + (0x200 << (-m - 1))) >> (9 - m)) << (9 - m);
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis t = g + x;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis t = t + t;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /*
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * HI(2*(1+x)) =
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * ((0x10000-(((hx&0xffff)|0x10000)>>(-m)))<<1)|0x3fff0000
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /*
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * i =
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * ((((0x10000-(((hx&0xffff)|0x10000)>>(-m)))<<1)|0x3fff0000)+
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * 0x200)>>10; H0(z)=i<<10;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis z = two * (one - g);
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis i = H0(z) >> 10;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis } else {
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis i = (iy + 0x200) >> 10;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis H0(z) = i << 10;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis t = y - z;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis }
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis s = t / (y + z);
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis j = i & 0x3f;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis z = s * s;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis qn = (long double) n;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis t = qn * ln2lo + _TBL_logl_lo[j];
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis h = qn * ln2hi + _TBL_logl_hi[j];
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis f = t + s * (A1 + z * (A2 + z * (A3 + z * (A4 + z * (A5 + z * (A6 +
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis z * A7))))));
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis return (h + f);
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis}