Poly *poly_sub(Poly *poly1, Poly *poly2) //return poly1-poly2 { Poly *poly; Term *term1, *term2; term1 = poly1->head; term2 = poly2->head; poly = poly_new(); while (term1 != NULL && term2 != NULL) { if (poly_data(term1)->expo > poly_data(term2)->expo) { poly_add_term(poly, term_new(poly_data(term1)->coef, poly_data(term1)->expo)); term1 = term1->next; } else if (poly_data(term1)->expo == poly_data(term2)->expo) { if (poly_data(term1)->coef - poly_data(term2)->coef != 0) poly_add_term(poly, term_new(poly_data(term1)->coef - poly_data(term2)->coef, poly_data(term1)->expo)); term1 = term1->next; term2 = term2->next; } else { poly_add_term(poly, term_new(-poly_data(term2)->coef, poly_data(term2)->expo)); term2 = term2->next; } } if (term1 == NULL) { while (term2 != NULL) { poly_add_term(poly, term_new(-poly_data(term2)->coef, poly_data(term2)->expo)); term2 = term2->next; } } else if (term2 == NULL) { while (term1 != NULL) { poly_add_term(poly, term_new(poly_data(term1)->coef, poly_data(term1)->expo)); term1 = term1->next; } } return poly; }
Poly *poly_term_multi(Poly *poly, Term *term) { Poly *retPoly; Term *iter; //iterator retPoly = poly_new(); // the return polynomial for (iter = poly->head; iter != NULL; iter = iter->next) { poly_add_term(retPoly, term_new(poly_data(iter)->coef * poly_data(term)->coef, poly_data(iter)->expo + poly_data(term)->expo)); } return retPoly; }
Poly *poly_parse(int size) { Poly *poly; double coef; int expo, i; poly = poly_new(); for (i = 0; i<size; i++) { scanf("%lf%d", &coef, &expo); poly_add_term(poly, term_new(coef, expo)); } return poly; }
static void ed_start_term(Ed *ed, varg_T *arg) { log_msg("ED", "ed_start_term"); ed->state++; if (ed->state > ED_CONFRM) { //error return ed_cleanup(ed); } ed_dump_contents(ed, arg); char *editor = getenv("EDITOR"); if (!editor) editor = "vi"; char *line; asprintf(&line, "%s %s", editor, ed->tmp_name); term_new(ed->base, ed->buf, line); free(line); term_set_editor(ed->base, ed); buf_set_status(ed->buf, "ED", NULL, NULL); }