![]() |
VOOZH | about |
dotnet add package info.lundin.math.dll --version 1.2.7
NuGet\Install-Package info.lundin.math.dll -Version 1.2.7
<PackageReference Include="info.lundin.math.dll" Version="1.2.7" />
<PackageVersion Include="info.lundin.math.dll" Version="1.2.7" />Directory.Packages.props
<PackageReference Include="info.lundin.math.dll" />Project file
paket add info.lundin.math.dll --version 1.2.7
#r "nuget: info.lundin.math.dll, 1.2.7"
#:package info.lundin.math.dll@1.2.7
#addin nuget:?package=info.lundin.math.dll&version=1.2.7Install as a Cake Addin
#tool nuget:?package=info.lundin.math.dll&version=1.2.7Install as a Cake Tool
Math expression parser, evaluates a string mathematical expression and returns a double value.
More information at http://lundin.live/mathparser
Author: Patrik Lundin
ExpressionParser parser = new ExpressionParser();
parser.Values.Add("x", 2); parser.Values.Add("y", 10);
double result = parser.Parse("x^3+5x^2-3");
ExpressionParser parser = new ExpressionParser();
// Create value instances DoubleValue xval = new DoubleValue(); DoubleValue yval = new DoubleValue();
// Add values for variables x and y parser.Values.Add("x", xval); parser.Values.Add("y", yval);
xval.Value = 2; // Update value of "x" yval.Value = 10; // Update value of "y"
double result = parser.Parse("x^3+5x^2-3");
Updating values using the SetValue method:
parser.Values["x"].SetValue(2); // x previously added with Add parser.Values["y"].SetValue(10); // y previously added with Add
Updating by casting and setting the Value property:
((DoubleValue)parser.Values["x"]).Value = 2; // x previously added with Add ((DoubleValue)parser.Values["y"]).Value = 10; // y previously added with Add
ExpressionParser parser = new ExpressionParser();
parser.Values.Add("x", 2); parser.Values.Add("y", 10);
// Parse once string func = "x^3+5x^2-3"; parser.Parse(func);
// Fetch expression Expression expression = parser.Expressions[func];
// Evaluate saved expression double result = parser.EvalExpression(expression);
To save some initial parsing time you can serialize the expressions to a Stream for storage and later use.
Both the Expression (see above) and the ExpressionDictionary accessable by the property parser.Expressions have Save and Load methods that take a Stream as parameter. Serializing should only be needed with large sets of expressions where the initial parse time may be significant.
Please note that serializing expressions and then deserializing using a different culture setting may have unintended effects. If you do use the serialization feature it is recommended to leave the culture setting to the default invariant culture.
+, -, *, /, ^, %
^ is raised to (power) for example 3^2 % is the modulo operator
sqrt, sin, cos, tan, atan, acos, asin, acotan, exp, ln, log, sinh, cosh, tanh, abs, ceil, floor, fac, sfac, round, fpart
These functions mostly map to the System.Math functions except fac, sfac which is the factorial and semi-factorial functions and fpart which returns the decimal part of a value.
!, ==, !=, ||, &&, >, < , >=, ⇐ Logical operators, 1.0 means true, 0.0 means false. If an expression evaluates to anything other than 1.0 it is considered false.
There is currently no support for adding additional operators or functions.
PI (value of System.Math.PI) Euler (value of System.Math.E) true (1.0) false (0.0) infinity (value of Double.PositiveInfinity)
All variable names must start with an alphabetic letter (a-z) and may contain digits at the end but not inside the variable name.
Examples: x, y, z, var1, var2, myverylongvariablename
Variable names can contain function keywords ONLY when ImplicitMultiplication is set to false and RequireParentheses is set to true.
Examples: glucose, sincosexp
The following properties can be set on the ExpressionParser:
RequireParentheses - toggles the requirement to use parentheses around function arguments (default true) ImplicitMultiplication - toggles if implicit multiplication is allowed (such as 3x instead of 3*x) (default true) Culture - the culture to use when parsing, affects decimal and groupign separators (default CurltureInfo.InvariantCulture) Expressions - provides access to the ExpressionDictionary containing all parsed expressions. Values - provides access to the ValuesDictionary for adding variable/value pairs to use for evaluating expressions.
The default culture is set to CultureInfo.InvariantCulture which uses a single dot (.) as the decimal separator and comma (,) as grouping (thousands) separator.
You can change the culture by setting the property Culture in the parser, if you do change the culture the number decimal separator in your expressions must match the culture. It is recommended that you use the default invariant culture and use a dot as a decimal separator especially if you decide to save parsed expressions as serialized data.
Culture fa, fa-IR uses the division operator (/) as the decimal separator, this is not allowed in the parser and the recommended solution is to use the invariant culture.
Currency symbols are not allowed. Thousands separators are supported but not recommended to use.
Cultures using the same decimal and grouping separators are not allowed.
If you use the parser for financial calculations please make sure you understand how IEEE754 floating point values work and the rounding errors that may result.
It is generally not recommended to use float or double values for money applications since these are floating point values with a binary representation, for languages that have them a decimal representation is recommended, however this parser uses the default System.Math library and only operate with double values.
The provided tests should not be considered to fully test every scenario.
Remember it is YOUR responsibility to verify that the parser works correctly for the intended use, it is recommended that you write some additional unit tests that tests with your specific data.
Patrik Lundin, patrik@lundin.live, http://www.lundin.live Copyright 2002-2019 Patrik Lundin
Library and Source code released under the Microsoft Public License (Ms-PL) https://opensource.org/licenses/ms-pl.html
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. 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 was computed. 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 | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net40 net40 is compatible. net403 net403 was computed. net45 net45 was computed. net451 net451 was computed. net452 net452 was computed. net46 net46 was computed. net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. 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 5 NuGet packages that depend on info.lundin.math.dll:
| Package | Downloads |
|---|---|
|
Myra
UI Library for MonoGame, FNA and Stride |
|
|
Myra.Stride
UI Library for MonoGame, FNA and Stride |
|
|
da.metervue.net
Used internally in MeterVue by I+P Services |
|
|
Myra.PlatformAgnostic
UI Library for MonoGame, FNA and Stride |
|
|
JKMP.Myra.Stride
UI Library for MonoGame, FNA and Stride. Note: this is a modified fork used by JKMP. |
Showing the top 2 popular GitHub repositories that depend on info.lundin.math.dll:
| Repository | Stars |
|---|---|
|
MyraUI/Myra
UI Library for MonoGame, FNA and Stride
|
|
|
bcssov/IronyModManager
Mod Manager for Paradox Games. Official Discord: https://discord.gg/t9JmY8KFrV
|
| Version | Downloads | Last Updated |
|---|
Package information updated with new links. No other changes.