X-Git-Url: https://secure.softndesign.org/git/?a=blobdiff_plain;f=parser.c;h=e20427cb0135215912ae9498ee4a5bb8e7f0c18d;hb=2a986c8f7340d3443b5a0a4f46b228b64963edc8;hp=e1e79268ef2ca11249140ad955d6651d0b4d3287;hpb=f50ed10b8c764e17158172ecc1b92de9239d173e;p=calc.git diff --git a/parser.c b/parser.c index e1e7926..e20427c 100644 --- a/parser.c +++ b/parser.c @@ -130,7 +130,7 @@ keyword_t operators[NB_OPERATORS] = { { "|", Or, 2, 1, -2} }; -#define NB_FUNCTIONS 31 +#define NB_FUNCTIONS 32 keyword_t functions[NB_FUNCTIONS] = { { "sqrt", Sqr, 1, 4, 5}, { "pow", Pow, 2, 3, 5}, @@ -140,6 +140,7 @@ keyword_t functions[NB_FUNCTIONS] = { { "acos", Acos, 1, 4, 5}, { "asin", Asin, 1, 4, 5}, { "atan", Atan, 1, 4, 5}, + { "ln", Ln, 1, 2, 5}, { "log", Log, 1, 3, 5}, { "exp", Exp, 1, 3, 5}, { "abs", Abs, 1, 3, 5}, @@ -513,7 +514,8 @@ void print_element (element_t *root, int level) case Acos: func = "Arc Cosine"; break; case Asin: func = "Arc Sine"; break; case Atan: func = "Arc Tangent"; break; - case Log: func = "Logarithm"; break; + case Ln: func = "Logarithm (e base)"; break; + case Log: func = "Logarithm (10 base)"; break; case Exp: func = "Exponantial"; break; case Abs: func = "Absolute value"; break; case Ceil: func = "Ceil value"; break; @@ -826,8 +828,8 @@ double call (int id, int nbops, element_t **ops) double *tmp = (double *) callocordie (nbops, sizeof (double)); memcpy (tmp, storage, storage_size * sizeof (double)); free (storage); - storage = tmp; - storage_size = nbops; + (programs + n)->storage = storage = tmp; + (programs + n)->storage_size = storage_size = nbops; } for (i = 0; i < nbops; i++) { double val = evaluate_element (ops[i], 0); @@ -962,19 +964,21 @@ void help (void) fprintf (stdout, "logical operators:"); fprintf (stdout, " & | !\n"); fprintf (stdout, "mathematic functions:"); - fprintf (stdout, " pow sqrt log exp\n"); + fprintf (stdout, " exp ln log pow sqrt\n"); fprintf (stdout, "trig. func.:"); - fprintf (stdout, " cos sin tan acos asin atan\n"); + fprintf (stdout, " acos asin atan cos sin tan\n"); fprintf (stdout, "supported functions:"); fprintf (stdout, " abs ceil floor\n"); - fprintf (stdout, "storage functions:"); - fprintf (stdout, " mem sto rcl inc dec disp\n"); + fprintf (stdout, "stor. functions:"); + fprintf (stdout, " clear dec disp inc mem rcl sto\n"); + fprintf (stdout, "cond. functions:"); + fprintf (stdout, " cond print while {} ;\n"); fprintf (stdout, "prog. functions:"); - fprintf (stdout, " cond while print {} ;\n"); + fprintf (stdout, " call del edit ls prog\n"); fprintf (stdout, "misc. functions:"); - fprintf (stdout, " quit help\n"); + fprintf (stdout, " help quit\n"); fprintf (stdout, "supported constants:"); - fprintf (stdout, " e pi\n"); + fprintf (stdout, " ans e pi\n"); } /* evaluate element tree */ @@ -1048,6 +1052,7 @@ double evaluate_element (element_t *root, char mask) case Acos: case Asin: case Atan: + case Ln: case Log: case Exp: case Abs: @@ -1106,7 +1111,8 @@ double evaluate_element (element_t *root, char mask) case Acos: return acos (op0); case Asin: return asin (op0); case Atan: return atan (op0); - case Log: return log (op0); + case Ln: return log (op0); + case Log: return log10 (op0); case Exp: return exp (op0); case Abs: return fabs (op0); case Ceil: return ceil (op0);