diff options
-rw-r--r-- | doc/manuel.tex | 11 | ||||
-rw-r--r-- | include/scalaires.h | 4 | ||||
-rw-r--r-- | lib/fonctions.c | 24 | ||||
-rw-r--r-- | lib/polynom.c | 10 |
4 files changed, 32 insertions, 17 deletions
diff --git a/doc/manuel.tex b/doc/manuel.tex index d1522f0..9a0d765 100644 --- a/doc/manuel.tex +++ b/doc/manuel.tex @@ -70,5 +70,12 @@ Le parseur de ligne étant totalement flexible, il est possible de mélanger toute . 388 -> -\end{verbatim}
\ No newline at end of file +> (R = 2*P^2 - 2*x)(36) * x^2 - 10; + + . 1389891136x^2 - 10 + +> R; + + . 2x^8 - 4x^7 + 74x^6 - 80x^5 + 632x^4 - 120x^3 - 424x^2 + 46x + 72 + +\end{verbatim} diff --git a/include/scalaires.h b/include/scalaires.h index 11754b2..06b798b 100644 --- a/include/scalaires.h +++ b/include/scalaires.h @@ -2,8 +2,8 @@ #define __SCALAIRES_H__ typedef struct { - int num; - unsigned int denom; + long long num; + unsigned long long denom; } rationnel; typedef enum typedisplay { 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) |