From b44d595ac1be31d01c568b0bd0386a1c60715ac6 Mon Sep 17 00:00:00 2001 From: Pixel Date: Tue, 1 May 2001 17:24:59 +0000 Subject: Plop --- lib/polynom.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'lib/polynom.c') diff --git a/lib/polynom.c b/lib/polynom.c index ab0ac07..dbb4334 100644 --- a/lib/polynom.c +++ b/lib/polynom.c @@ -17,6 +17,8 @@ #define _(x) x #endif +int smartprint = 1; + /* FIXME: manque div et mod */ polynome ply_constr(rationnel coef, int degre) @@ -272,6 +274,7 @@ char *ply_affichage(polynome poly) static char buf[BUFSIZ]; char temp[BUFSIZ]; int count = 0; + int first = 1; buf[0] = '\0'; if (!poly) { @@ -279,9 +282,26 @@ char *ply_affichage(polynome poly) } else { while (poly) { if (poly->degre != 0) { - sprintf(temp, "%s*%s^%u ", rat_to_string(poly->coef), mute, poly->degre); + if (smartprint) { + switch(poly->degre) { + case 1: + sprintf(temp, "%s%s ", rat_to_string(poly->coef, first), mute); + break; + case 2: + sprintf(temp, "%s%s² ", rat_to_string(poly->coef, first), mute); + break; + case 3: + sprintf(temp, "%s%s³ ", rat_to_string(poly->coef, first), mute); + break; + default: + sprintf(temp, "%s%s^%u ", rat_to_string(poly->coef, first), mute, poly->degre); + break; + } + } else { + sprintf(temp, "%s*%s^%u ", rat_to_string(poly->coef, first), mute, poly->degre); + } } else { - sprintf(temp, "%s ", rat_to_string(poly->coef)); + sprintf(temp, "%s ", rat_to_string(poly->coef, first)); } count += strlen(temp); if (count < BUFSIZ) @@ -289,6 +309,7 @@ char *ply_affichage(polynome poly) else exception(2, _("ply_affichage: strcat error, not enough space in buffer")); poly = poly->suiv; + first = 0; } } return buf; -- cgit v1.2.3