uCalc API Version: 5.7.0-preview.1 Released: 7/30/2026
Warning
uCalc API Preview Release Notice:This preview documentation describes the intended behavior of the API. It is not fully accurate or complete.The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.Use of the preview version in your production code is not recommended.
Product:
Class:
Evaluates a pre-parsed boolean expression, returning the native true or false result efficiently.
The result of the evaluated Boolean expression
The EvaluateBool method is the high-performance counterpart to Evaluate for expressions that result in a boolean value. It executes a pre-compiled expression object, created by Parse, and returns the native true or false result.
This method is ideal for performance-critical scenarios, such as evaluating conditions inside a loop, where the overhead of parsing the same string repeatedly would be prohibitive.
Expressions involving comparison operators (<, >, ==, <>), logical operators (And, Or, Not), or functions that return a boolean will produce a boolean result. When you Parse such an expression, uCalc creates a compiled object typed to return a boolean. EvaluateBool is the most direct and efficient way to execute this object.
EvaluateBool vs. EvaluateWhile the generic Evaluate method can also return a boolean result (which it casts to a double where 1.0 is true and 0.0 is false), EvaluateBool has distinct advantages:
| Feature | EvaluateBool() | Evaluate() | EvaluateStr() |
|---|---|---|---|
| Return Type | Native bool | double | string |
| Type Safety | 🟢 High. Fails predictably if expression is not boolean. | 🟡 Medium. Casts boolean to number. | 🟢 High. Converts boolean to text. |
| Performance | 🟢 Highest for boolean logic. | 🟡 High, but with a slight overhead for type casting. | 🔴 Lowest due to string allocation/formatting. |
| Use Case | Conditional logic, loops, validation rules. | General numeric calculations. | User-facing display, logging. |
In native languages, you might use compiled lambda expressions or function pointers for dynamic conditional logic.
Func<bool>: A Func<bool> delegate can be compiled from an expression tree for performance, but building that tree from a raw string is a complex, multi-step process.uCalc provides a much simpler workflow: Parse a string once, then call EvaluateBool in a tight loop. This delivers the performance of a compiled delegate with the flexibility of dynamic string input, offering a powerful middle ground between static code and heavy scripting engines.
ID: 93
using uCalcSoftware;
var uc = new uCalc();
var VariableX = uc.DefineVariable("x");
var ParsedExpr = uc.Parse("x > 3"); // The > operation returns a Boolean instead of the default floating point
for (double x = 1; x <= 5; x++) {
VariableX.Value(x);
Console.WriteLine($"x = {VariableX.ValueStr()} x > 3 is {ParsedExpr.EvaluateBool()}");
}
ParsedExpr.Release();
VariableX.Release();
x = 1 x > 3 is False
x = 2 x > 3 is False
x = 3 x > 3 is False
x = 4 x > 3 is True
x = 5 x > 3 is True using uCalcSoftware; var uc = new uCalc(); var VariableX = uc.DefineVariable("x"); var ParsedExpr = uc.Parse("x > 3"); // The > operation returns a Boolean instead of the default floating point for (double x = 1; x <= 5; x++) { VariableX.Value(x); Console.WriteLine($"x = {VariableX.ValueStr()} x > 3 is {ParsedExpr.EvaluateBool()}"); } ParsedExpr.Release(); VariableX.Release();
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
#define tf(IsTrue) ((IsTrue) ? "True" : "False")
int main() {
uCalc uc;
auto VariableX = uc.DefineVariable("x");
auto ParsedExpr = uc.Parse("x > 3"); // The > operation returns a Boolean instead of the default floating point
for (double x = 1; x <= 5; x++) {
VariableX.Value(x);
cout << "x = " << VariableX.ValueStr() << " x > 3 is " << tf(ParsedExpr.EvaluateBool()) << endl;
}
ParsedExpr.Release();
VariableX.Release();
}
x = 1 x > 3 is False
x = 2 x > 3 is False
x = 3 x > 3 is False
x = 4 x > 3 is True
x = 5 x > 3 is True #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; #define tf(IsTrue) ((IsTrue) ? "True" : "False") int main() { uCalc uc; auto VariableX = uc.DefineVariable("x"); auto ParsedExpr = uc.Parse("x > 3"); // The > operation returns a Boolean instead of the default floating point for (double x = 1; x <= 5; x++) { VariableX.Value(x); cout << "x = " << VariableX.ValueStr() << " x > 3 is " << tf(ParsedExpr.EvaluateBool()) << endl; } ParsedExpr.Release(); VariableX.Release(); }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim VariableX = uc.DefineVariable("x")
Dim ParsedExpr = uc.Parse("x > 3") '// The > operation returns a Boolean instead of the default floating point
For x As Double = 1 To 5
VariableX.Value(x)
Console.WriteLine($"x = {VariableX.ValueStr()} x > 3 is {ParsedExpr.EvaluateBool()}")
Next
ParsedExpr.Release()
VariableX.Release()
End Sub
End Module
x = 1 x > 3 is False
x = 2 x > 3 is False
x = 3 x > 3 is False
x = 4 x > 3 is True
x = 5 x > 3 is True Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim VariableX = uc.DefineVariable("x") Dim ParsedExpr = uc.Parse("x > 3") '// The > operation returns a Boolean instead of the default floating point For x As Double = 1 To 5 VariableX.Value(x) Console.WriteLine($"x = {VariableX.ValueStr()} x > 3 is {ParsedExpr.EvaluateBool()}") Next ParsedExpr.Release() VariableX.Release() End Sub End Module