コード例 #1
0
ファイル: w_scalbl.c プロジェクト: AubrCool/glibc
/* Wrapper scalbl */
long double
__scalbl (long double x, long double fn)
{
  if (__glibc_unlikely (_LIB_VERSION == _SVID_))
    return sysv_scalbl (x, fn);
  else
    {
      long double z = __ieee754_scalbl (x, fn);

      if (__glibc_unlikely (!__finitel (z) || z == 0.0L))
	{
	  if (__isnanl (z))
	    {
	      if (!__isnanl (x) && !__isnanl (fn))
		__set_errno (EDOM);
	    }
	  else if (__isinf_nsl (z))
	    {
	      if (!__isinf_nsl (x) && !__isinf_nsl (fn))
		__set_errno (ERANGE);
	    }
	  else
	    {
	      /* z == 0.  */
	      if (x != 0.0L && !__isinf_nsl (fn))
		__set_errno (ERANGE);
	    }
	}
      return z;
    }
}
コード例 #2
0
ファイル: s_cprojl.c プロジェクト: Drakey83/steamlink-sdk
__complex__ long double
__cprojl (__complex__ long double x)
{
  if (__isinf_nsl (__real__ x) || __isinf_nsl (__imag__ x))
    {
      __complex__ long double res;

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

      return res;
    }

  return x;
}
コード例 #3
0
ファイル: divtc3.c プロジェクト: Drakey83/steamlink-sdk
attribute_hidden
long double _Complex
__divtc3 (long double a, long double b, long double c, long double d)
{
  long double denom, ratio, x, y;

  /* ??? We can get better behavior from logarithmic scaling instead of
     the division.  But that would mean starting to link libgcc against
     libm.  We could implement something akin to ldexp/frexp as gcc builtins
     fairly easily...  */
  if (fabsl (c) < fabsl (d))
    {
      ratio = c / d;
      denom = (c * ratio) + d;
      x = ((a * ratio) + b) / denom;
      y = ((b * ratio) - a) / denom;
    }
  else
    {
      ratio = d / c;
      denom = (d * ratio) + c;
      x = ((b * ratio) + a) / denom;
      y = (b - (a * ratio)) / denom;
    }

  /* Recover infinities and zeros that computed as NaN+iNaN; the only cases
     are nonzero/zero, infinite/finite, and finite/infinite.  */
  if (isnan (x) && isnan (y))
    {
      if (denom == 0.0 && (!isnan (a) || !isnan (b)))
	{
	  x = __copysignl (INFINITY, c) * a;
	  y = __copysignl (INFINITY, c) * b;
	}
      else if ((__isinf_nsl (a) || __isinf_nsl (b))
	       && isfinite (c) && isfinite (d))
	{
	  a = __copysignl (__isinf_nsl (a) ? 1 : 0, a);
	  b = __copysignl (__isinf_nsl (b) ? 1 : 0, b);
	  x = INFINITY * (a * c + b * d);
	  y = INFINITY * (b * c - a * d);
	}
      else if ((__isinf_nsl (c) || __isinf_nsl (d))
	       && isfinite (a) && isfinite (b))
	{
	  c = __copysignl (__isinf_nsl (c) ? 1 : 0, c);
	  d = __copysignl (__isinf_nsl (d) ? 1 : 0, d);
	  x = 0.0 * (a * c + b * d);
	  y = 0.0 * (b * c - a * d);
	}
    }

  return x + I * y;
}
コード例 #4
0
ファイル: w_remainderl.c プロジェクト: dreal/tai
/* wrapper remainderl */
long double
__remainderl (long double x, long double y)
{
  if (((__builtin_expect (y == 0.0L, 0) && ! __isnanl (x))
       || (__builtin_expect (__isinf_nsl (x), 0) && ! __isnanl (y)))
      && _LIB_VERSION != _IEEE_)
    return __kernel_standard (x, y, 228); /* remainder domain */

  return __ieee754_remainderl (x, y);
}
コード例 #5
0
ファイル: w_fmodl.c プロジェクト: KubaKaszycki/kklibc
/* wrapper fmodl */
long double
__fmodl (long double x, long double y)
{
  if (__builtin_expect (__isinf_nsl (x) || y == 0.0L, 0)
      && _LIB_VERSION != _IEEE_ && !isnan (y) && !isnan (x))
    /* fmod(+-Inf,y) or fmod(x,0) */
    return __kernel_standard_l (x, y, 227);

  return __ieee754_fmodl (x, y);
}
コード例 #6
0
ファイル: s_casinl.c プロジェクト: Xilinx/eglibc
__complex__ long double
__casinl (__complex__ long double x)
{
  __complex__ long double res;

  if (isnan (__real__ x) || isnan (__imag__ x))
    {
      if (__real__ x == 0.0)
	{
	  res = x;
	}
      else if (__isinf_nsl (__real__ x) || __isinf_nsl (__imag__ x))
	{
	  __real__ res = __nanl ("");
	  __imag__ res = __copysignl (HUGE_VALL, __imag__ x);
	}
      else
	{
	  __real__ res = __nanl ("");
	  __imag__ res = __nanl ("");
	}
    }
  else
    {
      __complex__ long double y;

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

      y = __casinhl (y);

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

  return res;
}
コード例 #7
0
ファイル: s_ctanl.c プロジェクト: wilseypa/llamaOS
__complex__ long double
__ctanl (__complex__ long double x)
{
  __complex__ long double res;

  if (__builtin_expect (!isfinite (__real__ x) || !isfinite (__imag__ x), 0))
    {
      if (__isinf_nsl (__imag__ x))
	{
	  __real__ res = __copysignl (0.0, __real__ x);
	  __imag__ res = __copysignl (1.0, __imag__ x);
	}
      else if (__real__ x == 0.0)
	{
	  res = x;
	}
      else
	{
	  __real__ res = __nanl ("");
	  __imag__ res = __nanl ("");

	  if (__isinf_nsl (__real__ x))
	    feraiseexcept (FE_INVALID);
	}
    }
  else
    {
      long double sinrx, cosrx;
      long double den;
      const int t = (int) ((LDBL_MAX_EXP - 1) * M_LN2l / 2);
      int rcls = fpclassify (__real__ x);

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

      if (__builtin_expect (rcls != FP_SUBNORMAL, 1))
	{
	  __sincosl (__real__ x, &sinrx, &cosrx);
	}
      else
	{
	  sinrx = __real__ x;
	  cosrx = 1.0;
	}

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

	  __imag__ res = __copysignl (1.0, __imag__ x);
	  __real__ res = 4 * sinrx * cosrx;
	  __imag__ x = fabsl (__imag__ x);
	  __imag__ x -= t;
	  __real__ res /= exp_2t;
	  if (__imag__ x > t)
	    {
	      /* Underflow (original imaginary part of x has absolute
		 value > 2t).  */
	      __real__ res /= exp_2t;
	    }
	  else
	    __real__ res /= __ieee754_expl (2 * __imag__ x);
	}
      else
	{
	  long double sinhix, coshix;
	  if (fabsl (__imag__ x) > LDBL_MIN)
	    {
	      sinhix = __ieee754_sinhl (__imag__ x);
	      coshix = __ieee754_coshl (__imag__ x);
	    }
	  else
	    {
	      sinhix = __imag__ x;
	      coshix = 1.0L;
	    }

	  if (fabsl (sinhix) > fabsl (cosrx) * LDBL_EPSILON)
	    den = cosrx * cosrx + sinhix * sinhix;
	  else
	    den = cosrx * cosrx;
	  __real__ res = sinrx * cosrx / den;
	  __imag__ res = sinhix * coshix / den;
	}
    }

  return res;
}
コード例 #8
0
ファイル: s_ctanl.c プロジェクト: Drakey83/steamlink-sdk
__complex__ long double
__ctanl (__complex__ long double x)
{
  __complex__ long double res;

  if (!isfinite (__real__ x) || !isfinite (__imag__ x))
    {
      if (__isinfl (__imag__ x))
	{
	  __real__ res = __copysignl (0.0, __real__ x);
	  __imag__ res = __copysignl (1.0, __imag__ x);
	}
      else if (__real__ x == 0.0)
	{
	  res = x;
	}
      else
	{
	  __real__ res = __nanl ("");
	  __imag__ res = __nanl ("");

	  if (__isinf_nsl (__real__ x))
	    feraiseexcept (FE_INVALID);
	}
    }
  else
    {
      long double sinrx, cosrx;
      long double den;
      const int t = (int) ((LDBL_MAX_EXP - 1) * M_LN2l / 2.0L);

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

      __sincosl (__real__ x, &sinrx, &cosrx);

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

	  __imag__ res = __copysignl (1.0L, __imag__ x);
	  __real__ res = 4 * sinrx * cosrx;
	  __imag__ x = fabsl (__imag__ x);
	  __imag__ x -= t;
	  __real__ res /= exp_2t;
	  if (__imag__ x > t)
	    {
	      /* Underflow (original imaginary part of x has absolute
		 value > 2t).  */
	      __real__ res /= exp_2t;
	    }
	  else
	    __real__ res /= __ieee754_expl (2.0L * __imag__ x);
	}
      else
	{
	  long double sinhix, coshix;
	  if (fabsl (__imag__ x) > LDBL_MIN)
	    {
	      sinhix = __ieee754_sinhl (__imag__ x);
	      coshix = __ieee754_coshl (__imag__ x);
	    }
	  else
	    {
	      sinhix = __imag__ x;
	      coshix = 1.0L;
	    }

	  if (fabsl (sinhix) > fabsl (cosrx) * ldbl_eps)
	    den = cosrx * cosrx + sinhix * sinhix;
	  else
	    den = cosrx * cosrx;
	  __real__ res = sinrx * (cosrx / den);
	  __imag__ res = sinhix * (coshix / den);
	}

      /* __gcc_qmul does not respect -0.0 so we need the following fixup.  */
      if ((__real__ res == 0.0L) && (__real__ x == 0.0L))
        __real__ res = __real__ x;

      if ((__real__ res == 0.0L) && (__imag__ x == 0.0L))
        __imag__ res = __imag__ x;
    }

  return res;
}
コード例 #9
0
ファイル: multc3.c プロジェクト: AubrCool/glibc
attribute_hidden
long double _Complex
__multc3 (long double a, long double b, long double c, long double d)
{
  long double ac, bd, ad, bc, x, y;

  ac = a * c;
  bd = b * d;
  ad = a * d;
  bc = b * c;

  x = ac - bd;
  y = ad + bc;

  if (isnan (x) && isnan (y))
    {
      /* Recover infinities that computed as NaN + iNaN.  */
      bool recalc = 0;
      if (__isinf_nsl (a) || __isinf_nsl (b))
	{
	  /* z is infinite.  "Box" the infinity and change NaNs in
	     the other factor to 0.  */
	  a = __copysignl (__isinf_nsl (a) ? 1 : 0, a);
	  b = __copysignl (__isinf_nsl (b) ? 1 : 0, b);
	  if (isnan (c)) c = __copysignl (0, c);
	  if (isnan (d)) d = __copysignl (0, d);
	  recalc = 1;
	}
     if (__isinf_nsl (c) || __isinf_nsl (d))
	{
	  /* w is infinite.  "Box" the infinity and change NaNs in
	     the other factor to 0.  */
	  c = __copysignl (__isinf_nsl (c) ? 1 : 0, c);
	  d = __copysignl (__isinf_nsl (d) ? 1 : 0, d);
	  if (isnan (a)) a = __copysignl (0, a);
	  if (isnan (b)) b = __copysignl (0, b);
	  recalc = 1;
	}
     if (!recalc
	  && (__isinf_nsl (ac) || __isinf_nsl (bd)
	      || __isinf_nsl (ad) || __isinf_nsl (bc)))
	{
	  /* Recover infinities from overflow by changing NaNs to 0.  */
	  if (isnan (a)) a = __copysignl (0, a);
	  if (isnan (b)) b = __copysignl (0, b);
	  if (isnan (c)) c = __copysignl (0, c);
	  if (isnan (d)) d = __copysignl (0, d);
	  recalc = 1;
	}
      if (recalc)
	{
	  x = INFINITY * (a * c - b * d);
	  y = INFINITY * (a * d + b * c);
	}
    }

  return x + I * y;
}