![]() |
VOOZH | about |
dotnet add package StringMath --version 4.1.3
NuGet\Install-Package StringMath -Version 4.1.3
<PackageReference Include="StringMath" Version="4.1.3" />
<PackageVersion Include="StringMath" Version="4.1.3" />Directory.Packages.props
<PackageReference Include="StringMath" />Project file
paket add StringMath --version 4.1.3
#r "nuget: StringMath, 4.1.3"
#:package StringMath@4.1.3
#addin nuget:?package=StringMath&version=4.1.3Install as a Cake Addin
#tool nuget:?package=StringMath&version=4.1.3Install as a Cake Tool
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
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
double result = "{a} + 2 * {b}".Substitute("a", 2).Substitute("b", 3).Result; // 8
These variables are inherited and cannot be substituted.
MathExpr.AddVariable("PI", 3.1415926535897931);
double result = "1 + {PI}".Eval(); // 4.1415926535897931
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
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
var expr = "{a} + {b} + {PI}".ToMathExpr();
var variables = expr.Variables; // { "a", "b", "PI" }
var localVariables = expr.LocalVariables; // { "a", "b" }
Func<double, double> fn = "{a} + 2".ToMathExpr().Compile("a");
double result = fn(5); // 7
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
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);
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);
+ (addition)
- (subtraction)
* (multiplication)
/ (division)
% (remainder)
^ (power)
log (logarithm)
max (maximum)
min (minimum)
- (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. |
Showing the top 1 NuGet packages that depend on StringMath:
| Package | Downloads |
|---|---|
|
KS.CoreCLR
Simulates our future-planned kernel |
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 |
Fixed a parsing error for some operators.