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.

EvaluateInt32

Method

Product: 

Fast Math Parser

Class: 

Expression

Evaluates a pre-parsed expression and returns the result as a 32-bit integer.

Syntax

EvaluateInt32()

Parameters

[None]

Return

int32

The 32-bit integer result of the evaluated expression.

Remarks

The EvaluateInt32 method executes a pre-compiled Expression and returns its result as a 32-bit signed integer. It is designed for high-performance scenarios where the same integer-based expression is evaluated multiple times.

🚀 The Parse/Evaluate Performance Pattern

For optimal performance, especially in loops, you should separate parsing from evaluation:

  1. Parse Once: Call Parse() outside the loop to convert the expression string into an efficient, executable object. When parsing, you must specify an integer type (e.g., "Int32", "Integer", or "Int") to ensure the result is correctly typed.
  2. Evaluate Many Times: Call EvaluateInt32() inside the loop. This step is extremely fast as it bypasses the string parsing overhead.

EvaluateInt32 vs. Evaluate vs. EvaluateDbl

MethodReturn TypeUse Case
EvaluateInt32()int32_tFor expressions explicitly parsed to an integer type. Offers the best performance and type safety for integer math.
Evaluate()doubleA general-purpose method that can evaluate numeric types (including integers) but always returns them as a double, involving a potential conversion.
EvaluateDbl()doubleStrictly for expressions that return a double. Calling it on an integer-parsed expression may lead to incorrect results.

Best Practice: Always match the Evaluate<Type>() method to the data type specified during the Parse() call.

💡 Comparative Analysis

  • vs. Native Compilation (C++/C#): A compiled language resolves expressions at compile-time for maximum speed. uCalc's Parse/Evaluate pattern provides a runtime equivalent. The Parse step is analogous to compilation, creating a highly optimized intermediate representation. The EvaluateInt32 step is the fast execution of that compiled code. This gives you the performance benefits of compilation with the flexibility of a dynamic, string-based input.

  • vs. Scripting Engines (eval): A generic eval() function in languages like Python or JavaScript must parse and evaluate the string every time it's called. This is convenient but slow. uCalc's two-step process is orders of magnitude faster for repeated evaluations.

For convenience, "Int" and "Integer" are defined as synonyms for "Int32" when specifying a return type for a function or operator via DefineFunction() or DefineOperator().

Examples

Displaying Integer (Int32) results with Evaluate32
				
					using uCalcSoftware;

var uc = new uCalc();
var VariableX = uc.DefineVariable("x");

var ParsedExpr = uc.Parse("x / 2", "Integer"); // Causes output of "x / 2" to convert to an integer

// NOTE: EvaluateInt32 should only be used when Parse() explicitly specifies Integer
// (Or Int, or Int32) as the second argument, or if the expression evaluates to an integer
// (such as evaluating a variable that was explicitly defined as integer;
// other arithmetic operators typically evaluate to Double floating point).

for (double x = 1; x <= 10; x++) {
   VariableX.Value(x);
   Console.WriteLine("x = " + VariableX.ValueStr() + "  Result = " + (ParsedExpr.EvaluateInt32()).ToString());
}

ParsedExpr.Release();
VariableX.Release();
				
			
x = 1  Result = 0
x = 2  Result = 1
x = 3  Result = 1
x = 4  Result = 2
x = 5  Result = 2
x = 6  Result = 3
x = 7  Result = 3
x = 8  Result = 4
x = 9  Result = 4
x = 10  Result = 5
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto VariableX = uc.DefineVariable("x");

   auto ParsedExpr = uc.Parse("x / 2", "Integer"); // Causes output of "x / 2" to convert to an integer

   // NOTE: EvaluateInt32 should only be used when Parse() explicitly specifies Integer
   // (Or Int, or Int32) as the second argument, or if the expression evaluates to an integer
   // (such as evaluating a variable that was explicitly defined as integer;
   // other arithmetic operators typically evaluate to Double floating point).

   for (double x = 1; x <= 10; x++) {
      VariableX.Value(x);
      cout << "x = " + VariableX.ValueStr() + "  Result = " + to_string(ParsedExpr.EvaluateInt32()) << endl;
   }

   ParsedExpr.Release();
   VariableX.Release();
}
				
			
x = 1  Result = 0
x = 2  Result = 1
x = 3  Result = 1
x = 4  Result = 2
x = 5  Result = 2
x = 6  Result = 3
x = 7  Result = 3
x = 8  Result = 4
x = 9  Result = 4
x = 10  Result = 5
				
					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 / 2", "Integer") '// Causes output of "x / 2" to convert to an integer
      
      '// NOTE: EvaluateInt32 should only be used when Parse() explicitly specifies Integer
      '// (Or Int, or Int32) as the second argument, or if the expression evaluates to an integer
      '// (such as evaluating a variable that was explicitly defined as integer;
      '// other arithmetic operators typically evaluate to Double floating point).
      
      For x  As Double = 1 To 10
         VariableX.Value(x)
         Console.WriteLine("x = " + VariableX.ValueStr() + "  Result = " + (ParsedExpr.EvaluateInt32()).ToString())
      Next
      
      ParsedExpr.Release()
      VariableX.Release()
   End Sub
End Module
				
			
x = 1  Result = 0
x = 2  Result = 1
x = 3  Result = 1
x = 4  Result = 2
x = 5  Result = 2
x = 6  Result = 3
x = 7  Result = 3
x = 8  Result = 4
x = 9  Result = 4
x = 10  Result = 5