From b05b13f4f74e253f844d168e057f3be5408d06f5 Mon Sep 17 00:00:00 2001 From: biouman Date: Tue, 1 May 2001 12:41:41 +0000 Subject: *** empty log message *** --- lib/polynom.c | 10 ++-------- lib/scalaires.c | 21 ++++++++++++++++----- 2 files changed, 18 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/polynom.c b/lib/polynom.c index 241c2da..f9f3c1c 100644 --- a/lib/polynom.c +++ b/lib/polynom.c @@ -274,15 +274,9 @@ char *ply_affichage(polynome poly) while (poly) { if (poly->degre != 0) { - if (poly->coef.denom == 1) - sprintf(temp, "%+d*%s^%u ", poly->coef.num, mute, poly->degre); - else - sprintf(temp, "%+d/%d*%s^%u ", poly->coef.num, poly->coef.denom, mute, poly->degre); + sprintf(temp, "%s*%s^%u ", rat_to_string(poly->coef), mute, poly->degre); } else { - if (poly->coef.denom == 1) - sprintf(temp, "%+d ", poly->coef.num); - else - sprintf(temp, "%+d/%d ", poly->coef.num, poly->coef.denom); + sprintf(temp, "%s ", rat_to_string(poly->coef)); } count += strlen(temp); if (count < BUFSIZ) diff --git a/lib/scalaires.c b/lib/scalaires.c index d2f24fb..33b7ef2 100644 --- a/lib/scalaires.c +++ b/lib/scalaires.c @@ -4,6 +4,7 @@ * */ #include +#include #include "scalaires.h" #include "exceptions.h" #ifdef HAVE_CONFIG_H @@ -115,6 +116,7 @@ rationnel rat_division(rationnel rat1, rationnel rat2) } + char *rat_to_string(rationnel rat) { char resultat[128]; @@ -129,13 +131,22 @@ char *rat_to_string(rationnel rat) switch(display) { case DEC: - sprintf(temp,"%d/%d", rat.num, rat.denom); + if (rat.denom==1) + sprintf(temp,"%d", rat.num); + else + sprintf(temp,"%d/%d", rat.num, rat.denom); break; case HEX: - sprintf(temp,"%x/%x", rat.num, rat.denom); + if (rat.denom==1) + sprintf(temp,"%x", rat.num); + else + sprintf(temp,"%x/%x", rat.num, rat.denom); break; - case OCT: - sprintf(temp,"%o/%o", rat.num, rat.denom); + case OCT: + if (rat.denom==1) + sprintf(temp,"%o", rat.num); + else + sprintf(temp,"%o/%o", rat.num, rat.denom); break; case FLT: sprintf(temp,"%f", rat_to_double(rat)); @@ -143,6 +154,6 @@ char *rat_to_string(rationnel rat) } strcat(resultat, temp); - return resultat; + return Estrdup(resultat); } -- cgit v1.2.3