uCalcSoftware.Cpp
5.7.0-preview.7
dotnet add package uCalcSoftware.Cpp --version 5.7.0-preview.7
NuGet\Install-Package uCalcSoftware.Cpp -Version 5.7.0-preview.7
<PackageReference Include="uCalcSoftware.Cpp" Version="5.7.0-preview.7" />
<PackageVersion Include="uCalcSoftware.Cpp" Version="5.7.0-preview.7" />
<PackageReference Include="uCalcSoftware.Cpp" />
paket add uCalcSoftware.Cpp --version 5.7.0-preview.7
#r "nuget: uCalcSoftware.Cpp, 5.7.0-preview.7"
#:package uCalcSoftware.Cpp@5.7.0-preview.7
#addin nuget:?package=uCalcSoftware.Cpp&version=5.7.0-preview.7&prerelease
#tool nuget:?package=uCalcSoftware.Cpp&version=5.7.0-preview.7&prerelease
uCalc: The High-Performance Math Expression Evaluator and Token-Aware Text Transformation Engine
Homepage | Documentation | Online interactive examples | What's New | Release Notes | License
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.
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
}
}
Links
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| native | native is compatible. |
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.0-preview.7 | 0 | 8/27/2026 |
| 5.7.0-preview.6 | 45 | 8/23/2026 |
| 5.7.0-preview.5 | 52 | 8/21/2026 |
| 5.7.0-preview.4 | 46 | 8/20/2026 |
| 5.7.0-preview.3 | 61 | 8/14/2026 |
| 5.7.0-preview.2 | 53 | 8/7/2026 |
| 5.7.0-preview.1 | 63 | 7/30/2026 |
# Release Notes
---
5.7.0-preview.7 August 26, 2026
### 🛠️ Improvements & Refinements
* Added gcd() function
---
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
