Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gmsh
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Larry Price
gmsh
Commits
8f6b0b90
Commit
8f6b0b90
authored
21 years ago
by
Christophe Geuzaine
Browse files
Options
Downloads
Patches
Plain Diff
operator is a reverved C++ keyword: operato->operatorr
parent
58d10eca
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
MathEval/node.cpp
+571
-570
571 additions, 570 deletions
MathEval/node.cpp
MathEval/node.h
+2
-2
2 additions, 2 deletions
MathEval/node.h
TODO
+5
-1
5 additions, 1 deletion
TODO
with
578 additions
and
573 deletions
MathEval/node.cpp
+
571
−
570
View file @
8f6b0b90
...
@@ -46,7 +46,6 @@ node_create(char type,...)
...
@@ -46,7 +46,6 @@ node_create(char type,...)
* Initialize constant value.
* Initialize constant value.
*/
*/
node
->
data
.
constant
=
va_arg
(
ap
,
double
);
node
->
data
.
constant
=
va_arg
(
ap
,
double
);
break
;
break
;
case
'v'
:
case
'v'
:
...
@@ -70,8 +69,7 @@ node_create(char type,...)
...
@@ -70,8 +69,7 @@ node_create(char type,...)
/*
/*
* Initialize operator type and operand.
* Initialize operator type and operand.
*/
*/
node
->
data
.
un_op
.
operato
=
(
char
)
va_arg
(
ap
,
int
);
node
->
data
.
un_op
.
operatorr
=
(
char
)
va_arg
(
ap
,
int
);
node
->
data
.
un_op
.
child
=
va_arg
(
ap
,
Node
*
);
node
->
data
.
un_op
.
child
=
va_arg
(
ap
,
Node
*
);
break
;
break
;
...
@@ -79,8 +77,7 @@ node_create(char type,...)
...
@@ -79,8 +77,7 @@ node_create(char type,...)
/*
/*
* Initialize operator type and operands.
* Initialize operator type and operands.
*/
*/
node
->
data
.
un_op
.
operato
=
(
char
)
va_arg
(
ap
,
int
);
node
->
data
.
un_op
.
operatorr
=
(
char
)
va_arg
(
ap
,
int
);
node
->
data
.
bin_op
.
left
=
va_arg
(
ap
,
Node
*
);
node
->
data
.
bin_op
.
left
=
va_arg
(
ap
,
Node
*
);
node
->
data
.
bin_op
.
right
=
va_arg
(
ap
,
Node
*
);
node
->
data
.
bin_op
.
right
=
va_arg
(
ap
,
Node
*
);
break
;
break
;
...
@@ -148,10 +145,10 @@ node_copy(Node * node)
...
@@ -148,10 +145,10 @@ node_copy(Node * node)
return
node_create
(
'f'
,
node
->
data
.
function
.
record
,
node_copy
(
node
->
data
.
function
.
child
));
return
node_create
(
'f'
,
node
->
data
.
function
.
record
,
node_copy
(
node
->
data
.
function
.
child
));
case
'u'
:
case
'u'
:
return
node_create
(
'u'
,
node
->
data
.
un_op
.
operato
,
node_copy
(
node
->
data
.
un_op
.
child
));
return
node_create
(
'u'
,
node
->
data
.
un_op
.
operato
rr
,
node_copy
(
node
->
data
.
un_op
.
child
));
case
'b'
:
case
'b'
:
return
node_create
(
'b'
,
node
->
data
.
bin_op
.
operato
,
node_copy
(
node
->
data
.
bin_op
.
left
),
node_copy
(
node
->
data
.
bin_op
.
right
));
return
node_create
(
'b'
,
node
->
data
.
bin_op
.
operato
rr
,
node_copy
(
node
->
data
.
bin_op
.
left
),
node_copy
(
node
->
data
.
bin_op
.
right
));
}
}
return
NULL
;
return
NULL
;
...
@@ -179,7 +176,8 @@ node_simplify(Node * node)
...
@@ -179,7 +176,8 @@ node_simplify(Node * node)
node_destroy
(
node
);
node_destroy
(
node
);
return
node_create
(
'c'
,
value
);
return
node_create
(
'c'
,
value
);
}
else
}
else
return
node
;
return
node
;
case
'u'
:
case
'u'
:
...
@@ -188,12 +186,13 @@ node_simplify(Node * node)
...
@@ -188,12 +186,13 @@ node_simplify(Node * node)
* operator and replace operator node with constant node.
* operator and replace operator node with constant node.
*/
*/
node
->
data
.
un_op
.
child
=
node_simplify
(
node
->
data
.
un_op
.
child
);
node
->
data
.
un_op
.
child
=
node_simplify
(
node
->
data
.
un_op
.
child
);
if
(
node
->
data
.
un_op
.
operato
==
'-'
&&
node
->
data
.
un_op
.
child
->
type
==
'c'
)
{
if
(
node
->
data
.
un_op
.
operato
rr
==
'-'
&&
node
->
data
.
un_op
.
child
->
type
==
'c'
)
{
double
value
=
node_evaluate
(
node
);
double
value
=
node_evaluate
(
node
);
node_destroy
(
node
);
node_destroy
(
node
);
return
node_create
(
'c'
,
value
);
return
node_create
(
'c'
,
value
);
}
else
}
else
return
node
;
return
node
;
case
'b'
:
case
'b'
:
...
@@ -216,91 +215,94 @@ node_simplify(Node * node)
...
@@ -216,91 +215,94 @@ node_simplify(Node * node)
/*
/*
* Eliminate 0 as neutral addition operand.
* Eliminate 0 as neutral addition operand.
*/
*/
else
if
(
node
->
data
.
bin_op
.
operato
==
'+'
)
else
if
(
node
->
data
.
bin_op
.
operato
rr
==
'+'
)
if
(
node
->
data
.
bin_op
.
left
->
type
==
'c'
&&
node
->
data
.
bin_op
.
left
->
data
.
constant
==
0
)
{
if
(
node
->
data
.
bin_op
.
left
->
type
==
'c'
&&
node
->
data
.
bin_op
.
left
->
data
.
constant
==
0
)
{
Node
*
right
;
Node
*
right
;
right
=
node
->
data
.
bin_op
.
right
;
right
=
node
->
data
.
bin_op
.
right
;
node
->
data
.
bin_op
.
right
=
NULL
;
node
->
data
.
bin_op
.
right
=
NULL
;
node_destroy
(
node
);
node_destroy
(
node
);
return
right
;
return
right
;
}
else
if
(
node
->
data
.
bin_op
.
right
->
type
==
'c'
&&
node
->
data
.
bin_op
.
right
->
data
.
constant
==
0
)
{
}
else
if
(
node
->
data
.
bin_op
.
right
->
type
==
'c'
&&
node
->
data
.
bin_op
.
right
->
data
.
constant
==
0
)
{
Node
*
left
;
Node
*
left
;
left
=
node
->
data
.
bin_op
.
left
;
left
=
node
->
data
.
bin_op
.
left
;
node
->
data
.
bin_op
.
left
=
NULL
;
node
->
data
.
bin_op
.
left
=
NULL
;
node_destroy
(
node
);
node_destroy
(
node
);
return
left
;
return
left
;
}
else
}
else
return
node
;
return
node
;
/*
/*
* Eliminate 0 as neutral subtraction right operand.
* Eliminate 0 as neutral subtraction right operand.
*/
*/
else
if
(
node
->
data
.
bin_op
.
operato
==
'-'
)
else
if
(
node
->
data
.
bin_op
.
operato
rr
==
'-'
)
if
(
node
->
data
.
bin_op
.
right
->
type
==
'c'
&&
node
->
data
.
bin_op
.
right
->
data
.
constant
==
0
)
{
if
(
node
->
data
.
bin_op
.
right
->
type
==
'c'
&&
node
->
data
.
bin_op
.
right
->
data
.
constant
==
0
)
{
Node
*
left
;
Node
*
left
;
left
=
node
->
data
.
bin_op
.
left
;
left
=
node
->
data
.
bin_op
.
left
;
node
->
data
.
bin_op
.
left
=
NULL
;
node
->
data
.
bin_op
.
left
=
NULL
;
node_destroy
(
node
);
node_destroy
(
node
);
return
left
;
return
left
;
}
else
}
else
return
node
;
return
node
;
/*
/*
* Eliminate 1 as neutral multiplication operand.
* Eliminate 1 as neutral multiplication operand.
*/
*/
else
if
(
node
->
data
.
bin_op
.
operato
==
'*'
)
else
if
(
node
->
data
.
bin_op
.
operato
rr
==
'*'
)
if
(
node
->
data
.
bin_op
.
left
->
type
==
'c'
&&
node
->
data
.
bin_op
.
left
->
data
.
constant
==
1
)
{
if
(
node
->
data
.
bin_op
.
left
->
type
==
'c'
&&
node
->
data
.
bin_op
.
left
->
data
.
constant
==
1
)
{
Node
*
right
;
Node
*
right
;
right
=
node
->
data
.
bin_op
.
right
;
right
=
node
->
data
.
bin_op
.
right
;
node
->
data
.
bin_op
.
right
=
NULL
;
node
->
data
.
bin_op
.
right
=
NULL
;
node_destroy
(
node
);
node_destroy
(
node
);
return
right
;
return
right
;
}
else
if
(
node
->
data
.
bin_op
.
right
->
type
==
'c'
&&
node
->
data
.
bin_op
.
right
->
data
.
constant
==
1
)
{
}
else
if
(
node
->
data
.
bin_op
.
right
->
type
==
'c'
&&
node
->
data
.
bin_op
.
right
->
data
.
constant
==
1
)
{
Node
*
left
;
Node
*
left
;
left
=
node
->
data
.
bin_op
.
left
;
left
=
node
->
data
.
bin_op
.
left
;
node
->
data
.
bin_op
.
left
=
NULL
;
node
->
data
.
bin_op
.
left
=
NULL
;
node_destroy
(
node
);
node_destroy
(
node
);
return
left
;
return
left
;
}
else
}
else
return
node
;
return
node
;
/*
/*
* Eliminate 1 as neutral division right operand.
* Eliminate 1 as neutral division right operand.
*/
*/
else
if
(
node
->
data
.
bin_op
.
operato
==
'/'
)
else
if
(
node
->
data
.
bin_op
.
operato
rr
==
'/'
)
if
(
node
->
data
.
bin_op
.
right
->
type
==
'c'
&&
node
->
data
.
bin_op
.
right
->
data
.
constant
==
1
)
{
if
(
node
->
data
.
bin_op
.
right
->
type
==
'c'
&&
node
->
data
.
bin_op
.
right
->
data
.
constant
==
1
)
{
Node
*
left
;
Node
*
left
;
left
=
node
->
data
.
bin_op
.
left
;
left
=
node
->
data
.
bin_op
.
left
;
node
->
data
.
bin_op
.
left
=
NULL
;
node
->
data
.
bin_op
.
left
=
NULL
;
node_destroy
(
node
);
node_destroy
(
node
);
return
left
;
return
left
;
}
else
}
else
return
node
;
return
node
;
/*
/*
* Eliminate 0 and 1 as both left and right exponentiation
* Eliminate 0 and 1 as both left and right exponentiation
* operands.
* operands.
*/
*/
else
if
(
node
->
data
.
bin_op
.
operato
==
'^'
)
else
if
(
node
->
data
.
bin_op
.
operato
rr
==
'^'
)
if
(
node
->
data
.
bin_op
.
left
->
type
==
'c'
&&
node
->
data
.
bin_op
.
left
->
data
.
constant
==
0
)
{
if
(
node
->
data
.
bin_op
.
left
->
type
==
'c'
&&
node
->
data
.
bin_op
.
left
->
data
.
constant
==
0
)
{
node_destroy
(
node
);
node_destroy
(
node
);
return
node_create
(
'c'
,
0.0
);
return
node_create
(
'c'
,
0.0
);
}
else
if
(
node
->
data
.
bin_op
.
left
->
type
==
'c'
&&
node
->
data
.
bin_op
.
left
->
data
.
constant
==
1
)
{
}
else
if
(
node
->
data
.
bin_op
.
left
->
type
==
'c'
&&
node
->
data
.
bin_op
.
left
->
data
.
constant
==
1
)
{
node_destroy
(
node
);
node_destroy
(
node
);
return
node_create
(
'c'
,
1.0
);
return
node_create
(
'c'
,
1.0
);
}
else
if
(
node
->
data
.
bin_op
.
right
->
type
==
'c'
&&
node
->
data
.
bin_op
.
right
->
data
.
constant
==
0
)
{
}
else
if
(
node
->
data
.
bin_op
.
right
->
type
==
'c'
&&
node
->
data
.
bin_op
.
right
->
data
.
constant
==
0
)
{
node_destroy
(
node
);
node_destroy
(
node
);
return
node_create
(
'c'
,
1.0
);
return
node_create
(
'c'
,
1.0
);
}
else
if
(
node
->
data
.
bin_op
.
right
->
type
==
'c'
&&
node
->
data
.
bin_op
.
right
->
data
.
constant
==
1
)
{
}
else
if
(
node
->
data
.
bin_op
.
right
->
type
==
'c'
&&
node
->
data
.
bin_op
.
right
->
data
.
constant
==
1
)
{
Node
*
left
;
Node
*
left
;
left
=
node
->
data
.
bin_op
.
left
;
left
=
node
->
data
.
bin_op
.
left
;
node
->
data
.
bin_op
.
left
=
NULL
;
node
->
data
.
bin_op
.
left
=
NULL
;
node_destroy
(
node
);
node_destroy
(
node
);
return
left
;
return
left
;
}
else
}
else
return
node
;
return
node
;
else
else
return
node
;
return
node
;
...
@@ -336,7 +338,7 @@ node_evaluate(Node * node)
...
@@ -336,7 +338,7 @@ node_evaluate(Node * node)
* Unary operator node is evaluated according to operator
* Unary operator node is evaluated according to operator
* type.
* type.
*/
*/
switch
(
node
->
data
.
un_op
.
operato
)
{
switch
(
node
->
data
.
un_op
.
operato
rr
)
{
case
'-'
:
case
'-'
:
return
-
node_evaluate
(
node
->
data
.
un_op
.
child
);
return
-
node_evaluate
(
node
->
data
.
un_op
.
child
);
}
}
...
@@ -346,7 +348,7 @@ node_evaluate(Node * node)
...
@@ -346,7 +348,7 @@ node_evaluate(Node * node)
* Binary operator node is evaluated according to operator
* Binary operator node is evaluated according to operator
* type.
* type.
*/
*/
switch
(
node
->
data
.
un_op
.
operato
)
{
switch
(
node
->
data
.
un_op
.
operato
rr
)
{
case
'+'
:
case
'+'
:
return
node_evaluate
(
node
->
data
.
bin_op
.
left
)
+
node_evaluate
(
node
->
data
.
bin_op
.
right
);
return
node_evaluate
(
node
->
data
.
bin_op
.
left
)
+
node_evaluate
(
node
->
data
.
bin_op
.
right
);
...
@@ -494,7 +496,7 @@ node_derivative(Node * node, char *name, SymbolTable * symbol_table)
...
@@ -494,7 +496,7 @@ node_derivative(Node * node, char *name, SymbolTable * symbol_table)
return
node_create
(
'b'
,
'/'
,
node_create
(
'b'
,
'*'
,
node_derivative
(
node
->
data
.
function
.
child
,
name
,
symbol_table
),
node_copy
(
node
->
data
.
function
.
child
)),
node_create
(
'f'
,
symbol_table_lookup
(
symbol_table
,
"Sqrt"
),
node_create
(
'b'
,
'^'
,
node_copy
(
node
->
data
.
function
.
child
),
node_create
(
'c'
,
2.0
))));
return
node_create
(
'b'
,
'/'
,
node_create
(
'b'
,
'*'
,
node_derivative
(
node
->
data
.
function
.
child
,
name
,
symbol_table
),
node_copy
(
node
->
data
.
function
.
child
)),
node_create
(
'f'
,
symbol_table_lookup
(
symbol_table
,
"Sqrt"
),
node_create
(
'b'
,
'^'
,
node_copy
(
node
->
data
.
function
.
child
),
node_create
(
'c'
,
2.0
))));
case
'u'
:
case
'u'
:
switch
(
node
->
data
.
un_op
.
operato
)
{
switch
(
node
->
data
.
un_op
.
operato
rr
)
{
case
'-'
:
case
'-'
:
/*
/*
* Apply (-f)'=-f' derivative rule.
* Apply (-f)'=-f' derivative rule.
...
@@ -503,7 +505,7 @@ node_derivative(Node * node, char *name, SymbolTable * symbol_table)
...
@@ -503,7 +505,7 @@ node_derivative(Node * node, char *name, SymbolTable * symbol_table)
}
}
case
'b'
:
case
'b'
:
switch
(
node
->
data
.
bin_op
.
operato
)
{
switch
(
node
->
data
.
bin_op
.
operato
rr
)
{
case
'+'
:
case
'+'
:
/*
/*
* Apply (f+g)'=f'+g' derivative rule.
* Apply (f+g)'=f'+g' derivative rule.
...
@@ -542,7 +544,6 @@ node_derivative(Node * node, char *name, SymbolTable * symbol_table)
...
@@ -542,7 +544,6 @@ node_derivative(Node * node, char *name, SymbolTable * symbol_table)
*/
*/
else
{
else
{
Node
*
log_node
,
*
derivative
;
Node
*
log_node
,
*
derivative
;
log_node
=
node_create
(
'b'
,
'*'
,
node_copy
(
node
->
data
.
bin_op
.
right
),
node_create
(
'f'
,
symbol_table_lookup
(
symbol_table
,
"Log"
),
node_copy
(
node
->
data
.
bin_op
.
left
)));
log_node
=
node_create
(
'b'
,
'*'
,
node_copy
(
node
->
data
.
bin_op
.
right
),
node_create
(
'f'
,
symbol_table_lookup
(
symbol_table
,
"Log"
),
node_copy
(
node
->
data
.
bin_op
.
left
)));
derivative
=
node_create
(
'b'
,
'*'
,
node_copy
(
node
),
node_derivative
(
log_node
,
name
,
symbol_table
));
derivative
=
node_create
(
'b'
,
'*'
,
node_copy
(
node
),
node_derivative
(
log_node
,
name
,
symbol_table
));
node_destroy
(
log_node
);
node_destroy
(
log_node
);
...
@@ -628,7 +629,7 @@ node_write(Node * node, char *string)
...
@@ -628,7 +629,7 @@ node_write(Node * node, char *string)
case
'u'
:
case
'u'
:
sprintf
(
string
,
"%c"
,
'('
);
sprintf
(
string
,
"%c"
,
'('
);
string
+=
strlen
(
string
);
string
+=
strlen
(
string
);
sprintf
(
string
,
"%c"
,
node
->
data
.
un_op
.
operato
);
sprintf
(
string
,
"%c"
,
node
->
data
.
un_op
.
operato
rr
);
string
+=
strlen
(
string
);
string
+=
strlen
(
string
);
node_write
(
node
->
data
.
un_op
.
child
,
string
);
node_write
(
node
->
data
.
un_op
.
child
,
string
);
string
+=
strlen
(
string
);
string
+=
strlen
(
string
);
...
@@ -640,7 +641,7 @@ node_write(Node * node, char *string)
...
@@ -640,7 +641,7 @@ node_write(Node * node, char *string)
string
+=
strlen
(
string
);
string
+=
strlen
(
string
);
node_write
(
node
->
data
.
bin_op
.
left
,
string
);
node_write
(
node
->
data
.
bin_op
.
left
,
string
);
string
+=
strlen
(
string
);
string
+=
strlen
(
string
);
sprintf
(
string
,
"%c"
,
node
->
data
.
bin_op
.
operato
);
sprintf
(
string
,
"%c"
,
node
->
data
.
bin_op
.
operato
rr
);
string
+=
strlen
(
string
);
string
+=
strlen
(
string
);
node_write
(
node
->
data
.
bin_op
.
right
,
string
);
node_write
(
node
->
data
.
bin_op
.
right
,
string
);
string
+=
strlen
(
string
);
string
+=
strlen
(
string
);
...
...
This diff is collapsed.
Click to expand it.
MathEval/node.h
+
2
−
2
View file @
8f6b0b90
...
@@ -41,13 +41,13 @@ typedef struct _Node {
...
@@ -41,13 +41,13 @@ typedef struct _Node {
}
function
;
/* Structure representing
}
function
;
/* Structure representing
* function. */
* function. */
struct
{
struct
{
char
operato
;
/* Operator type ('-'
char
operato
rr
;
/* Operator type ('-'
* for unary minus). */
* for unary minus). */
struct
_Node
*
child
;
/* Operand node. */
struct
_Node
*
child
;
/* Operand node. */
}
un_op
;
/* Structure representing unary
}
un_op
;
/* Structure representing unary
* operator. */
* operator. */
struct
{
struct
{
char
operato
;
/* Operator type ('+'
char
operato
rr
;
/* Operator type ('+'
* for adition, '-' for
* for adition, '-' for
* subtraction, '*' for
* subtraction, '*' for
* multiplication, '/'
* multiplication, '/'
...
...
This diff is collapsed.
Click to expand it.
TODO
+
5
−
1
View file @
8f6b0b90
$Id: TODO,v 1.44 2004-05-12 03:22:13 geuzaine Exp $
$Id: TODO,v 1.45 2004-05-13 05:34:06 geuzaine Exp $
add ternary operator and <,>,<=,>=,== tests in MathEval
********************************************************************
generalize Plugin(Triangulate) to vector and tensor points
generalize Plugin(Triangulate) to vector and tensor points
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment