From b05b13f4f74e253f844d168e057f3be5408d06f5 Mon Sep 17 00:00:00 2001 From: biouman Date: Tue, 1 May 2001 12:41:41 +0000 Subject: *** empty log message *** --- include/hash.h | 4 ++++ include/scalaires.h | 1 + lib/polynom.c | 10 ++-------- lib/scalaires.c | 21 ++++++++++++++++----- src/Polynom.c | 2 ++ 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/include/hash.h b/include/hash.h index 4f40659..701b241 100644 --- a/include/hash.h +++ b/include/hash.h @@ -38,4 +38,8 @@ char SupprimerDansTab(_TableauVariable * t, char *Nom); /* Detruit le tableau */ void DetruitTab(_TableauVariable * t); +/* Affiche le tableau */ +void AfficheTableau(_TableauVariable t); + + #endif diff --git a/include/scalaires.h b/include/scalaires.h index fcd0b00..30e7f82 100644 --- a/include/scalaires.h +++ b/include/scalaires.h @@ -25,5 +25,6 @@ rationnel rat_soustraction(rationnel rat1, rationnel rat2); /* soustraction */ rationnel rat_moinsunaire(rationnel rat1); /* moins unaire */ rationnel rat_multiplication(rationnel rat1, rationnel rat2); /* multiplication */ rationnel rat_division(rationnel rat, rationnel rat2); /* division */ +char *rat_to_string(rationnel rat); #endif 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); } diff --git a/src/Polynom.c b/src/Polynom.c index 6121f7d..9da1d49 100644 --- a/src/Polynom.c +++ b/src/Polynom.c @@ -11,6 +11,7 @@ #include "polynom.h" #include "pile.h" #include "exceptions.h" +#include "scalaires.h" #ifdef HAVE_CONFIG_H #include "config.h" #else @@ -29,6 +30,7 @@ int main(void) Initialise(&variables); mute = "x"; + display=DEC; /* nom de la variable utilisee pour la saisie des polynomes, a recuperer en argv eventuellt ATTENTION: elle est case sensitive */ parse_line("P=-4.5+2*x+3*x^2;"); -- cgit v1.2.3