uCalc API Version: 2.1.3-preview.2 Released: 6/16/2026
Warning
uCalc API Preview Release Notice:The documentation describes the intended behavior of the API. The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.
EvaluateBool
Method
Product:
Class:
Evaluates a pre-parsed boolean expression, returning the native true or false result efficiently.
Syntax
Parameters
Return
bool
The result of the evaluated Boolean expression
Remarks
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.
⚙️ How It Works
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. Evaluate
While 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. |
💡 Comparative Analysis
In native languages, you might use compiled lambda expressions or function pointers for dynamic conditional logic.
- C#
Func<bool>: AFunc<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. - Standard C++: Evaluating string-based boolean logic typically requires integrating a full-blown parsing library.
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.
Examples
EvaluateBool, also ValueStr which converts numeric value to string
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