Soft'N'Design Software
/
projects
/
calc.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
add commands deg, grad and rad
[calc.git]
/
parser.c
diff --git
a/parser.c
b/parser.c
index 0f4e6418e46593fe9afd14ed4fb4b63a09fe3109..24afb116c98f19a4a2d0e2724a4d52b6982984fb 100644
(file)
--- a/
parser.c
+++ b/
parser.c
@@
-18,6
+18,8
@@
double answer = 0;
double answer = 0;
+double anglefactor = 1;
+
/* compare codes */
int codecmp (char *ref, char *str)
/* compare codes */
int codecmp (char *ref, char *str)
@@
-62,7
+64,7
@@
keyword_t operators[NB_OPERATORS] = {
{ "|", Or, 2, 1, -2}
};
{ "|", Or, 2, 1, -2}
};
-#define NB_FUNCTIONS 5
2
+#define NB_FUNCTIONS 5
5
keyword_t functions[NB_FUNCTIONS] = {
{ "sqrt", Sqr, 1, 4, 5},
{ "pow", Pow, 2, 3, 5},
keyword_t functions[NB_FUNCTIONS] = {
{ "sqrt", Sqr, 1, 4, 5},
{ "pow", Pow, 2, 3, 5},
@@
-115,7
+117,10
@@
keyword_t functions[NB_FUNCTIONS] = {
{ "sum", Sum, 0, 3, 5},
{ "var", Variance, 2, 3, 5},
{ "format", Precision, 1, 6, 9},
{ "sum", Sum, 0, 3, 5},
{ "var", Variance, 2, 3, 5},
{ "format", Precision, 1, 6, 9},
- { "base", Base, 2, 4, 9}
+ { "base", Base, 2, 4, 9},
+ { "deg", Deg, 0, 3, 9},
+ { "grad", Grad, 0, 4, 9},
+ { "rad", Rad, 0, 3, 9}
};
#define NB_CONSTANTS 3
};
#define NB_CONSTANTS 3
@@
-523,6
+528,9
@@
void print_element (element_t *root, int level)
case Variance: func = "Variance"; break;
case Precision: func = "Precision"; break;
case Base: func = "Base"; break;
case Variance: func = "Variance"; break;
case Precision: func = "Precision"; break;
case Base: func = "Base"; break;
+ case Deg: func = "Degree"; break;
+ case Grad: func = "Gradian"; break;
+ case Rad: func = "Radian"; break;
}
printf ("Function: %s\n", func);
}
printf ("Function: %s\n", func);
@@
-618,7
+626,7
@@
void help (void)
printf ("stack func.:");
printf (" max mean med min ord prod sum var\n");
printf ("control management:");
printf ("stack func.:");
printf (" max mean med min ord prod sum var\n");
printf ("control management:");
- printf (" base
format help quit
\n");
+ printf (" base
deg format grad help quit rad
\n");
printf ("constants:");
printf (" ans e pi\n");
}
printf ("constants:");
printf (" ans e pi\n");
}
@@
-767,6
+775,9
@@
double evaluate_element (element_t *root, char mask)
case Order:
case Prod:
case Sum:
case Order:
case Prod:
case Sum:
+ case Deg:
+ case Grad:
+ case Rad:
break;
case While:
if (root->ops[0] == NULL) {
break;
case While:
if (root->ops[0] == NULL) {
@@
-827,12
+838,12
@@
double evaluate_element (element_t *root, char mask)
case Mod: return fmod (op0, op1);
case Pow: return pow (op0, op1);
case Sqr: return sqrt (op0);
case Mod: return fmod (op0, op1);
case Pow: return pow (op0, op1);
case Sqr: return sqrt (op0);
- case Cos: return cos (op0);
- case Sin: return sin (op0);
- case Tan: return tan (op0);
- case Acos: return acos (op0);
- case Asin: return asin (op0);
- case Atan: return atan (op0);
+ case Cos: return cos (op0
/ anglefactor
);
+ case Sin: return sin (op0
/ anglefactor
);
+ case Tan: return tan (op0
/ anglefactor
);
+ case Acos: return acos (op0)
* anglefactor
;
+ case Asin: return asin (op0)
* anglefactor
;
+ case Atan: return atan (op0)
* anglefactor
;
case Ln: return log (op0);
case Log: return log10 (op0);
case Exp: return exp (op0);
case Ln: return log (op0);
case Log: return log10 (op0);
case Exp: return exp (op0);
@@
-933,6
+944,15
@@
double evaluate_element (element_t *root, char mask)
case Base:
base ((int)op0, (int)op1);
break;
case Base:
base ((int)op0, (int)op1);
break;
+ case Deg:
+ anglefactor = 180 / M_PI;
+ break;
+ case Grad:
+ anglefactor = 200 / M_PI;
+ break;
+ case Rad:
+ anglefactor = 1;
+ break;
}
return 0;
}
return 0;