示例#1
0
文件: s_clog10.c 项目: dreal/tai
__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;
}
示例#2
0
文件: s_clog.c 项目: AdvancedC/glibc
__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;
}
示例#3
0
文件: s_ctanh.c 项目: dreal/tai
__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
__complex__ double
__ccos (__complex__ double x)
{
  __complex__ double res;

  if (!isfinite (__real__ x) || __isnan (__imag__ x))
    {
      if (__real__ x == 0.0 || __imag__ x == 0.0)
	{
	  __real__ res = __nan ("");
	  __imag__ res = 0.0;

#ifdef FE_INVALID
	  if (__isinf (__real__ x))
	    feraiseexcept (FE_INVALID);
#endif
	}
      else if (__isinf (__imag__ x))
	{
	  __real__ res = HUGE_VAL;
	  __imag__ res = __nan ("");

#ifdef FE_INVALID
	  if (__isinf (__real__ x))
	    feraiseexcept (FE_INVALID);
#endif
	}
      else
	{
	  __real__ res = __nan ("");
	  __imag__ res = __nan ("");

#ifdef FE_INVALID
	  if (isfinite (__imag__ x))
	    feraiseexcept (FE_INVALID);
#endif
	}
    }
  else
    {
      __complex__ double y;

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

      res = __ccosh (y);
    }

  return res;
}
示例#5
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;
}
示例#6
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;
}
示例#7
0
invalid_fn (long double x, long double fn)
{
  if (__rintl (fn) != fn)
    {
      feraiseexcept (FE_INVALID);
      return __nan ("");
    }
  else if (fn > 65000.0L)
    return __scalbnl (x, 65000);
  else
    return __scalbnl (x,-65000);
}
示例#8
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;
}
示例#9
0
文件: math.c 项目: can-vas/nikkishore
//
// atanh
//
double atanh(double x)
{
   if(fabs(x) >= 1) {errno = EDOM; return __nan();}

   return log((1 + x) / (1 - x)) >> 1;
}
示例#10
0
文件: s_cacosh.c 项目: gapry/pemu
__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;
}
示例#11
0
文件: s_cexp.c 项目: Xilinx/eglibc
__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;
}
示例#12
0
文件: s_csin.c 项目: AubrCool/glibc
__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;
}
示例#13
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;
}
示例#14
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;
}
示例#15
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;
}
示例#16
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;
}
示例#17
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;
}
示例#18
0
// ---------------------------------------------------------------------------
// 
// ------------
double bSubStyle::getclassbound(int idx){
double	v=__nan();
	_valbounds.get(idx,&v);
	return(v);
}
示例#19
0
文件: math.c 项目: can-vas/nikkishore
//
// nan
//
double nan(char const *tagp)
{
   return __nan();
}
示例#20
0
文件: math.c 项目: can-vas/nikkishore
//
// acosh
//
double acosh(double x)
{
   if(x < 1) {errno = EDOM; return __nan();}

   return log(x + sqrt(x * x - 1));
}
示例#21
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;
}
示例#22
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;
}
示例#23
0
文件: s_ccosh.c 项目: Xilinx/eglibc
__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;
}
示例#24
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;
}