int main () { double a, b, c, x1, x2, D = -1.0 ; printf("For equation 0 = ax^2 + bx + c\n") ; while( D < 0 ) { //get coefficients get_coefs(&a, &b, &c) ; //compute determinant D = comp_D(a, b, c) ; //compute roots get_roots(a, b, D, &x1, &x2) ; //print values print_values(x1, x2, D) ; } }
static void populate_x12a_arma_model (MODEL *pmod, const char *path, const DATASET *dset, arma_info *ainfo) { char fname[MAXLEN]; int err; pmod->t1 = ainfo->t1; pmod->t2 = ainfo->t2; pmod->ncoeff = ainfo->nc; pmod->full_n = dset->n; err = gretl_model_allocate_storage(pmod); if (err) { pmod->errcode = err; return; } sprintf(fname, "%s.est", path); err = get_estimates(fname, pmod, ainfo); if (!err) { sprintf(fname, "%s.rsd", path); err = get_uhat(fname, pmod, dset); } if (!err) { sprintf(fname, "%s.lks", path); err = get_ll_stats(fname, pmod); } if (!err) { sprintf(fname, "%s.rts", path); err = get_roots(fname, pmod, ainfo); } #if 0 if (!err) { sprintf(fname, "%s.acm", path); err = get_x12a_vcv(fname, pmod, nc); /* also .rcm */ } #endif if (err) { fprintf(stderr, "problem reading X-12-ARIMA model info\n"); pmod->errcode = err; } else { write_arma_model_stats(pmod, ainfo, dset); } }
int main() { Coef coefs; // a, b and c for the quadratic eqaution Root roots; // Root struct with x1 and x1 int num, ret; // return value from num_roots() and get_roots() double a, b, c; // scratch variables double x1, x2; // scratch variables int count; // number of times the mock object qsolve_sqrt(0 is called. double x; // arguement passed to qsolve_sqrt() char str[100]; // messsaage for assert() double d; // scratch for discriminate double sqrtd; // scratch for sqrt(d) cunit_init(); // // A "good" unit test, need to allow for round off! // qsolve_roots() passes this one. ;-) // This allows about one base 10 least significant digit of error // (x - x1)*(x - x2) = 0 x1 = 3.1; x2 = 3.3; a = coefs.a = 1.0; b = coefs.b = -x1 + -x2; c = coefs.c = x1 * x2; d = b * b - 4.0 * a * c; sqrtd = sqrt(d); setup_mock_sqrt(d, sqrtd, cunit_dmacheps * 2.0 * d); num = num_roots(coefs); ret = get_roots(coefs, num, &roots); assert_eq("ret", ret, true); assert_feqrerr("x1", roots.x1, x2, 2.0 * cunit_dmacheps * 3.3); assert_feqrerr("x2", roots.x2, x1, 2.0 * cunit_dmacheps * 3.1); ret = check_mock_sqrt(&count, &x); snprintf(str, 99, "count ret = %d x =%20.61e", count, x); assert_eq(str, ret, 0); exit(0); }