OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
mathexpr.h File Reference

Parsing and evaluation of mathematical expressions. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ExprNode
 

Typedefs

typedef struct ExprNode MathExpr
 

Functions

MathExpr * mathexpr_create (char *s, int(*getVar)(char *))
 Compile an infix formula into an owned postfix expression list.
 
double mathexpr_eval (MathExpr *expr, double(*getVal)(int))
 Evaluate a legacy postfix expression using a local operand stack.
 
void mathexpr_delete (MathExpr *expr)
 Recursively release a complete postfix MathExpr list.
 

Detailed Description

Parsing and evaluation of mathematical expressions.

Author
Caleb Buahin caleb.nosp@m..bua.nosp@m.hin@g.nosp@m.mail.nosp@m..com (OpenSWMM maintenance and extensions)
License
Apache-2.0 for OpenSWMM contributions; original EPA SWMM provenance is retained.

Typedef Documentation

◆ MathExpr

typedef struct ExprNode MathExpr

Function Documentation

◆ mathexpr_create()

MathExpr * mathexpr_create ( char * formula,
int(* getVar )(char *) )

Compile an infix formula into an owned postfix expression list.

Parameters
[in]formulaNon-null null-terminated input; identifiers and numeric literals must fit the parser's 255-byte token buffers and strlen must fit in int.
[in]getVarOptional synchronous variable-name-to-index callback; negative indices reject names. The temporary token pointer must not be retained.
Returns
Owned expression head to release with mathexpr_delete(), or NULL for detected syntax/parenthesis errors or an empty result.
Note
The compiled list stores values/indices and evaluates independently of the input/callback. Parsing uses shared globals and is not reentrant or thread-safe; allocation failures are not comprehensively recovered.
Here is the caller graph for this function:

◆ mathexpr_delete()

void mathexpr_delete ( MathExpr * expr)

Recursively release a complete postfix MathExpr list.

Parameters
[in]exprOwned list head, or NULL for no action.
Postcondition
All reachable next-linked nodes are freed. The caller must discard its original pointer; deep expressions consume recursive call-stack space.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mathexpr_eval()

double mathexpr_eval ( MathExpr * expr,
double(* getVariableValue )(int) )

Evaluate a legacy postfix expression using a local operand stack.

Parameters
[in]exprBorrowed valid linked expression; NULL evaluates to zero.
[in]getVariableValueOptional synchronous index-to-value callback; NULL supplies zero for every variable. The callback is not retained.
Returns
Final expression value; malformed stack underflow and NaN results are mapped to zero. Infinite results are not changed.
Precondition
Expression operand counts and peak stack occupancy fit the fixed MAX_STACK_SIZE array; stack overflow is not safely recovered by this routine.
Note
The local stack permits recursive expression evaluation. Domain behavior varies by opcode: negative sqrt and nonpositive log become zero, while other illegal math may become NaN and then zero at the final check.
Here is the call graph for this function:
Here is the caller graph for this function: