Пример #1
0
double
__modf (double x, double *iptr)
{
  if (__builtin_isinf (x))
    {
      *iptr = x;
      return __copysign (0.0, x);
    }
  else if (__builtin_isnan (x))
    {
      *iptr = NAN;
      return NAN;
    }

  if (x >= 0.0)
    {
      *iptr = __floor (x);
      return __copysign (x - *iptr, x);
    }
  else
    {
      *iptr = __ceil (x);
      return __copysign (x - *iptr, x);
    }
}
Пример #2
0
__complex__ double
__kernel_casinh (__complex__ double x, int adj)
{
  __complex__ double res;
  double rx, ix;
  __complex__ double y;

  /* Avoid cancellation by reducing to the first quadrant.  */
  rx = fabs (__real__ x);
  ix = fabs (__imag__ x);

  if (rx >= 1.0 / DBL_EPSILON || ix >= 1.0 / DBL_EPSILON)
    {
      /* For large x in the first quadrant, x + csqrt (1 + x * x)
	 is sufficiently close to 2 * x to make no significant
	 difference to the result; avoid possible overflow from
	 the squaring and addition.  */
      __real__ y = rx;
      __imag__ y = ix;

      if (adj)
	{
	  double t = __real__ y;
	  __real__ y = __copysign (__imag__ y, __imag__ x);
	  __imag__ y = t;
	}

      res = __clog (y);
      __real__ res += M_LN2;
    }
  else
    {
      __real__ y = (rx - ix) * (rx + ix) + 1.0;
      __imag__ y = 2.0 * rx * ix;

      y = __csqrt (y);

      __real__ y += rx;
      __imag__ y += ix;

      if (adj)
	{
	  double t = __real__ y;
	  __real__ y = copysign (__imag__ y, __imag__ x);
	  __imag__ y = t;
	}

      res = __clog (y);
    }

  /* Give results the correct sign for the original argument.  */
  __real__ res = __copysign (__real__ res, __real__ x);
  __imag__ res = __copysign (__imag__ res, (adj ? 1.0 : __imag__ x));

  return res;
}
Пример #3
0
__complex__ double
__ctanh (__complex__ double x)
{
  __complex__ double res;

  if (__builtin_expect (!isfinite (__real__ x) || !isfinite (__imag__ x), 0))
    {
      if (__isinf_ns (__real__ x))
	{
	  __real__ res = __copysign (1.0, __real__ x);
	  __imag__ res = __copysign (0.0, __imag__ x);
	}
      else if (__imag__ x == 0.0)
	{
	  res = x;
	}
      else
	{
	  __real__ res = __nan ("");
	  __imag__ res = __nan ("");

	  if (__isinf_ns (__imag__ x))
	    feraiseexcept (FE_INVALID);
	}
    }
  else
    {
      double sin2ix, cos2ix;
      double den;

      __sincos (2.0 * __imag__ x, &sin2ix, &cos2ix);

      den = (__ieee754_cosh (2.0 * __real__ x) + cos2ix);

      if (den == 0.0)
	{
	  __complex__ double ez = __cexp (x);
	  __complex__ double emz = __cexp (-x);

	  res = (ez - emz) / (ez + emz);
	}
      else
	{
	  __real__ res = __ieee754_sinh (2.0 * __real__ x) / den;
	  __imag__ res = sin2ix / den;
	}
    }

  return res;
}
Пример #4
0
double
__ieee754_atanh (double x)
{
  double xa = fabs (x);
  double t;
  if (isless (xa, 0.5))
    {
      if (__glibc_unlikely (xa < 0x1.0p-28))
	{
	  math_force_eval (huge + x);
	  math_check_force_underflow (x);
	  return x;
	}

      t = xa + xa;
      t = 0.5 * __log1p (t + t * xa / (1.0 - xa));
    }
  else if (__glibc_likely (isless (xa, 1.0)))
    t = 0.5 * __log1p ((xa + xa) / (1.0 - xa));
  else
    {
      if (isgreater (xa, 1.0))
	return (x - x) / (x - x);

      return x / 0.0;
    }

  return __copysign (t, x);
}
Пример #5
0
__complex__ double
__clog10 (__complex__ double x)
{
  __complex__ double result;
  int rcls = fpclassify (__real__ x);
  int icls = fpclassify (__imag__ x);

  if (__builtin_expect (rcls == FP_ZERO && icls == FP_ZERO, 0))
    {
      /* Real and imaginary part are 0.0.  */
      __imag__ result = signbit (__real__ x) ? M_PI : 0.0;
      __imag__ result = __copysign (__imag__ result, __imag__ x);
      /* Yes, the following line raises an exception.  */
      __real__ result = -1.0 / fabs (__real__ x);
    }
  else if (__builtin_expect (rcls != FP_NAN && icls != FP_NAN, 1))
    {
      /* Neither real nor imaginary part is NaN.  */
      __real__ result = __ieee754_log10 (__ieee754_hypot (__real__ x,
							  __imag__ x));
      __imag__ result = M_LOG10E * __ieee754_atan2 (__imag__ x, __real__ x);
    }
  else
    {
      __imag__ result = __nan ("");
      if (rcls == FP_INFINITE || icls == FP_INFINITE)
	/* Real or imaginary part is infinite.  */
	__real__ result = HUGE_VAL;
      else
	__real__ result = __nan ("");
    }

  return result;
}
Пример #6
0
double
__ieee754_atanh (double x)
{
  double xa = fabs (x);
  double t;
  if (isless (xa, 0.5))
    {
      if (__builtin_expect (xa < 0x1.0p-28, 0))
	{
	  math_force_eval (huge + x);
	  return x;
	}

      t = xa + xa;
      t = 0.5 * __log1p (t + t * xa / (1.0 - xa));
    }
  else if (__builtin_expect (isless (xa, 1.0), 1))
    t = 0.5 * __log1p ((xa + xa) / (1.0 - xa));
  else
    {
      if (isgreater (xa, 1.0))
	return (x - x) / (x - x);

      return x / 0.0;
    }

  return __copysign (t, x);
}
Пример #7
0
double
__asinh (double x)
{
    double w;
    int32_t hx, ix;
    GET_HIGH_WORD (hx, x);
    ix = hx & 0x7fffffff;
    if (__glibc_unlikely (ix < 0x3e300000))                  /* |x|<2**-28 */
    {
        if (huge + x > one)
            return x;                       /* return x inexact except 0 */
    }
    if (__glibc_unlikely (ix > 0x41b00000))                  /* |x| > 2**28 */
    {
        if (ix >= 0x7ff00000)
            return x + x;                           /* x is inf or NaN */
        w = __ieee754_log (fabs (x)) + ln2;
    }
    else
    {
        double xa = fabs (x);
        if (ix > 0x40000000)              /* 2**28 > |x| > 2.0 */
        {
            w = __ieee754_log (2.0 * xa + one / (__ieee754_sqrt (xa * xa + one) +
                                                 xa));
        }
        else                      /* 2.0 > |x| > 2**-28 */
        {
            double t = xa * xa;
            w = __log1p (xa + t / (one + __ieee754_sqrt (one + t)));
        }
    }
    return __copysign (w, x);
}
Пример #8
0
__complex__ double
__casinh (__complex__ double x)
{
  __complex__ double res;
  int rcls = fpclassify (__real__ x);
  int icls = fpclassify (__imag__ x);

  if (rcls <= FP_INFINITE || icls <= FP_INFINITE)
    {
      if (icls == FP_INFINITE)
	{
	  __real__ res = __copysign (HUGE_VAL, __real__ x);

	  if (rcls == FP_NAN)
	    __imag__ res = __nan ("");
	  else
	    __imag__ res = __copysign (rcls >= FP_ZERO ? M_PI_2 : M_PI_4,
				       __imag__ x);
	}
      else if (rcls <= FP_INFINITE)
	{
	  __real__ res = __real__ x;
	  if ((rcls == FP_INFINITE && icls >= FP_ZERO)
	      || (rcls == FP_NAN && icls == FP_ZERO))
	    __imag__ res = __copysign (0.0, __imag__ x);
	  else
	    __imag__ res = __nan ("");
	}
      else
	{
	  __real__ res = __nan ("");
	  __imag__ res = __nan ("");
	}
    }
  else if (rcls == FP_ZERO && icls == FP_ZERO)
    {
      res = x;
    }
  else
    {
      res = __kernel_casinh (x, 0);
    }

  return res;
}
Пример #9
0
__complex__ double
__ctanh (__complex__ double x)
{
  __complex__ double res;

  if (!isfinite (__real__ x) || !isfinite (__imag__ x))
    {
      if (__isinf (__real__ x))
	{
	  __real__ res = __copysign (1.0, __real__ x);
	  __imag__ res = __copysign (0.0, __imag__ x);
	}
      else if (__imag__ x == 0.0)
	{
	  res = x;
	}
      else
	{
	  __real__ res = __nan ("");
	  __imag__ res = __nan ("");

#ifdef FE_INVALID
	  if (__isinf (__imag__ x))
	    feraiseexcept (FE_INVALID);
#endif
	}
    }
  else
    {
      double sin2ix, cos2ix;
      double den;

      __sincos (2.0 * __imag__ x, &sin2ix, &cos2ix);

      den = (__ieee754_cosh (2.0 * __real__ x) + cos2ix);

      __real__ res = __ieee754_sinh (2.0 * __real__ x) / den;
      __imag__ res = sin2ix / den;
    }

  return res;
}
Пример #10
0
__complex__ double
__clog (__complex__ double x)
{
  __complex__ double result;
  int rcls = fpclassify (__real__ x);
  int icls = fpclassify (__imag__ x);

  if (__builtin_expect (rcls == FP_ZERO && icls == FP_ZERO, 0))
    {
      /* Real and imaginary part are 0.0.  */
      __imag__ result = signbit (__real__ x) ? M_PI : 0.0;
      __imag__ result = __copysign (__imag__ result, __imag__ x);
      /* Yes, the following line raises an exception.  */
      __real__ result = -1.0 / fabs (__real__ x);
    }
  else if (__builtin_expect (rcls != FP_NAN && icls != FP_NAN, 1))
    {
      /* Neither real nor imaginary part is NaN.  */
      double d;
      int scale = 0;

      if (fabs (__real__ x) > DBL_MAX / 2.0
	  || fabs (__imag__ x) > DBL_MAX / 2.0)
	{
	  scale = -1;
	  __real__ x = __scalbn (__real__ x, scale);
	  __imag__ x = __scalbn (__imag__ x, scale);
	}
      else if (fabs (__real__ x) < DBL_MIN
	       && fabs (__imag__ x) < DBL_MIN)
	{
	  scale = DBL_MANT_DIG;
	  __real__ x = __scalbn (__real__ x, scale);
	  __imag__ x = __scalbn (__imag__ x, scale);
	}

      d = __ieee754_hypot (__real__ x, __imag__ x);

      __real__ result = __ieee754_log (d) - scale * M_LN2;
      __imag__ result = __ieee754_atan2 (__imag__ x, __real__ x);
    }
  else
    {
      __imag__ result = __nan ("");
      if (rcls == FP_INFINITE || icls == FP_INFINITE)
	/* Real or imaginary part is infinite.  */
	__real__ result = HUGE_VAL;
      else
	__real__ result = __nan ("");
    }

  return result;
}
Пример #11
0
__complex__ double
__cproj (__complex__ double x)
{
  if (isinf (__real__ x) || isinf (__imag__ x))
    {
      __complex__ double res;

      __real__ res = INFINITY;
      __imag__ res = __copysign (0.0, __imag__ x);

      return res;
    }

  return x;
}
Пример #12
0
__complex__ double
__casin (__complex__ double x)
{
  __complex__ double res;

  if (isnan (__real__ x) || isnan (__imag__ x))
    {
      if (__real__ x == 0.0)
	{
	  res = x;
	}
      else if (isinf (__real__ x) || isinf (__imag__ x))
	{
	  __real__ res = __nan ("");
	  __imag__ res = __copysign (HUGE_VAL, __imag__ x);
	}
      else
	{
	  __real__ res = __nan ("");
	  __imag__ res = __nan ("");
	}
    }
  else
    {
      __complex__ double y;

      __real__ y = -__imag__ x;
      __imag__ y = __real__ x;

      y = __casinh (y);

      __real__ res = __imag__ y;
      __imag__ res = -__real__ y;
    }

  return res;
}
Пример #13
0
Err mathlib_copysign(UInt16 refnum, double x, double y, double *result) {
#pragma unused(refnum)
	*result = __copysign(x, y);
	return mlErrNone;
}
Пример #14
0
__complex__ double
__kernel_casinh (__complex__ double x, int adj)
{
  __complex__ double res;
  double rx, ix;
  __complex__ double y;

  /* Avoid cancellation by reducing to the first quadrant.  */
  rx = fabs (__real__ x);
  ix = fabs (__imag__ x);

  if (rx >= 1.0 / DBL_EPSILON || ix >= 1.0 / DBL_EPSILON)
    {
      /* For large x in the first quadrant, x + csqrt (1 + x * x)
	 is sufficiently close to 2 * x to make no significant
	 difference to the result; avoid possible overflow from
	 the squaring and addition.  */
      __real__ y = rx;
      __imag__ y = ix;

      if (adj)
	{
	  double t = __real__ y;
	  __real__ y = __copysign (__imag__ y, __imag__ x);
	  __imag__ y = t;
	}

      res = __clog (y);
      __real__ res += M_LN2;
    }
  else if (rx >= 0.5 && ix < DBL_EPSILON / 8.0)
    {
      double s = __ieee754_hypot (1.0, rx);

      __real__ res = __ieee754_log (rx + s);
      if (adj)
	__imag__ res = __ieee754_atan2 (s, __imag__ x);
      else
	__imag__ res = __ieee754_atan2 (ix, s);
    }
  else if (rx < DBL_EPSILON / 8.0 && ix >= 1.5)
    {
      double s = __ieee754_sqrt ((ix + 1.0) * (ix - 1.0));

      __real__ res = __ieee754_log (ix + s);
      if (adj)
	__imag__ res = __ieee754_atan2 (rx, __copysign (s, __imag__ x));
      else
	__imag__ res = __ieee754_atan2 (s, rx);
    }
  else if (ix > 1.0 && ix < 1.5 && rx < 0.5)
    {
      if (rx < DBL_EPSILON * DBL_EPSILON)
	{
	  double ix2m1 = (ix + 1.0) * (ix - 1.0);
	  double s = __ieee754_sqrt (ix2m1);

	  __real__ res = __log1p (2.0 * (ix2m1 + ix * s)) / 2.0;
	  if (adj)
	    __imag__ res = __ieee754_atan2 (rx, __copysign (s, __imag__ x));
	  else
	    __imag__ res = __ieee754_atan2 (s, rx);
	}
      else
	{
	  double ix2m1 = (ix + 1.0) * (ix - 1.0);
	  double rx2 = rx * rx;
	  double f = rx2 * (2.0 + rx2 + 2.0 * ix * ix);
	  double d = __ieee754_sqrt (ix2m1 * ix2m1 + f);
	  double dp = d + ix2m1;
	  double dm = f / dp;
	  double r1 = __ieee754_sqrt ((dm + rx2) / 2.0);
	  double r2 = rx * ix / r1;

	  __real__ res = __log1p (rx2 + dp + 2.0 * (rx * r1 + ix * r2)) / 2.0;
	  if (adj)
	    __imag__ res = __ieee754_atan2 (rx + r1, __copysign (ix + r2,
								 __imag__ x));
	  else
	    __imag__ res = __ieee754_atan2 (ix + r2, rx + r1);
	}
    }
  else if (ix == 1.0 && rx < 0.5)
    {
      if (rx < DBL_EPSILON / 8.0)
	{
	  __real__ res = __log1p (2.0 * (rx + __ieee754_sqrt (rx))) / 2.0;
	  if (adj)
	    __imag__ res = __ieee754_atan2 (__ieee754_sqrt (rx),
					    __copysign (1.0, __imag__ x));
	  else
	    __imag__ res = __ieee754_atan2 (1.0, __ieee754_sqrt (rx));
	}
      else
	{
	  double d = rx * __ieee754_sqrt (4.0 + rx * rx);
	  double s1 = __ieee754_sqrt ((d + rx * rx) / 2.0);
	  double s2 = __ieee754_sqrt ((d - rx * rx) / 2.0);

	  __real__ res = __log1p (rx * rx + d + 2.0 * (rx * s1 + s2)) / 2.0;
	  if (adj)
	    __imag__ res = __ieee754_atan2 (rx + s1, __copysign (1.0 + s2,
								 __imag__ x));
	  else
	    __imag__ res = __ieee754_atan2 (1.0 + s2, rx + s1);
	}
    }
  else if (ix < 1.0 && rx < 0.5)
    {
      if (ix >= DBL_EPSILON)
	{
	  if (rx < DBL_EPSILON * DBL_EPSILON)
	    {
	      double onemix2 = (1.0 + ix) * (1.0 - ix);
	      double s = __ieee754_sqrt (onemix2);

	      __real__ res = __log1p (2.0 * rx / s) / 2.0;
	      if (adj)
		__imag__ res = __ieee754_atan2 (s, __imag__ x);
	      else
		__imag__ res = __ieee754_atan2 (ix, s);
	    }
	  else
	    {
	      double onemix2 = (1.0 + ix) * (1.0 - ix);
	      double rx2 = rx * rx;
	      double f = rx2 * (2.0 + rx2 + 2.0 * ix * ix);
	      double d = __ieee754_sqrt (onemix2 * onemix2 + f);
	      double dp = d + onemix2;
	      double dm = f / dp;
	      double r1 = __ieee754_sqrt ((dp + rx2) / 2.0);
	      double r2 = rx * ix / r1;

	      __real__ res
		= __log1p (rx2 + dm + 2.0 * (rx * r1 + ix * r2)) / 2.0;
	      if (adj)
		__imag__ res = __ieee754_atan2 (rx + r1,
						__copysign (ix + r2,
							    __imag__ x));
	      else
		__imag__ res = __ieee754_atan2 (ix + r2, rx + r1);
	    }
	}
      else
	{
	  double s = __ieee754_hypot (1.0, rx);

	  __real__ res = __log1p (2.0 * rx * (rx + s)) / 2.0;
	  if (adj)
	    __imag__ res = __ieee754_atan2 (s, __imag__ x);
	  else
	    __imag__ res = __ieee754_atan2 (ix, s);
	}
      math_check_force_underflow_nonneg (__real__ res);
    }
  else
    {
      __real__ y = (rx - ix) * (rx + ix) + 1.0;
      __imag__ y = 2.0 * rx * ix;

      y = __csqrt (y);

      __real__ y += rx;
      __imag__ y += ix;

      if (adj)
	{
	  double t = __real__ y;
	  __real__ y = __copysign (__imag__ y, __imag__ x);
	  __imag__ y = t;
	}

      res = __clog (y);
    }

  /* Give results the correct sign for the original argument.  */
  __real__ res = __copysign (__real__ res, __real__ x);
  __imag__ res = __copysign (__imag__ res, (adj ? 1.0 : __imag__ x));

  return res;
}
Пример #15
0
__complex__ double
__cacosh (__complex__ double x)
{
    __complex__ double res;
    int rcls = fpclassify (__real__ x);
    int icls = fpclassify (__imag__ x);

    if (rcls <= FP_INFINITE || icls <= FP_INFINITE)
    {
        if (icls == FP_INFINITE)
        {
            __real__ res = HUGE_VAL;

            if (rcls == FP_NAN)
                __imag__ res = __nan ("");
            else
                __imag__ res = __copysign ((rcls == FP_INFINITE
                                            ? (__real__ x < 0.0
                                               ? M_PI - M_PI_4 : M_PI_4)
                                            : M_PI_2), __imag__ x);
        }
        else if (rcls == FP_INFINITE)
        {
            __real__ res = HUGE_VAL;

            if (icls >= FP_ZERO)
                __imag__ res = __copysign (signbit (__real__ x) ? M_PI : 0.0,
                                           __imag__ x);
            else
                __imag__ res = __nan ("");
        }
        else
        {
            __real__ res = __nan ("");
            __imag__ res = __nan ("");
        }
    }
    else if (rcls == FP_ZERO && icls == FP_ZERO)
    {
        __real__ res = 0.0;
        __imag__ res = __copysign (M_PI_2, __imag__ x);
    }
    else
    {
        __complex__ double y;

        __real__ y = (__real__ x - __imag__ x) * (__real__ x + __imag__ x) - 1.0;
        __imag__ y = 2.0 * __real__ x * __imag__ x;

        y = __csqrt (y);

        if (__real__ x < 0.0)
            y = -y;

        __real__ y += __real__ x;
        __imag__ y += __imag__ x;

        res = __clog (y);

        /* We have to use the positive branch.  */
        if (__real__ res < 0.0)
            res = -res;
    }

    return res;
}
Пример #16
0
  /* Fix the sign and return after stage 1 or stage 2 */
static double
signArctan2 (double y, double z)
{
  return __copysign (z, y);
}
Пример #17
0
__complex__ double
__clog10 (__complex__ double x)
{
  __complex__ double result;
  int rcls = fpclassify (__real__ x);
  int icls = fpclassify (__imag__ x);

  if (__builtin_expect (rcls == FP_ZERO && icls == FP_ZERO, 0))
    {
      /* Real and imaginary part are 0.0.  */
      __imag__ result = signbit (__real__ x) ? M_PI : 0.0;
      __imag__ result = __copysign (__imag__ result, __imag__ x);
      /* Yes, the following line raises an exception.  */
      __real__ result = -1.0 / fabs (__real__ x);
    }
  else if (__builtin_expect (rcls != FP_NAN && icls != FP_NAN, 1))
    {
      /* Neither real nor imaginary part is NaN.  */
      double absx = fabs (__real__ x), absy = fabs (__imag__ x);
      int scale = 0;

      if (absx < absy)
	{
	  double t = absx;
	  absx = absy;
	  absy = t;
	}

      if (absx > DBL_MAX / 2.0)
	{
	  scale = -1;
	  absx = __scalbn (absx, scale);
	  absy = (absy >= DBL_MIN * 2.0 ? __scalbn (absy, scale) : 0.0);
	}
      else if (absx < DBL_MIN && absy < DBL_MIN)
	{
	  scale = DBL_MANT_DIG;
	  absx = __scalbn (absx, scale);
	  absy = __scalbn (absy, scale);
	}

      if (absx == 1.0 && scale == 0)
	{
	  double absy2 = absy * absy;
	  if (absy2 <= DBL_MIN * 2.0 * M_LN10)
	    {
#if __FLT_EVAL_METHOD__ == 0
	      __real__ result = (absy2 / 2.0 - absy2 * absy2 / 4.0) * M_LOG10E;
#else
	      volatile double force_underflow = absy2 * absy2 / 4.0;
	      __real__ result = (absy2 / 2.0 - force_underflow) * M_LOG10E;
#endif
	    }
	  else
	    __real__ result = __log1p (absy2) * (M_LOG10E / 2.0);
	}
      else if (absx > 1.0 && absx < 2.0 && absy < 1.0 && scale == 0)
	{
	  double d2m1 = (absx - 1.0) * (absx + 1.0);
	  if (absy >= DBL_EPSILON)
	    d2m1 += absy * absy;
	  __real__ result = __log1p (d2m1) * (M_LOG10E / 2.0);
	}
      else if (absx < 1.0
	       && absx >= 0.75
	       && absy < DBL_EPSILON / 2.0
	       && scale == 0)
	{
	  double d2m1 = (absx - 1.0) * (absx + 1.0);
	  __real__ result = __log1p (d2m1) * (M_LOG10E / 2.0);
	}
      else if (absx < 1.0 && (absx >= 0.75 || absy >= 0.5) && scale == 0)
	{
	  double d2m1 = __x2y2m1 (absx, absy);
	  __real__ result = __log1p (d2m1) * (M_LOG10E / 2.0);
	}
      else
	{
	  double d = __ieee754_hypot (absx, absy);
	  __real__ result = __ieee754_log10 (d) - scale * M_LOG10_2;
	}

      __imag__ result = M_LOG10E * __ieee754_atan2 (__imag__ x, __real__ x);
    }
  else
    {
      __imag__ result = __nan ("");
      if (rcls == FP_INFINITE || icls == FP_INFINITE)
	/* Real or imaginary part is infinite.  */
	__real__ result = HUGE_VAL;
      else
	__real__ result = __nan ("");
    }

  return result;
}
Пример #18
0
long double
__copysignl(long double x, long double y)
{
	return ( (long double)__copysign((double)x, (double)y) );
}
Пример #19
0
__complex__ double
__csin (__complex__ double x)
{
  __complex__ double retval;
  int negate = signbit (__real__ x);
  int rcls = fpclassify (__real__ x);
  int icls = fpclassify (__imag__ x);

  __real__ x = fabs (__real__ x);

  if (__glibc_likely (icls >= FP_ZERO))
    {
      /* Imaginary part is finite.  */
      if (__glibc_likely (rcls >= FP_ZERO))
	{
	  /* Real part is finite.  */
	  const int t = (int) ((DBL_MAX_EXP - 1) * M_LN2);
	  double sinix, cosix;

	  if (__glibc_likely (rcls != FP_SUBNORMAL))
	    {
	      __sincos (__real__ x, &sinix, &cosix);
	    }
	  else
	    {
	      sinix = __real__ x;
	      cosix = 1.0;
	    }

	  if (fabs (__imag__ x) > t)
	    {
	      double exp_t = __ieee754_exp (t);
	      double ix = fabs (__imag__ x);
	      if (signbit (__imag__ x))
		cosix = -cosix;
	      ix -= t;
	      sinix *= exp_t / 2.0;
	      cosix *= exp_t / 2.0;
	      if (ix > t)
		{
		  ix -= t;
		  sinix *= exp_t;
		  cosix *= exp_t;
		}
	      if (ix > t)
		{
		  /* Overflow (original imaginary part of x > 3t).  */
		  __real__ retval = DBL_MAX * sinix;
		  __imag__ retval = DBL_MAX * cosix;
		}
	      else
		{
		  double exp_val = __ieee754_exp (ix);
		  __real__ retval = exp_val * sinix;
		  __imag__ retval = exp_val * cosix;
		}
	    }
	  else
	    {
	      __real__ retval = __ieee754_cosh (__imag__ x) * sinix;
	      __imag__ retval = __ieee754_sinh (__imag__ x) * cosix;
	    }

	  if (negate)
	    __real__ retval = -__real__ retval;

	  if (fabs (__real__ retval) < DBL_MIN)
	    {
	      volatile double force_underflow
		= __real__ retval * __real__ retval;
	      (void) force_underflow;
	    }
	  if (fabs (__imag__ retval) < DBL_MIN)
	    {
	      volatile double force_underflow
		= __imag__ retval * __imag__ retval;
	      (void) force_underflow;
	    }
	}
      else
	{
	  if (icls == FP_ZERO)
	    {
	      /* Imaginary part is 0.0.  */
	      __real__ retval = __nan ("");
	      __imag__ retval = __imag__ x;

	      if (rcls == FP_INFINITE)
		feraiseexcept (FE_INVALID);
	    }
	  else
	    {
	      __real__ retval = __nan ("");
	      __imag__ retval = __nan ("");

	      feraiseexcept (FE_INVALID);
	    }
	}
    }
  else if (icls == FP_INFINITE)
    {
      /* Imaginary part is infinite.  */
      if (rcls == FP_ZERO)
	{
	  /* Real part is 0.0.  */
	  __real__ retval = __copysign (0.0, negate ? -1.0 : 1.0);
	  __imag__ retval = __imag__ x;
	}
      else if (rcls > FP_ZERO)
	{
	  /* Real part is finite.  */
	  double sinix, cosix;

	  if (__glibc_likely (rcls != FP_SUBNORMAL))
	    {
	      __sincos (__real__ x, &sinix, &cosix);
	    }
	  else
	    {
	      sinix = __real__ x;
	      cosix = 1.0;
	    }

	  __real__ retval = __copysign (HUGE_VAL, sinix);
	  __imag__ retval = __copysign (HUGE_VAL, cosix);

	  if (negate)
	    __real__ retval = -__real__ retval;
	  if (signbit (__imag__ x))
	    __imag__ retval = -__imag__ retval;
	}
      else
	{
	  /* The addition raises the invalid exception.  */
	  __real__ retval = __nan ("");
	  __imag__ retval = HUGE_VAL;

	  if (rcls == FP_INFINITE)
	    feraiseexcept (FE_INVALID);
	}
    }
  else
    {
      if (rcls == FP_ZERO)
	__real__ retval = __copysign (0.0, negate ? -1.0 : 1.0);
      else
	__real__ retval = __nan ("");
      __imag__ retval = __nan ("");
    }

  return retval;
}
Пример #20
0
  /* Fix the sign of y and return */
static double
__signArctan (double x, double y)
{
  return __copysign (y, x);
}
Пример #21
0
double
__kernel_standard(double x, double y, int type)
{
	struct exception exc;
#ifndef HUGE_VAL	/* this is the only routine that uses HUGE_VAL */
#define HUGE_VAL inf
	double inf = 0.0;

	SET_HIGH_WORD(inf,0x7ff00000);	/* set inf to infinite */
#endif

#ifdef _USE_WRITE
	(void) fflush(stdout);
#endif
	exc.arg1 = x;
	exc.arg2 = y;
	switch(type) {
	    case 1:
	    case 101:
	    case 201:
		/* acos(|x|>1) */
		exc.type = DOMAIN;
		exc.name = type < 100 ? "acos" : (type < 200
						  ? "acosf" : "acosl");;
		if (_LIB_VERSION == _SVID_)
		  exc.retval = HUGE;
		else
		  exc.retval = NAN;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (EDOM);
		else if (!matherr(&exc)) {
		  if(_LIB_VERSION == _SVID_) {
		    (void) WRITE2("acos: DOMAIN error\n", 19);
		  }
		  __set_errno (EDOM);
		}
		break;
	    case 2:
	    case 102:
	    case 202:
		/* asin(|x|>1) */
		exc.type = DOMAIN;
		exc.name = type < 100 ? "asin" : (type < 200
						  ? "asinf" : "asinl");
		if (_LIB_VERSION == _SVID_)
		  exc.retval = HUGE;
		else
		  exc.retval = NAN;
		if(_LIB_VERSION == _POSIX_)
		  __set_errno (EDOM);
		else if (!matherr(&exc)) {
		  if(_LIB_VERSION == _SVID_) {
			(void) WRITE2("asin: DOMAIN error\n", 19);
		  }
		  __set_errno (EDOM);
		}
		break;
	    case 3:
	    case 103:
	    case 203:
		/* atan2(+-0,+-0) */
		exc.arg1 = y;
		exc.arg2 = x;
		exc.type = DOMAIN;
		exc.name = type < 100 ? "atan2" : (type < 200
						   ? "atan2f" : "atan2l");
		assert (_LIB_VERSION == _SVID_);
		exc.retval = HUGE;
		if(_LIB_VERSION == _POSIX_)
		  __set_errno (EDOM);
		else if (!matherr(&exc)) {
		  if(_LIB_VERSION == _SVID_) {
			(void) WRITE2("atan2: DOMAIN error\n", 20);
		      }
		  __set_errno (EDOM);
		}
		break;
	    case 4:
	    case 104:
	    case 204:
		/* hypot(finite,finite) overflow */
		exc.type = OVERFLOW;
		exc.name = type < 100 ? "hypot" : (type < 200
						   ? "hypotf" : "hypotl");
		if (_LIB_VERSION == _SVID_)
		  exc.retval = HUGE;
		else
		  exc.retval = HUGE_VAL;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (ERANGE);
		else if (!matherr(&exc)) {
			__set_errno (ERANGE);
		}
		break;
	    case 5:
	    case 105:
	    case 205:
		/* cosh(finite) overflow */
		exc.type = OVERFLOW;
		exc.name = type < 100 ? "cosh" : (type < 200
						  ? "coshf" : "coshl");
		if (_LIB_VERSION == _SVID_)
		  exc.retval = HUGE;
		else
		  exc.retval = HUGE_VAL;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (ERANGE);
		else if (!matherr(&exc)) {
			__set_errno (ERANGE);
		}
		break;
	    case 6:
	    case 106:
	    case 206:
		/* exp(finite) overflow */
		exc.type = OVERFLOW;
		exc.name = type < 100 ? "exp" : (type < 200
						 ? "expf" : "expl");
		if (_LIB_VERSION == _SVID_)
		  exc.retval = HUGE;
		else
		  exc.retval = HUGE_VAL;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (ERANGE);
		else if (!matherr(&exc)) {
			__set_errno (ERANGE);
		}
		break;
	    case 7:
	    case 107:
	    case 207:
		/* exp(finite) underflow */
		exc.type = UNDERFLOW;
		exc.name = type < 100 ? "exp" : (type < 200
						 ? "expf" : "expl");
		exc.retval = zero;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (ERANGE);
		else if (!matherr(&exc)) {
			__set_errno (ERANGE);
		}
		break;
	    case 8:
	    case 108:
	    case 208:
		/* y0(0) = -inf */
		exc.type = DOMAIN;	/* should be SING for IEEE */
		exc.name = type < 100 ? "y0" : (type < 200 ? "y0f" : "y0l");
		if (_LIB_VERSION == _SVID_)
		  exc.retval = -HUGE;
		else
		  exc.retval = -HUGE_VAL;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (EDOM);
		else if (!matherr(&exc)) {
		  if (_LIB_VERSION == _SVID_) {
			(void) WRITE2("y0: DOMAIN error\n", 17);
		      }
		  __set_errno (EDOM);
		}
		break;
	    case 9:
	    case 109:
	    case 209:
		/* y0(x<0) = NaN */
		exc.type = DOMAIN;
		exc.name = type < 100 ? "y0" : (type < 200 ? "y0f" : "y0l");
		if (_LIB_VERSION == _SVID_)
		  exc.retval = -HUGE;
		else
		  exc.retval = -HUGE_VAL;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (EDOM);
		else if (!matherr(&exc)) {
		  if (_LIB_VERSION == _SVID_) {
			(void) WRITE2("y0: DOMAIN error\n", 17);
		      }
		  __set_errno (EDOM);
		}
		break;
	    case 10:
	    case 110:
	    case 210:
		/* y1(0) = -inf */
		exc.type = DOMAIN;	/* should be SING for IEEE */
		exc.name = type < 100 ? "y1" : (type < 200 ? "y1f" : "y1l");
		if (_LIB_VERSION == _SVID_)
		  exc.retval = -HUGE;
		else
		  exc.retval = -HUGE_VAL;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (EDOM);
		else if (!matherr(&exc)) {
		  if (_LIB_VERSION == _SVID_) {
			(void) WRITE2("y1: DOMAIN error\n", 17);
		      }
		  __set_errno (EDOM);
		}
		break;
	    case 11:
	    case 111:
	    case 211:
		/* y1(x<0) = NaN */
		exc.type = DOMAIN;
		exc.name = type < 100 ? "y1" : (type < 200 ? "y1f" : "y1l");
		if (_LIB_VERSION == _SVID_)
		  exc.retval = -HUGE;
		else
		  exc.retval = -HUGE_VAL;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (EDOM);
		else if (!matherr(&exc)) {
		  if (_LIB_VERSION == _SVID_) {
			(void) WRITE2("y1: DOMAIN error\n", 17);
		      }
		  __set_errno (EDOM);
		}
		break;
	    case 12:
	    case 112:
	    case 212:
		/* yn(n,0) = -inf */
		exc.type = DOMAIN;	/* should be SING for IEEE */
		exc.name = type < 100 ? "yn" : (type < 200 ? "ynf" : "ynl");
		if (_LIB_VERSION == _SVID_)
		  exc.retval = -HUGE;
		else
		  exc.retval = -HUGE_VAL;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (EDOM);
		else if (!matherr(&exc)) {
		  if (_LIB_VERSION == _SVID_) {
			(void) WRITE2("yn: DOMAIN error\n", 17);
		      }
		  __set_errno (EDOM);
		}
		break;
	    case 13:
	    case 113:
	    case 213:
		/* yn(x<0) = NaN */
		exc.type = DOMAIN;
		exc.name = type < 100 ? "yn" : (type < 200 ? "ynf" : "ynl");
		if (_LIB_VERSION == _SVID_)
		  exc.retval = -HUGE;
		else
		  exc.retval = -HUGE_VAL;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (EDOM);
		else if (!matherr(&exc)) {
		  if (_LIB_VERSION == _SVID_) {
			(void) WRITE2("yn: DOMAIN error\n", 17);
		      }
		  __set_errno (EDOM);
		}
		break;
	    case 14:
	    case 114:
	    case 214:
		/* lgamma(finite) overflow */
		exc.type = OVERFLOW;
		exc.name = type < 100 ? "lgamma" : (type < 200
						    ? "lgammaf" : "lgammal");
		if (_LIB_VERSION == _SVID_)
		  exc.retval = HUGE;
		else
		  exc.retval = HUGE_VAL;
		if (_LIB_VERSION == _POSIX_)
			__set_errno (ERANGE);
		else if (!matherr(&exc)) {
			__set_errno (ERANGE);
		}
		break;
	    case 15:
	    case 115:
	    case 215:
		/* lgamma(-integer) or lgamma(0) */
		exc.type = SING;
		exc.name = type < 100 ? "lgamma" : (type < 200
						    ? "lgammaf" : "lgammal");
		if (_LIB_VERSION == _SVID_)
		  exc.retval = HUGE;
		else
		  exc.retval = HUGE_VAL;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (ERANGE);
		else if (!matherr(&exc)) {
		  if (_LIB_VERSION == _SVID_) {
			(void) WRITE2("lgamma: SING error\n", 19);
		      }
		  __set_errno (EDOM);
		}
		break;
	    case 16:
	    case 116:
	    case 216:
		/* log(0) */
		exc.type = SING;
		exc.name = type < 100 ? "log" : (type < 200 ? "logf" : "logl");
		if (_LIB_VERSION == _SVID_)
		  exc.retval = -HUGE;
		else
		  exc.retval = -HUGE_VAL;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (ERANGE);
		else if (!matherr(&exc)) {
		  if (_LIB_VERSION == _SVID_) {
			(void) WRITE2("log: SING error\n", 16);
		      }
		  __set_errno (EDOM);
		}
		break;
	    case 17:
	    case 117:
	    case 217:
		/* log(x<0) */
		exc.type = DOMAIN;
		exc.name = type < 100 ? "log" : (type < 200 ? "logf" : "logl");
		if (_LIB_VERSION == _SVID_)
		  exc.retval = -HUGE;
		else
		  exc.retval = NAN;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (EDOM);
		else if (!matherr(&exc)) {
		  if (_LIB_VERSION == _SVID_) {
			(void) WRITE2("log: DOMAIN error\n", 18);
		      }
		  __set_errno (EDOM);
		}
		break;
	    case 18:
	    case 118:
	    case 218:
		/* log10(0) */
		exc.type = SING;
		exc.name = type < 100 ? "log10" : (type < 200
						   ? "log10f" : "log10l");
		if (_LIB_VERSION == _SVID_)
		  exc.retval = -HUGE;
		else
		  exc.retval = -HUGE_VAL;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (ERANGE);
		else if (!matherr(&exc)) {
		  if (_LIB_VERSION == _SVID_) {
			(void) WRITE2("log10: SING error\n", 18);
		      }
		  __set_errno (EDOM);
		}
		break;
	    case 19:
	    case 119:
	    case 219:
		/* log10(x<0) */
		exc.type = DOMAIN;
		exc.name = type < 100 ? "log10" : (type < 200
						   ? "log10f" : "log10l");
		if (_LIB_VERSION == _SVID_)
		  exc.retval = -HUGE;
		else
		  exc.retval = NAN;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (EDOM);
		else if (!matherr(&exc)) {
		  if (_LIB_VERSION == _SVID_) {
			(void) WRITE2("log10: DOMAIN error\n", 20);
		      }
		  __set_errno (EDOM);
		}
		break;
	    case 20:
	    case 120:
	    case 220:
		/* pow(0.0,0.0) */
		/* error only if _LIB_VERSION == _SVID_ */
		exc.type = DOMAIN;
		exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
		exc.retval = zero;
		if (_LIB_VERSION != _SVID_) exc.retval = 1.0;
		else if (!matherr(&exc)) {
			(void) WRITE2("pow(0,0): DOMAIN error\n", 23);
			__set_errno (EDOM);
		}
		break;
	    case 21:
	    case 121:
	    case 221:
		/* pow(x,y) overflow */
		exc.type = OVERFLOW;
		exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
		if (_LIB_VERSION == _SVID_) {
		  exc.retval = HUGE;
		  y *= 0.5;
		  if(x<zero&&__rint(y)!=y) exc.retval = -HUGE;
		} else {
		  exc.retval = HUGE_VAL;
		  y *= 0.5;
		  if(x<zero&&__rint(y)!=y) exc.retval = -HUGE_VAL;
		}
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (ERANGE);
		else if (!matherr(&exc)) {
			__set_errno (ERANGE);
		}
		break;
	    case 22:
	    case 122:
	    case 222:
		/* pow(x,y) underflow */
		exc.type = UNDERFLOW;
		exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
		exc.retval =  zero;
		y *= 0.5;
		if (x < zero && __rint (y) != y)
		  exc.retval = -zero;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (ERANGE);
		else if (!matherr(&exc)) {
			__set_errno (ERANGE);
		}
		break;
	    case 23:
	    case 123:
	    case 223:
		/* -0**neg */
		exc.type = DOMAIN;
		exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
		if (_LIB_VERSION == _SVID_)
		  exc.retval = zero;
		else
		  exc.retval = -HUGE_VAL;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (ERANGE);
		else if (!matherr(&exc)) {
		  if (_LIB_VERSION == _SVID_) {
			(void) WRITE2("pow(0,neg): DOMAIN error\n", 25);
		      }
		  __set_errno (EDOM);
		}
		break;
	    case 43:
	    case 143:
	    case 243:
		/* +0**neg */
		exc.type = DOMAIN;
		exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
		if (_LIB_VERSION == _SVID_)
		  exc.retval = zero;
		else
		  exc.retval = HUGE_VAL;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (ERANGE);
		else if (!matherr(&exc)) {
		  if (_LIB_VERSION == _SVID_) {
			(void) WRITE2("pow(0,neg): DOMAIN error\n", 25);
		      }
		  __set_errno (EDOM);
		}
		break;
	    case 24:
	    case 124:
	    case 224:
		/* neg**non-integral */
		exc.type = DOMAIN;
		exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
		if (_LIB_VERSION == _SVID_)
		    exc.retval = zero;
		else
		    exc.retval = zero/zero;	/* X/Open allow NaN */
		if (_LIB_VERSION == _POSIX_)
		   __set_errno (EDOM);
		else if (!matherr(&exc)) {
		  if (_LIB_VERSION == _SVID_) {
			(void) WRITE2("neg**non-integral: DOMAIN error\n", 32);
		      }
		  __set_errno (EDOM);
		}
		break;
	    case 25:
	    case 125:
	    case 225:
		/* sinh(finite) overflow */
		exc.type = OVERFLOW;
		exc.name = type < 100 ? "sinh" : (type < 200
						  ? "sinhf" : "sinhl");
		if (_LIB_VERSION == _SVID_)
		  exc.retval = ( (x>zero) ? HUGE : -HUGE);
		else
		  exc.retval = ( (x>zero) ? HUGE_VAL : -HUGE_VAL);
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (ERANGE);
		else if (!matherr(&exc)) {
			__set_errno (ERANGE);
		}
		break;
	    case 26:
	    case 126:
	    case 226:
		/* sqrt(x<0) */
		exc.type = DOMAIN;
		exc.name = type < 100 ? "sqrt" : (type < 200
						  ? "sqrtf" : "sqrtl");
		if (_LIB_VERSION == _SVID_)
		  exc.retval = zero;
		else
		  exc.retval = zero/zero;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (EDOM);
		else if (!matherr(&exc)) {
		  if (_LIB_VERSION == _SVID_) {
			(void) WRITE2("sqrt: DOMAIN error\n", 19);
		      }
		  __set_errno (EDOM);
		}
		break;
	    case 27:
	    case 127:
	    case 227:
		/* fmod(x,0) */
		exc.type = DOMAIN;
		exc.name = type < 100 ? "fmod" : (type < 200
						  ? "fmodf" : "fmodl");
		if (_LIB_VERSION == _SVID_)
		    exc.retval = x;
		else
		    exc.retval = zero/zero;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (EDOM);
		else if (!matherr(&exc)) {
		  if (_LIB_VERSION == _SVID_) {
		    (void) WRITE2("fmod:  DOMAIN error\n", 20);
		  }
		  __set_errno (EDOM);
		}
		break;
	    case 28:
	    case 128:
	    case 228:
		/* remainder(x,0) */
		exc.type = DOMAIN;
		exc.name = type < 100 ? "remainder" : (type < 200
						       ? "remainderf"
						       : "remainderl");
		exc.retval = zero/zero;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (EDOM);
		else if (!matherr(&exc)) {
		  if (_LIB_VERSION == _SVID_) {
		    (void) WRITE2("remainder: DOMAIN error\n", 24);
		  }
		  __set_errno (EDOM);
		}
		break;
	    case 29:
	    case 129:
	    case 229:
		/* acosh(x<1) */
		exc.type = DOMAIN;
		exc.name = type < 100 ? "acosh" : (type < 200
						   ? "acoshf" : "acoshl");
		exc.retval = zero/zero;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (EDOM);
		else if (!matherr(&exc)) {
		  if (_LIB_VERSION == _SVID_) {
		    (void) WRITE2("acosh: DOMAIN error\n", 20);
		  }
		  __set_errno (EDOM);
		}
		break;
	    case 30:
	    case 130:
	    case 230:
		/* atanh(|x|>1) */
		exc.type = DOMAIN;
		exc.name = type < 100 ? "atanh" : (type < 200
						   ? "atanhf" : "atanhl");
		exc.retval = zero/zero;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (EDOM);
		else if (!matherr(&exc)) {
		  if (_LIB_VERSION == _SVID_) {
		    (void) WRITE2("atanh: DOMAIN error\n", 20);
		  }
		  __set_errno (EDOM);
		}
		break;
	    case 31:
	    case 131:
	    case 231:
		/* atanh(|x|=1) */
		exc.type = SING;
		exc.name = type < 100 ? "atanh" : (type < 200
						   ? "atanhf" : "atanhl");
		exc.retval = x/zero;	/* sign(x)*inf */
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (ERANGE);
		else if (!matherr(&exc)) {
		  if (_LIB_VERSION == _SVID_) {
		    (void) WRITE2("atanh: SING error\n", 18);
		  }
		  __set_errno (EDOM);
		}
		break;
	    case 32:
	    case 132:
	    case 232:
		/* scalb overflow; SVID also returns +-HUGE_VAL */
		exc.type = OVERFLOW;
		exc.name = type < 100 ? "scalb" : (type < 200
						   ? "scalbf" : "scalbl");
		exc.retval = x > zero ? HUGE_VAL : -HUGE_VAL;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (ERANGE);
		else if (!matherr(&exc)) {
			__set_errno (ERANGE);
		}
		break;
	    case 33:
	    case 133:
	    case 233:
		/* scalb underflow */
		exc.type = UNDERFLOW;
		exc.name = type < 100 ? "scalb" : (type < 200
						   ? "scalbf" : "scalbl");
		exc.retval = __copysign(zero,x);
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (ERANGE);
		else if (!matherr(&exc)) {
			__set_errno (ERANGE);
		}
		break;
	    case 34:
	    case 134:
	    case 234:
		/* j0(|x|>X_TLOSS) */
		exc.type = TLOSS;
		exc.name = type < 100 ? "j0" : (type < 200 ? "j0f" : "j0l");
		exc.retval = zero;
		if (_LIB_VERSION == _POSIX_)
			__set_errno (ERANGE);
		else if (!matherr(&exc)) {
			if (_LIB_VERSION == _SVID_) {
				(void) WRITE2(exc.name, 2);
				(void) WRITE2(": TLOSS error\n", 14);
			}
			__set_errno (ERANGE);
		}
		break;
	    case 35:
	    case 135:
	    case 235:
		/* y0(x>X_TLOSS) */
		exc.type = TLOSS;
		exc.name = type < 100 ? "y0" : (type < 200 ? "y0f" : "y0l");
		exc.retval = zero;
		if (_LIB_VERSION == _POSIX_)
			__set_errno (ERANGE);
		else if (!matherr(&exc)) {
			if (_LIB_VERSION == _SVID_) {
				(void) WRITE2(exc.name, 2);
				(void) WRITE2(": TLOSS error\n", 14);
			}
			__set_errno (ERANGE);
		}
		break;
	    case 36:
	    case 136:
	    case 236:
		/* j1(|x|>X_TLOSS) */
		exc.type = TLOSS;
		exc.name = type < 100 ? "j1" : (type < 200 ? "j1f" : "j1l");
		exc.retval = zero;
		if (_LIB_VERSION == _POSIX_)
			__set_errno (ERANGE);
		else if (!matherr(&exc)) {
			if (_LIB_VERSION == _SVID_) {
				(void) WRITE2(exc.name, 2);
				(void) WRITE2(": TLOSS error\n", 14);
			}
			__set_errno (ERANGE);
		}
		break;
	    case 37:
	    case 137:
	    case 237:
		/* y1(x>X_TLOSS) */
		exc.type = TLOSS;
		exc.name = type < 100 ? "y1" : (type < 200 ? "y1f" : "y1l");
		exc.retval = zero;
		if (_LIB_VERSION == _POSIX_)
			__set_errno (ERANGE);
		else if (!matherr(&exc)) {
			if (_LIB_VERSION == _SVID_) {
				(void) WRITE2(exc.name, 2);
				(void) WRITE2(": TLOSS error\n", 14);
			}
			__set_errno (ERANGE);
		}
		break;
	    case 38:
	    case 138:
	    case 238:
		/* jn(|x|>X_TLOSS) */
		exc.type = TLOSS;
		exc.name = type < 100 ? "jn" : (type < 200 ? "jnf" : "jnl");
		exc.retval = zero;
		if (_LIB_VERSION == _POSIX_)
			__set_errno (ERANGE);
		else if (!matherr(&exc)) {
			if (_LIB_VERSION == _SVID_) {
				(void) WRITE2(exc.name, 2);
				(void) WRITE2(": TLOSS error\n", 14);
			}
			__set_errno (ERANGE);
		}
		break;
	    case 39:
	    case 139:
	    case 239:
		/* yn(x>X_TLOSS) */
		exc.type = TLOSS;
		exc.name = type < 100 ? "yn" : (type < 200 ? "ynf" : "ynl");
		exc.retval = zero;
		if (_LIB_VERSION == _POSIX_)
			__set_errno (ERANGE);
		else if (!matherr(&exc)) {
			if (_LIB_VERSION == _SVID_) {
				(void) WRITE2(exc.name, 2);
				(void) WRITE2(": TLOSS error\n", 14);
			}
			__set_errno (ERANGE);
		}
		break;
	    case 40:
	    case 140:
	    case 240:
		/* tgamma(finite) overflow */
		exc.type = OVERFLOW;
		exc.name = type < 100 ? "tgamma" : (type < 200
						   ? "tgammaf" : "tgammal");
		exc.retval = HUGE_VAL;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (ERANGE);
		else if (!matherr(&exc)) {
		  __set_errno (ERANGE);
		}
		break;
	    case 41:
	    case 141:
	    case 241:
		/* tgamma(-integer) */
		exc.type = SING;
		exc.name = type < 100 ? "tgamma" : (type < 200
						   ? "tgammaf" : "tgammal");
		exc.retval = NAN;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (EDOM);
		else if (!matherr(&exc)) {
		  if (_LIB_VERSION == _SVID_) {
			(void) WRITE2("tgamma: SING error\n", 18);
			exc.retval = HUGE_VAL;
		      }
		  __set_errno (EDOM);
		}
		break;
	    case 42:
	    case 142:
	    case 242:
		/* pow(NaN,0.0) */
		/* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */
		exc.type = DOMAIN;
		exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
		exc.retval = x;
		if (_LIB_VERSION == _IEEE_ ||
		    _LIB_VERSION == _POSIX_) exc.retval = 1.0;
		else if (!matherr(&exc)) {
			__set_errno (EDOM);
		}
		break;

	    case 44:
	    case 144:
	    case 244:
		/* exp(finite) overflow */
		exc.type = OVERFLOW;
		exc.name = type < 100 ? "exp2" : (type < 200
						  ? "exp2f" : "exp2l");
		if (_LIB_VERSION == _SVID_)
		  exc.retval = HUGE;
		else
		  exc.retval = HUGE_VAL;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (ERANGE);
		else if (!matherr(&exc)) {
			__set_errno (ERANGE);
		}
		break;
	    case 45:
	    case 145:
	    case 245:
		/* exp(finite) underflow */
		exc.type = UNDERFLOW;
		exc.name = type < 100 ? "exp2" : (type < 200
						  ? "exp2f" : "exp2l");
		exc.retval = zero;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (ERANGE);
		else if (!matherr(&exc)) {
			__set_errno (ERANGE);
		}
		break;

	    case 46:
	    case 146:
	    case 246:
		/* exp(finite) overflow */
		exc.type = OVERFLOW;
		exc.name = type < 100 ? "exp10" : (type < 200
						   ? "exp10f" : "exp10l");
		if (_LIB_VERSION == _SVID_)
		  exc.retval = HUGE;
		else
		  exc.retval = HUGE_VAL;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (ERANGE);
		else if (!matherr(&exc)) {
			__set_errno (ERANGE);
		}
		break;
	    case 47:
	    case 147:
	    case 247:
		/* exp(finite) underflow */
		exc.type = UNDERFLOW;
		exc.name = type < 100 ? "exp10" : (type < 200
						   ? "exp10f" : "exp10l");
		exc.retval = zero;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (ERANGE);
		else if (!matherr(&exc)) {
			__set_errno (ERANGE);
		}
		break;
	    case 48:
	    case 148:
	    case 248:
		/* log2(0) */
		exc.type = SING;
		exc.name = type < 100 ? "log2" : (type < 200
						   ? "log2f" : "log2l");
		if (_LIB_VERSION == _SVID_)
		  exc.retval = -HUGE;
		else
		  exc.retval = -HUGE_VAL;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (ERANGE);
		else if (!matherr(&exc)) {
		  __set_errno (EDOM);
		}
		break;
	    case 49:
	    case 149:
	    case 249:
		/* log2(x<0) */
		exc.type = DOMAIN;
		exc.name = type < 100 ? "log2" : (type < 200
						   ? "log2f" : "log2l");
		if (_LIB_VERSION == _SVID_)
		  exc.retval = -HUGE;
		else
		  exc.retval = NAN;
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (EDOM);
		else if (!matherr(&exc)) {
		  __set_errno (EDOM);
		}
		break;
	    case 50:
	    case 150:
	    case 250:
		/* tgamma(+-0) */
		exc.type = SING;
		exc.name = type < 100 ? "tgamma" : (type < 200
						    ? "tgammaf" : "tgammal");
		exc.retval = __copysign (HUGE_VAL, x);
		if (_LIB_VERSION == _POSIX_)
		  __set_errno (ERANGE);
		else if (!matherr(&exc)) {
		  if (_LIB_VERSION == _SVID_)
		    (void) WRITE2("tgamma: SING error\n", 18);
		  __set_errno (ERANGE);
		}
		break;

		/* #### Last used is 50/150/250 ### */
	}
	return exc.retval;
}
Пример #22
0
__complex__ double
__ctanh (__complex__ double x)
{
  __complex__ double res;

  if (__glibc_unlikely (!isfinite (__real__ x) || !isfinite (__imag__ x)))
    {
      if (isinf (__real__ x))
	{
	  __real__ res = __copysign (1.0, __real__ x);
	  if (isfinite (__imag__ x) && fabs (__imag__ x) > 1.0)
	    {
	      double sinix, cosix;
	      __sincos (__imag__ x, &sinix, &cosix);
	      __imag__ res = __copysign (0.0, sinix * cosix);
	    }
	  else
	    __imag__ res = __copysign (0.0, __imag__ x);
	}
      else if (__imag__ x == 0.0)
	{
	  res = x;
	}
      else
	{
	  __real__ res = __nan ("");
	  __imag__ res = __nan ("");

	  if (isinf (__imag__ x))
	    feraiseexcept (FE_INVALID);
	}
    }
  else
    {
      double sinix, cosix;
      double den;
      const int t = (int) ((DBL_MAX_EXP - 1) * M_LN2 / 2);

      /* tanh(x+iy) = (sinh(2x) + i*sin(2y))/(cosh(2x) + cos(2y))
	 = (sinh(x)*cosh(x) + i*sin(y)*cos(y))/(sinh(x)^2 + cos(y)^2).  */

      if (__glibc_likely (fabs (__imag__ x) > DBL_MIN))
	{
	  __sincos (__imag__ x, &sinix, &cosix);
	}
      else
	{
	  sinix = __imag__ x;
	  cosix = 1.0;
	}

      if (fabs (__real__ x) > t)
	{
	  /* Avoid intermediate overflow when the imaginary part of
	     the result may be subnormal.  Ignoring negligible terms,
	     the real part is +/- 1, the imaginary part is
	     sin(y)*cos(y)/sinh(x)^2 = 4*sin(y)*cos(y)/exp(2x).  */
	  double exp_2t = __ieee754_exp (2 * t);

	  __real__ res = __copysign (1.0, __real__ x);
	  __imag__ res = 4 * sinix * cosix;
	  __real__ x = fabs (__real__ x);
	  __real__ x -= t;
	  __imag__ res /= exp_2t;
	  if (__real__ x > t)
	    {
	      /* Underflow (original real part of x has absolute value
		 > 2t).  */
	      __imag__ res /= exp_2t;
	    }
	  else
	    __imag__ res /= __ieee754_exp (2 * __real__ x);
	}
      else
	{
	  double sinhrx, coshrx;
	  if (fabs (__real__ x) > DBL_MIN)
	    {
	      sinhrx = __ieee754_sinh (__real__ x);
	      coshrx = __ieee754_cosh (__real__ x);
	    }
	  else
	    {
	      sinhrx = __real__ x;
	      coshrx = 1.0;
	    }

	  if (fabs (sinhrx) > fabs (cosix) * DBL_EPSILON)
	    den = sinhrx * sinhrx + cosix * cosix;
	  else
	    den = cosix * cosix;
	  __real__ res = sinhrx * coshrx / den;
	  __imag__ res = sinix * cosix / den;
	}
      math_check_force_underflow_complex (res);
    }

  return res;
}
Пример #23
0
__complex__ double
__clog (__complex__ double x)
{
  __complex__ double result;
  int rcls = fpclassify (__real__ x);
  int icls = fpclassify (__imag__ x);

  if (__glibc_unlikely (rcls == FP_ZERO && icls == FP_ZERO))
    {
      /* Real and imaginary part are 0.0.  */
      __imag__ result = signbit (__real__ x) ? M_PI : 0.0;
      __imag__ result = __copysign (__imag__ result, __imag__ x);
      /* Yes, the following line raises an exception.  */
      __real__ result = -1.0 / fabs (__real__ x);
    }
  else if (__glibc_likely (rcls != FP_NAN && icls != FP_NAN))
    {
      /* Neither real nor imaginary part is NaN.  */
      double absx = fabs (__real__ x), absy = fabs (__imag__ x);
      int scale = 0;

      if (absx < absy)
	{
	  double t = absx;
	  absx = absy;
	  absy = t;
	}

      if (absx > DBL_MAX / 2.0)
	{
	  scale = -1;
	  absx = __scalbn (absx, scale);
	  absy = (absy >= DBL_MIN * 2.0 ? __scalbn (absy, scale) : 0.0);
	}
      else if (absx < DBL_MIN && absy < DBL_MIN)
	{
	  scale = DBL_MANT_DIG;
	  absx = __scalbn (absx, scale);
	  absy = __scalbn (absy, scale);
	}

      if (absx == 1.0 && scale == 0)
	{
	  __real__ result = __log1p (absy * absy) / 2.0;
	  math_check_force_underflow_nonneg (__real__ result);
	}
      else if (absx > 1.0 && absx < 2.0 && absy < 1.0 && scale == 0)
	{
	  double d2m1 = (absx - 1.0) * (absx + 1.0);
	  if (absy >= DBL_EPSILON)
	    d2m1 += absy * absy;
	  __real__ result = __log1p (d2m1) / 2.0;
	}
      else if (absx < 1.0
	       && absx >= 0.5
	       && absy < DBL_EPSILON / 2.0
	       && scale == 0)
	{
	  double d2m1 = (absx - 1.0) * (absx + 1.0);
	  __real__ result = __log1p (d2m1) / 2.0;
	}
      else if (absx < 1.0
	       && absx >= 0.5
	       && scale == 0
	       && absx * absx + absy * absy >= 0.5)
	{
	  double d2m1 = __x2y2m1 (absx, absy);
	  __real__ result = __log1p (d2m1) / 2.0;
	}
      else
	{
	  double d = __ieee754_hypot (absx, absy);
	  __real__ result = __ieee754_log (d) - scale * M_LN2;
	}

      __imag__ result = __ieee754_atan2 (__imag__ x, __real__ x);
    }
  else
    {
      __imag__ result = __nan ("");
      if (rcls == FP_INFINITE || icls == FP_INFINITE)
	/* Real or imaginary part is infinite.  */
	__real__ result = HUGE_VAL;
      else
	__real__ result = __nan ("");
    }

  return result;
}
Пример #24
0
__complex__ double
__csinh (__complex__ double x)
{
  __complex__ double retval;
  int negate = signbit (__real__ x);
  int rcls = fpclassify (__real__ x);
  int icls = fpclassify (__imag__ x);

  __real__ x = fabs (__real__ x);

  if (rcls >= FP_ZERO)
    {
      /* Real part is finite.  */
      if (icls >= FP_ZERO)
	{
	  /* Imaginary part is finite.  */
	  double sinh_val = __ieee754_sinh (__real__ x);
	  double cosh_val = __ieee754_cosh (__real__ x);
	  double sinix, cosix;

	  __sincos (__imag__ x, &sinix, &cosix);

	  __real__ retval = sinh_val * cosix;
	  __imag__ retval = cosh_val * sinix;

	  if (negate)
	    __real__ retval = -__real__ retval;
	}
      else
	{
	  if (rcls == FP_ZERO)
	    {
	      /* Real part is 0.0.  */
	      __real__ retval = __copysign (0.0, negate ? -1.0 : 1.0);
	      __imag__ retval = __nan ("") + __nan ("");

#ifdef FE_INVALID
	      if (icls == FP_INFINITE)
		feraiseexcept (FE_INVALID);
#endif
	    }
	  else
	    {
	      __real__ retval = __nan ("");
	      __imag__ retval = __nan ("");

#ifdef FE_INVALID
	      feraiseexcept (FE_INVALID);
#endif
	    }
	}
    }
  else if (rcls == FP_INFINITE)
    {
      /* Real part is infinite.  */
      if (icls == FP_ZERO)
	{
	  /* Imaginary part is 0.0.  */
	  __real__ retval = negate ? -HUGE_VAL : HUGE_VAL;
	  __imag__ retval = __imag__ x;
	}
      else if (icls > FP_ZERO)
	{
	  /* Imaginary part is finite.  */
	  double sinix, cosix;

	  __sincos (__imag__ x, &sinix, &cosix);

	  __real__ retval = __copysign (HUGE_VAL, cosix);
	  __imag__ retval = __copysign (HUGE_VAL, sinix);

	  if (negate)
	    __real__ retval = -__real__ retval;
	}
      else
	{
	  /* The addition raises the invalid exception.  */
	  __real__ retval = HUGE_VAL;
	  __imag__ retval = __nan ("") + __nan ("");

#ifdef FE_INVALID
	  if (icls == FP_INFINITE)
	    feraiseexcept (FE_INVALID);
#endif
	}
    }
  else
    {
      __real__ retval = __nan ("");
      __imag__ retval = __imag__ x == 0.0 ? __imag__ x : __nan ("");
    }

  return retval;
}
Пример #25
0
__complex__ double
__cexp (__complex__ double x)
{
  __complex__ double retval;
  int rcls = fpclassify (__real__ x);
  int icls = fpclassify (__imag__ x);

  if (__builtin_expect (rcls >= FP_ZERO, 1))
    {
      /* Real part is finite.  */
      if (__builtin_expect (icls >= FP_ZERO, 1))
	{
	  /* Imaginary part is finite.  */
	  const int t = (int) ((DBL_MAX_EXP - 1) * M_LN2);
	  double sinix, cosix;

	  if (__builtin_expect (icls != FP_SUBNORMAL, 1))
	    {
	      __sincos (__imag__ x, &sinix, &cosix);
	    }
	  else
	    {
	      sinix = __imag__ x;
	      cosix = 1.0;
	    }

	  if (__real__ x > t)
	    {
	      double exp_t = __ieee754_exp (t);
	      __real__ x -= t;
	      sinix *= exp_t;
	      cosix *= exp_t;
	      if (__real__ x > t)
		{
		  __real__ x -= t;
		  sinix *= exp_t;
		  cosix *= exp_t;
		}
	    }
	  if (__real__ x > t)
	    {
	      /* Overflow (original real part of x > 3t).  */
	      __real__ retval = DBL_MAX * cosix;
	      __imag__ retval = DBL_MAX * sinix;
	    }
	  else
	    {
	      double exp_val = __ieee754_exp (__real__ x);
	      __real__ retval = exp_val * cosix;
	      __imag__ retval = exp_val * sinix;
	    }
	  if (fabs (__real__ retval) < DBL_MIN)
	    {
	      volatile double force_underflow
		= __real__ retval * __real__ retval;
	      (void) force_underflow;
	    }
	  if (fabs (__imag__ retval) < DBL_MIN)
	    {
	      volatile double force_underflow
		= __imag__ retval * __imag__ retval;
	      (void) force_underflow;
	    }
	}
      else
	{
	  /* If the imaginary part is +-inf or NaN and the real part
	     is not +-inf the result is NaN + iNaN.  */
	  __real__ retval = __nan ("");
	  __imag__ retval = __nan ("");

	  feraiseexcept (FE_INVALID);
	}
    }
  else if (__builtin_expect (rcls == FP_INFINITE, 1))
    {
      /* Real part is infinite.  */
      if (__builtin_expect (icls >= FP_ZERO, 1))
	{
	  /* Imaginary part is finite.  */
	  double value = signbit (__real__ x) ? 0.0 : HUGE_VAL;

	  if (icls == FP_ZERO)
	    {
	      /* Imaginary part is 0.0.  */
	      __real__ retval = value;
	      __imag__ retval = __imag__ x;
	    }
	  else
	    {
	      double sinix, cosix;

	      if (__builtin_expect (icls != FP_SUBNORMAL, 1))
		{
		  __sincos (__imag__ x, &sinix, &cosix);
		}
	      else
		{
		  sinix = __imag__ x;
		  cosix = 1.0;
		}

	      __real__ retval = __copysign (value, cosix);
	      __imag__ retval = __copysign (value, sinix);
	    }
	}
      else if (signbit (__real__ x) == 0)
	{
	  __real__ retval = HUGE_VAL;
	  __imag__ retval = __nan ("");

	  if (icls == FP_INFINITE)
	    feraiseexcept (FE_INVALID);
	}
      else
	{
	  __real__ retval = 0.0;
	  __imag__ retval = __copysign (0.0, __imag__ x);
	}
    }
  else
    {
      /* If the real part is NaN the result is NaN + iNaN.  */
      __real__ retval = __nan ("");
      __imag__ retval = __nan ("");

      if (rcls != FP_NAN || icls != FP_NAN)
	feraiseexcept (FE_INVALID);
    }

  return retval;
}
Пример #26
0
__complex__ double
__catanh (__complex__ double x)
{
  __complex__ double res;
  int rcls = fpclassify (__real__ x);
  int icls = fpclassify (__imag__ x);

  if (__glibc_unlikely (rcls <= FP_INFINITE || icls <= FP_INFINITE))
    {
      if (icls == FP_INFINITE)
	{
	  __real__ res = __copysign (0.0, __real__ x);
	  __imag__ res = __copysign (M_PI_2, __imag__ x);
	}
      else if (rcls == FP_INFINITE || rcls == FP_ZERO)
	{
	  __real__ res = __copysign (0.0, __real__ x);
	  if (icls >= FP_ZERO)
	    __imag__ res = __copysign (M_PI_2, __imag__ x);
	  else
	    __imag__ res = __nan ("");
	}
      else
	{
	  __real__ res = __nan ("");
	  __imag__ res = __nan ("");
	}
    }
  else if (__glibc_unlikely (rcls == FP_ZERO && icls == FP_ZERO))
    {
      res = x;
    }
  else
    {
      if (fabs (__real__ x) >= 16.0 / DBL_EPSILON
	  || fabs (__imag__ x) >= 16.0 / DBL_EPSILON)
	{
	  __imag__ res = __copysign (M_PI_2, __imag__ x);
	  if (fabs (__imag__ x) <= 1.0)
	    __real__ res = 1.0 / __real__ x;
	  else if (fabs (__real__ x) <= 1.0)
	    __real__ res = __real__ x / __imag__ x / __imag__ x;
	  else
	    {
	      double h = __ieee754_hypot (__real__ x / 2.0, __imag__ x / 2.0);
	      __real__ res = __real__ x / h / h / 4.0;
	    }
	}
      else
	{
	  if (fabs (__real__ x) == 1.0
	      && fabs (__imag__ x) < DBL_EPSILON * DBL_EPSILON)
	    __real__ res = (__copysign (0.5, __real__ x)
			    * (M_LN2 - __ieee754_log (fabs (__imag__ x))));
	  else
	    {
	      double i2 = 0.0;
	      if (fabs (__imag__ x) >= DBL_EPSILON * DBL_EPSILON)
		i2 = __imag__ x * __imag__ x;

	      double num = 1.0 + __real__ x;
	      num = i2 + num * num;

	      double den = 1.0 - __real__ x;
	      den = i2 + den * den;

	      double f = num / den;
	      if (f < 0.5)
		__real__ res = 0.25 * __ieee754_log (f);
	      else
		{
		  num = 4.0 * __real__ x;
		  __real__ res = 0.25 * __log1p (num / den);
		}
	    }

	  double absx, absy, den;

	  absx = fabs (__real__ x);
	  absy = fabs (__imag__ x);
	  if (absx < absy)
	    {
	      double t = absx;
	      absx = absy;
	      absy = t;
	    }

	  if (absy < DBL_EPSILON / 2.0)
	    {
	      den = (1.0 - absx) * (1.0 + absx);
	      if (den == -0.0)
		den = 0.0;
	    }
	  else if (absx >= 1.0)
	    den = (1.0 - absx) * (1.0 + absx) - absy * absy;
	  else if (absx >= 0.75 || absy >= 0.5)
	    den = -__x2y2m1 (absx, absy);
	  else
	    den = (1.0 - absx) * (1.0 + absx) - absy * absy;

	  __imag__ res = 0.5 * __ieee754_atan2 (2.0 * __imag__ x, den);
	}

      math_check_force_underflow_complex (res);
    }

  return res;
}
Пример #27
0
Файл: s_cexp.c Проект: dreal/tai
__complex__ double
__cexp (__complex__ double x)
{
  __complex__ double retval;
  int rcls = fpclassify (__real__ x);
  int icls = fpclassify (__imag__ x);

  if (__builtin_expect (rcls >= FP_ZERO, 1))
    {
      /* Real part is finite.  */
      if (__builtin_expect (icls >= FP_ZERO, 1))
	{
	  /* Imaginary part is finite.  */
	  double exp_val = __ieee754_exp (__real__ x);
	  double sinix, cosix;

	  __sincos (__imag__ x, &sinix, &cosix);

	  if (isfinite (exp_val))
	    {
	      __real__ retval = exp_val * cosix;
	      __imag__ retval = exp_val * sinix;
	    }
	  else
	    {
	      __real__ retval = __copysign (exp_val, cosix);
	      __imag__ retval = __copysign (exp_val, sinix);
	    }
	}
      else
	{
	  /* If the imaginary part is +-inf or NaN and the real part
	     is not +-inf the result is NaN + iNaN.  */
	  __real__ retval = __nan ("");
	  __imag__ retval = __nan ("");

	  feraiseexcept (FE_INVALID);
	}
    }
  else if (__builtin_expect (rcls == FP_INFINITE, 1))
    {
      /* Real part is infinite.  */
      if (__builtin_expect (icls >= FP_ZERO, 1))
	{
	  /* Imaginary part is finite.  */
	  double value = signbit (__real__ x) ? 0.0 : HUGE_VAL;

	  if (icls == FP_ZERO)
	    {
	      /* Imaginary part is 0.0.  */
	      __real__ retval = value;
	      __imag__ retval = __imag__ x;
	    }
	  else
	    {
	      double sinix, cosix;

	      __sincos (__imag__ x, &sinix, &cosix);

	      __real__ retval = __copysign (value, cosix);
	      __imag__ retval = __copysign (value, sinix);
	    }
	}
      else if (signbit (__real__ x) == 0)
	{
	  __real__ retval = HUGE_VAL;
	  __imag__ retval = __nan ("");

	  if (icls == FP_INFINITE)
	    feraiseexcept (FE_INVALID);
	}
      else
	{
	  __real__ retval = 0.0;
	  __imag__ retval = __copysign (0.0, __imag__ x);
	}
    }
  else
    {
      /* If the real part is NaN the result is NaN + iNaN.  */
      __real__ retval = __nan ("");
      __imag__ retval = __nan ("");

      if (rcls != FP_NAN || icls != FP_NAN)
	feraiseexcept (FE_INVALID);
    }

  return retval;
}
Пример #28
0
__complex__ double
__csqrt (__complex__ double x)
{
  __complex__ double res;
  int rcls = fpclassify (__real__ x);
  int icls = fpclassify (__imag__ x);

  if (__builtin_expect (rcls <= FP_INFINITE || icls <= FP_INFINITE, 0))
    {
      if (icls == FP_INFINITE)
	{
	  __real__ res = HUGE_VAL;
	  __imag__ res = __imag__ x;
	}
      else if (rcls == FP_INFINITE)
	{
	  if (__real__ x < 0.0)
	    {
	      __real__ res = icls == FP_NAN ? __nan ("") : 0;
	      __imag__ res = __copysign (HUGE_VAL, __imag__ x);
	    }
	  else
	    {
	      __real__ res = __real__ x;
	      __imag__ res = (icls == FP_NAN
			      ? __nan ("") : __copysign (0.0, __imag__ x));
	    }
	}
      else
	{
	  __real__ res = __nan ("");
	  __imag__ res = __nan ("");
	}
    }
  else
    {
      if (__builtin_expect (icls == FP_ZERO, 0))
	{
	  if (__real__ x < 0.0)
	    {
	      __real__ res = 0.0;
	      __imag__ res = __copysign (__ieee754_sqrt (-__real__ x),
					 __imag__ x);
	    }
	  else
	    {
	      __real__ res = fabs (__ieee754_sqrt (__real__ x));
	      __imag__ res = __copysign (0.0, __imag__ x);
	    }
	}
      else if (__builtin_expect (rcls == FP_ZERO, 0))
	{
	  double r;
	  if (fabs (__imag__ x) >= 2.0 * DBL_MIN)
	    r = __ieee754_sqrt (0.5 * fabs (__imag__ x));
	  else
	    r = 0.5 * __ieee754_sqrt (2.0 * fabs (__imag__ x));

	  __real__ res = r;
	  __imag__ res = __copysign (r, __imag__ x);
	}
      else
	{
	  double d, r, s;
	  int scale = 0;

	  if (fabs (__real__ x) > DBL_MAX / 4.0)
	    {
	      scale = 1;
	      __real__ x = __scalbn (__real__ x, -2 * scale);
	      __imag__ x = __scalbn (__imag__ x, -2 * scale);
	    }
	  else if (fabs (__imag__ x) > DBL_MAX / 4.0)
	    {
	      scale = 1;
	      if (fabs (__real__ x) >= 4.0 * DBL_MIN)
		__real__ x = __scalbn (__real__ x, -2 * scale);
	      else
		__real__ x = 0.0;
	      __imag__ x = __scalbn (__imag__ x, -2 * scale);
	    }
	  else if (fabs (__real__ x) < DBL_MIN
		   && fabs (__imag__ x) < DBL_MIN)
	    {
	      scale = -(DBL_MANT_DIG / 2);
	      __real__ x = __scalbn (__real__ x, -2 * scale);
	      __imag__ x = __scalbn (__imag__ x, -2 * scale);
	    }

	  d = __ieee754_hypot (__real__ x, __imag__ x);
	  /* Use the identity   2  Re res  Im res = Im x
	     to avoid cancellation error in  d +/- Re x.  */
	  if (__real__ x > 0)
	    {
	      r = __ieee754_sqrt (0.5 * (d + __real__ x));
	      s = 0.5 * (__imag__ x / r);
	    }
	  else
	    {
	      s = __ieee754_sqrt (0.5 * (d - __real__ x));
	      r = fabs (0.5 * (__imag__ x / s));
	    }

	  if (scale)
	    {
	      r = __scalbn (r, scale);
	      s = __scalbn (s, scale);
	    }

	  __real__ res = r;
	  __imag__ res = __copysign (s, __imag__ x);
	}
    }

  return res;
}
Пример #29
0
__complex__ double
__ccosh (__complex__ double x)
{
  __complex__ double retval;
  int rcls = fpclassify (__real__ x);
  int icls = fpclassify (__imag__ x);

  if (__builtin_expect (rcls >= FP_ZERO, 1))
    {
      /* Real part is finite.  */
      if (__builtin_expect (icls >= FP_ZERO, 1))
	{
	  /* Imaginary part is finite.  */
	  const int t = (int) ((DBL_MAX_EXP - 1) * M_LN2);
	  double sinix, cosix;

	  if (__builtin_expect (icls != FP_SUBNORMAL, 1))
	    {
	      __sincos (__imag__ x, &sinix, &cosix);
	    }
	  else
	    {
	      sinix = __imag__ x;
	      cosix = 1.0;
	    }

	  if (fabs (__real__ x) > t)
	    {
	      double exp_t = __ieee754_exp (t);
	      double rx = fabs (__real__ x);
	      if (signbit (__real__ x))
		sinix = -sinix;
	      rx -= t;
	      sinix *= exp_t / 2.0;
	      cosix *= exp_t / 2.0;
	      if (rx > t)
		{
		  rx -= t;
		  sinix *= exp_t;
		  cosix *= exp_t;
		}
	      if (rx > t)
		{
		  /* Overflow (original real part of x > 3t).  */
		  __real__ retval = DBL_MAX * cosix;
		  __imag__ retval = DBL_MAX * sinix;
		}
	      else
		{
		  double exp_val = __ieee754_exp (rx);
		  __real__ retval = exp_val * cosix;
		  __imag__ retval = exp_val * sinix;
		}
	    }
	  else
	    {
	      __real__ retval = __ieee754_cosh (__real__ x) * cosix;
	      __imag__ retval = __ieee754_sinh (__real__ x) * sinix;
	    }

	  if (fabs (__real__ retval) < DBL_MIN)
	    {
	      volatile double force_underflow
		= __real__ retval * __real__ retval;
	      (void) force_underflow;
	    }
	  if (fabs (__imag__ retval) < DBL_MIN)
	    {
	      volatile double force_underflow
		= __imag__ retval * __imag__ retval;
	      (void) force_underflow;
	    }
	}
      else
	{
	  __imag__ retval = __real__ x == 0.0 ? 0.0 : __nan ("");
	  __real__ retval = __nan ("") + __nan ("");

	  if (icls == FP_INFINITE)
	    feraiseexcept (FE_INVALID);
	}
    }
  else if (rcls == FP_INFINITE)
    {
      /* Real part is infinite.  */
      if (__builtin_expect (icls > FP_ZERO, 1))
	{
	  /* Imaginary part is finite.  */
	  double sinix, cosix;

	  if (__builtin_expect (icls != FP_SUBNORMAL, 1))
	    {
	      __sincos (__imag__ x, &sinix, &cosix);
	    }
	  else
	    {
	      sinix = __imag__ x;
	      cosix = 1.0;
	    }

	  __real__ retval = __copysign (HUGE_VAL, cosix);
	  __imag__ retval = (__copysign (HUGE_VAL, sinix)
			     * __copysign (1.0, __real__ x));
	}
      else if (icls == FP_ZERO)
	{
	  /* Imaginary part is 0.0.  */
	  __real__ retval = HUGE_VAL;
	  __imag__ retval = __imag__ x * __copysign (1.0, __real__ x);
	}
      else
	{
	  /* The addition raises the invalid exception.  */
	  __real__ retval = HUGE_VAL;
	  __imag__ retval = __nan ("") + __nan ("");

	  if (icls == FP_INFINITE)
	    feraiseexcept (FE_INVALID);
	}
    }
  else
    {
      __real__ retval = __nan ("");
      __imag__ retval = __imag__ x == 0.0 ? __imag__ x : __nan ("");
    }

  return retval;
}
Пример #30
0
__complex__ double
__cacosh (__complex__ double x)
{
  __complex__ double res;
  int rcls = fpclassify (__real__ x);
  int icls = fpclassify (__imag__ x);

  if (rcls <= FP_INFINITE || icls <= FP_INFINITE)
    {
      if (icls == FP_INFINITE)
	{
	  __real__ res = HUGE_VAL;

	  if (rcls == FP_NAN)
	    __imag__ res = __nan ("");
	  else
	    __imag__ res = __copysign ((rcls == FP_INFINITE
					? (__real__ x < 0.0
					   ? M_PI - M_PI_4 : M_PI_4)
					: M_PI_2), __imag__ x);
	}
      else if (rcls == FP_INFINITE)
	{
	  __real__ res = HUGE_VAL;

	  if (icls >= FP_ZERO)
	    __imag__ res = __copysign (signbit (__real__ x) ? M_PI : 0.0,
				       __imag__ x);
	  else
	    __imag__ res = __nan ("");
	}
      else
	{
	  __real__ res = __nan ("");
	  __imag__ res = __nan ("");
	}
    }
  else if (rcls == FP_ZERO && icls == FP_ZERO)
    {
      __real__ res = 0.0;
      __imag__ res = __copysign (M_PI_2, __imag__ x);
    }
  else
    {
      __complex__ double y;

      __real__ y = -__imag__ x;
      __imag__ y = __real__ x;

      y = __kernel_casinh (y, 1);

      if (signbit (__imag__ x))
	{
	  __real__ res = __real__ y;
	  __imag__ res = -__imag__ y;
	}
      else
	{
	  __real__ res = -__real__ y;
	  __imag__ res = __imag__ y;
	}
    }

  return res;
}