Skip to content
Snippets Groups Projects
Commit bbfcc738 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

add suport for Log10 in matheval
parent 4bacd096
Branches
Tags
No related merge requests found
...@@ -403,6 +403,12 @@ node_derivative(Node * node, char *name, SymbolTable * symbol_table) ...@@ -403,6 +403,12 @@ node_derivative(Node * node, char *name, SymbolTable * symbol_table)
*/ */
else if (!strcmp(node->data.function.record->name, "Log")) else if (!strcmp(node->data.function.record->name, "Log"))
return node_create('b', '/', node_derivative(node->data.function.child, name, symbol_table), node_copy(node->data.function.child)); return node_create('b', '/', node_derivative(node->data.function.child, name, symbol_table), node_copy(node->data.function.child));
/*
* Apply rule of base 10 logarithmic function derivative.
*/
else if (!strcmp(node->data.function.record->name, "Log10"))
return node_create('b', '/', node_derivative(node->data.function.child, name, symbol_table),
node_create('b', '*', node_create('c', log(10.)), node_copy(node->data.function.child)));
/* /*
* Apply rule of square root function derivative. * Apply rule of square root function derivative.
*/ */
......
...@@ -46,7 +46,7 @@ static int input_from_string (char *buffer, int max_size); ...@@ -46,7 +46,7 @@ static int input_from_string (char *buffer, int max_size);
whitespace [\ \t]+ whitespace [\ \t]+
digit [0-9] digit [0-9]
number ({digit}+|{digit}+"."{digit}*|{digit}*"."{digit}+)([Ee][-+]?{digit}+)? number ({digit}+|{digit}+"."{digit}*|{digit}*"."{digit}+)([Ee][-+]?{digit}+)?
function "Exp"|"Log"|"Sqrt"|"Sin"|"Cos"|"Tan"|"Ctan"|"Asin"|"Acos"|"Atan"|"Actan"|"Sinh"|"Cosh"|"Tanh"|"Ctanh"|"Asinh"|"Acosh"|"Atanh"|"Actanh"|"Fabs"|"Rand" function "Exp"|"Log"|"Sqrt"|"Sin"|"Cos"|"Tan"|"Ctan"|"Asin"|"Acos"|"Atan"|"Actan"|"Sinh"|"Cosh"|"Tanh"|"Ctanh"|"Asinh"|"Acosh"|"Atanh"|"Actanh"|"Fabs"|"Rand"|"Log10"
identifier [a-zA-Z\_][a-zA-Z0-9\_]* identifier [a-zA-Z\_][a-zA-Z0-9\_]*
%% %%
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
/* A lexical scanner generated by flex */ /* A lexical scanner generated by flex */
/* Scanner skeleton version: /* Scanner skeleton version:
* $Header: /cvsroot/gmsh/contrib/MathEval/scanner.yy.cpp,v 1.1 2005-09-21 17:29:37 geuzaine Exp $ * $Header: /cvsroot/gmsh/contrib/MathEval/scanner.yy.cpp,v 1.2 2007-05-05 11:19:40 geuzaine Exp $
*/ */
#define FLEX_SCANNER #define FLEX_SCANNER
...@@ -303,15 +303,15 @@ static void yy_fatal_error YY_PROTO(( yyconst char msg[] )); ...@@ -303,15 +303,15 @@ static void yy_fatal_error YY_PROTO(( yyconst char msg[] ));
#define YY_NUM_RULES 13 #define YY_NUM_RULES 13
#define YY_END_OF_BUFFER 14 #define YY_END_OF_BUFFER 14
static yyconst short int yy_accept[65] = static yyconst short int yy_accept[67] =
{ 0, { 0,
0, 0, 14, 13, 1, 12, 10, 11, 7, 5, 0, 0, 14, 13, 1, 12, 10, 11, 7, 5,
6, 13, 8, 2, 4, 4, 4, 4, 4, 4, 6, 13, 8, 2, 4, 4, 4, 4, 4, 4,
4, 4, 4, 9, 1, 2, 2, 2, 0, 4, 4, 4, 4, 9, 1, 2, 2, 2, 0, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 2, 0, 2, 4, 4, 4, 4, 3, 4, 4, 2, 0, 2, 4, 4, 4, 4, 3,
4, 3, 4, 4, 3, 4, 3, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 3, 4,
3, 3, 3, 0 3, 3, 3, 4, 3, 0
} ; } ;
static yyconst int yy_ec[256] = static yyconst int yy_ec[256] =
...@@ -320,16 +320,16 @@ static yyconst int yy_ec[256] = ...@@ -320,16 +320,16 @@ static yyconst int yy_ec[256] =
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 2, 1, 1, 1, 1, 1, 1, 1, 4, 1, 2, 1, 1, 1, 1, 1, 1, 1, 4,
5, 6, 7, 1, 8, 9, 10, 11, 11, 11, 5, 6, 7, 1, 8, 9, 10, 11, 12, 13,
11, 11, 11, 11, 11, 11, 11, 1, 1, 1, 13, 13, 13, 13, 13, 13, 13, 1, 1, 1,
1, 1, 1, 1, 12, 13, 14, 13, 15, 16, 1, 1, 1, 1, 14, 15, 16, 15, 17, 18,
13, 13, 13, 13, 13, 17, 13, 13, 13, 13, 15, 15, 15, 15, 15, 19, 15, 15, 15, 15,
13, 18, 19, 20, 13, 13, 13, 13, 13, 13, 15, 20, 21, 22, 15, 15, 15, 15, 15, 15,
1, 1, 1, 21, 13, 1, 22, 23, 24, 25, 1, 1, 1, 23, 15, 1, 24, 25, 26, 27,
26, 13, 27, 28, 29, 13, 13, 13, 13, 30, 28, 15, 29, 30, 31, 15, 15, 15, 15, 32,
31, 32, 33, 34, 35, 36, 13, 13, 13, 37, 33, 34, 35, 36, 37, 38, 15, 15, 15, 39,
13, 13, 1, 1, 1, 1, 1, 1, 1, 1, 15, 15, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
...@@ -346,74 +346,78 @@ static yyconst int yy_ec[256] = ...@@ -346,74 +346,78 @@ static yyconst int yy_ec[256] =
1, 1, 1, 1, 1 1, 1, 1, 1, 1
} ; } ;
static yyconst int yy_meta[38] = static yyconst int yy_meta[40] =
{ 0, { 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2 2, 2, 2, 2, 2, 2, 2, 2, 2
} ; } ;
static yyconst short int yy_base[66] = static yyconst short int yy_base[68] =
{ 0, { 0,
0, 0, 106, 107, 103, 107, 107, 107, 107, 107, 0, 0, 122, 123, 119, 123, 123, 123, 123, 123,
107, 93, 107, 29, 15, 0, 10, 66, 80, 70, 123, 29, 123, 34, 18, 0, 15, 81, 95, 85,
78, 14, 77, 107, 96, 34, 37, 47, 46, 0, 93, 19, 92, 123, 113, 46, 53, 0, 60, 0,
28, 68, 74, 60, 72, 61, 69, 64, 60, 59, 42, 83, 89, 75, 87, 76, 84, 79, 75, 74,
54, 57, 50, 75, 74, 49, 61, 52, 51, 52, 69, 72, 65, 72, 75, 66, 78, 69, 68, 69,
49, 0, 43, 52, 47, 38, 44, 43, 40, 41, 66, 0, 60, 84, 68, 64, 54, 61, 60, 57,
40, 39, 38, 107, 40 49, 39, 31, 49, 22, 123, 47
} ; } ;
static yyconst short int yy_def[66] = static yyconst short int yy_def[68] =
{ 0, { 0,
64, 1, 64, 64, 64, 64, 64, 64, 64, 64, 66, 1, 66, 66, 66, 66, 66, 66, 66, 66,
64, 64, 64, 64, 65, 65, 65, 65, 65, 65, 66, 66, 66, 66, 67, 67, 67, 67, 67, 67,
65, 65, 65, 64, 64, 64, 64, 64, 64, 65, 67, 67, 67, 66, 66, 66, 66, 14, 66, 67,
65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
65, 65, 64, 64, 64, 65, 65, 65, 65, 65, 67, 67, 66, 66, 66, 67, 67, 67, 67, 67,
65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
65, 65, 65, 0, 64 67, 67, 67, 67, 67, 0, 66
} ; } ;
static yyconst short int yy_nxt[145] = static yyconst short int yy_nxt[163] =
{ 0, { 0,
4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 14, 14, 14, 15, 16, 17, 18, 19, 20, 21,
24, 16, 16, 16, 16, 16, 16, 16, 16, 16, 22, 23, 24, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 27, 31, 28, 16, 16, 16, 16, 16, 16, 16, 16, 16, 26,
34, 30, 40, 29, 26, 35, 41, 43, 29, 32, 26, 26, 27, 31, 28, 28, 28, 34, 30, 40,
33, 29, 44, 44, 29, 27, 45, 28, 46, 29, 29, 52, 35, 41, 32, 33, 26, 26, 26, 52,
43, 29, 29, 47, 29, 52, 52, 52, 52, 63, 52, 29, 29, 43, 43, 43, 44, 44, 52, 29,
52, 52, 29, 52, 52, 29, 52, 52, 62, 52, 45, 45, 45, 29, 46, 43, 43, 43, 52, 47,
61, 60, 59, 58, 45, 45, 57, 56, 55, 54, 29, 29, 45, 45, 45, 45, 45, 45, 65, 52,
52, 53, 52, 51, 50, 49, 48, 25, 42, 39, 52, 52, 29, 52, 52, 64, 52, 63, 52, 62,
38, 37, 36, 26, 25, 64, 3, 64, 64, 64, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 51, 50, 49, 48, 25, 42, 39, 38, 37, 36,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 25, 66, 3, 66, 66, 66, 66, 66, 66, 66,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
64, 64, 64, 64 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
66, 66
} ; } ;
static yyconst short int yy_chk[145] = static yyconst short int yy_chk[163] =
{ 0, { 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 14, 15, 14, 1, 1, 1, 1, 1, 1, 1, 1, 1, 12,
17, 65, 22, 14, 26, 17, 22, 27, 26, 15, 12, 12, 14, 15, 14, 14, 14, 17, 67, 22,
15, 27, 29, 29, 14, 28, 29, 28, 31, 26, 14, 65, 17, 22, 15, 15, 26, 26, 26, 64,
43, 28, 27, 31, 43, 63, 62, 61, 60, 59, 63, 14, 26, 27, 27, 27, 29, 29, 62, 27,
58, 57, 28, 56, 55, 43, 54, 53, 51, 50, 29, 29, 29, 26, 31, 43, 43, 43, 61, 31,
49, 48, 47, 46, 45, 44, 42, 41, 40, 39, 27, 43, 44, 44, 44, 45, 45, 45, 60, 59,
38, 37, 36, 35, 34, 33, 32, 25, 23, 21, 58, 57, 43, 56, 55, 54, 53, 51, 50, 49,
20, 19, 18, 12, 5, 3, 64, 64, 64, 64, 48, 47, 46, 42, 41, 40, 39, 38, 37, 36,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 35, 34, 33, 32, 25, 23, 21, 20, 19, 18,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 5, 3, 66, 66, 66, 66, 66, 66, 66, 66,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
64, 64, 64, 64 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
66, 66
} ; } ;
static yy_state_type yy_last_accepting_state; static yy_state_type yy_last_accepting_state;
...@@ -472,7 +476,7 @@ extern char *matheval_input_string; /* String representing function. */ ...@@ -472,7 +476,7 @@ extern char *matheval_input_string; /* String representing function. */
/* Read next max_size character from string into buffer. */ /* Read next max_size character from string into buffer. */
static int input_from_string (char *buffer, int max_size); static int input_from_string (char *buffer, int max_size);
/* Token definitions. */ /* Token definitions. */
#line 476 "scanner.yy.cpp" #line 480 "scanner.yy.cpp"
/* Macros after this point can all be overridden by user definitions in /* Macros after this point can all be overridden by user definitions in
* section 1. * section 1.
...@@ -626,7 +630,7 @@ YY_DECL ...@@ -626,7 +630,7 @@ YY_DECL
#line 52 "scanner.l" #line 52 "scanner.l"
#line 630 "scanner.yy.cpp" #line 634 "scanner.yy.cpp"
if ( yy_init ) if ( yy_init )
{ {
...@@ -677,13 +681,13 @@ yy_match: ...@@ -677,13 +681,13 @@ yy_match:
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[yy_current_state]; yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 65 ) if ( yy_current_state >= 67 )
yy_c = yy_meta[(unsigned int) yy_c]; yy_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
++yy_cp; ++yy_cp;
} }
while ( yy_base[yy_current_state] != 107 ); while ( yy_base[yy_current_state] != 123 );
yy_find_action: yy_find_action:
yy_act = yy_accept[yy_current_state]; yy_act = yy_accept[yy_current_state];
...@@ -804,7 +808,7 @@ YY_RULE_SETUP ...@@ -804,7 +808,7 @@ YY_RULE_SETUP
#line 108 "scanner.l" #line 108 "scanner.l"
ECHO; ECHO;
YY_BREAK YY_BREAK
#line 808 "scanner.yy.cpp" #line 812 "scanner.yy.cpp"
case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(INITIAL):
yyterminate(); yyterminate();
...@@ -1096,7 +1100,7 @@ static yy_state_type yy_get_previous_state() ...@@ -1096,7 +1100,7 @@ static yy_state_type yy_get_previous_state()
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[yy_current_state]; yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 65 ) if ( yy_current_state >= 67 )
yy_c = yy_meta[(unsigned int) yy_c]; yy_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
...@@ -1131,11 +1135,11 @@ yy_state_type yy_current_state; ...@@ -1131,11 +1135,11 @@ yy_state_type yy_current_state;
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[yy_current_state]; yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 65 ) if ( yy_current_state >= 67 )
yy_c = yy_meta[(unsigned int) yy_c]; yy_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
yy_is_jam = (yy_current_state == 64); yy_is_jam = (yy_current_state == 66);
return yy_is_jam ? 0 : yy_current_state; return yy_is_jam ? 0 : yy_current_state;
} }
......
...@@ -42,11 +42,12 @@ symbol_table_create(int length) ...@@ -42,11 +42,12 @@ symbol_table_create(int length)
SymbolTable *symbol_table; /* Pointer to symbol table. */ SymbolTable *symbol_table; /* Pointer to symbol table. */
static char *names[] = {"Exp", "Log", "Sqrt", "Sin", "Cos", "Tan", "Ctan", static char *names[] = {"Exp", "Log", "Sqrt", "Sin", "Cos", "Tan", "Ctan",
"Asin", "Acos", "Atan", "Actan", "Sinh", "Cosh", "Tanh", "Asin", "Acos", "Atan", "Actan", "Sinh", "Cosh", "Tanh",
"Ctanh", "Asinh", "Acosh", "Atanh", "Actanh", "Fabs", "Rand" }; "Ctanh", "Asinh", "Acosh", "Atanh", "Actanh", "Fabs",
"Rand", "Log10" };
static double (*functions[]) (double) = { exp, log, sqrt, sin, cos, tan, x_ctan, static double (*functions[]) (double) = { exp, log, sqrt, sin, cos, tan, x_ctan,
asin, acos, atan, x_actan, sinh, cosh, tanh, asin, acos, atan, x_actan, sinh, cosh, tanh,
x_ctanh, x_asinh, x_acosh, x_atanh, x_actanh, x_ctanh, x_asinh, x_acosh, x_atanh, x_actanh,
fabs, x_rand}; fabs, x_rand, log10};
unsigned int i; unsigned int i;
/* /*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment