1  Usage

TinyExpr++ is a formula-solving library which accepts math and logic expressions such as:

ABS(((5+2) / (ABS(-2))) * -9 + 2) - 5^2

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:

SUM(C1, C2, C3, D1, D2, D3)

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:

IF(AND(P_LEVEL < .05, N_OBS >= 30),
   P_LEVEL,
   NAN)

Logical checks can also be nested, creating a “case”-like statement:

IF(AND(smartMeter1.power > 1900, sensor1.temperature < 52), TRUE,
1   IF(AND(smartMeter1.power < 300, sensor1.temperature > 55), FALSE,
2      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:

IFS(AND(smartMeter1.power > 1900, sensor1.temperature < 52), TRUE,
1    AND(smartMeter1.power < 0), FALSE,
2    AND(smartMeter1.power < 300, sensor1.temperature > 55), FALSE)
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.