uCalc API Version: 2.1.3-preview.2 Released: 6/17/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.
EvaluateDbl
Method
Product:
Class:
Rapidly evaluates a pre-parsed expression, optimized specifically for double-precision floating-point results.
Syntax
Parameters
Return
double
The double-precision floating-point result of the expression. Returns an undefined value if the expression does not yield a double.
Remarks
The EvaluateDbl method evaluates a pre-parsed expression, optimized specifically for performance-critical scenarios that return a double-precision floating-point value. It is the type-strict counterpart to the more flexible Evaluate method.
This method is a key component of uCalc's two-step evaluation model:
- Parse Once: Call uCalc.Parse() to convert an expression string into a compiled Expression object.
- Evaluate Many: Call
EvaluateDbl()repeatedly on theExpressionobject, which is significantly faster than re-parsing the string each time with Eval().
🎯 Strict Type Enforcement
EvaluateDbl is designed for speed and requires that the parsed expression's result is a double.
- Success: Works correctly for expressions like
3.14 * r^2. - Failure: Returns an undefined or incorrect value if the expression yields another numeric type (like
Int32orBoolean) or a non-numeric type (String,Complex). No conversion is attempted, and no error is raised.
Use the general-purpose Evaluate() method if your expression might return other numeric types, as it will handle the conversion to double automatically.
EvaluateDbl vs. Evaluate
| Feature | EvaluateDbl() | Evaluate() |
|---|---|---|
| Performance | 🟢 Highest. Optimized for direct double evaluation. | 🟡 High. Slightly slower due to type-checking and potential conversion logic. |
| Type Safety | 🔴 Strict. Only works for expressions returning double. | 🟢 Flexible. Handles any numeric type by converting it to double. |
| Use Case | Ideal for high-speed loops in scientific or financial calculations where the return type is known to be double. | General-purpose numeric evaluation where flexibility is more important than maximum performance. |
💡 Comparative Analysis: Why Use a Two-Step Process?
In many programming environments, evaluating a string expression is a single, monolithic operation. uCalc separates parsing from evaluation, which mirrors how compilers work and offers significant performance advantages.
- vs.
eval()in Scripting Languages: Functions like JavaScript'seval()re-parse the string on every call, making them inefficient for loops. - vs. C#
DataTable.Compute: This common .NET workaround is notoriously slow because it involves significant overhead for each calculation. - vs. Compiled Code: The Parse step is analogous to a just-in-time (JIT) compilation. Once the Expression object is created, calls to
EvaluateDblare nearly as fast as calling a native, compiled function, but with the full dynamic flexibility of a runtime engine.
This model allows uCalc to achieve performance levels suitable for real-time simulations and data processing tasks that would be too slow for traditional script evaluators.
Examples
Evaluate() auto-conversion
using uCalcSoftware;
var uc = new uCalc();
// The int return value type in MyExprB is converted to
// Double with .Evaluate(), but not with .EvaluateDbl()
var MyExprA = uc.Parse("3.2 + 5.2");
var MyExprB = uc.Parse("int(3.2 + 5.2)");
Console.WriteLine(MyExprA.Evaluate());
Console.WriteLine(MyExprA.EvaluateDbl() == 8.4);
Console.WriteLine(MyExprB.Evaluate());
Console.WriteLine(MyExprB.EvaluateDbl() == 8);
8.4
True
8
False using uCalcSoftware; var uc = new uCalc(); // The int return value type in MyExprB is converted to // Double with .Evaluate(), but not with .EvaluateDbl() var MyExprA = uc.Parse("3.2 + 5.2"); var MyExprB = uc.Parse("int(3.2 + 5.2)"); Console.WriteLine(MyExprA.Evaluate()); Console.WriteLine(MyExprA.EvaluateDbl() == 8.4); Console.WriteLine(MyExprB.Evaluate()); Console.WriteLine(MyExprB.EvaluateDbl() == 8);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
#define tf(IsTrue) ((IsTrue) ? "True" : "False")
int main() {
uCalc uc;
// The int return value type in MyExprB is converted to
// Double with .Evaluate(), but not with .EvaluateDbl()
auto MyExprA = uc.Parse("3.2 + 5.2");
auto MyExprB = uc.Parse("int(3.2 + 5.2)");
cout << MyExprA.Evaluate() << endl;
cout << tf(MyExprA.EvaluateDbl() == 8.4) << endl;
cout << MyExprB.Evaluate() << endl;
cout << tf(MyExprB.EvaluateDbl() == 8) << endl;
}
8.4
True
8
False #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; #define tf(IsTrue) ((IsTrue) ? "True" : "False") int main() { uCalc uc; // The int return value type in MyExprB is converted to // Double with .Evaluate(), but not with .EvaluateDbl() auto MyExprA = uc.Parse("3.2 + 5.2"); auto MyExprB = uc.Parse("int(3.2 + 5.2)"); cout << MyExprA.Evaluate() << endl; cout << tf(MyExprA.EvaluateDbl() == 8.4) << endl; cout << MyExprB.Evaluate() << endl; cout << tf(MyExprB.EvaluateDbl() == 8) << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// The int return value type in MyExprB is converted to
'// Double with .Evaluate(), but not with .EvaluateDbl()
Dim MyExprA = uc.Parse("3.2 + 5.2")
Dim MyExprB = uc.Parse("int(3.2 + 5.2)")
Console.WriteLine(MyExprA.Evaluate())
Console.WriteLine(MyExprA.EvaluateDbl() = 8.4)
Console.WriteLine(MyExprB.Evaluate())
Console.WriteLine(MyExprB.EvaluateDbl() = 8)
End Sub
End Module
8.4
True
8
False Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// The int return value type in MyExprB is converted to '// Double with .Evaluate(), but not with .EvaluateDbl() Dim MyExprA = uc.Parse("3.2 + 5.2") Dim MyExprB = uc.Parse("int(3.2 + 5.2)") Console.WriteLine(MyExprA.Evaluate()) Console.WriteLine(MyExprA.EvaluateDbl() = 8.4) Console.WriteLine(MyExprB.Evaluate()) Console.WriteLine(MyExprB.EvaluateDbl() = 8) End Sub End Module