diff options
author | Pixel <Pixel> | 2001-05-02 11:21:03 +0000 |
---|---|---|
committer | Pixel <Pixel> | 2001-05-02 11:21:03 +0000 |
commit | 22a4fa35ca3845c130c49406ae342bbcb60ada55 (patch) | |
tree | 43bc8ed2b0695b4b0cc3beeb9100cb31f948b424 /lib | |
parent | 744672b90fe21495913fc321633bc6d103e3cb6b (diff) |
Pouet
Diffstat (limited to 'lib')
-rw-r--r-- | lib/fonctions.c | 24 | ||||
-rw-r--r-- | lib/polynom.c | 10 |
2 files changed, 21 insertions, 13 deletions
diff --git a/lib/fonctions.c b/lib/fonctions.c index 44cdf91..1a7da13 100644 --- a/lib/fonctions.c +++ b/lib/fonctions.c @@ -146,18 +146,18 @@ void ans(polynome p1, polynome p2, polynome p3) void help(polynome p1, polynome p2, polynome p3) { - printf(_("Available functions:\n - deriv(p); first derivative of p\n - derivn(p, n); nth derivative of p\n - integ(p); primitive of p\n - printvars(); print all variables\n - ans(); last result\n - help(); this help message\n - setdisplay(n); set integer display format\n - \tn=1: DECIMAL, n=2: HEXA\n - \tn=3: OCTAL, n=4: FLOAT\n - reinit(); clear all variables\n - exit(); end program\n")); + printf(_("Available functions:\n" + ". deriv(p); first derivative of p\n" + ". derivn(p, n); nth derivative of p\n" + ". integ(p); primitive of p\n" + ". printvars(); print all variables\n" + ". ans(); last result\n" + ". help(); this help message\n" + ". setdisplay(n); set integer display format\n" + "\tn=1: DECIMAL, n=2: HEXA\n" + "\tn=3: OCTAL, n=4: FLOAT\n" + ". reinit(); clear all variables\n" + ". exit(); end program\n")); } void setdisplay(polynome p1, polynome p2, polynome p3) diff --git a/lib/polynom.c b/lib/polynom.c index ff92e5d..8cdac59 100644 --- a/lib/polynom.c +++ b/lib/polynom.c @@ -223,6 +223,7 @@ polynome ply_multiplication(polynome poly1, polynome poly2) polynome ply_division(polynome dividende, polynome diviseur) { /* division de deux polynomes */ polynome interdividende = ply_copy(dividende), interdiviseur = NULL, inter = NULL, reste = dividende, resultat = NULL, r = NULL; + int b = 0; #ifdef DEBUG printf("On divise %s", ply_affichage(dividende)); @@ -231,6 +232,7 @@ polynome ply_division(polynome dividende, polynome diviseur) printf("diviseur degre = %u\n", diviseur->degre); #endif while ((interdividende) && (interdividende->degre >= diviseur->degre)) { + b = 1; inter = ply_constr(rat_division(interdividende->coef, diviseur->coef), interdividende->degre - diviseur->degre); #ifdef DEBUG printf("On trouve qu'il nous faut soustraire %s fois\n", ply_affichage(inter)); @@ -254,6 +256,8 @@ polynome ply_division(polynome dividende, polynome diviseur) resultat = r; interdividende = reste; } + + if (!b) ply_destruct(interdividende); return resultat; } @@ -261,6 +265,7 @@ polynome ply_division(polynome dividende, polynome diviseur) polynome ply_modulo(polynome dividende, polynome diviseur) { /* reste de la division de deux polynomes */ polynome interdividende = ply_copy(dividende), interdiviseur = NULL, inter = NULL, reste = dividende, resultat = NULL, r = NULL; + int b; #ifdef DEBUG printf("On divise %s", ply_affichage(dividende)); @@ -269,6 +274,7 @@ polynome ply_modulo(polynome dividende, polynome diviseur) printf("diviseur degre = %u\n", diviseur->degre); #endif while ((interdividende) && (interdividende->degre >= diviseur->degre)) { + b = 1; inter = ply_constr(rat_division(interdividende->coef, diviseur->coef), interdividende->degre - diviseur->degre); #ifdef DEBUG printf("On trouve qu'il nous faut soustraire %s fois\n", ply_affichage(inter)); @@ -293,7 +299,9 @@ polynome ply_modulo(polynome dividende, polynome diviseur) interdividende = reste; } - return reste; + if (!b) ply_destruct(interdividende); + + return b ? reste : ply_copy(reste); } polynome ply_exposant(polynome poly, unsigned int exp) |