info.lundin.math.dll 1.2.7

.NET Standard 2.0 .NET Framework 4.0
The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
NuGet\Install-Package info.lundin.math.dll -Version 1.2.7
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.
dotnet add package info.lundin.math.dll --version 1.2.7
<PackageReference Include="info.lundin.math.dll" Version="1.2.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add info.lundin.math.dll --version 1.2.7
#r "nuget: info.lundin.math.dll, 1.2.7"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install info.lundin.math.dll as a Cake Addin
#addin nuget:?package=info.lundin.math.dll&version=1.2.7

// Install info.lundin.math.dll as a Cake Tool
#tool nuget:?package=info.lundin.math.dll&version=1.2.7

info.lundin.math - ExpressionParser

Math expression parser, evaluates a string mathematical expression and returns a double value.

More information at

Author: Patrik Lundin

Quick use

ExpressionParser parser = new ExpressionParser();

parser.Values.Add("x", 2); parser.Values.Add("y", 10);

double result = parser.Parse("x^3+5x^2-3");

Changing variable values

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

Faster evaluation by keeping the expression tree

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);

Serialization of parsed expressions

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.

Supported operators and functions

+, -, *, /, ^, %

^ 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.

Supported constants

PI (value of System.Math.PI) Euler (value of System.Math.E) true (1.0) false (0.0) infinity (value of Double.PositiveInfinity)

Variable naming restrictions

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

Properties and settings

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.

Cultures and decimal separators

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.

Limitations of using double values

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.

Unit testing

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.

License and disclaimer

Patrik Lundin,, Copyright 2002-2019 Patrik Lundin

Library and Source code released under the Microsoft Public License (Ms-PL)

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net40 net403 net45 net451 net452 net46 net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.0

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (8)

Showing the top 5 NuGet packages that depend on info.lundin.math.dll:

Package Downloads

UI Library for MonoGame, FNA and Stride

Used internally in MeterVue by I+P Services


UI Library for MonoGame, FNA and Xenko


UI Library for MonoGame, FNA and Stride


UI Library for MonoGame, FNA and Stride

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on info.lundin.math.dll:

Repository Stars
UI Library for MonoGame, FNA and Stride
Mod Manager for Paradox Games. Official Discord:
Version Downloads Last updated

Package information updated with new links. No other changes.