uCalcSoftware.Cpp 5.7.1-preview.4

This is a prerelease version of uCalcSoftware.Cpp.
dotnet add package uCalcSoftware.Cpp --version 5.7.1-preview.4
                    
NuGet\Install-Package uCalcSoftware.Cpp -Version 5.7.1-preview.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="uCalcSoftware.Cpp" Version="5.7.1-preview.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="uCalcSoftware.Cpp" Version="5.7.1-preview.4" />
                    
Directory.Packages.props
<PackageReference Include="uCalcSoftware.Cpp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add uCalcSoftware.Cpp --version 5.7.1-preview.4
                    
#r "nuget: uCalcSoftware.Cpp, 5.7.1-preview.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package uCalcSoftware.Cpp@5.7.1-preview.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=uCalcSoftware.Cpp&version=5.7.1-preview.4&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=uCalcSoftware.Cpp&version=5.7.1-preview.4&prerelease
                    
Install as a Cake Tool

uCalc: The High-Performance Math Expression Evaluator and Token-Aware Text Transformation Engine

NuGet Version Dotnet C++ OS Documentation License Sponsor

Homepage | Documentation | Online interactive examples | What's New | Release Notes | License

uCalc Engine

uCalc API Preview Release Notice: The uCalc engine has successfully transitioned to modern cross-platform environments. The next phase envolves some structural changes, performance optimizations, and API refinements. The API is subject to breaking changes prior to the stable release. Please evaluate the preview version thoroughly before production use.

uCalc is a suite of three components: a Fast Math Parser, a token-aware text Transformer, and a String library. They are powered by the same underlying advanced parser engine and designed to seamlessly integrate for sophisticated operations. The uCalc SDK is backed by extensive online documentation with numerous interactive examples.

Use uCalc to build spreadsheet calculation engines, dynamic report generators, static analysis/code refactoring tools, linters, game scripting environments, custom domain-specific languages (DSLs), and to perform data extraction, complex string building, markup language conversion, and more.

  • uCalc Fast Math Parser lets you evaluate math expressions defined at runtime. It comes with many functions and operators, and lets you define your own as well, either at runtime, or by attaching them to functions in your source code. You can call the simple Eval() to evaluate an expression right away, or parse the expression once and evaluate it many times in a loop at optimal speeds. uCalc is easy to use, yet very powerful.
  • uCalc Transformer is a smart, token-aware engine for searching, replacing, and restructuring text. Use it to parse structured or unstructured text alike. Not limited to character units, it understands units of text like quoted strings, whitespace, nested brackets, user-defined comment structures, etc., and shines where regex falls short. It supports advanced rewrite rules, while also being designed for human readability to make it simple to use.
  • uCalc String Library is a smart, mutable string manipulation library that offers you live views into strings for surgical in-place editing of different parts of the string, respecting structural boundaries (for instance it can distinguish between alphanumeric symbols, quoted text, etc., or user defined units of text), using the same underlying token-aware parser as the transformer. Methods can be chained together fluently for easy deployment.

Runtimes for Windows (x86, x64, and ARM64), Linux (x64 and ARM64), macOS (Intel osx-64 and osx-ARM64 Apple Silicon), are carefully packaged into the same NuGet library. This allows for immediate plug-and-play integration without the hassle of setting up platform-specific plumbing.

Quick Start

Fast Math Parser

#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;

   // 1. Expression Parser: Evaluating a simple math or string expression
   uc.DefineVariable("n = 10");
   uc.DefineFunction("Area(length, width) = length * width");
   cout << uc.Eval("5 * Area(n, 6) / 2") << endl; // Output: 150

   uc.DefineVariable("FirstName = 'John'");
   cout << uc.EvalStr("UCase(FirstName) + ' Doe'") << endl; // Output: JOHN Doe

   // 2. Evaluate an expression faster in a loop
   auto myVar = uc.DefineVariable("x");
   auto expr = uc.Parse("x * 2");

   for (double i = 1; i <= 5; i++) {
      myVar.Value(i);
      cout << "When x is " << i << " result is: " << expr.Evaluate() << endl;
   }
   // Output:
   // When x is 1, result is: 2
   // ...
   // When x is 5, result is: 10

}

Transformer

#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   // Transformer: Performing a basic find-and-replace to reformat a person's name
   uCalc::Transformer t;
   t.FromTo("First Name: {first} [Middle Name: {middle}] Last Name: {last}", "Name: {last}, {first} {middle}");
   cout << t.Transform("First Name: John-Paul    Last Name: Doe") << endl; // Output: Doe, John-Paul
   cout << t.Transform("First Name: John  Middle Name: Peter  Last Name: Doe") << endl; // Output: Doe, John Peter

}

String Library

#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   // String Library: Using a fluent, chainable operation to modify a subsection of text in-place within a string
   uCalc::String log("INFO: File-handling task. ERROR: File not found.");
   log.After("ERROR: ").Replace("File", "Resource");
   cout << log << endl; // Output: INFO: File-handling task. ERROR: Resource not found.

}

Practical example: Creating a JSON minifier that takes a formatted string and removes all non-essential whitespace

#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc::Transformer t;

   // 1. Define rules to remove whitespace and newlines.
   // The engine's default QuoteSensitive=true ensures whitespace inside strings is protected.
   t.FromTo("{@Whitespace}", "");
   t.FromTo("{@Newline}", "");

   // 2. Define the formatted input string.
   auto formattedJson = R"(
{
  "id": 123,
  "name": "Example, with spaces",
  "tags": [
    "A",
    "B"
  ]
}
)";

   // 3. Run the transformation and print the result.
   cout << t.Transform(formattedJson) << endl;
   // Output: {"id":123,"name":"Example, with spaces","tags":["A","B"]}

}

Building an Equation Solver with the Parser and Transformer


#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

void ucalc_call EqSolveCb(uCalcBase::Callback cb) { // Callback based on the Bisection Method
   auto expr = cb.ArgExpr(1);     // ByExpr: Unevaluated Expression object (lazy evaluation)
   auto a = cb.Arg(2);            // Argument 2: Range Minimum
   auto b = cb.Arg(3);            // Argument 3: Range Maximum
   auto variable = cb.ArgItem(4); // ByHandle: The variable Item object

   // Helper to update the variable in the uCalc engine and evaluate the expression
   auto EvaluateAt = [&](double val) -> double {
      variable.Value(val);
      return expr.Evaluate();
   };

   // Ensure f(a) < f(b) so we always know which direction to slide the bounds; swap a & b if necessary
   if (EvaluateAt(b) < EvaluateAt(a)) swap(a, b);

   auto midpoint = 0.0;
   auto fMidpoint = 0.0;

   // Bisection loop
   for (int i = 0; i <= 100; i++) {
      midpoint = (a + b) / 2;
      fMidpoint = EvaluateAt(midpoint);

      if (abs(fMidpoint) < 1e-7) break; // Stop if close enough to 0

      // Narrow the bounds (compact logic!)
      if (fMidpoint < 0) a = midpoint; else b = midpoint;
   }

   if (abs(fMidpoint) > 1e-5) cb.Error().Raise("No solution found in the given range.");
   cb.Return(round(midpoint * 10000000.0) / 10000000.0); // Return the final solved value
}
int main() {
   uCalc uc;
   // 1. Define variables that might be used by the end-user
   uc.DefineVariable("x");
   uc.DefineVariable("MyVar");

   // 2. Transformer converts `EqSolve(L = R)` into `EqSolve(L - (R))` & sets defaults before it hits the parser
   auto t = uc.ExpressionTransformer();
   t.FromTo("EqSolve({L} = {R} [[,]for {var}][, {min}, {max}])",
   "EqSolve({L} - ({R}), {min}{!min:-10000}, {max}{!max: 10000}, {var}{!var: x})");

   // 3. Define the custom function signature
   uc.DefineFunction("EqSolve(ByExpr eq, min, max, ByHandle variable)", EqSolveCb);

   // --- Demo Executions ---
   vector<string> eqList = {
      "EqSolve(x + 5 = 125)", // Using default range [-10000,10000]
      "EqSolve(x^2 + 5 = 105)", // Picks one result from the default range
      "EqSolve(x^2 + 5 = 105, 0, 100)", // Restricts to positive root
      "EqSolve(x^2 + 5 = 105, -100, 0)", // Restricts to negative root
      "EqSolve(x^2 + 1000 = 5)", // No existing solution
      "EqSolve(40 + MyVar * 6 = 88, for MyVar)" // Uses custom variable 'MyVar' instead of 'x'
   };

   for(auto eq : eqList) {
      cout << uc.ExpressionTransformer().Transform(eq) << endl; // Displays transformed expression
      cout << "Result: " << uc.EvalStr(eq) << endl; // Returns result
   }

}

Current Status & Roadmap

The uCalc SDK has been successfully packaged for modern cross-platform environments. This Developer Preview allows you to evaluate the engine's token-aware architecture, explore the interactive documentation, and integrate early before General Availability (GA).

While the core logic relies on decades of mature development, this preview is a transitional build. To set proper expectations for production use, please note the current development roadmap:

  • Performance Optimization: The Math Parser successfully targets modern compilers, but needs to undergo heavy re-optimization to match or exceed the extreme execution speeds of its legacy predecessors.

  • Structural Refinement & API Stability: The Text Transformer is slated for a clean structural rewrite under the hood to bypass current limitations and natively support advanced Language Building capabilities. Additionally, the uCalc String Library is currently still in its active design phase. Expect notable breaking API changes, especially in the String Library, as final architectures are locked in.

Product Compatible and additional computed target framework versions.
native native is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
5.7.1-preview.4 29 9/18/2026
5.7.1-preview.3 36 9/15/2026
5.7.1-preview.2 52 9/13/2026
5.7.1-preview.1 56 9/10/2026
5.7.1-preview.0 59 9/6/2026
5.7.0-preview.9 79 8/30/2026
5.7.0-preview.8 67 8/28/2026
5.7.0-preview.7 66 8/27/2026
5.7.0-preview.6 67 8/23/2026
5.7.0-preview.5 70 8/21/2026
5.7.0-preview.4 62 8/20/2026
5.7.0-preview.3 76 8/14/2026
5.7.0-preview.2 67 8/7/2026
5.7.0-preview.1 76 7/30/2026

# Release Notes

---

5.7.1-preview.4 September 18, 2026

### 🛠️ Improvements & Refinements

* Fixed: NuGet package also works with legacy .NET Framework.


---

5.7.1-preview.3 September 15, 2026

### 🛠️ Improvements & Refinements

* Added constants: `pi`, and `e`; more to come later.

**Note**: The introduction of `e` as a constant may break your code if you relied on `e` as a parameter; for instance: `DefineFunction("f(a,b,c,d,e) = a+b+c+d+e")`

---

5.7.1-preview.2 September 13, 2026

### 🛠️ Improvements & Refinements

* Support for simplified syntax in .NET, such as:
```
var myExpr = new uCalc.Expression("5+4");
Console.WriteLine(myExpr); // returns 9
```

### ⚠️ Deprecations & Breaking Changes
The previous implementation for this syntactic sugar caused ambiguity in .NET (but not C++) for some cases.  Now an Expression object evaluates as a string as though EvaluateStr() were invoked.  For other types, either casting or functions like EvaluateInt(), EvaluateDbl(), etc. must explicitly be used.

---

5.7.1-preview.1 September 9, 2026

### 🛠️ Improvements & Refinements

* The `{@File}` pattern method and `File()` and `FileSize()` functions now work across platforms (was previously implemented for Windows only).  Access restrictions to these will be configurable in a later update.
* Additional configuration constants were added; config constants are now documented.

---

5.7.1-preview.0 September 6, 2026

### 🛠️ Improvements & Refinements

* Changed the wording for the preview warning and added more context further down in the README.

---

5.7.0-preview.9 August 30, 2026

### 🛠️ Improvements & Refinements

* Added lcm() function (Least Common Multiple)

---

5.7.0-preview.8 August 28, 2026

### 🛠️ Improvements & Refinements

* The following optional parameters were added to TraceTransform(): separator, format, elementVarName, indexVarName, and stepCountVarName.

---

5.7.0-preview.7 August 26, 2026

### 🛠️ Improvements & Refinements

* Added gcd() function (Greatest Common Divisor)

---

5.7.0-preview.6 August 23, 2026

### 🛠️ Improvements & Refinements

* Fixed incorrect placement of markdown closing markers in examples for the C++ NuGet README
* Removed elements not meant to show in the NuGet README examples (both .net and C++)
* Added separate links for C++ and .NET packages in the NuGet README

---

5.7.0-preview.5 August 21, 2026

### 🛠️ Improvements & Refinements

* Embedded release notes into the NuGet package
* The README for the uCalc SDK for C++ NuGet package has examples in C++ instead of C#
* Fixed: code snippet display in the Remarks section of the documentation
* Fixed: StringRepeat crash that happened with negative value (Ex: "'a' * -1")
* Added "Invalid operation" error, distinct from "Invalid floating point operation"

---

5.7.0-preview.4 August 19, 2026

### 🛠️ Improvements & Refinements

* Equation solver example added to NuGet README file and online documentation.

---

5.7.0-preview.3 August 14, 2026

### 🛠️ Improvements & Refinements

* Hyphens mistakenly included in NuGet package tags as space substitute removed.
* Some documentation dead links fixed.
* Documentation page template restructured in more SEO-friendly way
* More accurate display of doc page change and sdk version timestamps

---

5.7.0-preview.2 August 7, 2026

### 🛠️ Improvements & Refinements

* Improved clarity for the NuGet package title, description, README, tags.

---

5.7.0-preview.1 July 29, 2026

### 🚀 Major Features & Additions

Major relaunch of uCalc with smarter functionality and extensive documentation, including 600+ interactive online examples, and AI assistant.

### 🛠️ Improvements & Refinements

### 🐛 Bug Fixes

### ⚠️ Deprecations & Breaking Changes