Exemplo n.º 1
0
int
gl_signbitl (long double arg)
{
#if defined LDBL_SIGNBIT_WORD && defined LDBL_SIGNBIT_BIT
  /* The use of a union to extract the bits of the representation of a
     'long double' is safe in practice, despite of the "aliasing rules" of
     C99, because the GCC docs say
       "Even with '-fstrict-aliasing', type-punning is allowed, provided the
        memory is accessed through the union type."
     and similarly for other compilers.  */
# define NWORDS \
    ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
  union { long double value; unsigned int word[NWORDS]; } m;
  m.value = arg;
  return (m.word[LDBL_SIGNBIT_WORD] >> LDBL_SIGNBIT_BIT) & 1;
#elif HAVE_COPYSIGNL_IN_LIBC
  return copysignl (1.0L, arg) < 0;
#else
  /* This does not do the right thing for NaN, but this is irrelevant for
     most use cases.  */
  if (isnanl (arg))
    return 0;
  if (arg < 0.0L)
    return 1;
  else if (arg == 0.0L)
    {
      /* Distinguish 0.0L and -0.0L.  */
      static long double plus_zero = 0.0L;
      long double arg_mem = arg;
      return (memcmp (&plus_zero, &arg_mem, SIZEOF_LDBL) != 0);
    }
  else
    return 0;
#endif
}
int
main ()
{
  DECL_LONG_DOUBLE_ROUNDING

  BEGIN_LONG_DOUBLE_ROUNDING ();

  /* See IEEE 754, section 6.3:
       "the sign of the result of the round floating-point number to
        integral value operation is the sign of the operand. These rules
        shall apply even when operands or results are zero or infinite."  */

  /* Zero.  */
  ASSERT (!signbit (truncl (0.0L)));
  ASSERT (!!signbit (truncl (minus_zerol)) == !!signbit (minus_zerol));
  /* Positive numbers.  */
  ASSERT (!signbit (truncl (0.3L)));
  ASSERT (!signbit (truncl (0.7L)));
  /* Negative numbers.  */
  ASSERT (!!signbit (truncl (-0.3L)) == !!signbit (minus_zerol));
  ASSERT (!!signbit (truncl (-0.7L)) == !!signbit (minus_zerol));

  /* [MX] shaded specification in POSIX.  */

  /* NaN.  */
  ASSERT (isnanl (truncl (NaNl ())));
  /* Infinity.  */
  ASSERT (truncl (Infinityl ()) == Infinityl ());
  ASSERT (truncl (- Infinityl ()) == - Infinityl ());

  return 0;
}
Exemplo n.º 3
0
Arquivo: tanl.c Projeto: FEI17N/gnulib
long double
tanl (long double x)
{
  long double y[2], z = 0.0L;
  int n;

  /* tanl(NaN) is NaN */
  if (isnanl (x))
    return x;

  /* |x| ~< pi/4 */
  if (x >= -0.7853981633974483096156608458198757210492 &&
      x <= 0.7853981633974483096156608458198757210492)
    return kernel_tanl (x, z, 1);

  /* tanl(Inf) is NaN, tanl(0) is 0 */
  else if (x + x == x)
    return x - x;               /* NaN */

  /* argument reduction needed */
  else
    {
      n = ieee754_rem_pio2l (x, y);
      /* 1 -- n even, -1 -- n odd */
      return kernel_tanl (y[0], y[1], 1 - ((n & 1) << 1));
    }
}
/* A simple Newton-Raphson method. */
long double
sqrtl (long double x)
{
  long double delta, y;
  int exponent;

  /* Check for NaN */
  if (isnanl (x))
    return x;

  /* Check for negative numbers */
  if (x < 0.0L)
    return (long double) sqrt (-1);

  /* Check for zero and infinites */
  if (x + x == x)
    return x;

  frexpl (x, &exponent);
  y = ldexpl (x, -exponent / 2);

  do
    {
      delta = y;
      y = (y + x / y) * 0.5L;
      delta -= y;
    }
  while (delta != 0.0L);

  return y;
}
Exemplo n.º 5
0
long double
tanhl(long double x) {
	long double t, y, z;
	int signx;
#ifndef lint
	volatile long double dummy;
#endif

	if (isnanl(x))
		return (x + x);		/* x is NaN */
	signx = signbitl(x);
	t = fabsl(x);
	z = one;
	if (t <= threshold) {
		if (t > one)
			z = one - two / (expm1l(t + t) + two);
		else if (t > small) {
			y = expm1l(-t - t);
			z = -y / (y + two);
		} else {
#ifndef lint
			dummy = t + big;
							/* inexact if t != 0 */
#endif
			return (x);
		}
	} else if (!finitel(t))
		return (copysignl(one, x));
	else
		return (signx ? -z + small * small : z - small * small);
	return (signx ? -z : z);
}
Exemplo n.º 6
0
long double
asinl(long double x) {
	long double t, w;
#ifndef lint
	volatile long double dummy;
#endif

	w = fabsl(x);
	if (isnanl(x))
		return (x + x);
	else if (w <= half) {
		if (w < small) {
#ifndef lint
			dummy = w + big;
							/* inexact if w != 0 */
#endif
			return (x);
		} else
			return (atanl(x / sqrtl(one - x * x)));
	} else if (w < one) {
		t = one - w;
		w = t + t;
		return (atanl(x / sqrtl(w - t * t)));
	} else if (w == one)
		return (atan2l(x, zero));	/* asin(+-1) =  +- PI/2 */
	else
		return (zero / zero);		/* |x| > 1: invalid */
}
Exemplo n.º 7
0
long double
acoshl(long double x) {
	long double t;

	if (isnanl(x))
		return (x + x);
	else if (x > big)
		return (logl(x) + ln2);
	else if (x > one) {
		t = sqrtl(x - one);
		return (log1pl(t * (t + sqrtl(x + one))));
	} else if (x == one)
		return (zero);
	else
		return ((x - x) / (x - x));
}
Exemplo n.º 8
0
long double
asinhl(long double x) {
	long double t, w;

	w = fabsl(x);
	if (isnanl(x))
		return (x + x);	/* x is NaN */
	if (w < tiny) {
#ifndef lint
		volatile long double dummy = x + big;	/* inexact if x != 0 */
#endif
		return (x);	/* tiny x */
	} else if (w < big) {
		t = one / w;
		return (copysignl(log1pl(w + w / (t + sqrtl(one + t * t))), x));
	} else
		return (copysignl(logl(w) + ln2, x));
}
Exemplo n.º 9
0
int
main ()
{
    DECL_LONG_DOUBLE_ROUNDING

    BEGIN_LONG_DOUBLE_ROUNDING ();

    /* Zero.  */
    ASSERT (roundl (0.0L) == 0.0L);
    ASSERT (roundl (minus_zerol) == 0.0L);
    /* Positive numbers.  */
    ASSERT (roundl (0.3L) == 0.0L);
    ASSERT (roundl (0.5L) == 1.0L);
    ASSERT (roundl (0.7L) == 1.0L);
    ASSERT (roundl (1.0L) == 1.0L);
    ASSERT (roundl (1.5L) == 2.0L);
    ASSERT (roundl (2.5L) == 3.0L);
    ASSERT (roundl (1.999L) == 2.0L);
    ASSERT (roundl (2.0L) == 2.0L);
    ASSERT (roundl (65535.999L) == 65536.0L);
    ASSERT (roundl (65536.0L) == 65536.0L);
    ASSERT (roundl (65536.001L) == 65536.0L);
    ASSERT (roundl (2.341e31L) == 2.341e31L);
    /* Negative numbers.  */
    ASSERT (roundl (-0.3L) == 0.0L);
    ASSERT (roundl (-0.5L) == -1.0L);
    ASSERT (roundl (-0.7L) == -1.0L);
    ASSERT (roundl (-1.0L) == -1.0L);
    ASSERT (roundl (-1.5L) == -2.0L);
    ASSERT (roundl (-2.5L) == -3.0L);
    ASSERT (roundl (-1.999L) == -2.0L);
    ASSERT (roundl (-2.0L) == -2.0L);
    ASSERT (roundl (-65535.999L) == -65536.0L);
    ASSERT (roundl (-65536.0L) == -65536.0L);
    ASSERT (roundl (-65536.001L) == -65536.0L);
    ASSERT (roundl (-2.341e31L) == -2.341e31L);
    /* Infinite numbers.  */
    ASSERT (roundl (Infinityl ()) == Infinityl ());
    ASSERT (roundl (- Infinityl ()) == - Infinityl ());
    /* NaNs.  */
    ASSERT (isnanl (roundl (NaNl ())));

    return 0;
}
Exemplo n.º 10
0
long double
log2l (long double x)
{
  if (isnanl (x))
    return x;

  if (x <= 0.0L)
    {
      if (x == 0.0L)
        /* Return -Infinity.  */
        return - HUGE_VALL;
      else
        {
          /* Return NaN.  */
#if defined _MSC_VER || (defined __sgi && !defined __GNUC__)
          static long double zero;
          return zero / zero;
#else
          return 0.0L / 0.0L;
#endif
        }
    }

  /* Decompose x into
       x = 2^e * y
     where
       e is an integer,
       1/2 < y < 2.
     Then log2(x) = e + log2(y) = e + log(y)/log(2).  */
  {
    int e;
    long double y;

    y = frexpl (x, &e);
    if (y < SQRT_HALF)
      {
        y = 2.0L * y;
        e = e - 1;
      }

    return (long double) e + logl (y) * LOG2_INVERSE;
  }
}
Exemplo n.º 11
0
long double
ldexpl (long double x, int exp)
{
  long double factor;
  int bit;
  DECL_LONG_DOUBLE_ROUNDING

  BEGIN_LONG_DOUBLE_ROUNDING ();

  /* Check for zero, nan and infinity. */
  if (!(isnanl (x) || x + x == x))
    {
      if (exp < 0)
        {
          exp = -exp;
          factor = 0.5L;
        }
      else
        factor = 2.0L;

      if (exp > 0)
        for (bit = 1;;)
          {
            /* Invariant: Here bit = 2^i, factor = 2^-2^i or = 2^2^i,
               and bit <= exp.  */
            if (exp & bit)
              x *= factor;
            bit <<= 1;
            if (bit > exp)
              break;
            factor = factor * factor;
          }
    }

  END_LONG_DOUBLE_ROUNDING ();

  return x;
}
Exemplo n.º 12
0
long double
cosl (long double x)
{
  long double y[2],z=0.0L;
  int n;

  /* cosl(NaN) is NaN */
  if (isnanl (x))
    return x;

  /* |x| ~< pi/4 */
  if (x >= -0.7853981633974483096156608458198757210492
      && x <= 0.7853981633974483096156608458198757210492)
    return kernel_cosl(x, z);

  /* cosl(Inf) is NaN, cosl(0) is 1 */
  else if (x + x == x && x != 0.0)
    return x - x;           /* NaN */

  /* argument reduction needed */
  else
    {
      n = ieee754_rem_pio2l (x, y);
      switch (n & 3)
        {
        case 0:
          return  kernel_cosl (y[0], y[1]);
        case 1:
          return -kernel_sinl (y[0], y[1], 1);
        case 2:
          return -kernel_cosl (y[0], y[1]);
        default:
          return  kernel_sinl (y[0], y[1], 1);
        }
    }
}
Exemplo n.º 13
0
int
main ()
{
    int i;
    long double x;
    DECL_LONG_DOUBLE_ROUNDING

    BEGIN_LONG_DOUBLE_ROUNDING ();

    {   /* NaN.  */
        int exp = -9999;
        long double mantissa;
        x = 0.0L / 0.0L;
        mantissa = frexpl (x, &exp);
        ASSERT (isnanl (mantissa));
    }

    {   /* Positive infinity.  */
        int exp = -9999;
        long double mantissa;
        x = 1.0L / 0.0L;
        mantissa = frexpl (x, &exp);
        ASSERT (mantissa == x);
    }

    {   /* Negative infinity.  */
        int exp = -9999;
        long double mantissa;
        x = -1.0L / 0.0L;
        mantissa = frexpl (x, &exp);
        ASSERT (mantissa == x);
    }

    {   /* Positive zero.  */
        int exp = -9999;
        long double mantissa;
        x = 0.0L;
        mantissa = frexpl (x, &exp);
        ASSERT (exp == 0);
        ASSERT (mantissa == x);
        ASSERT (!signbit (mantissa));
    }

    {   /* Negative zero.  */
        int exp = -9999;
        long double mantissa;
        x = minus_zero;
        mantissa = frexpl (x, &exp);
        ASSERT (exp == 0);
        ASSERT (mantissa == x);
        ASSERT (signbit (mantissa));
    }

    for (i = 1, x = 1.0L; i <= LDBL_MAX_EXP; i++, x *= 2.0L)
    {
        int exp = -9999;
        long double mantissa = frexpl (x, &exp);
        ASSERT (exp == i);
        ASSERT (mantissa == 0.5L);
    }
    for (i = 1, x = 1.0L; i >= MIN_NORMAL_EXP; i--, x *= 0.5L)
    {
        int exp = -9999;
        long double mantissa = frexpl (x, &exp);
        ASSERT (exp == i);
        ASSERT (mantissa == 0.5L);
    }
    for (; i >= LDBL_MIN_EXP - 100 && x > 0.0L; i--, x *= 0.5L)
    {
        int exp = -9999;
        long double mantissa = frexpl (x, &exp);
        ASSERT (exp == i);
        ASSERT (mantissa == 0.5L);
    }

    for (i = 1, x = -1.0L; i <= LDBL_MAX_EXP; i++, x *= 2.0L)
    {
        int exp = -9999;
        long double mantissa = frexpl (x, &exp);
        ASSERT (exp == i);
        ASSERT (mantissa == -0.5L);
    }
    for (i = 1, x = -1.0L; i >= MIN_NORMAL_EXP; i--, x *= 0.5L)
    {
        int exp = -9999;
        long double mantissa = frexpl (x, &exp);
        ASSERT (exp == i);
        ASSERT (mantissa == -0.5L);
    }
    for (; i >= LDBL_MIN_EXP - 100 && x < 0.0L; i--, x *= 0.5L)
    {
        int exp = -9999;
        long double mantissa = frexpl (x, &exp);
        ASSERT (exp == i);
        ASSERT (mantissa == -0.5L);
    }

    for (i = 1, x = 1.01L; i <= LDBL_MAX_EXP; i++, x *= 2.0L)
    {
        int exp = -9999;
        long double mantissa = frexpl (x, &exp);
        ASSERT (exp == i);
        ASSERT (mantissa == 0.505L);
    }
    for (i = 1, x = 1.01L; i >= MIN_NORMAL_EXP; i--, x *= 0.5L)
    {
        int exp = -9999;
        long double mantissa = frexpl (x, &exp);
        ASSERT (exp == i);
        ASSERT (mantissa == 0.505L);
    }
    for (; i >= LDBL_MIN_EXP - 100 && x > 0.0L; i--, x *= 0.5L)
    {
        int exp = -9999;
        long double mantissa = frexpl (x, &exp);
        ASSERT (exp == i);
        ASSERT (mantissa >= 0.5L);
        ASSERT (mantissa < 1.0L);
        ASSERT (mantissa == my_ldexp (x, - exp));
    }

    for (i = 1, x = 1.73205L; i <= LDBL_MAX_EXP; i++, x *= 2.0L)
    {
        int exp = -9999;
        long double mantissa = frexpl (x, &exp);
        ASSERT (exp == i);
        ASSERT (mantissa == 0.866025L);
    }
    for (i = 1, x = 1.73205L; i >= MIN_NORMAL_EXP; i--, x *= 0.5L)
    {
        int exp = -9999;
        long double mantissa = frexpl (x, &exp);
        ASSERT (exp == i);
        ASSERT (mantissa == 0.866025L);
    }
    for (; i >= LDBL_MIN_EXP - 100 && x > 0.0L; i--, x *= 0.5L)
    {
        int exp = -9999;
        long double mantissa = frexpl (x, &exp);
        ASSERT (exp == i || exp == i + 1);
        ASSERT (mantissa >= 0.5L);
        ASSERT (mantissa < 1.0L);
        ASSERT (mantissa == my_ldexp (x, - exp));
    }

    return 0;
}
Exemplo n.º 14
0
long double
exp2l (long double x)
{
  /* exp2(x) = exp(x*log(2)).
     If we would compute it like this, there would be rounding errors for
     integer or near-integer values of x.  To avoid these, we inline the
     algorithm for exp(), and the multiplication with log(2) cancels a
     division by log(2).  */

  if (isnanl (x))
    return x;

  if (x > (long double) LDBL_MAX_EXP)
    /* x > LDBL_MAX_EXP
       hence exp2(x) > 2^LDBL_MAX_EXP, overflows to Infinity.  */
    return HUGE_VALL;

  if (x < (long double) (LDBL_MIN_EXP - 1 - LDBL_MANT_DIG))
    /* x < (LDBL_MIN_EXP - 1 - LDBL_MANT_DIG)
       hence exp2(x) < 2^(LDBL_MIN_EXP-1-LDBL_MANT_DIG),
       underflows to zero.  */
    return 0.0L;

  /* Decompose x into
       x = n + m/256 + y/log(2)
     where
       n is an integer,
       m is an integer, -128 <= m <= 128,
       y is a number, |y| <= log(2)/512 + epsilon = 0.00135...
     Then
       exp2(x) = 2^n * exp(m * log(2)/256) * exp(y)
     The first factor is an ldexpl() call.
     The second factor is a table lookup.
     The third factor is computed
     - either as sinh(y) + cosh(y)
       where sinh(y) is computed through the power series:
         sinh(y) = y + y^3/3! + y^5/5! + ...
       and cosh(y) is computed as hypot(1, sinh(y)),
     - or as exp(2*z) = (1 + tanh(z)) / (1 - tanh(z))
       where z = y/2
       and tanh(z) is computed through its power series:
         tanh(z) = z
                   - 1/3 * z^3
                   + 2/15 * z^5
                   - 17/315 * z^7
                   + 62/2835 * z^9
                   - 1382/155925 * z^11
                   + 21844/6081075 * z^13
                   - 929569/638512875 * z^15
                   + ...
       Since |z| <= log(2)/1024 < 0.0007, the relative contribution of the
       z^13 term is < 0.0007^12 < 2^-120 <= 2^-LDBL_MANT_DIG, therefore we
       can truncate the series after the z^11 term.  */

  {
    long double nm = roundl (x * 256.0L); /* = 256 * n + m */
    long double z = (x * 256.0L - nm) * (LOG2_BY_256 * 0.5L);

/* Coefficients of the power series for tanh(z).  */
#define TANH_COEFF_1   1.0L
#define TANH_COEFF_3  -0.333333333333333333333333333333333333334L
#define TANH_COEFF_5   0.133333333333333333333333333333333333334L
#define TANH_COEFF_7  -0.053968253968253968253968253968253968254L
#define TANH_COEFF_9   0.0218694885361552028218694885361552028218L
#define TANH_COEFF_11 -0.00886323552990219656886323552990219656886L
#define TANH_COEFF_13  0.00359212803657248101692546136990581435026L
#define TANH_COEFF_15 -0.00145583438705131826824948518070211191904L

    long double z2 = z * z;
    long double tanh_z =
      (((((TANH_COEFF_11
           * z2 + TANH_COEFF_9)
          * z2 + TANH_COEFF_7)
         * z2 + TANH_COEFF_5)
        * z2 + TANH_COEFF_3)
       * z2 + TANH_COEFF_1)
      * z;

    long double exp_y = (1.0L + tanh_z) / (1.0L - tanh_z);

    int n = (int) roundl (nm * (1.0L / 256.0L));
    int m = (int) nm - 256 * n;

    return ldexpl (gl_expl_table[128 + m] * exp_y, n);
  }
}
Exemplo n.º 15
0
ldcomplex
cpowl(ldcomplex z, ldcomplex w) {
	ldcomplex ans;
	long double x, y, u, v, t, c, s, r;
	long double t1, t2, t3, t4, x1, x2, y1, y2, u1, v1, b[4], w1, w2;
	int ix, iy, hx, hy, hv, hu, iu, iv, i, j, k;

	x = LD_RE(z);
	y = LD_IM(z);
	u = LD_RE(w);
	v = LD_IM(w);
	hx = HI_XWORD(x);
	hy = HI_XWORD(y);
	hu = HI_XWORD(u);
	hv = HI_XWORD(v);
	ix = hx & 0x7fffffff;
	iy = hy & 0x7fffffff;
	iu = hu & 0x7fffffff;
	iv = hv & 0x7fffffff;

	j = 0;
	if (v == zero) {	/* z**(real) */
		if (u == one) {	/* (anything) ** 1  is itself */
			LD_RE(ans) = x;
			LD_IM(ans) = y;
		} else if (u == zero) {	/* (anything) ** 0  is 1 */
			LD_RE(ans) = one;
			LD_IM(ans) = zero;
		} else if (y == zero) {	/* real ** real */
			LD_IM(ans) = zero;
			if (hx < 0 && ix < hiinf && iu < hiinf) {
			/* -x ** u  is exp(i*pi*u)*pow(x,u) */
				r = powl(-x, u);
				sincospil(u, &s, &c);
				LD_RE(ans) = (c == zero)? c: c * r;
				LD_IM(ans) = (s == zero)? s: s * r;
			} else
				LD_RE(ans) = powl(x, u);
		} else if (x == zero || ix >= hiinf || iy >= hiinf) {
			if (isnanl(x) || isnanl(y) || isnanl(u))
				LD_RE(ans) = LD_IM(ans) = x + y + u;
			else {
				if (x == zero)
					r = fabsl(y);
				else
					r = fabsl(x) + fabsl(y);
				t = atan2pil(y, x);
				sincospil(t * u, &s, &c);
				LD_RE(ans) = (c == zero)? c: c * r;
				LD_IM(ans) = (s == zero)? s: s * r;
			}
		} else if (fabsl(x) == fabsl(y)) {    /* |x| = |y| */
			if (hx >= 0) {
				t = (hy >= 0)? 0.25L : -0.25L;
				sincospil(t * u, &s, &c);
			} else if ((LAST(u) & 3) == 0) {
				t = (hy >= 0)? 0.75L : -0.75L;
				sincospil(t * u, &s, &c);
			} else {
				r = (hy >= 0)? u : -u;
				t = -0.25L * r;
				w1 = r + t;
				w2 = t - (w1 - r);
				sincospil(w1, &t1, &t2);
				sincospil(w2, &t3, &t4);
				s = t1 * t4 + t3 * t2;
				c = t2 * t4 - t1 * t3;
			}
			if (ix < 0x3ffe0000)	/* |x| < 1/2 */
				r = powl(fabsl(x + x), u) * exp2l(-0.5L * u);
			else if (ix >= 0x3fff0000 || iu < 0x400cfff8)
				/* |x| >= 1 or |u| < 16383 */
				r = powl(fabsl(x), u) * exp2l(0.5L * u);
			else   /* special treatment */
				j = 2;
			if (j == 0) {
				LD_RE(ans) = (c == zero)? c: c * r;
				LD_IM(ans) = (s == zero)? s: s * r;
			}
		} else
			j = 1;
		if (j == 0)
			return (ans);
	}
	if (iu >= hiinf || iv >= hiinf || ix >= hiinf || iy >= hiinf) {
		/*
		 * non-zero imag part(s) with inf component(s) yields NaN
		 */
		t = fabsl(x) + fabsl(y) + fabsl(u) + fabsl(v);
		LD_RE(ans) = LD_IM(ans) = t - t;
	} else {
		k = 0;	/* no scaling */
		if (iu > 0x7ffe0000 || iv > 0x7ffe0000) {
			u *= 1.52587890625000000000e-05L;
			v *= 1.52587890625000000000e-05L;
			k = 1;	/* scale u and v by 2**-16 */
		}
		/*
		 * Use similated higher precision arithmetic to compute:
		 * r = u * log(hypot(x, y)) - v * atan2(y, x)
		 * q = u * atan2(y, x) + v * log(hypot(x, y))
		 */

		t1 = __k_clog_rl(x, y, &t2);
		t3 = __k_atan2l(y, x, &t4);
		x1 = t1; HALF(x1);
		y1 = t3; HALF(y1);
		u1 = u; HALF(u1);
		v1 = v; HALF(v1);
		x2 = t2 - (x1 - t1);    /* log(hypot(x,y)) = x1 + x2 */
		y2 = t4 - (y1 - t3);    /* atan2(y,x) = y1 + y2 */
		/* compute q = u * atan2(y, x) + v * log(hypot(x, y)) */
		if (j != 2) {
			b[0] = u1 * y1;
			b[1] = (u - u1) * y1 + u * y2;
			if (j == 1) {	/* v = 0 */
				w1 = b[0] + b[1];
				w2 = b[1] - (w1 - b[0]);
			} else {
				b[2] = v1 * x1;
				b[3] = (v - v1) * x1 + v * x2;
				w1 = sum4fpl(b, &w2);
			}
			sincosl(w1, &t1, &t2);
			sincosl(w2, &t3, &t4);
			s = t1 * t4 + t3 * t2;
			c = t2 * t4 - t1 * t3;
			if (k == 1)	/* square j times */
				for (i = 0; i < 10; i++) {
					t1 = s * c;
					c = (c + s) * (c - s);
					s = t1 + t1;
				}
		}
		/* compute r = u * (t1, t2) - v * (t3, t4) */
		b[0] = u1 * x1;
		b[1] = (u - u1) * x1 + u * x2;
		if (j == 1) {   /* v = 0 */
			w1 = b[0] + b[1];
			w2 = b[1] - (w1 - b[0]);
		} else {
			b[2] = -v1 * y1;
			b[3] = (v1 - v) * y1 - v * y2;
			w1 = sum4fpl(b, &w2);
		}
		/* scale back unless w1 is large enough to cause exception */
		if (k != 0 && fabsl(w1) < 20000.0L) {
			w1 *= 65536.0L; w2 *= 65536.0L;
		}
		hx = HI_XWORD(w1);
		ix = hx & 0x7fffffff;
		/* compute exp(w1 + w2) */
		k = 0;
		if (ix < 0x3f8c0000) /* exp(tiny < 2**-115) = 1 */
			r = one;
		else if (ix >= 0x400c6760) /* overflow/underflow */
			r = (hx < 0)? tiny * tiny : huge * huge;
		else {  /* compute exp(w1 + w2) */
			k = (int) (invln2 * w1 + ((hx >= 0)? 0.5L : -0.5L));
			t1 = (long double) k;
			t2 = w1 - t1 * ln2hil;
			t3 = w2 - t1 * ln2lol;
			r = expl(t2 + t3);
		}
		if (c != zero) c *= r;
		if (s != zero) s *= r;
		if (k != 0) {
			c = scalbnl(c, k);
			s = scalbnl(s, k);
		}
		LD_RE(ans) = c;
		LD_IM(ans) = s;
	}
	return (ans);
}
Exemplo n.º 16
0
long double
expm1l (long double x)
{
  if (isnanl (x))
    return x;

  if (x >= (long double) LDBL_MAX_EXP * LOG2_PLUS_EPSILON)
    /* x > LDBL_MAX_EXP * log(2)
       hence exp(x) > 2^LDBL_MAX_EXP, overflows to Infinity.  */
    return HUGE_VALL;

  if (x <= (long double) (- LDBL_MANT_DIG) * LOG2_PLUS_EPSILON)
    /* x < (- LDBL_MANT_DIG) * log(2)
       hence 0 < exp(x) < 2^-LDBL_MANT_DIG,
       hence -1 < exp(x)-1 < -1 + 2^-LDBL_MANT_DIG
       rounds to -1.  */
    return -1.0L;

  if (x <= - LOG2_PLUS_EPSILON)
    /* 0 < exp(x) < 1/2.
       Just compute exp(x), then subtract 1.  */
    return expl (x) - 1.0L;

  if (x == 0.0L)
    /* Return a zero with the same sign as x.  */
    return x;

  /* Decompose x into
       x = n * log(2) + m * log(2)/256 + y
     where
       n is an integer, n >= -1,
       m is an integer, -128 <= m <= 128,
       y is a number, |y| <= log(2)/512 + epsilon = 0.00135...
     Then
       exp(x) = 2^n * exp(m * log(2)/256) * exp(y)
     Compute each factor minus one, then combine them through the
     formula (1+a)*(1+b) = 1 + (a+b*(1+a)),
     that is (1+a)*(1+b) - 1 = a + b*(1+a).
     The first factor is an ldexpl() call.
     The second factor is a table lookup.
     The third factor minus one is computed
     - either as sinh(y) + sinh(y)^2 / (cosh(y) + 1)
       where sinh(y) is computed through the power series:
         sinh(y) = y + y^3/3! + y^5/5! + ...
       and cosh(y) is computed as hypot(1, sinh(y)),
     - or as exp(2*z) - 1 = 2 * tanh(z) / (1 - tanh(z))
       where z = y/2
       and tanh(z) is computed through its power series:
         tanh(z) = z
                   - 1/3 * z^3
                   + 2/15 * z^5
                   - 17/315 * z^7
                   + 62/2835 * z^9
                   - 1382/155925 * z^11
                   + 21844/6081075 * z^13
                   - 929569/638512875 * z^15
                   + ...
       Since |z| <= log(2)/1024 < 0.0007, the relative contribution of the
       z^13 term is < 0.0007^12 < 2^-120 <= 2^-LDBL_MANT_DIG, therefore we
       can truncate the series after the z^11 term.

     Given the usual bounds LDBL_MAX_EXP <= 16384, LDBL_MANT_DIG <= 120, we
     can estimate x:  -84 <= x <= 11357.
     This means, when dividing x by log(2), where we want x mod log(2)
     to be precise to LDBL_MANT_DIG bits, we have to use an approximation
     to log(2) that has 14+LDBL_MANT_DIG bits.  */

  {
    long double nm = roundl (x * LOG2_BY_256_INVERSE); /* = 256 * n + m */
    /* n has at most 15 bits, nm therefore has at most 23 bits, therefore
       n * LOG2_HI_PART is computed exactly, and n * LOG2_LO_PART is computed
       with an absolute error < 2^15 * 2e-10 * 2^-LDBL_MANT_DIG.  */
    long double y_tmp = x - nm * LOG2_BY_256_HI_PART;
    long double y = y_tmp - nm * LOG2_BY_256_LO_PART;
    long double z = 0.5L * y;

/* Coefficients of the power series for tanh(z).  */
#define TANH_COEFF_1   1.0L
#define TANH_COEFF_3  -0.333333333333333333333333333333333333334L
#define TANH_COEFF_5   0.133333333333333333333333333333333333334L
#define TANH_COEFF_7  -0.053968253968253968253968253968253968254L
#define TANH_COEFF_9   0.0218694885361552028218694885361552028218L
#define TANH_COEFF_11 -0.00886323552990219656886323552990219656886L
#define TANH_COEFF_13  0.00359212803657248101692546136990581435026L
#define TANH_COEFF_15 -0.00145583438705131826824948518070211191904L

    long double z2 = z * z;
    long double tanh_z =
      (((((TANH_COEFF_11
           * z2 + TANH_COEFF_9)
          * z2 + TANH_COEFF_7)
         * z2 + TANH_COEFF_5)
        * z2 + TANH_COEFF_3)
       * z2 + TANH_COEFF_1)
      * z;

    long double exp_y_minus_1 = 2.0L * tanh_z / (1.0L - tanh_z);

    int n = (int) roundl (nm * (1.0L / 256.0L));
    int m = (int) nm - 256 * n;

    /* expm1l_table[i] = exp((i - 128) * log(2)/256) - 1.
       Computed in GNU clisp through
         (setf (long-float-digits) 128)
         (setq a 0L0)
         (setf (long-float-digits) 256)
         (dotimes (i 257)
           (format t "        ~D,~%"
                   (float (- (exp (* (/ (- i 128) 256) (log 2L0))) 1) a)))  */
    static const long double expm1l_table[257] =
      {
        -0.292893218813452475599155637895150960716L,
        -0.290976057839792401079436677742323809165L,
        -0.289053698915417220095325702647879950038L,
        -0.287126127947252846596498423285616993819L,
        -0.285193330804014994382467110862430046956L,
        -0.283255293316105578740250215722626632811L,
        -0.281312001275508837198386957752147486471L,
        -0.279363440435687168635744042695052413926L,
        -0.277409596511476689981496879264164547161L,
        -0.275450455178982509740597294512888729286L,
        -0.273486002075473717576963754157712706214L,
        -0.271516222799278089184548475181393238264L,
        -0.269541102909676505674348554844689233423L,
        -0.267560627926797086703335317887720824384L,
        -0.265574783331509036569177486867109287348L,
        -0.263583554565316202492529493866889713058L,
        -0.261586927030250344306546259812975038038L,
        -0.259584886088764114771170054844048746036L,
        -0.257577417063623749727613604135596844722L,
        -0.255564505237801467306336402685726757248L,
        -0.253546135854367575399678234256663229163L,
        -0.251522294116382286608175138287279137577L,
        -0.2494929651867872398674385184702356751864L,
        -0.247458134188296727960327722100283867508L,
        -0.24541778620328863011699022448340323429L,
        -0.243371906273695048903181511842366886387L,
        -0.24132047940089265059510885341281062657L,
        -0.239263490545592708236869372901757573532L,
        -0.237200924627730846574373155241529522695L,
        -0.23513276652635648805745654063657412692L,
        -0.233059001079521999099699248246140670544L,
        -0.230979613084171535783261520405692115669L,
        -0.228894587296029588193854068954632579346L,
        -0.226803908429489222568744221853864674729L,
        -0.224707561157500020438486294646580877171L,
        -0.222605530111455713940842831198332609562L,
        -0.2204977998810815164831359552625710592544L,
        -0.218384355014321147927034632426122058645L,
        -0.2162651800172235534675441445217774245016L,
        -0.214140259353829315375718509234297186439L,
        -0.212009577446056756772364919909047495547L,
        -0.209873118673587736597751517992039478005L,
        -0.2077308673737531349400659265343210916196L,
        -0.205582807841418027883101951185666435317L,
        -0.2034289243288665510313756784404656320656L,
        -0.201269201045686450868589852895683430425L,
        -0.199103622158653323103076879204523186316L,
        -0.196932171791614537151556053482436428417L,
        -0.19475483402537284591023966632129970827L,
        -0.192571592897569679960015418424270885733L,
        -0.190382432402568125350119133273631796029L,
        -0.188187336491335584102392022226559177731L,
        -0.185986289071326116575890738992992661386L,
        -0.183779274006362464829286135533230759947L,
        -0.181566275116517756116147982921992768975L,
        -0.17934727617799688564586793151548689933L,
        -0.1771222609230175777406216376370887771665L,
        -0.1748912130396911245164132617275148983224L,
        -0.1726541161719028012138814282020908791644L,
        -0.170410953919191957302175212789218768074L,
        -0.168161709836631782476831771511804777363L,
        -0.165906367434708746670203829291463807099L,
        -0.1636449101792017131905953879307692887046L,
        -0.161377321491060724103867675441291294819L,
        -0.15910358474628545696887452376678510496L,
        -0.15682368327580335203567701228614769857L,
        -0.154537600365347409013071332406381692911L,
        -0.152245319255333652509541396360635796882L,
        -0.149946823140738265249318713251248832456L,
        -0.147642095170974388162796469615281683674L,
        -0.145331118449768586448102562484668501975L,
        -0.143013876035036980698187522160833990549L,
        -0.140690350938761042185327811771843747742L,
        -0.138360526126863051392482883127641270248L,
        -0.136024384519081218878475585385633792948L,
        -0.133681908988844467561490046485836530346L,
        -0.131333082363146875502898959063916619876L,
        -0.128977887422421778270943284404535317759L,
        -0.126616306900415529961291721709773157771L,
        -0.1242483234840609219490048572320697039866L,
        -0.121873919813350258443919690312343389353L,
        -0.1194930784812080879189542126763637438278L,
        -0.11710578203336358947830887503073906297L,
        -0.1147120129682226132300120925687579825894L,
        -0.1123117537367393737247203999003383961205L,
        -0.1099049867422877955201404475637647649574L,
        -0.1074916943405325099278897180135900838485L,
        -0.1050718588392995019970556101123417014993L,
        -0.102645462498446406786148378936109092823L,
        -0.1002124875297324539725723033374854302454L,
        -0.097772916096688059846161368344495155786L,
        -0.0953267303144840657307406742107731280055L,
        -0.092873912249800621875082699818829828767L,
        -0.0904144439206957158520284361718212536293L,
        -0.0879483072964733445019372468353990225585L,
        -0.0854754842975513284540160873038416459095L,
        -0.0829959567953287682564584052058555719614L,
        -0.080509706612053141143695628825336081184L,
        -0.078016715520687037466429613329061550362L,
        -0.075516965244774535807472733052603963221L,
        -0.073010437458307215803773464831151680239L,
        -0.070497113785589807692349282254427317595L,
        -0.067976975801105477595185454402763710658L,
        -0.0654500050293807475554878955602008567352L,
        -0.06291618294485004933500052502277673278L,
        -0.0603754909717199109794126487955155117284L,
        -0.0578279104838327751561896480162548451191L,
        -0.055273422804530448266460732621318468453L,
        -0.0527120092065171793298906732865376926237L,
        -0.0501436509117223676387482401930039000769L,
        -0.0475683290911628981746625337821392744829L,
        -0.044986024864805103778829470427200864833L,
        -0.0423967193014263530636943648520845560749L,
        -0.0398003934184762630513928111129293882558L,
        -0.0371970281819375355214808849088086316225L,
        -0.0345866045061864160477270517354652168038L,
        -0.0319691032538527747009720477166542375817L,
        -0.0293445052356798073922893825624102948152L,
        -0.0267127912103833568278979766786970786276L,
        -0.0240739418845108520444897665995250062307L,
        -0.0214279379122998654908388741865642544049L,
        -0.018774759895536286618755114942929674984L,
        -0.016114388383412110943633198761985316073L,
        -0.01344680387238284353202993186779328685225L,
        -0.0107719868060245158708750409344163322253L,
        -0.00808991757489031507008688867384418356197L,
        -0.00540057651636682434752231377783368554176L,
        -0.00270394391452987374234008615207739887604L,
        0.0L,
        0.00271127505020248543074558845036204047301L,
        0.0054299011128028213513839559347998147001L,
        0.00815589811841751578309489081720103927357L,
        0.0108892860517004600204097905618605243881L,
        0.01363008495148943884025892906393992959584L,
        0.0163783149109530379404931137862940627635L,
        0.0191339960777379496848780958207928793998L,
        0.0218971486541166782344801347832994397821L,
        0.0246677928971356451482890762708149276281L,
        0.0274459491187636965388611939222137814994L,
        0.0302316376860410128717079024539045670944L,
        0.0330248790212284225001082839704609180866L,
        0.0358256936019571200299832090180813718441L,
        0.0386341019613787906124366979546397325796L,
        0.0414501246883161412645460790118931264803L,
        0.0442737824274138403219664787399290087847L,
        0.0471050958792898661299072502271122405627L,
        0.049944085800687266082038126515907909062L,
        0.0527907730046263271198912029807463031904L,
        0.05564517836055715880834132515293865216L,
        0.0585073227945126901057721096837166450754L,
        0.0613772272892620809505676780038837262945L,
        0.0642549128844645497886112570015802206798L,
        0.0671404006768236181695211209928091626068L,
        0.070033711820241773542411936757623568504L,
        0.0729348675259755513850354508738275853402L,
        0.0758438890627910378032286484760570740623L,
        0.0787607977571197937406800374384829584908L,
        0.081685614993215201942115594422531125645L,
        0.0846183622133092378161051719066143416095L,
        0.0875590609177696653467978309440397078697L,
        0.090507732665257659207010655760707978993L,
        0.0934643990728858542282201462504471620805L,
        0.096429081816376823386138295859248481766L,
        0.099401802630221985463696968238829904039L,
        0.1023825833078409435564142094256468575113L,
        0.1053714457017412555882746962569503110404L,
        0.1083684117236786380094236494266198501387L,
        0.111373503344817603850149254228916637444L,
        0.1143867425958925363088129569196030678004L,
        0.1174081515673691990545799630857802666544L,
        0.120437752409606684429003879866313012766L,
        0.1234755673330198007337297397753214319548L,
        0.1265216186082418997947986437870347776336L,
        0.12957592856628814599726498884024982591L,
        0.1326385195987192279870737236776230843835L,
        0.135709414157805514240390330676117013429L,
        0.1387886347566916537038302838415112547204L,
        0.14187620396956162271229760828788093894L,
        0.144972144431804219394413888222915895793L,
        0.148076478840179006778799662697342680031L,
        0.15118922995298270581775963520198253612L,
        0.154310420590216039548221528724806960684L,
        0.157440073633751029613085766293796821108L,
        0.160578212027498746369459472576090986253L,
        0.163724858777577513813573599092185312343L,
        0.166880036952481570555516298414089287832L,
        0.1700437696832501880802590357927385730016L,
        0.1732160801636372475348043545132453888896L,
        0.176396991650281276284645728483848641053L,
        0.1795865274628759454861005667694405189764L,
        0.182784710984341029924457204693850757963L,
        0.185991565660993831371265649534215563735L,
        0.189207115002721066717499970560475915293L,
        0.192431382583151222142727558145431011481L,
        0.1956643920398273745838370498654519757025L,
        0.1989061670743804817703025579763002069494L,
        0.202156731452703142096396957497765876L,
        0.205416109005123825604211432558411335666L,
        0.208684323626581577354792255889216998483L,
        0.211961399276801194468168917732493045449L,
        0.2152473599804688781165202513387984576236L,
        0.218542229827408361758207148117394510722L,
        0.221846032972757516903891841911570785834L,
        0.225158793637145437709464594384845353705L,
        0.2284805361068700056940089577927818403626L,
        0.231811284734075935884556653212794816605L,
        0.235151063936933305692912507415415760296L,
        0.238499898199816567833368865859612431546L,
        0.241857812073484048593677468726595605511L,
        0.245224830175257932775204967486152674173L,
        0.248600977189204736621766097302495545187L,
        0.251986277866316270060206031789203597321L,
        0.255380757024691089579390657442301194598L,
        0.258784439549716443077860441815162618762L,
        0.262197350394250708014010258518416459672L,
        0.265619514578806324196273999873453036297L,
        0.269050957191733222554419081032338004715L,
        0.272491703389402751236692044184602176772L,
        0.27594177839639210038120243475928938891L,
        0.279401207505669226913587970027852545961L,
        0.282870016078778280726669781021514051111L,
        0.286348229546025533601482208069738348358L,
        0.289835873406665812232747295491552189677L,
        0.293332973229089436725559789048704304684L,
        0.296839554651009665933754117792451159835L,
        0.300355643379650651014140567070917791291L,
        0.303881265191935898574523648951997368331L,
        0.30741644593467724479715157747196172848L,
        0.310961211524764341922991786330755849366L,
        0.314515587949354658485983613383997794966L,
        0.318079601266063994690185647066116617661L,
        0.321653277603157514326511812330609226158L,
        0.325236643159741294629537095498721674113L,
        0.32882972420595439547865089632866510792L,
        0.33243254708316144935164337949073577407L,
        0.336045138204145773442627904371869759286L,
        0.339667524053303005360030669724352576023L,
        0.343299731186835263824217146181630875424L,
        0.346941786232945835788173713229537282073L,
        0.350593715892034391408522196060133960038L,
        0.354255546936892728298014740140702804344L,
        0.357927306212901046494536695671766697444L,
        0.361609020638224755585535938831941474643L,
        0.365300717204011815430698360337542855432L,
        0.369002422974590611929601132982192832168L,
        0.372714165087668369284997857144717215791L,
        0.376435970754530100216322805518686960261L,
        0.380167867260238095581945274358283464698L,
        0.383909881963831954872659527265192818003L,
        0.387662042298529159042861017950775988895L,
        0.391424375771926187149835529566243446678L,
        0.395196909966200178275574599249220994717L,
        0.398979672538311140209528136715194969206L,
        0.402772691220204706374713524333378817108L,
        0.40657599381901544248361973255451684411L,
        0.410389608217270704414375128268675481146L,
        0.414213562373095048801688724209698078569L
      };

    long double t = expm1l_table[128 + m];

    /* (1+t) * (1+exp_y_minus_1) - 1 = t + (1+t)*exp_y_minus_1 */
    long double p_minus_1 = t + (1.0L + t) * exp_y_minus_1;

    long double s = ldexpl (1.0L, n) - 1.0L;

    /* (1+s) * (1+p_minus_1) - 1 = s + (1+s)*p_minus_1 */
    return s + (1.0L + s) * p_minus_1;
  }
}
Exemplo n.º 17
0
long double
logl (long double x)
{
  long double z, y, w;
  long double t;
  int k, e;

  /* Check for IEEE special cases.  */

  /* log(NaN) = NaN. */
  if (isnanl (x))
    {
      return x;
    }
  /* log(0) = -infinity. */
  if (x == 0.0L)
    {
      return -0.5L / ZERO;
    }
  /* log ( x < 0 ) = NaN */
  if (x < 0.0L)
    {
      return (x - x) / ZERO;
    }
  /* log (infinity) */
  if (x + x == x)
    {
      return x + x;
    }

  /* Extract exponent and reduce domain to 0.703125 <= u < 1.40625  */
  x = frexpl (x, &e);
  if (x < 0.703125L)
    {
      x += x;
      e--;
    }

  /* On this interval the table is not used due to cancellation error.  */
  if ((x <= 1.0078125L) && (x >= 0.9921875L))
    {
      z = x - 1.0L;
      k = 64;
      t = 1.0L;
    }
  else
    {
      k = floorl ((x - 0.5L) * 128.0L);
      t = 0.5L + k / 128.0L;
      z = (x - t) / t;
    }

  /* Series expansion of log(1+z).  */
  w = z * z;
  y = ((((((((((((l15 * z
                  + l14) * z
                 + l13) * z
                + l12) * z
               + l11) * z
              + l10) * z
             + l9) * z
            + l8) * z
           + l7) * z
          + l6) * z
         + l5) * z
        + l4) * z
       + l3) * z * w;
  y -= 0.5 * w;
  y += e * ln2b;  /* Base 2 exponent offset times ln(2).  */
  y += z;
  y += logtbl[k-26]; /* log(t) - (t-1) */
  y += (t - 1.0L);
  y += e * ln2a;
  return y;
}
Exemplo n.º 18
0
int gl_isfinitel (long double x)
{
  return !isnanl (x) && x - x == zerol;
}
Exemplo n.º 19
0
long double
log1pl (long double x)
{
  if (isnanl (x))
    return x;

  if (x <= -1.0L)
    {
      if (x == -1.0L)
        /* Return -Infinity.  */
        return - HUGE_VALL;
      else
        {
          /* Return NaN.  */
#if defined _MSC_VER || (defined __sgi && !defined __GNUC__)
          static long double zero;
          return zero / zero;
#else
          return 0.0L / 0.0L;
#endif
        }
    }

  if (x < -0.5L || x > 1.0L)
    return logl (1.0L + x);
  /* Here -0.5 <= x <= 1.0.  */

  if (x == 0.0L)
    /* Return a zero with the same sign as x.  */
    return x;

  /* Decompose x into
       1 + x = (1 + m/256) * (1 + y)
     where
       m is an integer, -128 <= m <= 256,
       y is a number, |y| <= 1/256.
     y is computed as
       y = (256 * x - m) / (256 + m).
     Then
       log(1+x) = log(m/256) + log(1+y)
     The first summand is a table lookup.
     The second summand is computed
       - either through the power series
           log(1+y) = y
                      - 1/2 * y^2
                      + 1/3 * y^3
                      - 1/4 * y^4
                      + 1/5 * y^5
                      - 1/6 * y^6
                      + 1/7 * y^7
                      - 1/8 * y^8
                      + 1/9 * y^9
                      - 1/10 * y^10
                      + 1/11 * y^11
                      - 1/12 * y^12
                      + 1/13 * y^13
                      - 1/14 * y^14
                      + 1/15 * y^15
                      - ...
       - or as log(1+y) = log((1+z)/(1-z)) = 2 * atanh(z)
         where z = y/(2+y)
         and atanh(z) is computed through its power series:
           atanh(z) = z
                      + 1/3 * z^3
                      + 1/5 * z^5
                      + 1/7 * z^7
                      + 1/9 * z^9
                      + 1/11 * z^11
                      + 1/13 * z^13
                      + 1/15 * z^15
                      + ...
         Since |z| <= 1/511 < 0.002, the relative contribution of the z^15
         term is < 1/15*0.002^14 < 2^-120 <= 2^-LDBL_MANT_DIG, therefore we
         can truncate the series after the z^13 term.  */

  {
    long double m = roundl (x * 256.0L);
    long double y = ((x * 256.0L) - m) / (m + 256.0L);
    long double z = y / (2.0L + y);

/* Coefficients of the power series for atanh(z).  */
#define ATANH_COEFF_1  1.0L
#define ATANH_COEFF_3  0.333333333333333333333333333333333333334L
#define ATANH_COEFF_5  0.2L
#define ATANH_COEFF_7  0.142857142857142857142857142857142857143L
#define ATANH_COEFF_9  0.1111111111111111111111111111111111111113L
#define ATANH_COEFF_11 0.090909090909090909090909090909090909091L
#define ATANH_COEFF_13 0.076923076923076923076923076923076923077L
#define ATANH_COEFF_15 0.066666666666666666666666666666666666667L

    long double z2 = z * z;
    long double atanh_z =
      ((((((ATANH_COEFF_13
            * z2 + ATANH_COEFF_11)
           * z2 + ATANH_COEFF_9)
          * z2 + ATANH_COEFF_7)
         * z2 + ATANH_COEFF_5)
        * z2 + ATANH_COEFF_3)
       * z2 + ATANH_COEFF_1)
      * z;

    /* logl_table[i] = log((i + 128) / 256).
       Computed in GNU clisp through
         (setf (long-float-digits) 128)
         (setq a 0L0)
         (setf (long-float-digits) 256)
         (dotimes (i 385)
           (format t "        ~D,~%"
                   (float (log (* (/ (+ i 128) 256) 1L0)) a)))  */
    static const long double logl_table[385] =
      {
        -0.693147180559945309417232121458176568075L,
        -0.6853650401178903604697692213970398044L,
        -0.677642994023980055266378075415729732197L,
        -0.669980121278410931188432960495886651496L,
        -0.662375521893191621046203913861404403985L,
        -0.65482831625780871022347679633437927773L,
        -0.647337644528651106250552853843513225963L,
        -0.639902666041133026551361927671647791137L,
        -0.632522558743510466836625989417756304788L,
        -0.625196518651437560022666843685547154042L,
        -0.617923759322357783718626781474514153438L,
        -0.61070351134887071814907205278986876216L,
        -0.60353502187025817679728065207969203929L,
        -0.59641755410139419712166106497071313106L,
        -0.58935038687830174459117031769420187977L,
        -0.582332814219655195222425952134964639978L,
        -0.575364144903561854878438011987654863008L,
        -0.568443702058988073553825606077313299585L,
        -0.561570822771226036828515992768693405624L,
        -0.554744857700826173731906247856527380683L,
        -0.547965170715447412135297057717612244552L,
        -0.541231138534103334345428696561292056747L,
        -0.534542150383306725323860946832334992828L,
        -0.527897607664638146541620672180936254347L,
        -0.52129692363328608707713317540302930314L,
        -0.514739523087127012297831879947234599722L,
        -0.50822484206593331675332852879892694707L,
        -0.50175232756031585480793331389686769463L,
        -0.495321437230025429054660050261215099L,
        -0.488931639131254417913411735261937295862L,
        -0.482582411452595671747679308725825054355L,
        -0.476273242259330949798142595713829069596L,
        -0.470003629245735553650937031148342064701L,
        -0.463773079495099479425751396412036696525L,
        -0.457581109247178400339643902517133157939L,
        -0.451427243672800141272924605544662667972L,
        -0.445311016655364052636629355711651820077L,
        -0.43923197057898186527990882355156990061L,
        -0.4331896561230192424451526269158655235L,
        -0.427183632062807368078106194920633178807L,
        -0.421213465076303550585562626925177406092L,
        -0.415278729556489003230882088534775334993L,
        -0.409379007429300711070330899107921801414L,
        -0.403513887976902632538339065932507598071L,
        -0.397682967666109433030550215403212372894L,
        -0.391885849981783528404356583224421075418L,
        -0.386122145265033447342107580922798666387L,
        -0.380391470556048421030985561769857535915L,
        -0.374693449441410693606984907867576972481L,
        -0.369027711905733333326561361023189215893L,
        -0.363393894187477327602809309537386757124L,
        -0.357791638638807479160052541644010369001L,
        -0.352220593589352099112142921677820359633L,
        -0.346680413213736728498769933032403617363L,
        -0.341170757402767124761784665198737642087L,
        -0.33569129163814153519122263131727209364L,
        -0.330241686870576856279407775480686721935L,
        -0.324821619401237656369001967407777741178L,
        -0.31943077076636122859621528874235306143L,
        -0.314068827624975851026378775827156709194L,
        -0.308735481649613269682442058976885699557L,
        -0.303430429419920096046768517454655701024L,
        -0.298153372319076331310838085093194799765L,
        -0.292904016432932602487907019463045397996L,
        -0.287682072451780927439219005993827431504L,
        -0.282487255574676923482925918282353780414L,
        -0.277319285416234343803903228503274262719L,
        -0.272177885915815673288364959951380595626L,
        -0.267062785249045246292687241862699949179L,
        -0.261973715741573968558059642502581569596L,
        -0.256910413785027239068190798397055267412L,
        -0.251872619755070079927735679796875342712L,
        -0.2468600779315257978846419408385075613265L,
        -0.24187253642048672427253973837916408939L,
        -0.2369097470783577150364265832942468196375L,
        -0.2319714654377751430492321958603212094726L,
        -0.2270574506353460848586128739534071682175L,
        -0.222167465341154296870334265401817316702L,
        -0.2173012756899813951520225351537951559L,
        -0.212458651214193401740613666010165016867L,
        -0.2076393647782445016154410442673876674964L,
        -0.202843192514751471266885961812429707545L,
        -0.1980699137620937948192675366153429027185L,
        -0.193319311003495979595900706211132426563L,
        -0.188591169807550022358923589720001638093L,
        -0.183885278770137362613157202229852743197L,
        -0.179201429457710992616226033183958974965L,
        -0.174539416351899677264255125093377869519L,
        -0.169899036795397472900424896523305726435L,
        -0.165280090939102924303339903679875604517L,
        -0.160682381690473465543308397998034325468L,
        -0.156105714663061654850502877304344269052L,
        -0.1515498981272009378406898175577424691056L,
        -0.1470147429618096590348349122269674042104L,
        -0.142500062607283030157283942253263107981L,
        -0.1380056730194437167017517619422725179055L,
        -0.1335313926245226231463436209313499745895L,
        -0.129077042275142343345847831367985856258L,
        -0.124642445207276597338493356591214304499L,
        -0.1202274269981598003244753948319154994493L,
        -0.115831815525121705099120059938680166568L,
        -0.1114554409253228268966213677328042273655L,
        -0.1070981355563671005131126851708522185606L,
        -0.1027597339577689347753154133345778104976L,
        -0.098440072813252519902888574928971234883L,
        -0.094138990913861910035632096996525066015L,
        -0.0898563291218610470766469347968659624282L,
        -0.0855919303354035139161469686670511961825L,
        -0.0813456394539524058873423550293617843895L,
        -0.077117303344431289769666193261475917783L,
        -0.072906770808087780565737488890929711303L,
        -0.0687138925480518083746933774035034481663L,
        -0.064538521137571171672923915683992928129L,
        -0.0603805109889074798714456529545968095868L,
        -0.0562397183228760777967376942769773768851L,
        -0.0521160011390140183616307870527840213665L,
        -0.0480092191863606077520036253234446621373L,
        -0.0439192339348354905263921515528654458042L,
        -0.0398459085471996706586162402473026835046L,
        -0.0357891078515852792753420982122404025613L,
        -0.0317486983145803011569962827485256299276L,
        -0.0277245480148548604671395114515163869272L,
        -0.0237165266173160421183468505286730579517L,
        -0.0197245053477785891192717326571593033246L,
        -0.015748356968139168607549511460828269521L,
        -0.0117879557520422404691605618900871263399L,
        -0.0078431774610258928731840424909435816546L,
        -0.00391389932113632909231778364357266484272L,
        0.0L,
        0.00389864041565732301393734309584290701073L,
        0.00778214044205494894746290006113676367813L,
        0.01165061721997527413559144280921434893315L,
        0.0155041865359652541508540460424468358779L,
        0.01934296284313093463590553454155047018545L,
        0.0231670592815343782287991609622899165794L,
        0.0269765876982020757480692925396595457815L,
        0.0307716586667536883710282075967721640917L,
        0.0345523815066597334073715005898328652816L,
        0.038318864302136599193755325123797290346L,
        0.042071213920687054375203805926962379448L,
        0.045809536031294203166679267614663342114L,
        0.049533935122276630882096208829824573267L,
        0.0532445145188122828658701937865287769396L,
        0.0569413764001384247590131015404494943015L,
        0.0606246218164348425806061320404202632862L,
        0.0642943507053972572162284502656114944857L,
        0.0679506619085077493945652777726294140346L,
        0.071593653187008817925605272752092034269L,
        0.075223421237587525698605339983662414637L,
        0.078840061707776024531540577859198294559L,
        0.082443669211074591268160068668307805914L,
        0.086034337341803153381797826721996075141L,
        0.0896121586896871326199514693784845287854L,
        0.093177224854183289768781353027759396216L,
        0.096729626458551112295571056487463437015L,
        0.1002694531636751493081301751297276601964L,
        0.1037967936816435648260618037639746883066L,
        0.1073117357890880506671750303711543368066L,
        0.1108143663402901141948061693232119280986L,
        0.1143047712800586336342591448151747734094L,
        0.1177830356563834545387941094705217050686L,
        0.1212492436328696851612122640808405265723L,
        0.1247034785009572358634065153808632684918L,
        0.128145822691930038174109886961074873852L,
        0.1315763577887192725887161286894831624516L,
        0.134995164537504830601983291147085645626L,
        0.138402322859119135685325873601649187393L,
        0.1417979118602573498789527352804727189846L,
        0.1451820098444978972819350637405643235226L,
        0.1485546943231371429098223170672938691604L,
        0.151916042025841975071803424896884511328L,
        0.1552661289111239515223833017101021786436L,
        0.1586050301766385840933711746258415752456L,
        0.161932820269313253240338285123614220592L,
        0.165249572895307162875611449277240313729L,
        0.1685553610298066669415865321701023169345L,
        0.171850256926659222340098946055147264935L,
        0.1751343321278491480142914649863898412374L,
        0.1784076574728182971194002415109419683545L,
        0.181670303107634678260605595617079739242L,
        0.184922338494011992663903592659249621006L,
        0.1881638324181829868259905803105539806714L,
        0.191394852999629454609298807561308873447L,
        0.194615467699671658858138593767269731516L,
        0.1978257433299198803625720711969614690756L,
        0.201025746060590741340908337591797808969L,
        0.204215541428690891503820386196239272214L,
        0.2073951943460705871587455788490062338536L,
        0.210564769107349637669552812732351513721L,
        0.2137243293977181388619051976331987647734L,
        0.216873938300614359619089525744347498479L,
        0.220013658305282095907358638661628360712L,
        0.2231435513142097557662950903098345033745L,
        0.226263678650453389361787082280390161607L,
        0.229374101064845829991480725046139871551L,
        0.232474878743094064920705078095567528222L,
        0.235566071312766909077588218941043410137L,
        0.2386477378501750099171491363522813392526L,
        0.241719936887145168144307515913513900104L,
        0.244782726417690916434704717466314811104L,
        0.247836163904581256780602765746524747999L,
        0.25088030628580941658844644154994089393L,
        0.253915209980963444137323297906606667466L,
        0.256940930897500425446759867911224262093L,
        0.259957524436926066972079494542311044577L,
        0.26296504550088135182072917321108602859L,
        0.265963548497137941339125926537543389269L,
        0.268953087345503958932974357924497845489L,
        0.271933715483641758831669494532999161983L,
        0.274905485872799249167009582983018668293L,
        0.277868451003456306186350032923401233082L,
        0.280822662900887784639519758873134832073L,
        0.28376817313064459834690122235025476666L,
        0.286705032803954314653250930842073965668L,
        0.289633292583042676878893055525668970004L,
        0.292553002686377439978201258664126644308L,
        0.295464212893835876386681906054964195182L,
        0.298366972551797281464900430293496918012L,
        0.301261330578161781012875538233755492657L,
        0.304147335467296717015819874720446989991L,
        0.30702503529491186207512454053537790169L,
        0.309894477722864687861624550833227164546L,
        0.31275571000389688838624655968831903216L,
        0.315608778986303334901366180667483174144L,
        0.318453731118534615810247213590599595595L,
        0.321290612453734292057863145522557457887L,
        0.324119468654211976090670760434987352183L,
        0.326940344995853320592356894073809191681L,
        0.329753286372467981814422811920789810952L,
        0.332558337300076601412275626573419425269L,
        0.335355541921137830257179579814166199074L,
        0.338144944008716397710235913939267433111L,
        0.340926586970593210305089199780356208443L,
        0.34370051385331844468019789211029452987L,
        0.346466767346208580918462188425772950712L,
        0.349225389785288304181275421187371759687L,
        0.35197642315717818465544745625943892599L,
        0.354719909102929028355011218999317665826L,
        0.357455888921803774226009490140904474434L,
        0.360184403575007796281574967493016620926L,
        0.362905493689368453137824345977489846141L,
        0.365619199560964711319396875217046453067L,
        0.368325561158707653048230154050398826898L,
        0.371024618127872663911964910806824955394L,
        0.373716409793584080821016832715823506644L,
        0.376400975164253065997877633436251593315L,
        0.379078352934969458390853345631019858882L,
        0.38174858149084833985966626493567607862L,
        0.384411698910332039734790062481290868519L,
        0.387067742968448287898902502261817665695L,
        0.38971675114002521337046360400352086705L,
        0.392358760602863872479379611988215363485L,
        0.39499380824086897810639403636498176831L,
        0.397621930647138489104829072973405554918L,
        0.40024316412701270692932510199513117008L,
        0.402857544701083514655197565487057707577L,
        0.405465108108164381978013115464349136572L,
        0.408065889808221748430198682969084124381L,
        0.410659924985268385934306203175822787661L,
        0.41324724855021933092547601552548590025L,
        0.415827895143710965613328892954902305356L,
        0.418401899138883817510763261966760106515L,
        0.42096929464412963612886716150679597245L,
        0.423530115505803295718430478017910109426L,
        0.426084395310900063124544879595476618897L,
        0.428632167389698760206812276426639053152L,
        0.43117346481837134085917247895559499848L,
        0.433708320421559393435847903042186017095L,
        0.436236766774918070349041323061121300663L,
        0.438758836207627937745575058511446738878L,
        0.441274560804875229489496441661301225362L,
        0.443783972410300981171768440588146426918L,
        0.446287102628419511532590180619669006749L,
        0.448783982827006710512822115683937186274L,
        0.451274644139458585144692383079012478686L,
        0.453759117467120506644794794442263270651L,
        0.456237433481587594380805538163929748437L,
        0.458709622626976664843883309250877913511L,
        0.461175715122170166367999925597855358603L,
        0.463635740963032513092182277331163919118L,
        0.466089729924599224558619247504769399859L,
        0.468537711563239270375665237462973542708L,
        0.470979715218791012546897856056359251373L,
        0.473415770016672131372578393236978550606L,
        0.475845904869963914265209586304381412175L,
        0.478270148481470280383546145497464809096L,
        0.480688529345751907676618455448011551209L,
        0.48310107575113582273837458485214554795L,
        0.485507815781700807801791077190788900579L,
        0.487908777319238973246173184132656942487L,
        0.490303988045193838150346159645746860531L,
        0.492693475442575255695076950020077845328L,
        0.495077266797851514597964584842833665358L,
        0.497455389202818942250859256731684928918L,
        0.499827869556449329821331415247044141512L,
        0.502194734566715494273584171951812573586L,
        0.504556010752395287058308531738174929982L,
        0.506911724444854354113196312660089270034L,
        0.509261901789807946804074919228323824878L,
        0.51160656874906207851888487520338193135L,
        0.51394575110223431680100608827421759311L,
        0.51627947444845449617281928478756106467L,
        0.518607764208045632152976996364798698556L,
        0.520930645624185312409809834659637709188L,
        0.52324814376454783651680722493487084164L,
        0.525560283522927371382427602307131424923L,
        0.527867089620842385113892217778300963557L,
        0.530168586609121617841419630845212405063L,
        0.532464798869471843873923723460142242606L,
        0.534755750616027675477923292032637111077L,
        0.537041465896883654566729244153832299024L,
        0.539321968595608874655355158077341155752L,
        0.54159728243274437157654230390043409897L,
        0.543867430967283517663338989065998323965L,
        0.546132437598135650382397209231209163864L,
        0.548392325565573162748150286179863158565L,
        0.550647117952662279259948179204913460093L,
        0.552896837686677737580717902230624314327L,
        0.55514150754050159271548035951590405017L,
        0.557381150134006357049816540361233647898L,
        0.559615787935422686270888500526826593487L,
        0.561845443262691817915664819160697456814L,
        0.564070138284802966071384290090190711817L,
        0.566289895023115872590849979337124343595L,
        0.568504735352668712078738764866962263577L,
        0.5707146810034715448536245647415894503L,
        0.572919753561785509092756726626261068625L,
        0.575119974471387940421742546569273429365L,
        0.577315365034823604318112061519496401506L,
        0.579505946414642223855274409488070989814L,
        0.58169173963462248252061075372537234071L,
        0.583872765580982679097413356975291104927L,
        0.586049045003578208904119436287324349516L,
        0.588220598517086043034868221609113995052L,
        0.590387446602176374641916708123598757576L,
        0.59254960960667159874199020959329739696L,
        0.594707107746692789514343546529205333192L,
        0.59685996110779383658731192302565801002L,
        0.59900818964608339938160002446165150206L,
        0.601151813189334836191674317068856441547L,
        0.603290851438084262340585186661310605647L,
        0.6054253239667168894375677681414899356L,
        0.607555250224541795501085152791125371894L,
        0.609680649536855273481833501660588408785L,
        0.611801541105992903529889766428814783686L,
        0.613917944012370492196929119645563790777L,
        0.616029877215514019647565928196700650293L,
        0.618137359555078733872689126674816271683L,
        0.620240409751857528851494632567246856773L,
        0.62233904640877874159710264120869663505L,
        0.62443328801189350104253874405467311991L,
        0.626523152931352759778820859734204069282L,
        0.628608659422374137744308205774183639946L,
        0.6306898256261987050837261409313532241L,
        0.63276666957103782954578646850357975849L,
        0.634839209173010211969493840510489008123L,
        0.63690746223706923162049442718119919119L,
        0.63897144645792072137962398326473680873L,
        0.64103117942093129105560133440539254671L,
        0.643086678603027315392053859585132960477L,
        0.645137961373584701665228496134731905937L,
        0.647185044995309550122320631377863036675L,
        0.64922794662510981889083996990531112227L,
        0.651266683314958103396333353349672108398L,
        0.653301272012745638758615881210873884572L,
        0.65533172956312763209494967856962559648L,
        0.657358072708360030141890023245936165513L,
        0.659380318089127826115336413370955804038L,
        0.661398482245365008260235838709650938148L,
        0.66341258161706625109695030429080128179L,
        0.665422632545090448950092610006660181147L,
        0.667428651271956189947234166318980478403L,
        0.669430653942629267298885270929503510123L,
        0.67142865660530232331713904200189252584L,
        0.67342267521216672029796038880101726475L,
        0.67541272562017673108090414397019748722L,
        0.677398823591806140809682609997348298556L,
        0.67938098479579735014710062847376425181L,
        0.681359224807903068948071559568089441735L,
        0.683333559111620688164363148387750369654L,
        0.68530400309891941654404807896723298642L,
        0.687270572070960267497006884394346103924L,
        0.689233281238808980324914337814603903233L,
        0.691192145724141958859604629216309755938L,
        0.693147180559945309417232121458176568075L
      };
    return logl_table[128 + (int)m] + 2.0L * atanh_z;
  }
}
Exemplo n.º 20
0
long double __tgammal_r(long double x, int* sgngaml)
{
	long double p, q, z;
	int i;

	*sgngaml = 1;
#ifdef NANS
	if (isnanl(x))
		return (NANL);
#endif
#ifdef INFINITIES
#ifdef NANS
	if (x == INFINITYL)
		return (x);
	if (x == -INFINITYL)
		return (NANL);
#else
	if (!isfinite(x))
		return (x);
#endif
#endif
	q = fabsl(x);

	if (q > 13.0L)
	{
		if (q > MAXGAML)
			goto goverf;
		if (x < 0.0L)
		{
			p = floorl(q);
			if (p == q)
			{
gsing:
				_SET_ERRNO(EDOM);
				mtherr("tgammal", SING);
#ifdef INFINITIES
				return (INFINITYL);
#else
				return (*sgngaml * MAXNUML);
#endif
			}
			i = p;
			if ((i & 1) == 0)
				*sgngaml = -1;
			z = q - p;
			if (z > 0.5L)
			{
				p += 1.0L;
				z = q - p;
			}
			z = q * sinl(PIL * z);
			z = fabsl(z) * stirf(q);
			if (z <= PIL/MAXNUML)
			{
goverf:
				_SET_ERRNO(ERANGE);
				mtherr("tgammal", OVERFLOW);
#ifdef INFINITIES
				return(*sgngaml * INFINITYL);
#else
				return(*sgngaml * MAXNUML);
#endif
			}
			z = PIL/z;
		}
		else
		{
			z = stirf(x);
		}
		return (*sgngaml * z);
	}

	z = 1.0L;
	while (x >= 3.0L)
	{
		x -= 1.0L;
		z *= x;
	}

	while (x < -0.03125L)
	{
		z /= x;
		x += 1.0L;
	}

	if (x <= 0.03125L)
		goto Small;

	while (x < 2.0L)
	{
		z /= x;
		x += 1.0L;
	}

	if (x == 2.0L)
		return (z);

	x -= 2.0L;
	p = polevll( x, P, 7 );
	q = polevll( x, Q, 8 );
	return (z * p / q);

Small:
	if (x == 0.0L)
	{
		goto gsing;
	}
	else
	{
		if (x < 0.0L)
		{
			x = -x;
			q = z / (x * polevll(x, SN, 8));
		}
		else
			q = z / (x * polevll(x, S, 8));
	}
	return q;
}
Exemplo n.º 21
0
static int
print_float (struct printf_info *pinfo, char *startp, char *endp, int *signp, snv_long_double n)
{
  int prec, fmtch;
  char *p, *t;
  snv_long_double fract;
  int expcnt, gformat = 0;
  snv_long_double integer, tmp;
  char expbuf[10];

  prec = pinfo->prec;
  fmtch = pinfo->spec;
  t = startp;
  *signp = 0;

  /* Do the special cases: nans, infinities, zero, and negative numbers. */
  if (isnanl (n))
    {
      /* Not-a-numbers are printed as a simple string. */
      *t++ = fmtch < 'a' ? 'N' : 'n';
      *t++ = fmtch < 'a' ? 'A' : 'a';
      *t++ = fmtch < 'a' ? 'N' : 'n';
      return t - startp;
    }

  /* Zero and infinity also can have a sign in front of them. */
  if (copysignl (1.0, n) < 0.0)
    {
      n = -1.0 * n;
      *signp = '-';
    }

  if (isinfl (n))
    {
      /* Infinities are printed as a simple string. */
      *t++ = fmtch < 'a' ? 'I' : 'i';
      *t++ = fmtch < 'a' ? 'N' : 'n';
      *t++ = fmtch < 'a' ? 'F' : 'f';
      goto set_signp;
    }

  expcnt = 0;
  fract = modfl (n, &integer);

  /* get an extra slot for rounding. */
  *t++ = '0';

  /* get integer portion of number; put into the end of the buffer; the
     .01 is added for modfl (356.0 / 10, &integer) returning .59999999...  */
  for (p = endp - 1; p >= startp && integer; ++expcnt)
    {
      tmp = modfl (integer / 10, &integer);
      *p-- = '0' + ((int) ((tmp + .01L) * 10));
    }

  switch (fmtch)
    {
    case 'g':
    case 'G':
      gformat = 1;

      /* a precision of 0 is treated as a precision of 1. */
      if (!prec)
	pinfo->prec = ++prec;

      /* ``The style used depends on the value converted; style e
         will be used only if the exponent resulting from the
         conversion is less than -4 or greater than the precision.''
                -- ANSI X3J11 */
      if (expcnt > prec || (!expcnt && fract && fract < .0001L))
	{
	  /* g/G format counts "significant digits, not digits of
	     precision; for the e/E format, this just causes an
	     off-by-one problem, i.e. g/G considers the digit
	     before the decimal point significant and e/E doesn't
	     count it as precision.  */
	  --prec;
	  fmtch -= 2;		/* G->E, g->e */
	  goto eformat;
	}
      else
	{
          /* Decrement precision */
          if (n != 0.0L)
	    prec -= (endp - p) - 1;
	  else
	    prec--;

	  goto fformat;
	}

    case 'f':
    case 'F':
    fformat:
      /* reverse integer into beginning of buffer */
      if (expcnt)
	for (; ++p < endp; *t++ = *p);
      else
	*t++ = '0';

      /* If precision required or alternate flag set, add in a
         decimal point.  */
      if (pinfo->prec || pinfo->alt)
	*t++ = '.';

      /* if requires more precision and some fraction left */
      if (fract)
	{
	  if (prec)
	    {
	      /* For %g, if no integer part, don't count initial
	         zeros as significant digits. */
	      do
		{
		  fract = modfl (fract * 10, &tmp);
		  *t++ = '0' + ((int) tmp);
		}
	      while (!tmp && !expcnt && gformat);

	      while (--prec && fract)
		{
		  fract = modfl (fract * 10, &tmp);
		  *t++ = '0' + ((int) tmp);
		}
	    }

	  if (fract)
	    startp =
	      print_float_round (fract, (int *) NULL, startp, t - 1, (char) 0, signp);
	}

      break;

    case 'e':
    case 'E':
    eformat:
      if (expcnt)
	{
	  *t++ = *++p;
	  if (pinfo->prec || pinfo->alt)
	    *t++ = '.';

	  /* if requires more precision and some integer left */
	  for (; prec && ++p < endp; --prec)
	    *t++ = *p;

	  /* if done precision and more of the integer component,
	     round using it; adjust fract so we don't re-round
	     later.  */
	  if (!prec && ++p < endp)
	    {
	      fract = 0;
	      startp = print_float_round ((snv_long_double) 0, &expcnt, startp, t - 1, *p, signp);
	    }

	  /* adjust expcnt for digit in front of decimal */
	  --expcnt;
	}

      /* until first fractional digit, decrement exponent */
      else if (fract)
	{
	  /* adjust expcnt for digit in front of decimal */
	  for (expcnt = -1;; --expcnt)
	    {
	      fract = modfl (fract * 10, &tmp);
	      if (tmp)
		break;
	    }
	  *t++ = '0' + ((int) tmp);
	  if (pinfo->prec || pinfo->alt)
	    *t++ = '.';
	}

      else
	{
	  *t++ = '0';
	  if (pinfo->prec || pinfo->alt)
	    *t++ = '.';
	}

      /* if requires more precision and some fraction left */
      if (fract)
	{
	  if (prec)
	    do
	      {
		fract = modfl (fract * 10, &tmp);
		*t++ = '0' + ((int) tmp);
	      }
	    while (--prec && fract);

	  if (fract)
	    startp = print_float_round (fract, &expcnt, startp, t - 1, (char) 0, signp);
	}
      break;

    default:
      abort ();
    }

  /* %e/%f/%#g add 0's for precision, others trim 0's */
  if (gformat && !pinfo->alt)
    {
      while (t > startp && *--t == '0');
      if (*t != '.')
        ++t;
    }
  else
    for (; prec--; *t++ = '0');

  if (fmtch == 'e' || fmtch == 'E')
    {
      *t++ = fmtch;
      if (expcnt < 0)
        {
          expcnt = -expcnt;
          *t++ = '-';
        }
      else
        *t++ = '+';

      p = expbuf;
      do
        *p++ = '0' + (expcnt % 10);
      while ((expcnt /= 10) > 9);
      *p++ = '0' + expcnt;
      while (p > expbuf)
	*t++ = *--p;
    }

set_signp:
  if (!*signp)
    {
      if (pinfo->showsign)
        *signp = '+';
      else if (pinfo->space)
        *signp = ' ';
    }

  return (t - startp);
}