예제 #1
0
static double sinpi(double x)
{
	int n;

	/* argument reduction: x = |x| mod 2 */
	/* spurious inexact when x is odd int */

	x = x * 0.5;
	x = 2 * (x - floor(x));

	/* reduce x into [-.25,.25] */

	n = 4 * x;
	n = (n + 1) / 2;
	x -= n * 0.5;

	x *= pi;
	switch (n) {
	default:					/* case 4 */
	case 0:
		return __sin(x, 0, 0);

	case 1:
		return __cos(x, 0);

	case 2:
		return __sin(-x, 0, 0);

	case 3:
		return -__cos(x, 0);
	}
}
예제 #2
0
파일: cos.c 프로젝트: 5kg/osv
double cos(double x)
{
	double y[2],z=0.0;
	int32_t n, ix;

	GET_HIGH_WORD(ix, x);

	/* |x| ~< pi/4 */
	ix &= 0x7fffffff;
	if (ix <= 0x3fe921fb) {
		if (ix < 0x3e46a09e)  /* if x < 2**-27 * sqrt(2) */
			/* raise inexact if x != 0 */
			if ((int)x == 0)
				return 1.0;
		return __cos(x, z);
	}

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

	/* argument reduction needed */
	n = __rem_pio2(x, y);
	switch (n&3) {
	case 0: return  __cos(y[0], y[1]);
	case 1: return -__sin(y[0], y[1], 1);
	case 2: return -__cos(y[0], y[1]);
	default:
		return  __sin(y[0], y[1], 1);
	}
}
예제 #3
0
파일: sin.c 프로젝트: bhuztez/barelibc
double sin(double x)
{
	double y[2];
	uint32_t ix;
	unsigned n;

	/* High word of x. */
	GET_HIGH_WORD(ix, x);
	ix &= 0x7fffffff;

	/* |x| ~< pi/4 */
	if (ix <= 0x3fe921fb) {
		if (ix < 0x3e500000) {  /* |x| < 2**-26 */
			/* raise inexact if x != 0 and underflow if subnormal*/
			FORCE_EVAL(ix < 0x00100000 ? x/0x1p120f : x+0x1p120f);
			return x;
		}
		return __sin(x, 0.0, 0);
	}

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

	/* argument reduction needed */
	n = __rem_pio2(x, y);
	switch (n&3) {
	case 0: return  __sin(y[0], y[1], 1);
	case 1: return  __cos(y[0], y[1]);
	case 2: return -__sin(y[0], y[1], 1);
	default:
		return -__cos(y[0], y[1]);
	}
}
예제 #4
0
파일: ctor.c 프로젝트: sharugupta/OpenUH
/*
 *      complex(kind=8) raised to a real(kind=8) = _CTOR
 *
 *	x = a+b*i
 *
 *	if ((x == 0+0*i) && (y == 0)) then return(NAN)
 *	if (x == 0+0*i) then return(0+0*i)
 *	if (y == 0) then return(1+0*i)
 */
void
_CTOR(c_complex_t *ret_val,
	c_complex_t x,
	_f_real8 *r)
{
	_f_real8 __atan2(_f_real8 x, _f_real8 y);
	_f_real8 __cos(_f_real8 x);
	_f_real8 __exp(_f_real8 x);
	_f_real8 __log(_f_real8 x);
	_f_real8 __sin(_f_real8 x);
	_f_real8 _CABS(c_complex_t z);
	_f_real8 y = *r;
	_f_real8 one;
	_f_real8 two;
	if (x.real == (_f_real8) 0.0 && x.imag == (_f_real8) 0.0) {
		if (y == (_f_real8) 0.0) {
			ret_val->real = _SGL_NaN;
			ret_val->imag = _SGL_NaN;
		}
		else {
			ret_val->real = (_f_real8) 0.0;
			ret_val->imag = (_f_real8) 0.0;
		}
		return;
	}
	one = y * __atan2(x.imag, x.real);
	two = y * __log(_CABS(x));
	ret_val->real = __exp(two) * __cos(one);
	ret_val->imag = __exp(two) * __sin(one);
}
예제 #5
0
파일: csin.c 프로젝트: sharugupta/OpenUH
/*
 * CSIN - complex(kind=8) - pass by value
 *
 * Semantics:  sin(z) = sin(a)*cosh(b) + cos(a)*sinh(b)*i
 *   (where z = a + b*i)
 */
void
_CSIN(c_complex_t *ret_val,
	c_complex_t z)
{
	_f_real8 __cos(_f_real8 x);
	_f_real8 __cosh(_f_real8 x);
	_f_real8 __sin(_f_real8 x);
	_f_real8 __sinh(_f_real8 x);
	ret_val->real = __sin(z.real) * __cosh(z.imag);
	ret_val->imag = __cos(z.real) * __sinh(z.imag);
}
예제 #6
0
void sincos(double x, double *sin, double *cos)
{
	double y[2], s, c;
	uint32_t ix;
	unsigned n;

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

	/* |x| ~< pi/4 */
	if (ix <= 0x3fe921fb) {
		/* if |x| < 2**-27 * sqrt(2) */
		if (ix < 0x3e46a09e) {
			/* raise inexact if x!=0 and underflow if subnormal */
			FORCE_EVAL(ix < 0x00100000 ? x/0x1p120f : x+0x1p120f);
			*sin = x;
			*cos = 1.0;
			return;
		}
		*sin = __sin(x, 0.0, 0);
		*cos = __cos(x, 0.0);
		return;
	}

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

	/* argument reduction needed */
	n = __rem_pio2(x, y);
	s = __sin(y[0], y[1], 1);
	c = __cos(y[0], y[1]);
	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;
	}
}
예제 #7
0
파일: chcos.c 프로젝트: sharugupta/OpenUH
void
_CHCOS( h_complex_t *ret_val,
	h_complex_t z )
{
	_f_real8 __cos(_f_real8 x);
	_f_real8 __cosh(_f_real8 x);
	_f_real8 __sin(_f_real8 x);
	_f_real8 __sinh(_f_real8 x);
	_f_real8 real = (_f_real8) z.real;
	_f_real8 imag = (_f_real8) z.imag;
	ret_val->real = (_f_real4) (__cos(real) * __cosh(imag));
	ret_val->imag = (_f_real4) (- (__sin(real) * __sinh(imag)));
}
예제 #8
0
파일: chexp.c 프로젝트: xyuan/Path64
void
_CHEXP(h_complex_t *ret_val,
	h_complex_t z )
{
	_f_real8 __exp(_f_real8 x);
	_f_real8 __cos(_f_real8 x);
	_f_real8 __sin(_f_real8 x);
	_f_real8 real = (_f_real8) z.real;
	_f_real8 imag = (_f_real8) z.imag;
	_f_real8 realtmp = __exp(real);

	ret_val->real = (_f_real4) (realtmp * __cos(imag));
	ret_val->imag = (_f_real4) (realtmp * __sin(imag));
}
예제 #9
0
static double sin_pi(double x)
{
	double y,z;
	int n,ix;

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

	if (ix < 0x3fd00000)
		return __sin(pi*x, 0.0, 0);

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

	/*
	 * argument reduction, make sure inexact flag not raised if input
	 * is an integer
	 */
	z = floor(y);
	if (z != y) {    /* inexact anyway */
		y *= 0.5;
		y  = 2.0*(y - floor(y));   /* y = |x| mod 2.0 */
		n  = (int)(y*4.0);
	} else {
		if (ix >= 0x43400000) {
			y = 0.0;    /* y must be even */
			n = 0;
		} else {
			if (ix < 0x43300000)
				z = y + two52;  /* exact */
			GET_LOW_WORD(n, z);
			n &= 1;
			y = n;
			n <<= 2;
		}
	}
	switch (n) {
	case 0:  y =  __sin(pi*y, 0.0, 0); break;
	case 1:
	case 2:  y =  __cos(pi*(0.5-y), 0.0); break;
	case 3:
	case 4:  y =  __sin(pi*(1.0-y), 0.0, 0); break;
	case 5:
	case 6:  y = -__cos(pi*(y-1.5), 0.0); break;
	default: y =  __sin(pi*(y-2.0), 0.0, 0); break;
	}
	return -y;
}
예제 #10
0
void
__sincos (double x, double *sinx, double *cosx)
{
  SET_RESTORE_ROUND_53BIT (FE_TONEAREST);

  *sinx = __sin (x);
  *cosx = __cos (x);
}
예제 #11
0
파일: s_sincos.c 프로젝트: walac/glibc
void
__sincos (double x, double *sinx, double *cosx)
{
  int32_t ix;

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

  /* |x| ~< pi/4 */
  ix &= 0x7fffffff;
  if (ix >= 0x7ff00000)
    {
      /* sin(Inf or NaN) is NaN */
      *sinx = *cosx = x - x;
    }
  else
    {
      *sinx = __sin (x);
      *cosx = __cos (x);
    }
}
예제 #12
0
파일: mathcalls.c 프로젝트: fidian/MathLib
Err mathlib_sin(UInt16 refnum, double x, double *result) {
#pragma unused(refnum)
	*result = __sin(x);
	return mlErrNone;
}
예제 #13
0
파일: hsin.c 프로젝트: sharugupta/OpenUH
/*
 * HSIN: SIN of real(kind=4)  - pass by value
 */
_f_real4
_HSIN( _f_real4 x )
{
	_f_real8 __sin(_f_real8 x);
	return ( (_f_real4) __sin((_f_real8) x) );
}
예제 #14
0
파일: sin.c 프로젝트: sharugupta/OpenUH
double sin( double x) {
  return __sin( x );
}
예제 #15
0
파일: sin.c 프로젝트: sharugupta/OpenUH
/*
 * SIN: SIN of real(kind=8)  - pass by address
 */
_f_real8
_SIN_( _f_real8 *x )
{
	_f_real8 __sin(_f_real8 x);
	return ((_f_real8) __sin((_f_real8) *x));
}
예제 #16
0
파일: e_gamma_r.c 프로젝트: AubrCool/glibc
double
__ieee754_gamma_r (double x, int *signgamp)
{
  int32_t hx;
  u_int32_t lx;

  EXTRACT_WORDS (hx, lx, x);

  if (__glibc_unlikely (((hx & 0x7fffffff) | lx) == 0))
    {
      /* Return value for x == 0 is Inf with divide by zero exception.  */
      *signgamp = 0;
      return 1.0 / x;
    }
  if (__builtin_expect (hx < 0, 0)
      && (u_int32_t) hx < 0xfff00000 && __rint (x) == x)
    {
      /* Return value for integer x < 0 is NaN with invalid exception.  */
      *signgamp = 0;
      return (x - x) / (x - x);
    }
  if (__glibc_unlikely ((unsigned int) hx == 0xfff00000 && lx == 0))
    {
      /* x == -Inf.  According to ISO this is NaN.  */
      *signgamp = 0;
      return x - x;
    }
  if (__glibc_unlikely ((hx & 0x7ff00000) == 0x7ff00000))
    {
      /* Positive infinity (return positive infinity) or NaN (return
	 NaN).  */
      *signgamp = 0;
      return x + x;
    }

  if (x >= 172.0)
    {
      /* Overflow.  */
      *signgamp = 0;
      return DBL_MAX * DBL_MAX;
    }
  else if (x > 0.0)
    {
      *signgamp = 0;
      int exp2_adj;
      double ret = gamma_positive (x, &exp2_adj);
      return __scalbn (ret, exp2_adj);
    }
  else if (x >= -DBL_EPSILON / 4.0)
    {
      *signgamp = 0;
      return 1.0 / x;
    }
  else
    {
      double tx = __trunc (x);
      *signgamp = (tx == 2.0 * __trunc (tx / 2.0)) ? -1 : 1;
      if (x <= -184.0)
	/* Underflow.  */
	return DBL_MIN * DBL_MIN;
      double frac = tx - x;
      if (frac > 0.5)
	frac = 1.0 - frac;
      double sinpix = (frac <= 0.25
		       ? __sin (M_PI * frac)
		       : __cos (M_PI * (0.5 - frac)));
      int exp2_adj;
      double ret = M_PI / (-x * sinpix * gamma_positive (-x, &exp2_adj));
      return __scalbn (ret, -exp2_adj);
    }
}