diff options
author | Pixel <Pixel> | 2001-05-01 17:24:59 +0000 |
---|---|---|
committer | Pixel <Pixel> | 2001-05-01 17:24:59 +0000 |
commit | b44d595ac1be31d01c568b0bd0386a1c60715ac6 (patch) | |
tree | d83d43d8f580c1b0f08155e3341f5e6378dfe2c9 /lib/polynom.c | |
parent | 759be422fcf0fcca5a91b01e5ed7f752d95f0f8d (diff) |
Plop
Diffstat (limited to 'lib/polynom.c')
-rw-r--r-- | lib/polynom.c | 25 |
1 files changed, 23 insertions, 2 deletions
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; |