NCalcSync 5.3.1
dotnet add package NCalcSync --version 5.3.1
NuGet\Install-Package NCalcSync -Version 5.3.1
<PackageReference Include="NCalcSync" Version="5.3.1" />
paket add NCalcSync --version 5.3.1
#r "nuget: NCalcSync, 5.3.1"
// Install NCalcSync as a Cake Addin #addin nuget:?package=NCalcSync&version=5.3.1 // Install NCalcSync as a Cake Tool #tool nuget:?package=NCalcSync&version=5.3.1
<div align="center"> <img src="NCalc.png" alt="NCalc" style="width:100px;"/> <h1>NCalc</h1> <a href="https://github.com/ncalc/ncalc/actions/workflows/build-test.yml"> <img src="https://img.shields.io/github/actions/workflow/status/ncalc/ncalc/build-test.yml" alt="GitHub Actions Workflow Status" /> </a> <a href="https://codecov.io/gh/ncalc/ncalc"> <img src="https://img.shields.io/codecov/c/github/ncalc/ncalc.svg" alt="Coverage" /> </a> <a href="https://nuget.org/packages/NCalcSync.signed"> <img src="https://img.shields.io/nuget/v/NCalcSync.signed.svg?label=nuget&color=004880" alt="NuGet" /> </a> <a href="https://nuget.org/packages/NCalcSync.signed"> <img src="https://img.shields.io/nuget/dt/NCalcSync.svg?color=004880" alt="NuGet Downloads" /> </a> <a href="https://discord.gg/TeJkmXbqFk"> <img src="https://img.shields.io/discord/1237181265426387005?color=5b62ef&label=discord" alt="Discord" /> </a> </div> <br>
NCalc is a fast and lightweight expression evaluator library for .NET, designed for flexibility and high performance. It supports a wide range of mathematical and logical operations. NCalc can parse any expression and evaluate the result, including static or dynamic parameters and custom functions. NCalc targets .NET 8, .NET Standard 2.0 and NET Framework 4.8.
Docs
Need help or want to learn more? Check our docs.
Learn more
For additional information on the technique we used to create this framework please read this article.
Help
[!IMPORTANT] If you need help, please open an issue and include the expression to help us better understand the problem. Providing this information will aid in resolving the issue effectively.
Getting Started
If you want to evaluate simple expressions:
dotnet add package NCalcSync
Want async
support at your functions and parameters?
dotnet add package NCalcAsync
Dependency Injection? We got you covered:
dotnet add package NCalc.DependencyInjection
Functionalities
Simple Expressions
var expression = new Expression("2 + 3 * 5");
Debug.Assert(17 == expression.Evaluate());
Evaluates .NET data types
Debug.Assert(123456 == new Expression("123456").Evaluate()); // integers
Debug.Assert(new DateTime(2001, 01, 01) == new Expression("#01/01/2001#").Evaluate()); // date and times
Debug.Assert(123.456 == new Expression("123.456").Evaluate()); // floating point numbers
Debug.Assert(true == new Expression("true").Evaluate()); // booleans
Debug.Assert("azerty" == new Expression("'azerty'").Evaluate()); // strings
Handles mathematical functional from System.Math
Debug.Assert(0 == new Expression("Sin(0)").Evaluate());
Debug.Assert(2 == new Expression("Sqrt(4)").Evaluate());
Debug.Assert(0 == new Expression("Tan(0)").Evaluate());
Evaluates custom functions
var expression = new Expression("SecretOperation(3, 6)");
expression.Functions["SecretOperation"] = (args) => {
return (int)args[0].Evaluate() + (int)args[1].Evaluate();
};
Debug.Assert(9 == expression.Evaluate());
Handles unicode characters
Debug.Assert("経済協力開発機構" == new Expression("'経済協力開発機構'").Evaluate());
Debug.Assert("Hello" == new Expression(@"'\u0048\u0065\u006C\u006C\u006F'").Evaluate());
Debug.Assert("だ" == new Expression(@"'\u3060'").Evaluate());
Debug.Assert("\u0100" == new Expression(@"'\u0100'").Evaluate());
Define parameters, even dynamic or expressions
var expression = new Expression("Round(Pow([Pi], 2) + Pow([Pi2], 2) + [X], 2)");
expression.Parameters["Pi2"] = new Expression("Pi * [Pi]");
expression.Parameters["X"] = 10;
expression.DynamicParameters["Pi"] = _ => {
Console.WriteLine("I'm evaluating π!");
return 3.14;
};
Debug.Assert(117.07 == expression.Evaluate());
JSON Serialization
At .NET 8+, NCalc have built-in support to polymorphic JSON serialization using System.Text.Json.
const string expressionString = "{waterLevel} > 4.0";
var logicalExpression = LogicalExpressionFactory.Create(expressionString, ExpressionOptions.NoCache); //Created a BinaryExpression object.
var jsonExpression = JsonSerializer.Serialize(parsedExpression);
var deserializedLogicalExpression = JsonSerializer.Deserialize<LogicalExpression>(jsonExpression); //The object is still a BinaryExpression.
var expression = new Expression(deserializedLogicalExpression);
expression.Parameters = new Dictionary<string, object> {
{"waterLevel", 4.0}
};
var result = expression.Evaluate();
Caching
NCalc automatically cache the parsing of strings using a ConcurrentDictionary
.
You can also use our Memory Cache plugin.
Lambda Expressions
var expression = new Expression("1 + 2");
Func<int> function = expression.ToLambda<int>();
Debug.Assert(function()); //3
Related projects
Parlot
Fast and lightweight parser creation tools by Sébastien Ros that NCalc uses at its parser.
PanoramicData.NCalcExtensions
Extension functions for NCalc to handle many general functions,
including string functions, switch, if, in, typeOf, cast etc.
Developed by David, Dan and all at Panoramic Data.
Jint
JavaScript Interpreter for .NET by Sébastien Ros, the author of NCalc library.
Runs on any modern .NET platform as it supports .NET Standard 2.0 and .NET 4.6.1 targets (and up).
NCalcJS
A TypeScript/JavaScript port of NCalc.
NCalc101
NCalc 101 is a simple web application that allows you to try out the NCalc expression evaluator, developed by Panoramic Data.
JJMasterData
JJMasterData is a runtime form generator from database metadata. It uses NCalc to evaluate expressions used in field visibility and other dynamic behaviors.
NCalc versioning
The project uses Nerdbank.GitVersioning tool to manage versions.
Each library build can be traced back to the original git commit.
Read more about versioning here.
Discord Server
If you want to talk with us, get support or just get the latest NCalc news, come to our discord server.
Star History
<a href="https://star-history.com/#ncalc/ncalc&Date"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=ncalc/ncalc&type=Date&theme=dark" /> <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=ncalc/ncalc&type=Date" /> <img alt="Star History Chart" src="https://api.star-history.com/svg?repos=ncalc/ncalc&type=Date" /> </picture> </a>
Product | Versions 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 is compatible. 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. net9.0 is compatible. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.2
- NCalc.Core (>= 5.3.1)
-
.NETStandard 2.0
- NCalc.Core (>= 5.3.1)
-
net8.0
- NCalc.Core (>= 5.3.1)
-
net9.0
- NCalc.Core (>= 5.3.1)
NuGet packages (11)
Showing the top 5 NuGet packages that depend on NCalcSync:
Package | Downloads |
---|---|
JJMasterData.Core
JJMasterData library to render JJMasterData's components. |
|
PGCG.commonItems
Package Description |
|
NCalc.DependencyInjection
NCalc is a mathematical expression evaluator for .NET. This assembly brings Dependency Injection support for NCalc. |
|
PikTools.NonModelElements.Shared
Набор инстументов, содержащих общую логику приложения "Создание немоделируемых элементов" |
|
Asgard.Yggdrasil
切换Mysql数据驱动到FreeSql.Provider.MySqlConnector |
GitHub repositories (5)
Showing the top 5 popular GitHub repositories that depend on NCalcSync:
Repository | Stars |
---|---|
squiggythings/WaveTracker
A free and open source music-making software for Windows. Uses wavetable synthesis and sampling to generate sounds.
|
|
AscensionGameDev/Intersect-Engine
Intersect provides a complete game development suite for creating 2d mmorpgs with no programming experience required!
|
|
egvijayanand/dotnet-maui-samples
.NET MAUI Samples
|
|
JJConsulting/JJMasterData
.NET CRUD generator library with Bootstrap support to create dynamic forms at runtime from a data dictionary.
|
|
naweed/MauiScientificCalculator
Scientific Calculator built using #dotnetmaui
|
Version | Downloads | Last updated |
---|---|---|
5.3.1 | 529 | 12/18/2024 |
5.3.0 | 8,688 | 11/16/2024 |
5.2.11 | 28,706 | 10/25/2024 |
5.2.10 | 12,113 | 10/7/2024 |
5.2.9 | 13,433 | 9/26/2024 |
5.2.8 | 22,255 | 9/3/2024 |
5.2.7 | 1,243 | 9/2/2024 |
5.2.6 | 1,154 | 8/30/2024 |
5.2.5 | 1,461 | 8/29/2024 |
5.2.4 | 474 | 8/28/2024 |
5.2.3 | 3,206 | 8/23/2024 |
5.2.2 | 12,681 | 8/9/2024 |
5.2.1 | 4,922 | 8/6/2024 |
5.2.0 | 21,796 | 7/26/2024 |
5.1.0 | 6,267 | 7/12/2024 |
5.0.0 | 13,486 | 7/1/2024 |
4.4.0-alpha | 197 | 6/10/2024 |
4.3.3 | 10,017 | 6/14/2024 |
4.3.2 | 2,577 | 6/12/2024 |
4.3.1 | 411 | 6/11/2024 |
4.3.0 | 379 | 6/10/2024 |
4.2.1 | 630 | 6/7/2024 |
4.2.0 | 1,475 | 6/4/2024 |
4.1.0 | 2,109 | 5/26/2024 |
4.0.0 | 8,551 | 5/21/2024 |
3.13.1 | 11,498 | 5/16/2024 |
3.13.0 | 3,979 | 5/6/2024 |
3.12.0 | 89,271 | 3/18/2024 |
3.11.0 | 94,311 | 2/26/2024 |
3.10.0 | 75,457 | 12/24/2023 |
3.9.0 | 24,687 | 12/5/2023 |
3.8.0 | 166,994 | 7/20/2023 |
3.7.0 | 15,078 | 7/14/2023 |
3.6.0 | 245,989 | 11/28/2022 |
3.5.0 | 111,800 | 6/10/2022 |
3.4.0 | 4,608 | 5/30/2022 |
3.2.0 | 1,068 | 5/26/2022 |
3.1.0 | 979 | 5/23/2022 |
3.0.0 | 969,306 | 12/22/2021 |
2.0.0 | 24,967 | 11/9/2020 |