1 Usage
TinyExpr++ is a formula-solving library which accepts math and logic expressions such as:
(((5+2) / (ABS(-2))) * -9 + 2) - 5^2 ABS
Applications using TinyExpr++ may provide context-specific variables that you can use in your expressions. For example, in a spreadsheet application, values representing cells such as C1
and D2
may be available. This would enable the use of expressions such as:
(C1, C2, C3, D1, D2, D3) SUM
As another example, in a statistical program, the values N_OBS
and P_LEVEL
may be available. This would make an expression such as this possible:
(AND(P_LEVEL < .05, N_OBS >= 30),
IF,
P_LEVEL) NAN
Logical checks can also be nested, creating a “case”-like statement:
(AND(smartMeter1.power > 1900, sensor1.temperature < 52), TRUE,
IF1(AND(smartMeter1.power < 300, sensor1.temperature > 55), FALSE,
IF2) ) NAN
- 1
- First logical check failed, so now check another scenario and return false if it meets our criteria.
- 2
- Neither scenario passed; return NaN because the values are in an unaccounted for scenario.
The same can be accomplished using the IFS()
function:
(AND(smartMeter1.power > 1900, sensor1.temperature < 52), TRUE,
IFS1(smartMeter1.power < 0), FALSE,
AND2(smartMeter1.power < 300, sensor1.temperature > 55), FALSE) AND
- 1
- First logical check failed, so now check another scenario and return false if it meets our criteria.
- 2
- Neither scenario passed; return NaN because the values are in an unaccounted for scenario.
Expressions can optionally begin with an =
, the same as spreadsheet programs. For example:
=SUM(C1, C2, C3, D1, D2, D3)
Please consult your application’s documentation for which custom variables and functions it may provide for its formulas.