StringMath 3.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package StringMath --version 3.0.1
NuGet\Install-Package StringMath -Version 3.0.1
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="StringMath" Version="3.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add StringMath --version 3.0.1
#r "nuget: StringMath, 3.0.1"
#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.
// Install StringMath as a Cake Addin
#addin nuget:?package=StringMath&version=3.0.1

// Install StringMath as a Cake Tool
#tool nuget:?package=StringMath&version=3.0.1

String Math NuGet Downloads .NET

Calculates the value of a math expression from a string returning a double. Supports variables and user-defined operators.

Creating and using a calculator

ICalculator myCalculator = new Calculator();
double result = myCalculator.Evaluate("1 * (2 - 3) ^ 2"); // 1

// Using custom operators
myCalculator.AddOperator("abs", a => a > 0 ? a : -a);
double result = myCalculator.Evaluate("abs -5"); // 5

// Using custom operator precedence (you can specify an int for precedence)
myCalculator.AddOperator("max", (a, b) => a > b ? a : b, Precedence.Power);
double result = myCalculator.Evaluate("2 * 3 max 4"); // 8

Creating and using variables

// Default variables collection is optional
ICalculator myCalculator = new Calculator(new VariablesCollection
{
	["a"] = 5,
	["PI"] = 3.1415926535897931
});

// Setting or creating variables
myCalculator.SetValue("a", 2);
myCalculator["b"] = 1;

double result = myCalculator.Evaluate("{a} + 2 * {b} + {PI}"); // 7.1415926535897931

Creating and reusing operations

myCalculator.SetValue("a", 5);

// Creating operations (expression tree is optimized and cached)
OperationInfo op = myCalculator.CreateOperation("2 * {a}");
double result1 = myCalculator.Evaluate(op); // 10

myCalculator["a"] = 3;
// Reusing the operation (improved performance)
double result2 = myCalculator.Evaluate(op); // 6

Using the static api: SMath

// Same API as a calculator instance except the Evaluate method
double result = SMath.Evaluate("1 + 1"); // 2
SMath.SetValues(new VariablesCollection { ["myVar"] = 1 });
double result = SMath.Evaluate("1 + {myVar}", ); // 2
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 is compatible. 
.NET Standard netstandard2.1 is compatible. 
.NET Framework net472 is compatible.  net48 is compatible.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.1

    • No dependencies.
  • .NETFramework 4.7.2

    • No dependencies.
  • .NETFramework 4.8

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on StringMath:

Package Downloads
KS.CoreCLR

Simulates our future-planned kernel

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on StringMath:

Repository Stars
miroiu/nodify
Highly performant and modular controls for node-based editors designed for data-binding and MVVM.
Version Downloads Last updated
4.1.2 5,278 1/22/2024
4.1.1 956 1/11/2024
4.1.0 24,400 10/12/2022
4.0.0 2,323 10/12/2022
3.0.2 116,036 12/20/2021
3.0.1 5,020 8/25/2021
3.0.0 288 8/25/2021
2.1.0 115,222 12/4/2020
2.0.0 505 2/1/2020
1.0.1 621 1/25/2020

Added multi-targeting and signed the assembly.