Example #1
0
float sinf(float x)
{
	double y;
	uint32_t ix;
	int n, sign;

	GET_FLOAT_WORD(ix, x);
	sign = ix >> 31;
	ix &= 0x7fffffff;

	if (ix <= 0x3f490fda) {  /* |x| ~<= pi/4 */
		if (ix < 0x39800000) {  /* |x| < 2**-12 */
			/* raise inexact if x!=0 and underflow if subnormal */
			FORCE_EVAL(ix < 0x00800000 ? x/0x1p120f : x+0x1p120f);
			return x;
		}
		return __sindf(x);
	}
	if (ix <= 0x407b53d1) {  /* |x| ~<= 5*pi/4 */
		if (ix <= 0x4016cbe3) {  /* |x| ~<= 3pi/4 */
			if (sign)
				return -__cosdf(x + s1pio2);
			else
				return __cosdf(x - s1pio2);
		}
		return __sindf(sign ? -(x + s2pio2) : -(x - s2pio2));
	}
	if (ix <= 0x40e231d5) {  /* |x| ~<= 9*pi/4 */
		if (ix <= 0x40afeddf) {  /* |x| ~<= 7*pi/4 */
			if (sign)
				return __cosdf(x + s3pio2);
			else
				return -__cosdf(x - s3pio2);
		}
		return __sindf(sign ? x + s4pio2 : x - s4pio2);
	}

	/* sin(Inf or NaN) is NaN */
	if (ix >= 0x7f800000)
		return x - x;

	/* general argument reduction needed */
	n = __rem_pio2f(x, &y);
	switch (n&3) {
	case 0: return  __sindf(y);
	case 1: return  __cosdf(y);
	case 2: return  __sindf(-y);
	default:
		return -__cosdf(y);
	}
}
Example #2
0
float sinf(float x)
{
	double y;
	int32_t n, hx, ix;

	GET_FLOAT_WORD(hx, x);
	ix = hx & 0x7fffffff;

	if (ix <= 0x3f490fda) {  /* |x| ~<= pi/4 */
		if (ix < 0x39800000)  /* |x| < 2**-12 */
			/* raise inexact if x != 0 */
			if((int)x == 0)
				return x;
		return __sindf(x);
	}
	if (ix <= 0x407b53d1) {  /* |x| ~<= 5*pi/4 */
		if (ix <= 0x4016cbe3) {  /* |x| ~<= 3pi/4 */
			if (hx > 0)
				return __cosdf(x - s1pio2);
			else
				return -__cosdf(x + s1pio2);
		}
		return __sindf(hx > 0 ? s2pio2 - x : -s2pio2 - x);
	}
	if (ix <= 0x40e231d5) {  /* |x| ~<= 9*pi/4 */
		if (ix <= 0x40afeddf) {  /* |x| ~<= 7*pi/4 */
			if (hx > 0)
				return -__cosdf(x - s3pio2);
			else
				return __cosdf(x + s3pio2);
		}
		return __sindf(hx > 0 ? x - s4pio2 : x + s4pio2);
	}

	/* sin(Inf or NaN) is NaN */
	if (ix >= 0x7f800000)
		return x - x;

	/* general argument reduction needed */
	n = __rem_pio2f(x, &y);
	switch (n&3) {
	case 0: return  __sindf(y);
	case 1: return  __cosdf(y);
	case 2: return  __sindf(-y);
	default:
		return -__cosdf(y);
	}
}
Example #3
0
File: lgammaf_r.c Project: 5kg/osv
static float sin_pif(float x)
{
	float y,z;
	int n,ix;

	GET_FLOAT_WORD(ix, x);
	ix &= 0x7fffffff;

	if(ix < 0x3e800000)
		return __sindf(pi*x);

	y = -x;  /* negative x is assumed */

	/*
	 * argument reduction, make sure inexact flag not raised if input
	 * is an integer
	 */
	z = floorf(y);
	if (z != y) {   /* inexact anyway */
		y *= 0.5f;
		y  = 2.0f*(y - floorf(y));   /* y = |x| mod 2.0 */
		n  = (int)(y*4.0f);
	} else {
		if (ix >= 0x4b800000) {
			y = 0.0f;  /* y must be even */
			n = 0;
		} else {
			if (ix < 0x4b000000)
				z = y + two23;  /* exact */
			GET_FLOAT_WORD(n, z);
			n &= 1;
			y = n;
			n <<= 2;
		}
	}
	switch (n) {
	case 0:  y =  __sindf(pi*y); break;
	case 1:
	case 2:  y =  __cosdf(pi*(0.5f - y)); break;
	case 3:
	case 4:  y =  __sindf(pi*(1.0f - y)); break;
	case 5:
	case 6:  y = -__cosdf(pi*(y - 1.5f)); break;
	default: y =  __sindf(pi*(y - 2.0f)); break;
	}
	return -y;
}
Example #4
0
/* sin(pi*x) assuming x > 2^-100, if sin(pi*x)==0 the sign is arbitrary */
static float sin_pi(float x)
{
	double_t y;
	int n;

	/* spurious inexact if odd int */
	x = 2*(x*0.5f - floorf(x*0.5f));  /* x mod 2.0 */

	n = (int)(x*4);
	n = (n+1)/2;
	y = x - n*0.5f;
	y *= 3.14159265358979323846;
	switch (n) {
	default: /* case 4: */
	case 0: return __sindf(y);
	case 1: return __cosdf(y);
	case 2: return __sindf(-y);
	case 3: return -__cosdf(y);
	}
}
Example #5
0
File: cosf.c Project: freiling/mojo
float cosf(float x) {
  double y;
  uint32_t ix;
  unsigned n, sign;

  GET_FLOAT_WORD(ix, x);
  sign = ix >> 31;
  ix &= 0x7fffffff;

  if (ix <= 0x3f490fda) {  /* |x| ~<= pi/4 */
    if (ix < 0x39800000) { /* |x| < 2**-12 */
      /* raise inexact if x != 0 */
      FORCE_EVAL(x + 0x1p120f);
      return 1.0f;
    }
    return __cosdf(x);
  }
  if (ix <= 0x407b53d1) { /* |x| ~<= 5*pi/4 */
    if (ix > 0x4016cbe3)  /* |x|  ~> 3*pi/4 */
      return -__cosdf(sign ? x + c2pio2 : x - c2pio2);
    else {
      if (sign)
        return __sindf(x + c1pio2);
      else
        return __sindf(c1pio2 - x);
    }
  }
  if (ix <= 0x40e231d5) { /* |x| ~<= 9*pi/4 */
    if (ix > 0x40afeddf)  /* |x| ~> 7*pi/4 */
      return __cosdf(sign ? x + c4pio2 : x - c4pio2);
    else {
      if (sign)
        return __sindf(-x - c3pio2);
      else
        return __sindf(x - c3pio2);
    }
  }

  /* cos(Inf or NaN) is NaN */
  if (ix >= 0x7f800000)
    return x - x;

  /* general argument reduction needed */
  n = __rem_pio2f(x, &y);
  switch (n & 3) {
    case 0:
      return __cosdf(y);
    case 1:
      return __sindf(-y);
    case 2:
      return -__cosdf(y);
    default:
      return __sindf(y);
  }
}
Example #6
0
File: sincosf.c Project: KGG814/AOS
void sincosf(float x, float *sin, float *cos)
{
	double y, s, c;
	uint32_t n, hx, ix;

	GET_FLOAT_WORD(hx, x);
	ix = hx & 0x7fffffff;

	/* |x| ~<= pi/4 */
	if (ix <= 0x3f490fda) {
		/* |x| < 2**-12 */
		if (ix < 0x39800000) {
			/* raise inexact if x != 0 */
			if((int)x == 0) {
				*sin = x;
				*cos = 1.0f;
			}
			return;
		}
		*sin = __sindf(x);
		*cos = __cosdf(x);
		return;
	}

	/* |x| ~<= 5*pi/4 */
	if (ix <= 0x407b53d1) {  
		if (ix <= 0x4016cbe3) {  /* |x| ~<= 3pi/4 */
			if (hx < 0x80000000) {
				*sin = __cosdf(x - s1pio2);
				*cos = __sindf(s1pio2 - x);
			} else {
				*sin = -__cosdf(x + s1pio2);
				*cos = __sindf(x + s1pio2);
			}
			return;
		}
		*sin = __sindf(hx < 0x80000000 ? s2pio2 - x : -s2pio2 - x);
		*cos = -__cosdf(hx < 0x80000000 ? x - s2pio2 : x + s2pio2);
		return;
	}

	/* |x| ~<= 9*pi/4 */
	if (ix <= 0x40e231d5) {
		if (ix <= 0x40afeddf) {  /* |x| ~<= 7*pi/4 */
			if (hx < 0x80000000) {
				*sin = -__cosdf(x - s3pio2);
				*cos = __sindf(x - s3pio2);
			} else {
				*sin = __cosdf(x + s3pio2);
				*cos = __sindf(-s3pio2 - x);
			}
			return;
		}
		*sin = __sindf(hx < 0x80000000 ? x - s4pio2 : x + s4pio2);
		*cos = __cosdf(hx < 0x80000000 ? x - s4pio2 : x + s4pio2);
		return;
	}

	/* sin(Inf or NaN) is NaN */
	if (ix >= 0x7f800000) {
		*sin = *cos = x - x;
		return;
	}

	/* general argument reduction needed */
	n = __rem_pio2f(x, &y);
	s = __sindf(y);
	c = __cosdf(y);
	switch (n&3) {
	case 0:
		*sin = s;
		*cos = c;
		break;
	case 1:
		*sin = c;
		*cos = -s;
		break;
	case 2:
		*sin = -s;
		*cos = -c;
		break;
	case 3:
	default:
		*sin = -c;
		*cos = s;
		break;
	}
}
void sincosf(float x, float *sin, float *cos)
{
	double y;
	float_t s, c;
	uint32_t ix;
	unsigned n, sign;

	GET_FLOAT_WORD(ix, x);
	sign = ix >> 31;
	ix &= 0x7fffffff;

	/* |x| ~<= pi/4 */
	if (ix <= 0x3f490fda) {
		/* |x| < 2**-12 */
		if (ix < 0x39800000) {
			/* raise inexact if x!=0 and underflow if subnormal */
			FORCE_EVAL(ix < 0x00100000 ? x/0x1p120f : x+0x1p120f);
			*sin = x;
			*cos = 1.0f;
			return;
		}
		*sin = __sindf(x);
		*cos = __cosdf(x);
		return;
	}

	/* |x| ~<= 5*pi/4 */
	if (ix <= 0x407b53d1) {
		if (ix <= 0x4016cbe3) {  /* |x| ~<= 3pi/4 */
			if (sign) {
				*sin = -__cosdf(x + s1pio2);
				*cos = __sindf(x + s1pio2);
			} else {
				*sin = __cosdf(s1pio2 - x);
				*cos = __sindf(s1pio2 - x);
			}
			return;
		}
		/* -sin(x+c) is not correct if x+c could be 0: -0 vs +0 */
		*sin = -__sindf(sign ? x + s2pio2 : x - s2pio2);
		*cos = -__cosdf(sign ? x + s2pio2 : x - s2pio2);
		return;
	}

	/* |x| ~<= 9*pi/4 */
	if (ix <= 0x40e231d5) {
		if (ix <= 0x40afeddf) {  /* |x| ~<= 7*pi/4 */
			if (sign) {
				*sin = __cosdf(x + s3pio2);
				*cos = -__sindf(x + s3pio2);
			} else {
				*sin = -__cosdf(x - s3pio2);
				*cos = __sindf(x - s3pio2);
			}
			return;
		}
		*sin = __sindf(sign ? x + s4pio2 : x - s4pio2);
		*cos = __cosdf(sign ? x + s4pio2 : x - s4pio2);
		return;
	}

	/* sin(Inf or NaN) is NaN */
	if (ix >= 0x7f800000) {
		*sin = *cos = x - x;
		return;
	}

	/* general argument reduction needed */
	n = __rem_pio2f(x, &y);
	s = __sindf(y);
	c = __cosdf(y);
	switch (n&3) {
	case 0:
		*sin = s;
		*cos = c;
		break;
	case 1:
		*sin = c;
		*cos = -s;
		break;
	case 2:
		*sin = -s;
		*cos = -c;
		break;
	case 3:
	default:
		*sin = -c;
		*cos = s;
		break;
	}
}