VOOZH about

URL: https://www.nuget.org/packages/StringMath/

⇱ NuGet Gallery | StringMath 4.1.3




StringMath 4.1.3

dotnet add package StringMath --version 4.1.3
 
 
NuGet\Install-Package StringMath -Version 4.1.3
 
 
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="4.1.3" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="StringMath" Version="4.1.3" />
 
Directory.Packages.props
<PackageReference Include="StringMath" />
 
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 StringMath --version 4.1.3
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: StringMath, 4.1.3"
 
 
#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 StringMath@4.1.3
 
 
#: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=StringMath&version=4.1.3
 
Install as a Cake Addin
#tool nuget:?package=StringMath&version=4.1.3
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

V3 README can be found here: https://github.com/miroiu/string-math/tree/release-3.0.0

NEW! Boolean math example: https://github.com/miroiu/string-math/pull/6/files

String Math 👁 NuGet
👁 Downloads
👁 .NET
👁 alternate text is missing from this package README image

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

double result = "1 * (2 - 3) ^ 2".Eval(); // 1

Variables

double result = "{a} + 2 * {b}".Substitute("a", 2).Substitute("b", 3).Result; // 8

Global variables

These variables are inherited and cannot be substituted.

MathExpr.AddVariable("PI", 3.1415926535897931);
double result = "1 + {PI}".Eval(); // 4.1415926535897931

Custom operators

Global operators

These operators are inherited and can be overidden.

MathExpr.AddOperator("abs", a => a > 0 ? a : -a);
double result = "abs -5".Eval(); // 5

// Operator precedence (you can specify an int for precedence)
MathExpr.AddOperator("max", (a, b) => a > b ? a : b, Precedence.Power);
double result = new MathExpr("2 * 3 max 4").Result; // 8

Local operators

These are applied only to the target expression.

MathExpr expr = "{PI} + 1";
expr.SetOperator("+", (a, b) => Math.Pow(a, b));
double result = expr; // 3.1415926535897931

double result2 = "{PI} + 1".Eval(); // 4.1415926535897931

Advanced

Extract variables

var expr = "{a} + {b} + {PI}".ToMathExpr();
var variables = expr.Variables; // { "a", "b", "PI" }
var localVariables = expr.LocalVariables; // { "a", "b" }

Compilation

Func<double, double> fn = "{a} + 2".ToMathExpr().Compile("a");
double result = fn(5); // 7

Conditional substitution

MathExpr expr = "1 / {a}".Substitute("a", 1);

double temp = expr.Result; // 1

if (someCondition) // true
 expr.Substitute("a", 2);

double final = expr.Result; // 0.5

Sharing math context

MathExpr expr = "{PI} + 1";
expr.SetOperator("+", (a, b) => Math.Pow(a, b));

MathExpr expr2 = "3 + 2".ToMathExpr(expr.Context);

double result = "1 + 2 + 3".Eval(expr.Context);

Custom math context

var context = new MathContext(); // new MathContext(MathContext.Default); // to inherit from global
context.RegisterBinary("+", (a, b) => Math.Pow(a, b));

MathExpr expr = new MathExpr("{PI} + 1", context);
MathExpr expr2 = "3 + 2".ToMathExpr(context);
double result = "1 + 2 + 3".Eval(context);

Default operators

Binary

+ (addition)
- (subtraction)
* (multiplication)
/ (division)
% (remainder)
^ (power)
log (logarithm)
max (maximum)
min (minimum)

Unary

- (negation)
! (factorial)
sqrt (square root)
sin (sine)
asin (arcsine)
cos (cosine)
acos (arccosine)
tan (tangent)
atan (arctangent)
rad (convert degrees to radians)
deg (convert radians to degrees)
ceil (ceiling)
floor (floor)
round (rounding)
exp (e raised to power)
abs (absolute)
Product Versions Compatible and additional computed target framework versions.
.NET net5.0 net5.0 is compatible.  net5.0-windows net5.0-windows was computed.  net6.0 net6.0 is compatible.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 is compatible.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
.NET Core netcoreapp3.0 netcoreapp3.0 was computed.  netcoreapp3.1 netcoreapp3.1 is compatible. 
.NET Standard netstandard2.1 netstandard2.1 is compatible. 
.NET Framework net461 net461 is compatible.  net462 net462 was computed.  net463 net463 was computed.  net47 net47 was computed.  net471 net471 was computed.  net472 net472 is compatible.  net48 net48 is compatible.  net481 net481 was computed. 
MonoAndroid monoandroid monoandroid was computed. 
MonoMac monomac monomac was computed. 
MonoTouch monotouch monotouch was computed. 
Tizen tizen60 tizen60 was computed. 
Xamarin.iOS xamarinios xamarinios was computed. 
Xamarin.Mac xamarinmac xamarinmac was computed. 
Xamarin.TVOS xamarintvos xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.6.1

    • No dependencies.
  • .NETFramework 4.7.2

    • No dependencies.
  • .NETFramework 4.8

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net5.0

    • No dependencies.
  • net6.0

    • No dependencies.
  • net8.0

    • 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 (2)

Showing the top 2 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.
PinchToDebug/EverythingQuickSearch
Version Downloads Last Updated
4.1.3 21,758 7/1/2025
4.1.2 64,067 1/22/2024
4.1.1 1,196 1/11/2024
4.1.0 29,237 10/12/2022
4.0.0 2,675 10/12/2022
3.0.2 334,147 12/20/2021
3.0.1 5,413 8/25/2021
3.0.0 533 8/25/2021
2.1.0 220,729 12/4/2020
2.0.0 795 2/1/2020
1.0.1 922 1/25/2020

Fixed a parsing error for some operators.