Exemplo n.º 1
0
/* wrapper fmodl */
long double
__fmodl (long double x, long double y)
{
  if (__builtin_expect (isinf (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);
}
Exemplo n.º 2
0
long double
__ieee754_remainderl(long double x, long double p)
{
	int64_t hx,hp;
	u_int64_t sx,lx,lp;
	long double p_half;
	double xhi, xlo, phi, plo;

	ldbl_unpack (x, &xhi, &xlo);
	EXTRACT_WORDS64 (hx, xhi);
	EXTRACT_WORDS64 (lx, xlo);
	ldbl_unpack (p, &phi, &plo);
	EXTRACT_WORDS64 (hp, phi);
	EXTRACT_WORDS64 (lp, plo);
	sx = hx&0x8000000000000000ULL;
	lp ^= hp & 0x8000000000000000ULL;
	hp &= 0x7fffffffffffffffLL;
	lx ^= sx;
	hx &= 0x7fffffffffffffffLL;
	if (lp == 0x8000000000000000ULL)
	  lp = 0;
	if (lx == 0x8000000000000000ULL)
	  lx = 0;

    /* purge off exception values */
	if(hp==0) return (x*p)/(x*p);	/* p = 0 */
	if((hx>=0x7ff0000000000000LL)||			/* x not finite */
	   (hp>0x7ff0000000000000LL))			/* p is NaN */
	    return (x*p)/(x*p);


	if (hp<=0x7fdfffffffffffffLL) x = __ieee754_fmodl(x,p+p);	/* now x < 2p */
	if (((hx-hp)|(lx-lp))==0) return zero*x;
	x  = fabsl(x);
	p  = fabsl(p);
	if (hp<0x0020000000000000LL) {
	    if(x+x>p) {
		x-=p;
		if(x+x>=p) x -= p;
	    }
	} else {
	    p_half = 0.5L*p;
	    if(x>p_half) {
		x-=p;
		if(x>=p_half) x -= p;
	    }
	}
	if (sx)
	  x = -x;
	return x;
}
Exemplo n.º 3
0
_Float128
__ieee754_remainderl(_Float128 x, _Float128 p)
{
	int64_t hx,hp;
	uint64_t sx,lx,lp;
	_Float128 p_half;

	GET_LDOUBLE_WORDS64(hx,lx,x);
	GET_LDOUBLE_WORDS64(hp,lp,p);
	sx = hx&0x8000000000000000ULL;
	hp &= 0x7fffffffffffffffLL;
	hx &= 0x7fffffffffffffffLL;

    /* purge off exception values */
	if((hp|lp)==0) return (x*p)/(x*p);	/* p = 0 */
	if((hx>=0x7fff000000000000LL)||			/* x not finite */
	  ((hp>=0x7fff000000000000LL)&&			/* p is NaN */
	  (((hp-0x7fff000000000000LL)|lp)!=0)))
	    return (x*p)/(x*p);


	if (hp<=0x7ffdffffffffffffLL) x = __ieee754_fmodl(x,p+p);	/* now x < 2p */
	if (((hx-hp)|(lx-lp))==0) return zero*x;
	x  = fabsl(x);
	p  = fabsl(p);
	if (hp<0x0002000000000000LL) {
	    if(x+x>p) {
		x-=p;
		if(x+x>=p) x -= p;
	    }
	} else {
	    p_half = L(0.5)*p;
	    if(x>p_half) {
		x-=p;
		if(x>=p_half) x -= p;
	    }
	}
	GET_LDOUBLE_MSW64(hx,x);
	SET_LDOUBLE_MSW64(x,hx^sx);
	return x;
}
Exemplo n.º 4
0
long double
__remquol (long double x, long double y, int *quo)
{
  int64_t hx,hy;
  u_int64_t sx,lx,ly,qs;
  int cquo;

  GET_LDOUBLE_WORDS64 (hx, lx, x);
  GET_LDOUBLE_WORDS64 (hy, ly, y);
  sx = hx & 0x8000000000000000ULL;
  qs = sx ^ (hy & 0x8000000000000000ULL);
  hy &= 0x7fffffffffffffffLL;
  hx &= 0x7fffffffffffffffLL;

  /* Purge off exception values.  */
  if ((hy | ly) == 0)
    return (x * y) / (x * y); 			/* y = 0 */
  if ((hx >= 0x7fff000000000000LL)		/* x not finite */
      || ((hy >= 0x7fff000000000000LL)		/* y is NaN */
	  && (((hy - 0x7fff000000000000LL) | ly) != 0)))
    return (x * y) / (x * y);

  if (hy <= 0x7ffbffffffffffffLL)
    x = __ieee754_fmodl (x, 8 * y);              /* now x < 8y */

  if (((hx - hy) | (lx - ly)) == 0)
    {
      *quo = qs ? -1 : 1;
      return zero * x;
    }

  x  = fabsl (x);
  y  = fabsl (y);
  cquo = 0;

  if (x >= 4 * y)
    {
      x -= 4 * y;
      cquo += 4;
    }
  if (x >= 2 * y)
    {
      x -= 2 * y;
      cquo += 2;
    }

  if (hy < 0x0002000000000000LL)
    {
      if (x + x > y)
	{
	  x -= y;
	  ++cquo;
	  if (x + x >= y)
	    {
	      x -= y;
	      ++cquo;
	    }
	}
    }
  else
    {
      long double y_half = 0.5L * y;
      if (x > y_half)
	{
	  x -= y;
	  ++cquo;
	  if (x >= y_half)
	    {
	      x -= y;
	      ++cquo;
	    }
	}
    }

  *quo = qs ? -cquo : cquo;

  if (sx)
    x = -x;
  return x;
}
Exemplo n.º 5
0
long double
__remquol (long double x, long double y, int *quo)
{
  int64_t hx,hy;
  u_int64_t sx,lx,ly,qs;
  int cquo;
  double xhi, xlo, yhi, ylo;

  ldbl_unpack (x, &xhi, &xlo);
  EXTRACT_WORDS64 (hx, xhi);
  EXTRACT_WORDS64 (lx, xlo);
  ldbl_unpack (y, &yhi, &ylo);
  EXTRACT_WORDS64 (hy, yhi);
  EXTRACT_WORDS64 (ly, ylo);
  sx = hx & 0x8000000000000000ULL;
  qs = sx ^ (hy & 0x8000000000000000ULL);
  hy &= 0x7fffffffffffffffLL;
  hx &= 0x7fffffffffffffffLL;

  /* Purge off exception values.  */
  if (hy == 0)
    return (x * y) / (x * y); 			/* y = 0 */
  if ((hx >= 0x7ff0000000000000LL)		/* x not finite */
      || (hy > 0x7ff0000000000000LL))		/* y is NaN */
    return (x * y) / (x * y);

  if (hy <= 0x7fbfffffffffffffLL)
    x = __ieee754_fmodl (x, 8 * y);              /* now x < 8y */

  if (((hx - hy) | (lx - ly)) == 0)
    {
      *quo = qs ? -1 : 1;
      return zero * x;
    }

  x  = fabsl (x);
  y  = fabsl (y);
  cquo = 0;

  if (hy <= 0x7fcfffffffffffffLL && x >= 4 * y)
    {
      x -= 4 * y;
      cquo += 4;
    }
  if (hy <= 0x7fdfffffffffffffLL && x >= 2 * y)
    {
      x -= 2 * y;
      cquo += 2;
    }

  if (hy < 0x0020000000000000LL)
    {
      if (x + x > y)
	{
	  x -= y;
	  ++cquo;
	  if (x + x >= y)
	    {
	      x -= y;
	      ++cquo;
	    }
	}
    }
  else
    {
      long double y_half = 0.5L * y;
      if (x > y_half)
	{
	  x -= y;
	  ++cquo;
	  if (x >= y_half)
	    {
	      x -= y;
	      ++cquo;
	    }
	}
    }

  *quo = qs ? -cquo : cquo;

  /* Ensure correct sign of zero result in round-downward mode.  */
  if (x == 0.0L)
    x = 0.0L;
  if (sx)
    x = -x;
  return x;
}
Exemplo n.º 6
0
_Float128
__remquol (_Float128 x, _Float128 y, int *quo)
{
  int64_t hx,hy;
  u_int64_t sx,lx,ly,qs;
  int cquo;

  GET_LDOUBLE_WORDS64 (hx, lx, x);
  GET_LDOUBLE_WORDS64 (hy, ly, y);
  sx = hx & 0x8000000000000000ULL;
  qs = sx ^ (hy & 0x8000000000000000ULL);
  hy &= 0x7fffffffffffffffLL;
  hx &= 0x7fffffffffffffffLL;

  /* Purge off exception values.  */
  if ((hy | ly) == 0)
    return (x * y) / (x * y); 			/* y = 0 */
  if ((hx >= 0x7fff000000000000LL)		/* x not finite */
      || ((hy >= 0x7fff000000000000LL)		/* y is NaN */
	  && (((hy - 0x7fff000000000000LL) | ly) != 0)))
    return (x * y) / (x * y);

  if (hy <= 0x7ffbffffffffffffLL)
    x = __ieee754_fmodl (x, 8 * y);              /* now x < 8y */

  if (((hx - hy) | (lx - ly)) == 0)
    {
      *quo = qs ? -1 : 1;
      return zero * x;
    }

  x  = fabsl (x);
  y  = fabsl (y);
  cquo = 0;

  if (hy <= 0x7ffcffffffffffffLL && x >= 4 * y)
    {
      x -= 4 * y;
      cquo += 4;
    }
  if (hy <= 0x7ffdffffffffffffLL && x >= 2 * y)
    {
      x -= 2 * y;
      cquo += 2;
    }

  if (hy < 0x0002000000000000LL)
    {
      if (x + x > y)
	{
	  x -= y;
	  ++cquo;
	  if (x + x >= y)
	    {
	      x -= y;
	      ++cquo;
	    }
	}
    }
  else
    {
      _Float128 y_half = L(0.5) * y;
      if (x > y_half)
	{
	  x -= y;
	  ++cquo;
	  if (x >= y_half)
	    {
	      x -= y;
	      ++cquo;
	    }
	}
    }

  *quo = qs ? -cquo : cquo;

  /* Ensure correct sign of zero result in round-downward mode.  */
  if (x == 0)
    x = 0;
  if (sx)
    x = -x;
  return x;
}