Exemplo n.º 1
0
__float128
sinhq (__float128 x)
{
  __float128 t, w, h;
  uint32_t jx, ix;
  ieee854_float128 u;

  /* Words of |x|. */
  u.value = x;
  jx = u.words32.w0;
  ix = jx & 0x7fffffff;

  /* x is INF or NaN */
  if (ix >= 0x7fff0000)
    return x + x;

  h = 0.5Q;
  if (jx & 0x80000000)
    h = -h;

  /* Absolute value of x.  */
  u.words32.w0 = ix;

  /* |x| in [0,40], return sign(x)*0.5*(E+E/(E+1))) */
  if (ix <= 0x40044000)
    {
      if (ix < 0x3fc60000) /* |x| < 2^-57 */
	{
	  math_check_force_underflow (x);
	  if (shuge + x > one)
	    return x;		/* sinh(tiny) = tiny with inexact */
	}
      t = expm1q (u.value);
      if (ix < 0x3fff0000)
	return h * (2.0Q * t - t * t / (t + one));
      return h * (t + t / (t + one));
    }

  /* |x| in [40, log(maxdouble)] return 0.5*exp(|x|) */
  if (ix <= 0x400c62e3) /* 11356.375 */
    return h * expq (u.value);

  /* |x| in [log(maxdouble), overflowthreshold]
     Overflow threshold is log(2 * maxdouble).  */
  if (u.value <= ovf_thresh)
    {
      w = expq (0.5Q * u.value);
      t = h * w;
      return t * w;
    }

  /* |x| > overflowthreshold, sinhq(x) overflow */
  return x * shuge;
}
Exemplo n.º 2
0
Arquivo: coshq.c Projeto: 0day-ci/gcc
__float128
coshq (__float128 x)
{
  __float128 t, w;
  int32_t ex;
  ieee854_float128 u;

  u.value = x;
  ex = u.words32.w0 & 0x7fffffff;

  /* Absolute value of x.  */
  u.words32.w0 = ex;

  /* x is INF or NaN */
  if (ex >= 0x7fff0000)
    return x * x;

  /* |x| in [0,0.5*ln2], return 1+expm1l(|x|)^2/(2*expq(|x|)) */
  if (ex < 0x3ffd62e4) /* 0.3465728759765625 */
    {
      t = expm1q (u.value);
      w = one + t;
      if (ex < 0x3fb80000) /* |x| < 2^-116 */
	return w;		/* cosh(tiny) = 1 */

      return one + (t * t) / (w + w);
    }

  /* |x| in [0.5*ln2,40], return (exp(|x|)+1/exp(|x|)/2; */
  if (ex < 0x40044000)
    {
      t = expq (u.value);
      return half * t + half / t;
    }

  /* |x| in [22, ln(maxdouble)] return half*exp(|x|) */
  if (ex <= 0x400c62e3) /* 11356.375 */
    return half * expq (u.value);

  /* |x| in [log(maxdouble), overflowthresold] */
  if (u.value <= ovf_thresh)
    {
      w = expq (half * u.value);
      t = half * w;
      return t * w;
    }

  /* |x| > overflowthresold, cosh(x) overflow */
  return huge * huge;
}
Exemplo n.º 3
0
int main()
{
    __float128 f = -2.0Q;
    f = fabsq(f);
    f = expq(f);

    return 0;
}
Exemplo n.º 4
0
__complex128
cexpq (__complex128 z)
{
  __float128 a, b;
  __complex128 v;

  a = REALPART (z);
  b = IMAGPART (z);
  COMPLEX_ASSIGN (v, cosq (b), sinq (b));
  return expq (a) * v;
}
Exemplo n.º 5
0
GFC_REAL_16
erfc_scaled_r16 (GFC_REAL_16 x)
{
  if (x < -106.566990228185312813205074546585730Q)
    {
      return __builtin_infq();
    }
  if (x < 12)
    {
      /* Compute directly as ERFC_SCALED(x) = ERFC(x) * EXP(X**2).
	 This is not perfect, but much better than netlib.  */
      return erfcq(x) * expq(x * x);
    }
  else
    {
      /* Calculate ERFC_SCALED(x) using a power series in 1/x:
	 ERFC_SCALED(x) = 1 / (x * sqrt(pi))
			 * (1 + Sum_n (-1)**n * (1 * 3 * 5 * ... * (2n-1))
					      / (2 * x**2)**n)
       */
      GFC_REAL_16 sum = 0, oldsum;
      GFC_REAL_16 inv2x2 = 1 / (2 * x * x);
      GFC_REAL_16 fac = 1;
      int n = 1;

      while (n < 200)
	{
	  fac *= - (2*n - 1) * inv2x2;
	  oldsum = sum;
	  sum += fac;

	  if (sum == oldsum)
	    break;

	  n++;
	}

      return (1 + sum) / x * (M_2_SQRTPIq / 2);
    }
}
Exemplo n.º 6
0
inline void eval_exp(float128_backend& result, const float128_backend& arg)
{
   result.value() = expq(arg.value());
}
Exemplo n.º 7
0
__float128 weight(__float128 t) {
    if(t<=0.Q || t>=1.Q) {
        return 0.Q;
    }
    return expq((1.Q)/(t*(t-1.Q)));
}
Exemplo n.º 8
0
Arquivo: expm1q.c Projeto: 0day-ci/gcc
__float128
expm1q (__float128 x)
{
  __float128 px, qx, xx;
  int32_t ix, sign;
  ieee854_float128 u;
  int k;

  /* Detect infinity and NaN.  */
  u.value = x;
  ix = u.words32.w0;
  sign = ix & 0x80000000;
  ix &= 0x7fffffff;
  if (!sign && ix >= 0x40060000)
    {
      /* If num is positive and exp >= 6 use plain exp.  */
      return expq (x);
    }
  if (ix >= 0x7fff0000)
    {
      /* Infinity. */
      if (((ix & 0xffff) | u.words32.w1 | u.words32.w2 | u.words32.w3) == 0)
	{
	  if (sign)
	    return -1.0Q;
	  else
	    return x;
	}
      /* NaN. No invalid exception. */
      return x;
    }

  /* expm1(+- 0) = +- 0.  */
  if ((ix == 0) && (u.words32.w1 | u.words32.w2 | u.words32.w3) == 0)
    return x;

  /* Overflow.  */
  if (x > maxlog)
    {
      errno = ERANGE;
      return (HUGE_VALQ * HUGE_VALQ);
    }

  /* Minimum value.  */
  if (x < minarg)
    return (4.0/HUGE_VALQ - 1.0Q);

  /* Express x = ln 2 (k + remainder), remainder not exceeding 1/2. */
  xx = C1 + C2;			/* ln 2. */
  px = floorq (0.5 + x / xx);
  k = px;
  /* remainder times ln 2 */
  x -= px * C1;
  x -= px * C2;

  /* Approximate exp(remainder ln 2).  */
  px = (((((((P7 * x
	      + P6) * x
	     + P5) * x + P4) * x + P3) * x + P2) * x + P1) * x + P0) * x;

  qx = (((((((x
	      + Q7) * x
	     + Q6) * x + Q5) * x + Q4) * x + Q3) * x + Q2) * x + Q1) * x + Q0;

  xx = x * x;
  qx = x + (0.5 * xx + xx * px / qx);

  /* exp(x) = exp(k ln 2) exp(remainder ln 2) = 2^k exp(remainder ln 2).

  We have qx = exp(remainder ln 2) - 1, so
  exp(x) - 1 = 2^k (qx + 1) - 1
             = 2^k qx + 2^k - 1.  */

  px = ldexpq (1.0Q, k);
  x = px * qx + (px - 1.0);
  return x;
}
Exemplo n.º 9
0
double weight(double t) {
    if(t<=0 || t>=1) { return 0; }
    return expq((1)/(t*(t-1)));
    //return t*(1-t);
}
Exemplo n.º 10
0
Arquivo: ctanhq.c Projeto: 0day-ci/gcc
__complex128
ctanhq (__complex128 x)
{
  __complex128 res;

  if (__builtin_expect (!finiteq (__real__ x) || !finiteq (__imag__ x), 0))
    {
      if (__quadmath_isinf_nsq (__real__ x))
	{
	  __real__ res = copysignq (1.0Q, __real__ x);
	  __imag__ res = copysignq (0.0Q, __imag__ x);
	}
      else if (__imag__ x == 0.0Q)
	{
	  res = x;
	}
      else
	{
	  __real__ res = nanq ("");
	  __imag__ res = nanq ("");

#ifdef HAVE_FENV_H
	  if (__quadmath_isinf_nsq (__imag__ x))
	    feraiseexcept (FE_INVALID);
#endif
	}
    }
  else
    {
      __float128 sinix, cosix;
      __float128 den;
      const int t = (int) ((FLT128_MAX_EXP - 1) * M_LN2q / 2);
      int icls = fpclassifyq (__imag__ x);

      /* 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 (__builtin_expect (icls != QUADFP_SUBNORMAL, 1))
	{
	  sincosq (__imag__ x, &sinix, &cosix);
	}
      else
	{
	  sinix = __imag__ x;
	  cosix = 1.0Q;
	}

      if (fabsq (__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).  */
	  __float128 exp_2t = expq (2 * t);

	  __real__ res = copysignq (1.0, __real__ x);
	  __imag__ res = 4 * sinix * cosix;
	  __real__ x = fabsq (__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 /= expq (2 * __real__ x);
	}
      else
	{
	  __float128 sinhrx, coshrx;
	  if (fabsq (__real__ x) > FLT128_MIN)
	    {
	      sinhrx = sinhq (__real__ x);
	      coshrx = coshq (__real__ x);
	    }
	  else
	    {
	      sinhrx = __real__ x;
	      coshrx = 1.0Q;
	    }

	  if (fabsq (sinhrx) > fabsq (cosix) * FLT128_EPSILON)
	    den = sinhrx * sinhrx + cosix * cosix;
	  else
	    den = cosix * cosix;
	  __real__ res = sinhrx * coshrx / den;
	  __imag__ res = sinix * cosix / den;
	}
    }

  return res;
}