예제 #1
0
파일: n_log1p.c 프로젝트: AgamAgarwal/minix
double
log1p(double x)
{
	static const double zero=0.0, negone= -1.0, one=1.0,
		      half=1.0/2.0, small=1.0E-20;   /* 1+small == 1 */
	double z,s,t,c;
	int k;

#if !defined(__vax__)&&!defined(tahoe)
	if(x!=x) return(x);	/* x is NaN */
#endif	/* !defined(__vax__)&&!defined(tahoe) */

	if(finite(x)) {
	   if( x > negone ) {

	   /* argument reduction */
	      if(copysign(x,one)<small) return(x);
	      k=logb(one+x); z=scalb(x,-k); t=scalb(one,-k);
	      if(z+t >= sqrt2 )
		  { k += 1 ; z *= half; t *= half; }
	      t += negone; x = z + t;
	      c = (t-x)+z ;		/* correction term for x */

 	   /* compute log(1+x)  */
              s = x/(2+x); t = x*x*half;
	      c += (k*ln2lo-c*x);
	      z = c+s*(t+__log__L(s*s));
	      x += (z - t) ;

	      return(k*ln2hi+x);
	   }
	/* end of if (x > negone) */

	    else {
#if defined(__vax__)||defined(tahoe)
		if ( x == negone )
		    return (infnan(-ERANGE));	/* -INF */
		else
		    return (infnan(EDOM));	/* NaN */
#else	/* defined(__vax__)||defined(tahoe) */
		/* x = -1, return -INF with signal */
		if ( x == negone ) return( negone/zero );

		/* negative argument for log, return NaN with signal */
	        else return ( zero / zero );
#endif	/* defined(__vax__)||defined(tahoe) */
	    }
	}
    /* end of if (finite(x)) */

    /* log(-INF) is NaN */
	else if(x<0)
	     return(zero/zero);

    /* log(+INF) is INF */
	else return(x);
}
예제 #2
0
파일: cosh.c 프로젝트: andy345/vxworks5
double cosh
    (
    double x	/* value to compute the hyperbolic cosine of */
    )

    {
	static double half=1.0/2.0,one=1.0, small=1.0E-18; /* fl(1+small)==1 */
	double scalb(),copysign(),exp(),exp__E(),t;

#if !defined(vax)&&!defined(tahoe)
	if(x!=x) return(x);	/* x is NaN */
#endif	/* !defined(vax)&&!defined(tahoe) */
	if((x=copysign(x,one)) <= 22)
	    if(x<0.3465)
		if(x<small) return(one+x);
		else {t=x+exp__E(x,0.0);x=t+t; return(one+t*t/(2.0+x)); }

	    else /* for x lies in [0.3465,22] */
	        { t=exp(x); return((t+one/t)*half); }

	if( lnovfl <= x && x <= (lnovfl+0.7))
        /* for x lies in [lnovfl, lnovfl+ln2], decrease x by ln(2^(max+1))
         * and return 2^max*exp(x) to avoid unnecessary overflow
         */
	    return(scalb(exp((x-mln2hi)-mln2lo), max));

	else
	    return(exp(x)*half);	/* for large x,  cosh(x)=exp(x)/2 */
    }
예제 #3
0
int main() {
    double x = 1.0;
    double y = 1.0;
    int i = 1;
    acosh(x);
    asinh(x);
    atanh(x);
    cbrt(x);
    expm1(x);
    erf(x);
    erfc(x);
    isnan(x);
    j0(x);
    j1(x);
    jn(i,x);
    ilogb(x);
    logb(x);
    log1p(x);
    rint(x);
    y0(x);
    y1(x);
    yn(i,x);
#   ifdef _THREAD_SAFE
    gamma_r(x,&i);
    lgamma_r(x,&i);
#   else
    gamma(x);
    lgamma(x);
#   endif
    hypot(x,y);
    nextafter(x,y);
    remainder(x,y);
    scalb(x,y);
    return 0;
}
예제 #4
0
double ldexp ( double value, int exp )
      {
      if ( exp > SHRT_MAX )
	    exp = SHRT_MAX;
      else if ( exp < -SHRT_MAX )
	    exp = -SHRT_MAX;
      return scalb ( value, exp  );
      }
예제 #5
0
double
__exp__D(double x, double c)
{
	double z, hi, lo;
	int k;

	if (isnan(x))	/* x is NaN */
		return(x);
	if ( x <= lnhuge ) {
		if ( x >= lntiny ) {

		    /* argument reduction : x --> x - k*ln2 */
			z = invln2*x;
			k = z + copysign(.5, x);

		    /* express (x+c)-k*ln2 as hi-lo and let x=hi-lo rounded */

			hi=(x-k*ln2hi);			/* Exact. */
			x= hi - (lo = k*ln2lo-c);
		    /* return 2^k*[1+x+x*c/(2+c)]  */
			z=x*x;
			c= x - z*(p1+z*(p2+z*(p3+z*(p4+z*p5))));
			c = (x*c)/(2.0-c);

			return  scalb(1.+(hi-(lo - c)), k);
		}
		/* end of x > lntiny */

		else
		     /* exp(-big#) underflows to zero */
		     if(finite(x))  return(scalb(1.0,-5000));

		     /* exp(-INF) is zero */
		     else return(0.0);
	}
	/* end of x < lnhuge */

	else
	/* exp(INF) is INF, exp(+big#) overflows to INF */
	    return( finite(x) ?  scalb(1.0,5000)  : x);
}
double
sinh(double x)
{
	static const double  one=1.0, half=1.0/2.0 ;
	double t, sign;
#if !defined(__vax__)&&!defined(tahoe)
	if(x!=x) return(x);	/* x is NaN */
#endif	/* !defined(__vax__)&&!defined(tahoe) */
	sign=copysign(one,x);
	x=copysign(x,one);
	if(x<lnovfl)
	    {t=expm1(x); return(copysign((t+t/(one+t))*half,sign));}

	else if(x <= lnovfl+0.7)
		/* subtract x by ln(2^(max+1)) and return 2^max*exp(x)
	    		to avoid unnecessary overflow */
	    return(copysign(scalb(one+expm1((x-mln2hi)-mln2lo),max),sign));

	else  /* sinh(+-INF) = +-INF, sinh(+-big no.) overflow to +-INF */
	    return( expm1(x)*sign );
}
예제 #7
0
double
significand(double x)
{
	return scalb(x,(double) -ilogb(x));
}
예제 #8
0
static void
F(compile_test) (void)
{
  TYPE a, b, c = 1.0;
  complex TYPE d;
  int i;
  int saved_count;
  long int j;
  long long int k;

  a = cos (cos (x));
  b = acos (acos (a));
  a = sin (sin (x));
  b = asin (asin (a));
  a = tan (tan (x));
  b = atan (atan (a));
  c = atan2 (atan2 (a, c), atan2 (b, x));
  a = cosh (cosh (x));
  b = acosh (acosh (a));
  a = sinh (sinh (x));
  b = asinh (asinh (a));
  a = tanh (tanh (x));
  b = atanh (atanh (a));
  a = exp (exp (x));
  b = log (log (a));
  a = log10 (log10 (x));
  b = ldexp (ldexp (a, 1), 5);
  a = frexp (frexp (x, &i), &i);
  b = expm1 (expm1 (a));
  a = log1p (log1p (x));
  b = logb (logb (a));
  a = exp2 (exp2 (x));
  b = log2 (log2 (a));
  a = pow (pow (x, a), pow (c, b));
  b = sqrt (sqrt (a));
  a = hypot (hypot (x, b), hypot (c, a));
  b = cbrt (cbrt (a));
  a = ceil (ceil (x));
  b = fabs (fabs (a));
  a = floor (floor (x));
  b = fmod (fmod (a, b), fmod (c, x));
  a = nearbyint (nearbyint (x));
  b = round (round (a));
  a = trunc (trunc (x));
  b = remquo (remquo (a, b, &i), remquo (c, x, &i), &i);
  j = lrint (x) + lround (a);
  k = llrint (b) + llround (c);
  a = erf (erf (x));
  b = erfc (erfc (a));
  a = tgamma (tgamma (x));
  b = lgamma (lgamma (a));
  a = rint (rint (x));
  b = nextafter (nextafter (a, b), nextafter (c, x));
  a = nextdown (nextdown (a));
  b = nexttoward (nexttoward (x, a), c);
  a = nextup (nextup (a));
  b = remainder (remainder (a, b), remainder (c, x));
  a = scalb (scalb (x, a), (TYPE) (6));
  k = scalbn (a, 7) + scalbln (c, 10l);
  i = ilogb (x);
  j = llogb (x);
  a = fdim (fdim (x, a), fdim (c, b));
  b = fmax (fmax (a, x), fmax (c, b));
  a = fmin (fmin (x, a), fmin (c, b));
  b = fma (sin (a), sin (x), sin (c));
  a = totalorder (totalorder (x, b), totalorder (c, x));
  b = totalordermag (totalordermag (x, a), totalordermag (c, x));

#ifdef TEST_INT
  a = atan2 (i, b);
  b = remquo (i, a, &i);
  c = fma (i, b, i);
  a = pow (i, c);
#endif
  x = a + b + c + i + j + k;

  saved_count = count;
  if (ccount != 0)
    ccount = -10000;

  d = cos (cos (z));
  z = acos (acos (d));
  d = sin (sin (z));
  z = asin (asin (d));
  d = tan (tan (z));
  z = atan (atan (d));
  d = cosh (cosh (z));
  z = acosh (acosh (d));
  d = sinh (sinh (z));
  z = asinh (asinh (d));
  d = tanh (tanh (z));
  z = atanh (atanh (d));
  d = exp (exp (z));
  z = log (log (d));
  d = sqrt (sqrt (z));
  z = conj (conj (d));
  d = fabs (conj (a));
  z = pow (pow (a, d), pow (b, z));
  d = cproj (cproj (z));
  z += fabs (cproj (a));
  a = carg (carg (z));
  b = creal (creal (d));
  c = cimag (cimag (z));
  x += a + b + c + i + j + k;
  z += d;

  if (saved_count != count)
    count = -10000;

  if (0)
    {
      a = cos (y);
      a = acos (y);
      a = sin (y);
      a = asin (y);
      a = tan (y);
      a = atan (y);
      a = atan2 (y, y);
      a = cosh (y);
      a = acosh (y);
      a = sinh (y);
      a = asinh (y);
      a = tanh (y);
      a = atanh (y);
      a = exp (y);
      a = log (y);
      a = log10 (y);
      a = ldexp (y, 5);
      a = frexp (y, &i);
      a = expm1 (y);
      a = log1p (y);
      a = logb (y);
      a = exp2 (y);
      a = log2 (y);
      a = pow (y, y);
      a = sqrt (y);
      a = hypot (y, y);
      a = cbrt (y);
      a = ceil (y);
      a = fabs (y);
      a = floor (y);
      a = fmod (y, y);
      a = nearbyint (y);
      a = round (y);
      a = trunc (y);
      a = remquo (y, y, &i);
      j = lrint (y) + lround (y);
      k = llrint (y) + llround (y);
      a = erf (y);
      a = erfc (y);
      a = tgamma (y);
      a = lgamma (y);
      a = rint (y);
      a = nextafter (y, y);
      a = nexttoward (y, y);
      a = remainder (y, y);
      a = scalb (y, (const TYPE) (6));
      k = scalbn (y, 7) + scalbln (y, 10l);
      i = ilogb (y);
      j = llogb (y);
      a = fdim (y, y);
      a = fmax (y, y);
      a = fmin (y, y);
      a = fma (y, y, y);
      a = totalorder (y, y);
      a = totalordermag (y, y);

#ifdef TEST_INT
      a = atan2 (i, y);
      a = remquo (i, y, &i);
      a = fma (i, y, i);
      a = pow (i, y);
#endif

      d = cos ((const complex TYPE) z);
      d = acos ((const complex TYPE) z);
      d = sin ((const complex TYPE) z);
      d = asin ((const complex TYPE) z);
      d = tan ((const complex TYPE) z);
      d = atan ((const complex TYPE) z);
      d = cosh ((const complex TYPE) z);
      d = acosh ((const complex TYPE) z);
      d = sinh ((const complex TYPE) z);
      d = asinh ((const complex TYPE) z);
      d = tanh ((const complex TYPE) z);
      d = atanh ((const complex TYPE) z);
      d = exp ((const complex TYPE) z);
      d = log ((const complex TYPE) z);
      d = sqrt ((const complex TYPE) z);
      d = pow ((const complex TYPE) z, (const complex TYPE) z);
      d = fabs ((const complex TYPE) z);
      d = carg ((const complex TYPE) z);
      d = creal ((const complex TYPE) z);
      d = cimag ((const complex TYPE) z);
      d = conj ((const complex TYPE) z);
      d = cproj ((const complex TYPE) z);
    }
}
float scalbf (float x, float y)
{
	return (float) scalb( (double)x, (double)y );
}
예제 #10
0
파일: n_atan2.c 프로젝트: AgamAgarwal/minix
double
atan2(double y, double x)
{
	static const double zero=0, one=1, small=1.0E-9, big=1.0E18;
	double t,z,signy,signx,hi,lo;
	int k,m;

#if !defined(__vax__)&&!defined(tahoe)
    /* if x or y is NAN */
	if(x!=x) return(x); if(y!=y) return(y);
#endif	/* !defined(__vax__)&&!defined(tahoe) */

    /* copy down the sign of y and x */
	signy = copysign(one,y) ;
	signx = copysign(one,x) ;

    /* if x is 1.0, goto begin */
	if(x==1) { y=copysign(y,one); t=y; if(finite(t)) goto begin;}

    /* when y = 0 */
	if(y==zero) return((signx==one)?y:copysign(PI,signy));

    /* when x = 0 */
	if(x==zero) return(copysign(PIo2,signy));

    /* when x is INF */
	if(!finite(x))
	    if(!finite(y))
		return(copysign((signx==one)?PIo4:3*PIo4,signy));
	    else
		return(copysign((signx==one)?zero:PI,signy));

    /* when y is INF */
	if(!finite(y)) return(copysign(PIo2,signy));

    /* compute y/x */
	x=copysign(x,one);
	y=copysign(y,one);
	if((m=(k=logb(y))-logb(x)) > 60) t=big+big;
	    else if(m < -80 ) t=y/x;
	    else { t = y/x ; y = scalb(y,-k); x=scalb(x,-k); }

    /* begin argument reduction */
begin:
	if (t < 2.4375) {

	/* truncate 4(t+1/16) to integer for branching */
	    k = 4 * (t+0.0625);
	    switch (k) {

	    /* t is in [0,7/16] */
	    case 0:
	    case 1:
		if (t < small)
		    { big + small ;  /* raise inexact flag */
		      return (copysign((signx>zero)?t:PI-t,signy)); }

		hi = zero;  lo = zero;  break;

	    /* t is in [7/16,11/16] */
	    case 2:
		hi = athfhi; lo = athflo;
		z = x+x;
		t = ( (y+y) - x ) / ( z +  y ); break;

	    /* t is in [11/16,19/16] */
	    case 3:
	    case 4:
		hi = PIo4; lo = zero;
		t = ( y - x ) / ( x + y ); break;

	    /* t is in [19/16,39/16] */
	    default:
		hi = at1fhi; lo = at1flo;
		z = y-x; y=y+y+y; t = x+x;
		t = ( (z+z)-x ) / ( t + y ); break;
	    }
	}
	/* end of if (t < 2.4375) */

	else
	{
	    hi = PIo2; lo = zero;

	    /* t is in [2.4375, big] */
	    if (t <= big)  t = - x / y;

	    /* t is in [big, INF] */
	    else
	      { big+small;	/* raise inexact flag */
		t = zero; }
	}
    /* end of argument reduction */

    /* compute atan(t) for t in [-.4375, .4375] */
	z = t*t;
#if defined(__vax__)||defined(tahoe)
	z = t*(z*(a1+z*(a2+z*(a3+z*(a4+z*(a5+z*(a6+z*(a7+z*(a8+
			z*(a9+z*(a10+z*(a11+z*a12))))))))))));
#else	/* defined(__vax__)||defined(tahoe) */
	z = t*(z*(a1+z*(a2+z*(a3+z*(a4+z*(a5+z*(a6+z*(a7+z*(a8+
			z*(a9+z*(a10+z*a11)))))))))));
#endif	/* defined(__vax__)||defined(tahoe) */
	z = lo - z; z += t; z += hi;

	return(copysign((signx>zero)?z:PI-z,signy));
}
static int
mainInt()
{
    long int			n = N, n8 = N8, m, i, j;
    signed long			vDotProduct, sDotProduct;
    signed short		*sx, *sy;
    vector signed short	*x, *y;
    IntegerToVector		*sX, *sY;

    sx = (short *) getMemory( 4*(n+3) );
    if (sx == nil)
        return 0;
    sy = (short *) getMemory( 4*(n+3) );
    if (sy == nil)
        return 0;

    x = (vector signed short *) getMemory( n8*16 );
    if ( x == nil)
        return 0;
    y = (vector signed short *) getMemory( n8*16 );
    if ( y == nil)
        return 0;

    sX = (IntegerToVector *) getMemory( n8*16 );
    if (sX == nil)
        return 0;
    sY = (IntegerToVector *) getMemory( n8*16 );
    if (sY == nil)
        return 0;

    for ( i = 0; i < n; i++ )
    {
        sx[i] = ( signed short ) scalb(( M_PI * ( double ) ( i ) / ( double ) n ), 8) + 0.5;
        sy[i] = ( signed short ) scalb(( M_PI * ( double ) ( n - i ) / ( double ) n ), 8) + 0.5;
    }

    m = n % 8;
    if (m != 0)
        for (i = n; i < n + 8 - m; i++)
        {
            sx[i] = 0.0;
            sy[i] = 0.0;
        }

    for ( i = 0; i < n8; i++ )
        for ( j = 0; j < 8; j++ )
        {
            sX[i].sInt[j] = sx[i*8+j];
            sY[i].sInt[j] = sy[i*8+j];
        }

    for ( i = 0; i < n8; i++ )
    {
        x[i] = sX[i].vInt;
        y[i] = sY[i].vInt;
    }

    vDotProduct = vIntDotProduct ( x, y, n8 );

    printf ( "\nVector dot product = %10d\n", (int) vDotProduct );

    return 0;
}
예제 #12
0
TEST(math, scalb) {
  ASSERT_DOUBLE_EQ(12.0, scalb(3.0, 2.0));
}
예제 #13
0
TEST(math, scalb) {
  ASSERT_FLOAT_EQ(12.0, scalb(3.0, 2.0));
}