예제 #1
0
파일: stable.c 프로젝트: cran/gnlm
static double romberg(double (*fcn)(double), double eps)
{
  int j,j1;
  double sum,errsum=0,x[16],fx[16];

  x[0]=1.0;
  for(j=0;j<16;j++){
    j1=j+1;
    fx[j]=evalfn(fcn,j1);
    if(j1>=5){
      interp(&x[j1-5],&fx[j1-5],&sum,&errsum);
      if(fabs(errsum)<eps*fabs(sum))return(sum);}
    x[j1]=x[j]/9.0;
    fx[j1]=fx[j];}
  sum=R_NaN;
  return(sum);}
예제 #2
0
파일: eval.c 프로젝트: chenguo/dash
void
evaltree(union node *n, int flags)
{
	int checkexit = 0;
	void (*evalfn)(union node *, int);
	unsigned isor;
	int status;
	if (n == NULL) {
		//TRACE(("evaltree(NULL) called\n"));
		goto out;
	}
#ifndef SMALL
	displayhist = 1;	/* show history substitutions done with fc */
#endif
	TRACE(("pid %d, evaltree(%p: %d, %d, %p) called\n",
	    getpid(), n, n->type, flags));
	switch (n->type) {
	default:
#ifdef DEBUG
#ifndef USE_GLIBC_STDIO
		flushout(out1);
#endif
		break;
#endif
	case NNOT:
		evaltree(n->nnot.com, EV_TESTED);
		status = !exitstatus;
		goto setstatus;
	case NREDIR:
		expredir(n->nredir.redirect);
		status = redirectsafe(n->nredir.redirect, REDIR_PUSH);
		if (!status) {
			evaltree(n->nredir.n, flags & EV_TESTED);
			status = exitstatus;
		}
		popredir(0);
		goto setstatus;
	case NCMD:
#ifdef notyet
		if (eflag && !(flags & EV_TESTED))
			checkexit = ~0;
		evalcommand(n, flags, (struct backcmd *)NULL);
		break;
#else
		evalfn = evalcommand;
checkexit:
		if (eflag && !(flags & EV_TESTED))
			checkexit = ~0;
		goto calleval;
#endif
	case NFOR:
		evalfn = evalfor;
		goto calleval;
	case NWHILE:
	case NUNTIL:
		evalfn = evalloop;
		goto calleval;
	case NSUBSHELL:
	case NBACKGND:
		evalfn = evalsubshell;
		evalsubshell (n, flags);
	case NPIPE:
		evalfn = evalpipe;
#ifdef notyet
		if (eflag && !(flags & EV_TESTED))
			checkexit = ~0;
		goto calleval;
#else
		goto checkexit;
#endif
	case NCASE:
		evalfn = evalcase;
		goto calleval;
	case NAND:
	case NOR:
	case NSEMI:
#if NAND + 1 != NOR
#error NAND + 1 != NOR
#endif
#if NOR + 1 != NSEMI
#error NOR + 1 != NSEMI
#endif
		isor = n->type - NAND;
		evaltree(
			n->nbinary.ch1,
			(flags | ((isor >> 1) - 1)) & EV_TESTED
		);
		if (!exitstatus == isor)
			break;
		if (!evalskip) {
			n = n->nbinary.ch2;
evaln:
			evaltree(n, flags);
			break;
calleval:
			evalfn(n, flags);
			break;
		}
		break;
	case NIF:
		evaltree(n->nif.test, EV_TESTED);
		if (evalskip)
			break;
		if (exitstatus == 0) {
			n = n->nif.ifpart;
			goto evaln;
		} else if (n->nif.elsepart) {
			n = n->nif.elsepart;
			goto evaln;
		}
		goto success;
	case NDEFUN:
		defun(n->narg.text, n->narg.next);
success:
		status = 0;
setstatus:
		exitstatus = status;
		break;
	}
out:
	if ((checkexit & exitstatus) ||
	    (pendingsigs && dotrap()) ||
	    (flags & EV_EXIT))
		exraise(EXEXIT);
}