Beispiel #1
0
float
sinf(float x)
{
	float y[2],z=0.0;
	int32_t n, ix;

	GET_FLOAT_WORD(ix,x);

    /* |x| ~< pi/4 */
	ix &= 0x7fffffff;
	if(ix <= 0x3f490fd8) return __kernel_sinf(x,z,0);

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

    /* argument reduction needed */
	else {
	    n = __ieee754_rem_pio2f(x,y);
	    switch(n&3) {
		case 0: return  __kernel_sinf(y[0],y[1],1);
		case 1: return  __kernel_cosf(y[0],y[1]);
		case 2: return -__kernel_sinf(y[0],y[1],1);
		default:
			return -__kernel_cosf(y[0],y[1]);
	    }
	}
}
Beispiel #2
0
float
cosf(float x)
{
    float y[2];
    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 */
            if(((int)x)==0) return 1.0;	/* 1 with inexact if x != 0 */
        return __kernel_cosdf(x);
    }
    if(ix<=0x407b53d1) {		/* |x| ~<= 5*pi/4 */
        if(ix>0x4016cbe3)		/* |x|  ~> 3*pi/4 */
            return -__kernel_cosdf(x + (hx > 0 ? -c2pio2 : c2pio2));
        else {
            if(hx>0)
                return __kernel_sindf(c1pio2 - x);
            else
                return __kernel_sindf(x + c1pio2);
        }
    }
    if(ix<=0x40e231d5) {		/* |x| ~<= 9*pi/4 */
        if(ix>0x40afeddf)		/* |x|  ~> 7*pi/4 */
            return __kernel_cosdf(x + (hx > 0 ? -c4pio2 : c4pio2));
        else {
            if(hx>0)
                return __kernel_sindf(x - c3pio2);
            else
                return __kernel_sindf(-c3pio2 - x);
        }
    }

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

    /* general argument reduction needed */
    else {
        n = __ieee754_rem_pio2f(x,y);
        switch(n&3) {
        case 0:
            return  __kernel_cosdf((double)y[0]+y[1]);
        case 1:
            return  __kernel_sindf(-(double)y[0]-y[1]);
        case 2:
            return -__kernel_cosdf((double)y[0]+y[1]);
        default:
            return  __kernel_sindf((double)y[0]+y[1]);
        }
    }
}
Beispiel #3
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 */
            if(((int)x)==0) return x;	/* x with inexact if x != 0 */
        return __kernel_sindf(x);
    }
    if(ix<=0x407b53d1) {		/* |x| ~<= 5*pi/4 */
        if(ix<=0x4016cbe3) {	/* |x| ~<= 3pi/4 */
            if(hx>0)
                return __kernel_cosdf(x - s1pio2);
            else
                return -__kernel_cosdf(x + s1pio2);
        } else
            return __kernel_sindf((hx > 0 ? s2pio2 : -s2pio2) - x);
    }
    if(ix<=0x40e231d5) {		/* |x| ~<= 9*pi/4 */
        if(ix<=0x40afeddf) {	/* |x| ~<= 7*pi/4 */
            if(hx>0)
                return -__kernel_cosdf(x - s3pio2);
            else
                return __kernel_cosdf(x + s3pio2);
        } else
            return __kernel_sindf(x + (hx > 0 ? -s4pio2 : s4pio2));
    }

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

    /* general argument reduction needed */
    else {
        n = __ieee754_rem_pio2f(x,&y);
        switch(n&3) {
        case 0:
            return  __kernel_sindf(y);
        case 1:
            return  __kernel_cosdf(y);
        case 2:
            return  __kernel_sindf(-y);
        default:
            return -__kernel_cosdf(y);
        }
    }
}
Beispiel #4
0
void
SINCOSF_FUNC (float x, float *sinx, float *cosx)
{
  int32_t ix;

  /* High word of x. */
  GET_FLOAT_WORD (ix, x);

  /* |x| ~< pi/4 */
  ix &= 0x7fffffff;
  if (ix <= 0x3f490fd8)
    {
      *sinx = __kernel_sinf (x, 0.0, 0);
      *cosx = __kernel_cosf (x, 0.0);
    }
  else if (ix>=0x7f800000)
    {
      /* sin(Inf or NaN) is NaN */
      *sinx = *cosx = x - x;
      if (ix == 0x7f800000)
	__set_errno (EDOM);
    }
  else
    {
      /* Argument reduction needed.  */
      float y[2];
      int n;

      n = __ieee754_rem_pio2f (x, y);
      switch (n & 3)
	{
	case 0:
	  *sinx = __kernel_sinf (y[0], y[1], 1);
	  *cosx = __kernel_cosf (y[0], y[1]);
	  break;
	case 1:
	  *sinx = __kernel_cosf (y[0], y[1]);
	  *cosx = -__kernel_sinf (y[0], y[1], 1);
	  break;
	case 2:
	  *sinx = -__kernel_sinf (y[0], y[1], 1);
	  *cosx = -__kernel_cosf (y[0], y[1]);
	  break;
	default:
	  *sinx = -__kernel_cosf (y[0], y[1]);
	  *cosx = __kernel_sinf (y[0], y[1], 1);
	  break;
	}
    }
}
Beispiel #5
0
float
__cosf (float x)
{
  float y[2], z = 0.0;
  float ix;
  int32_t n;

  ix = __builtin_fabsf (x);

  /* |x| ~< pi/4 */
  if (ix <= pio4)
    {
      return __kernel_cosf (x, z);
      /* cos(Inf or NaN) is NaN */
    }
  else if (isnanf (ix))
    {
      return x - x;
    }
  else if (isinff (ix))
    {
      __set_errno (EDOM);
      return x - x;
    }

  /* argument reduction needed */
  else
    {
      n = __ieee754_rem_pio2f (x, y);
      switch (n & 3)
	{
	case 0:
	  return __kernel_cosf (y[0], y[1]);
	case 1:
	  return -__kernel_sinf (y[0], y[1], 1);
	case 2:
	  return -__kernel_cosf (y[0], y[1]);
	default:
	  return __kernel_sinf (y[0], y[1], 1);
	}
    }
}
Beispiel #6
0
void
__sincosf(float x, float *sptr, float *cptr)
{
    float y[2], z=0.0;
    int32_t n, ix;
    float rs, rc;

    /* high word of x */
    GET_FLOAT_WORD(ix, x);

    /* |x| ~< pi/4 */
    ix &= 0x7fffffff;
    if (ix <= 0x3f490fd8) {
        __kernel_sincosf(x, z, 0, sptr, cptr);
        return;
    }

    /* cos(Inf or NaN) is NaN */
    if (ix >= 0x7f800000) {
        float n = x - x;
        *sptr = *cptr = n;
        return;
    }
    /* argument reduction needed */
    n = __ieee754_rem_pio2f(x, y);
    __kernel_sincosf(y[0], y[1], 1, &rs, &rc);
    switch(n&3) {
    case 0:
        *sptr = rs; *cptr = rc;
        break;
    case 1:
        *sptr = rc; *cptr = -rs;
        break;
    case 2:
        *sptr = -rs; *cptr = -rc;
        break;
    default:
        *sptr = -rc; *cptr = rs;
        break;
    }
}
Beispiel #7
0
float
tanf(float x)
{
	float y[2],z=0.0;
	int32_t n, ix;

	GET_FLOAT_WORD(ix,x);

    /* |x| ~< pi/4 */
	ix &= 0x7fffffff;
	if(ix <= 0x3f490fda) return __kernel_tanf(x,z,1);

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

    /* argument reduction needed */
	else {
	    n = __ieee754_rem_pio2f(x,y);
	    return __kernel_tanf(y[0],y[1],1-((n&1)<<1)); /*   1 -- n even
							      -1 -- n odd */
	}
}
Beispiel #8
0
float
tanf(float x)
{
	float y[2];
	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 */
		if(((int)x)==0) return x;	/* x with inexact if x != 0 */
	    return __kernel_tandf(x,1);
	}
	if(ix<=0x407b53d1) {		/* |x| ~<= 5*pi/4 */
	    if(ix<=0x4016cbe3)		/* |x| ~<= 3pi/4 */
		return __kernel_tandf(x + (hx>0 ? -t1pio2 : t1pio2), -1);
	    else
		return __kernel_tandf(x + (hx>0 ? -t2pio2 : t2pio2), 1);
	}
	if(ix<=0x40e231d5) {		/* |x| ~<= 9*pi/4 */
	    if(ix<=0x40afeddf)		/* |x| ~<= 7*pi/4 */
		return __kernel_tandf(x + (hx>0 ? -t3pio2 : t3pio2), -1);
	    else
		return __kernel_tandf(x + (hx>0 ? -t4pio2 : t4pio2), 1);
	}

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

    /* general argument reduction needed */
	else {
	    n = __ieee754_rem_pio2f(x,y);
	    /* integer parameter: 1 -- n even; -1 -- n odd */
	    return __kernel_tandf((double)y[0]+y[1],1-((n&1)<<1));
	}
}
Beispiel #9
0
DLLEXPORT void
sincosf(float x, float * s, float * c) {
	// Worst approximation of sin and cos NA
	*s = x;
	*c = x;

	double y;
	float k_c, k_s;
	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 */
			/* Check if x is exactly zero */
			if(((int)x)==0) {
				*s = x;
				*c = 1.0f;
				return;
			}
		}
		__kernel_sincosdf(x, s, c);
		return;
	}
	/* |x| ~<= 5*pi/4 */
	if (ix<=0x407b53d1) {
		/* |x| ~<= 3pi/4 */
	    if(ix<=0x4016cbe3) {
			if(hx>0) {
				__kernel_sincosdf( sc1pio2 - x, c, s );
			}
			else {
				__kernel_sincosdf( sc1pio2 + x, c, &k_s );
				*s = -k_s;
		    }
		} else {

			if(hx>0) {
				__kernel_sincosdf( sc2pio2 - x, s, &k_c );
				*c = -k_c;
			} else  {
				__kernel_sincosdf( -sc2pio2 - x, s, &k_c );
				*c = -k_c;
			}
		}
		return;
	}

	/* |x| ~<= 9*pi/4 */
	if(ix<=0x40e231d5) {
		/* |x|  ~> 7*pi/4 */
	    if(ix<=0x40afeddf) {	
			if(hx>0) {
				__kernel_sincosdf( x - sc3pio2, c, &k_s );
				*s = -k_s;
			} else {
				__kernel_sincosdf( x + sc3pio2, &k_c, s );
				*c = -k_c;
		    } 
		}
		else {
	    	if( hx > 0 ) {
	    		__kernel_sincosdf( x - sc4pio2, s, c );
	    	} else {
	    		__kernel_sincosdf( x + sc4pio2, s, c );
	    	}
	    }
		return;
	}

	/* cos(Inf or NaN) is NaN */
	else if(ix>=0x7f800000) {
		*c = *s = x-x;
	} else {
		/* general argument reduction needed */
		n = __ieee754_rem_pio2f(x,&y);

		switch(n&3) {
			case 0:
				__kernel_sincosdf( y, s, c );
				break;
			case 1:
				__kernel_sincosdf( -y, c, s );
				break;
			case 2: 
				__kernel_sincosdf( -y, s, &k_c);
				*c = -k_c;
				break;
			default:
				__kernel_sincosdf( -y, &k_c, &k_s );
				*c = -k_c;
				*s = -k_s;
				break;
	    }
	}

}