Пример #1
0
/* Parse and evaluate addition and subtraction expressions */
struct val *
eval3(void)
{
	struct val     *l, *r;
	enum token	op;

	l = eval4();
	while ((op = token) == ADD || op == SUB) {
		nexttoken(0);
		r = eval4();

		if (!to_integer(l) || !to_integer(r)) {
			errx(2, "non-numeric argument");
		}

		if (op == ADD) {
			l->u.i += r->u.i;
		} else {
			l->u.i -= r->u.i;
		}

		free_value(r);
	}

	return l;
}
Пример #2
0
static VALUE *eval3(void)
{
	VALUE *l, *r;
	int op;
	arith_t val;

	l = eval4();
	while (1) {
		op = nextarg("+");
		if (!op) {
			op = nextarg("-");
			if (!op) return l;
		}
		G.args++;
		r = eval4();
		val = arithmetic_common(l, r, op);
		freev(l);
		freev(r);
		l = int_value(val);
	}
}
Пример #3
0
static inline_macro int
drizzle_polynomial(void* state,
                   const double xd, const double yd,
                   const integer_t n,
                   const double* xin /*[n]*/, const double* yin /*[n]*/,
                   /* Output parameters */
                   double* xout, double* yout,
                   struct driz_error_t* error) {
  struct mapping_param_t* m = (struct mapping_param_t*)state;
  double xdoff, ydoff;
  integer_t i;
  bool_t new_reference;

  /* Check for the presence of "refpix" additional information in the
     coefficients.  If it is, set a flag and offset again */
  if (m->coeff_type > COEFF_OFFSET / 2) {
    new_reference = TRUE;
    m->coeff_type -= COEFF_OFFSET;
    xdoff = m->xcen - m->x_coeffs[m->num_coeffs - 1] + 1.0;
    ydoff = m->ycen - m->y_coeffs[m->num_coeffs - 1] + 1.0;
    m->num_coeffs--;
  } else {
    new_reference = FALSE;
    xdoff = 2.0;
    ydoff = 2.0;
  }

  if (m->coeff_type == 3) {
    for (i = 0; i < n; ++i) {
      xout[i] = eval3(xin[i] + xdoff, yin[i] + ydoff, m->x_coeffs) - xdoff;
      yout[i] = eval3(xin[i] + xdoff, yin[i] + ydoff, m->y_coeffs) - ydoff;
    }
  } else if (m->coeff_type == 4) {
    for (i = 0; i < n; ++i) {
      xout[i] = eval4(xin[i] + xdoff, yin[i] + ydoff, m->x_coeffs) - xdoff;
      yout[i] = eval4(xin[i] + xdoff, yin[i] + ydoff, m->y_coeffs) - ydoff;
    }
  } else if (m->coeff_type == 5) {
    for (i = 0; i < n; ++i) {
      xout[i] = eval5(xin[i] + xdoff, yin[i] + ydoff, m->x_coeffs) - xdoff;
      yout[i] = eval5(xin[i] + xdoff, yin[i] + ydoff, m->y_coeffs) - ydoff;
    }
  } else if (m->coeff_type >= 6 || m->coeff_type == 1 || m->coeff_type == 2) {
    for (i = 0; i < n; ++i) {
      if (evaln(xin[i] + xdoff, yin[i] + ydoff, m->x_coeffs, m->coeff_type, &xout[i], error) ||
          evaln(xin[i] + xdoff, yin[i] + ydoff, m->y_coeffs, m->coeff_type, &yout[i], error))
        return 1;
      xout[i] -= xdoff;
      yout[i] -= ydoff;
    }
  } else if (m->coeff_type == -3) {
    for (i = 0; i < n; ++i) {
      rad3(xin[i] + xdoff, yin[i] + ydoff, m->x_coeffs, &xout[i], &yout[i]);
      xout[i] -= xdoff;
      yout[i] -= ydoff;
    }
  } else {
    driz_error_format_message(error, "Invalid coefficient type %d", m->coeff_type);
    return 1;
  }

  if (new_reference) {
    m->coeff_type += COEFF_OFFSET;
    m->num_coeffs++;
  }

  return 0;
}