summaryrefslogtreecommitdiff
path: root/lib/fonctions.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/fonctions.c')
-rw-r--r--lib/fonctions.c52
1 files changed, 40 insertions, 12 deletions
diff --git a/lib/fonctions.c b/lib/fonctions.c
index eca44cb..2d25eea 100644
--- a/lib/fonctions.c
+++ b/lib/fonctions.c
@@ -19,7 +19,7 @@
#define _(x) x
#endif
-
+/* Nous allons utiliser des pointeurs sur des fonctions. Voici donc les typedefs pour notre structure... */
typedef void (*func_name)(polynome arg1, polynome arg2, polynome arg3);
typedef struct func_t {
@@ -28,6 +28,7 @@ typedef struct func_t {
int arite;
} func_t;
+/* ... et la structure elle-même */
static func_t func_table[] = {
{ deriv, "deriv", 1, },
@@ -38,9 +39,13 @@ static func_t func_table[] = {
{ setdisplay, "setdisplay", 1 },
{ reinit, "reinit", 0 },
{ exit_call, "exit", 0 },
+ { setsmartprint, "setsmartprint", 1 },
{ NULL, NULL, -1 }
};
+
+/* On cherche simplement la routine a appeler parmi la table des fonctions */
+
void appel_fonction(char *nom, int arite, polynome p1, polynome p2, polynome p3)
{
int i=0;
@@ -60,9 +65,10 @@ void appel_fonction(char *nom, int arite, polynome p1, polynome p2, polynome p3)
} else {
exception(1,_("appel_fonction: non-existent function"));
}
+}
-}
+/* Fonction de dérivation - rajoute le résultat sur la pile. */
void deriv(polynome p1, polynome p2, polynome p3)
{
@@ -71,14 +77,14 @@ void deriv(polynome p1, polynome p2, polynome p3)
while (p1) {
if (p1->degre) {
t=ply_constr(rat_constr((p1->coef.num)*(p1->degre), p1->coef.denom), (p1->degre-1));
- if (t) {
- if (resultat) {
- temp->suiv = t;
- temp = t;
- } else {
- resultat = t;
- temp = t;
- }
+ if (t) {
+ if (resultat) {
+ temp->suiv = t;
+ temp = t;
+ } else {
+ resultat = t;
+ temp = t;
+ }
}
}
p1=p1->suiv;
@@ -86,15 +92,19 @@ void deriv(polynome p1, polynome p2, polynome p3)
push_pile_poly(resultat);
}
+
+/* Fonction paresseuse */
+
void derivn(polynome p1, polynome p2, polynome p3)
{ pile_elem temp;
int i;
if (p1) {
if ((p1->degre==0) && (p1->coef.num>0) && (p1->coef.denom==1)) {
- push_pile_poly(p2);
+ push_pile_poly(NULL);
for(i=0; i<p1->coef.num; i++) {
- temp=pop_pile(1);
+ temp = pop_pile(1);
+ ply_destruct(temp.poly);
deriv(temp.poly, NULL, NULL);
}
} else {
@@ -105,6 +115,9 @@ void derivn(polynome p1, polynome p2, polynome p3)
}
}
+
+/* Intégration d'un polynome */
+
void integ(polynome p1, polynome p2, polynome p3)
{
polynome resultat = NULL, temp = NULL, t;
@@ -126,6 +139,8 @@ void integ(polynome p1, polynome p2, polynome p3)
push_pile_poly(resultat);
}
+/* Quelques fonctions explicites... */
+
void printvars(polynome p1, polynome p2, polynome p3)
{
AfficheTableau(variables);
@@ -142,6 +157,7 @@ void help(polynome p1, polynome p2, polynome p3)
". setdisplay(n); set integer display format\n"
"\tn=1: DECIMAL, n=2: HEXA\n"
"\tn=3: OCTAL, n=4: FLOAT\n"
+ ". smartprint(bool); toggle smart print of polynoms\n"
". reinit(); clear all variables\n"
". exit(); end program\n"));
}
@@ -184,3 +200,15 @@ void exit_call(polynome p1, polynome p2, polynome p3)
{
quit = 1;
}
+
+void setsmartprint(polynome p1, polynome p2, polynome p3) {
+ if (p1) {
+ if ((!p1->degre)) {
+ smartprint = p1->coef.num;
+ } else {
+ exception(1, _("setsmartprint: invalid arg"));
+ }
+ } else {
+ smartprint = 0;
+ }
+}