コード例 #1
0
ファイル: parser.c プロジェクト: Zhouxiaoqing/ztiny
// ID && NUM && ...
static TreeNode *
_factor(void) {
	TreeNode *t = NULL;
	switch(token) {
		case LPAREN:
			_match(LPAREN);
			t = _exp();
			_match(RPAREN);
			break;
		case NUM:
			t = new_exp_node(ConstK);
			t->attr.val = atoi(token_string);
			_match(NUM);
			break;
		case ID:
			t = new_exp_node(IdK);
			t->attr.name = copy_string(token_string);
			_match(ID);
			break;
		default :
			_syntax_error("Unexpected token.\n");
			print_token(token, token_string);
			token = get_token();
	}
	return t;
}
コード例 #2
0
ファイル: floatgamma.c プロジェクト: ruphy/speedcrunch
char
_gamma(
  floatnum x,
  int digits)
{
  floatstruct tmp;
  int infinity;
  char result;

  if (float_cmp(&cMinus20, x) > 0)
  {
    float_create(&tmp);
    result = _lngamma_prim(x, &tmp, &infinity, digits)
             && infinity == 0
             && _exp(x, digits)
             && float_div(x, x, &tmp, digits + 1);
    float_free(&tmp);
    if (infinity != 0)
      return _seterror(x, ZeroDivide);
    if (!result)
      float_setnan(x);
    return result;
  }
  return _gammagtminus20(x, digits);
}
コード例 #3
0
ファイル: parser.c プロジェクト: Zhouxiaoqing/ztiny
static TreeNode *
_write_stmt(void) {
	TreeNode *t = new_stmt_node(WriteK);
	_match(WRITE);
	if (t != NULL) t->child[0] = _exp();
	return t;
}
コード例 #4
0
ファイル: parser.c プロジェクト: Zhouxiaoqing/ztiny
static TreeNode *
_repeat_stmt(void) {
	_match(REPEAT);
	TreeNode *t = new_stmt_node(RepeatK);
	if (t != NULL) t->child[0] = _stmt_sequence();
	_match(UNTIL);
	if (t != NULL) t->child[1] = _exp();
	return t;
}
コード例 #5
0
ファイル: parser.c プロジェクト: Zhouxiaoqing/ztiny
static TreeNode *
_assign_stmt(void) {
	TreeNode *t = new_stmt_node(AssignK);
	if (t != NULL && token == ID)
		t->attr.name = copy_string(token_string);
	_match(ID);
	_match(ASSIGN);
	if (t != NULL) t->child[0] = _exp();
	return t;
}
コード例 #6
0
ファイル: sinh.c プロジェクト: lawliet89/pascal2arm
double sinh(double x)
{
    int sign;
    ip_number ix,r;

    ix=_d2e(x);
    if (fp_uncommon(ix)) goto dom_error;
    sign=fp_sign(ix);
    fp_abs(ix);

    if (fp_grpow(ix,0)) {
        /* _sinh_lnv is REQUIRED to read in as a number with the lower part of   */
        /* its floating point representation zero.                               */
        ip_number w,z,z2;

        w=_esub(ix,&sinh_lnv);
        z=_exp(w);
        if (fp_error(z)) goto range_error;
        if (!fp_grpow(z,32)) {
            ip_number t;
            z2=z;
            t=_erdv(z,&sinh_vm2);
            fp_negate(t);
            z=_eadd(t,&z2);
        }
        z2=z;
        r=_eadd(_emul(z,&sinh_v2m1),&z2);
        fp_abs(r);
        r.word.hi|=sign;
    } else if (!fp_grpow(ix,-32)) return x;
    else {
        ip_number g,t,ix2;
        ix2=ix;
        g=_esquare(ix);
        /* Use a (minimax) rational approximation. See Cody & Waite.     */
        t=__fp_poly1(g,4,sinhp_poly);
        r=_erdv(__fp_poly0(g,3,sinhq_poly),&t);

        ix2.word.hi|=sign;           /* put sign back */
        r=__fp_spike(r,&ix2);        /* r=r*ix+ix */
    }
    if (fp_error(r)) goto range_error;
    return _e2d(r);

dom_error:
    return __fp_edom(sign_bit, TRUE);
range_error:
    return __fp_erange(ix.word.hi, TRUE);
}
コード例 #7
0
ファイル: floathmath.c プロジェクト: 0pq76r/SpeedCrunch
char
float_exp(
  floatnum x,
  int digits)
{
  signed char sgn;

  if (!chckmathparam(x, digits))
    return 0;
  sgn = float_getsign(x);
  if (_exp(x, digits))
    return 1;
  if (sgn < 0)
    return _seterror(x, Underflow);
  return _seterror(x, Overflow);
}
コード例 #8
0
ファイル: parser.c プロジェクト: Zhouxiaoqing/ztiny
static TreeNode *
_if_stmt(void) {
//     each node have 3 children, for IF-STMT:
// 0 : is EXP tree
// 1 : is stmt-sequence after THEN
// 2 : is stmt-sequence after ELSE
	TreeNode *t = new_stmt_node(IfK);
	_match(IF);
	if (t != NULL) t->child[0] = _exp();
	_match(THEN);
	if (t != NULL) t->child[1] = _stmt_sequence();
	if (token == ELSE) {
		_match(ELSE);
		if (t != NULL) t->child[2] = _stmt_sequence();
	}
	_match(END);
	return t;
}
コード例 #9
0
ファイル: tanh.c プロジェクト: lawliet89/pascal2arm
double tanh(double x)
{
  /* The first two exits avoid premature overflow as well as needless use  */
  /* of the exp() function.                                                */
  int sign;
  dp_number fx;

  fx.d=x;

  sign=fp_sign(fx); fp_abs(fx);

  if (fx.d<=27.0) {
    ip_number ix=_d2e(fx.d);
    if (fp_uncommon(ix)) goto uncommon;

    if (_egr(ix,&log3_by_2)) {
      ix=_emul(ix,&two);
      ix=_exp(ix);
      if (fp_error(ix)) goto error;
      ix=_erdv(_eadd(ix,&one),&two); fp_negate(ix); ix=_eadd(ix,&one);
    } else {
      if (fp_grpow(ix,-32)) {
        ip_number g,t,r1,r2,ix2;
        ix2=ix;
        g=_esquare(ix2);
        r1=__fp_poly1(g,3,tanhp_poly);
        r2=__fp_poly0(g,3,tanhq_poly);
        t=_erdv(r2,&r1);
        ix=__fp_spike(t,&ix2);   /* ix=g*ix+ix */
      }
    }
    ix.word.hi|=sign;
    if (fp_error(ix)) goto error;
    return _e2d(ix);
  } else {
    dp_number result;
    result.word.hi=0x3ff00000 | sign;
    result.word.lo=0;
    return result.d;
  }

 error: return __fp_erange(sign, TRUE);
 uncommon: return __fp_edom(0, TRUE);
}
コード例 #10
0
ファイル: rpn.cpp プロジェクト: aliushn/Tengine
	void bbox_tranform_inv( float* m_box,float* local_anchors,
                            int height,int width,int channel,int num_anchors )
    {
		int step = height*width;
		float * a = m_box;
		float * b = local_anchors;
		int c_4=channel/4;
		for (int i = 0; i < c_4; ++i)
		{
			_axpy_(2*step, b + (i * 4 + 0)*step, b + (i * 4 + 2)*step);
			_add_one(2 * step, b + (i * 4 + 2)*step);
			_axpy_half(2*step, b + (i * 4 + 2)*step, b + (i * 4 + 0)*step);
			
			_mul(2 * step, b + (i * 4 + 2)*step, a + (i * 4 + 0)*step, a + (i * 4 + 0)*step);
			_add(2 * step, b + (i * 4 + 0)*step, a + (i * 4 + 0)*step, a + (i * 4 + 0)*step);

			_exp(2*step, a + (i * 4 + 2)*step, a + (i * 4 + 2)*step);
			_mul(2 * step, b + (i * 4 + 2)*step, a + (i * 4 + 2)*step, a + (i * 4 + 2)*step);
		}
	}
コード例 #11
0
ファイル: floatgamma.c プロジェクト: ruphy/speedcrunch
char
_gammagtminus20(
  floatnum x,
  int digits)
{
  floatstruct factor;
  int ofs;
  char result;

  float_create(&factor);
  ofs = _ofs(x, digits+1);
  float_copy(&factor, x, digits+1);
  _pochhammer_su(&factor, ofs, digits);
  float_addi(x, x, ofs, digits+2);
  result = _lngammabigx(x, digits) 
           && _exp(x, digits) 
           && float_div(x, x, &factor, digits+1);
  float_free(&factor);
  if (!result)
    float_setnan(x);
  return result;
}
コード例 #12
0
ファイル: floatgamma.c プロジェクト: ruphy/speedcrunch
static char
_pochhammer_g(
  floatnum x,
  cfloatnum n,
  int digits)
{
  /* this generalizes the rising Pochhammer symbol using the
     formula pochhammer(x,n) = Gamma(x+1)/Gamma(x-n+1) */
  floatstruct tmp, factor1, factor2;
  int inf1, inf2;
  char result;

  float_create(&tmp);
  float_create(&factor1);
  float_create(&factor2);
  inf2 = 0;
  float_add(&tmp, x, n, digits+1);
  result = _lngamma_prim(x, &factor1, &inf1, digits)
           && _lngamma_prim(&tmp, &factor2, &inf2, digits)
           && (inf2 -= inf1) <= 0;
  if (inf2 > 0)
    float_seterror(ZeroDivide);
  if (result && inf2 < 0)
    float_setzero(x);
  if (result && inf2 == 0)
    result = float_div(&factor1, &factor1, &factor2, digits+1)
             && float_sub(x, &tmp, x, digits+1)
             && _exp(x, digits)
             && float_mul(x, x, &factor1, digits+1);
  float_free(&tmp);
  float_free(&factor2);
  float_free(&factor1);
  if (!result)
    float_setnan(x);
  return result;
}
コード例 #13
0
ファイル: floatseries.c プロジェクト: ruphy/speedcrunch
char
erfcsum(
  floatnum x, /* should be the square of the parameter to erfc */
  int digits)
{
  int i, workprec;
  floatstruct sum, smd;
  floatnum Ei;

  if (digits > erfcdigits)
  {
    /* cannot re-use last evaluation's intermediate results */
    for (i = MAXERFCIDX; --i >= 0;)
      /* clear all exp(-k*k*alpha*alpha) to indicate their absence */
      float_free(&erfccoeff[i]);
    /* current precision */
    erfcdigits = digits;
    /* create new alpha appropriate for the desired precision
       This alpha need not be high precision, any alpha near the
       one evaluated here would do */
    float_muli(&erfcalpha, &cLn10, digits + 4, 3);
    float_sqrt(&erfcalpha, 3);
    float_div(&erfcalpha, &cPi, &erfcalpha, 3);
    float_mul(&erfcalphasqr, &erfcalpha, &erfcalpha, EXACT);
    /* the exp(-k*k*alpha*alpha) are later evaluated iteratively.
       Initiate the iteration here */
    float_copy(&erfct2, &erfcalphasqr, EXACT);
    float_neg(&erfct2);
    _exp(&erfct2, digits + 3); /* exp(-alpha*alpha) */
    float_copy(erfccoeff, &erfct2, EXACT); /* start value */
    float_mul(&erfct3, &erfct2, &erfct2, digits + 3); /* exp(-2*alpha*alpha) */
  }
  float_create(&sum);
  float_create(&smd);
  float_setzero(&sum);
  for (i = 0; ++i < MAXERFCIDX;)
  {
    Ei = &erfccoeff[i-1];
    if (float_isnan(Ei))
    {
      /* if exp(-i*i*alpha*alpha) is not available, evaluate it from
         the coefficient of the last summand */
      float_mul(&erfct2, &erfct2, &erfct3, workprec + 3);
      float_mul(Ei, &erfct2, &erfccoeff[i-2], workprec + 3);
    }
    /* Ei finally decays rapidly. save some time by adjusting the
       working precision */
    workprec = digits + float_getexponent(Ei) + 1;
    if (workprec <= 0)
      break;
    /* evaluate the summand exp(-i*i*alpha*alpha)/(i*i*alpha*alpha+x) */
    float_muli(&smd, &erfcalphasqr, i*i, workprec);
    float_add(&smd, x, &smd, workprec + 2);
    float_div(&smd, Ei, &smd, workprec + 1);
    /* add summand to the series */
    float_add(&sum, &sum, &smd, digits + 3);
  }
  float_move(x, &sum);
  float_free(&smd);
  return 1;
}
コード例 #14
0
ファイル: mix.cpp プロジェクト: gouchangjiang/opengeoda
/*
Returns the (1-tailed) probability value associated with the provided
chi-square value and df.  Adapted from chisq.c in Gary Perlman's |Stat.
*/
double chicdf(double chisq, int df)
{
    const double BIG = 20.0;
		double const pi = 3.141592653589793;
		double a,c,e,s,y,z;
		bool even = false;
		int k = df /2;

    if (chisq <=0 || df < 1)
        return 1.0;

    a = 0.5 * chisq;

    if (df==(k*2))
        even = true;

    if (df > 1)
        y = _exp(-a);

    if (even)
        s = y;
    else
        s = 2.0 * zprob(-sqrt(chisq));
    if (df > 2)
		{
        double chisq1 = 0.5 * (df - 1.0);
        if (even)
            z = 1.0;
        else
            z = 0.5;

        if (a > BIG)
        {
            if (even)
                e = 0.0;
            else
                e = log(sqrt(pi));
            c = log(a);
            while (z <= chisq)
						{
                e = log(z) + e;
                s = s + _exp(c*z-a-e);
                z = z + 1.0;
						}
            return s;
				}
        else
				{
            if (even)
                e = 1.0;
            else
                e = 1.0 / sqrt(pi) / sqrt(a);
            c = 0.0;
            while (z <= chisq)
						{
                e = e * (a/float(z));
                c = c + e;
                z = z + 1.0;
						}
            return (c*y+s);
				}
			}
    else
        return s;

}