{"id":19990712,"url":"https://github.com/ncalc/ncalc","last_synced_at":"2025-07-12T10:03:12.232Z","repository":{"id":28872871,"uuid":"110869485","full_name":"ncalc/ncalc","owner":"ncalc","description":"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.","archived":false,"fork":false,"pushed_at":"2025-07-09T18:56:09.000Z","size":1123,"stargazers_count":856,"open_issues_count":32,"forks_count":103,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-07-09T21:10:09.963Z","etag":null,"topics":["antlr","antlr4","async","csharp","dotnet","evaluation","expressions","math","ncalc","parser","runtime"],"latest_commit_sha":null,"homepage":"https://ncalc.github.io/ncalc/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ncalc.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["gumbarros"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":null,"custom":null}},"created_at":"2017-11-15T18:13:47.000Z","updated_at":"2025-07-09T18:56:14.000Z","dependencies_parsed_at":"2024-02-22T12:31:34.336Z","dependency_job_id":"af251472-f415-4c3b-95bb-8f38f4edbecf","html_url":"https://github.com/ncalc/ncalc","commit_stats":{"total_commits":76,"total_committers":15,"mean_commits":5.066666666666666,"dds":0.381578947368421,"last_synced_commit":"0d42f54f51e66780777da8022132660e11d13800"},"previous_names":[],"tags_count":45,"template":false,"template_full_name":null,"purl":"pkg:github/ncalc/ncalc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ncalc%2Fncalc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ncalc%2Fncalc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ncalc%2Fncalc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ncalc%2Fncalc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ncalc","download_url":"https://codeload.github.com/ncalc/ncalc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ncalc%2Fncalc/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264677175,"owners_count":23648121,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["antlr","antlr4","async","csharp","dotnet","evaluation","expressions","math","ncalc","parser","runtime"],"created_at":"2024-11-13T04:51:26.094Z","updated_at":"2025-07-12T10:03:12.217Z","avatar_url":"https://github.com/ncalc.png","language":"C#","funding_links":["https://github.com/sponsors/gumbarros"],"categories":["C\\#"],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n    \u003cimg src=\"NCalc.png\" alt=\"NCalc\" style=\"width:100px;\"/\u003e\n    \u003ch1\u003eNCalc\u003c/h1\u003e\n    \u003ca href=\"https://github.com/ncalc/ncalc/actions/workflows/build-test.yml\"\u003e\n      \u003cimg src=\"https://img.shields.io/github/actions/workflow/status/ncalc/ncalc/build-test.yml\" alt=\"GitHub Actions Workflow Status\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://codecov.io/gh/ncalc/ncalc\"\u003e\n      \u003cimg src=\"https://img.shields.io/codecov/c/github/ncalc/ncalc.svg\" alt=\"Coverage\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://nuget.org/packages/NCalcSync.signed\"\u003e\n      \u003cimg src=\"https://img.shields.io/nuget/v/NCalcSync.signed.svg?label=nuget\u0026color=004880\" alt=\"NuGet\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://nuget.org/packages/NCalcSync.signed\"\u003e\n      \u003cimg src=\"https://img.shields.io/nuget/dt/NCalcSync.svg?color=004880\" alt=\"NuGet Downloads\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://discord.gg/TeJkmXbqFk\"\u003e\n      \u003cimg src=\"https://img.shields.io/discord/1237181265426387005?color=5b62ef\u0026label=discord\" alt=\"Discord\" /\u003e\n    \u003c/a\u003e\n\u003c/div\u003e\n\u003cbr\u003e\n\n\n\nNCalc is a fast and lightweight expression evaluator library for .NET, designed for flexibility and high performance. It\nsupports a wide range of mathematical and logical operations. NCalc can parse any expression and evaluate the result,\nincluding static or dynamic parameters and custom functions. NCalc targets .NET 9, .NET 8, .NET Standard 2.0 and NET Framework\n4.8.\n\n## Docs\n\nNeed help or want to learn more? [Check our docs.](https://ncalc.github.io/ncalc)\n\n## Learn more\n\nFor additional information on the technique we used to create this framework please check these articles;\n- [How to execute mathematical expressions in a string in .NET](https://www.jjconsulting.com.br/en-us/blog/programming/ncalc)\n- [State of the Art Expression Evaluation](https://www.codeproject.com/Articles/18880/State-of-the-Art-Expression-Evaluation)\n\n## Help\n\n\u003e [!IMPORTANT]\n\u003e If you need help, [please open an issue](https://github.com/ncalc/ncalc/issues/new/choose) and include the expression\n\u003e to help us better understand the problem.\n\u003e Providing this information will aid in resolving the issue effectively.\n\n## Getting Started\n\nIf you want to evaluate simple expressions:\n\n```\ndotnet add package NCalcSync \n```\n\nWant `async` support at your functions and parameters?\n\n```\ndotnet add package NCalcAsync \n```\n\nDependency Injection? We got you covered:\n\n```\ndotnet add package NCalc.DependencyInjection\n```\n\n## Functionalities\n\n### Simple Expressions\n\n```c#\nvar expression = new Expression(\"2 + 3 * 5\");\nDebug.Assert(17 == expression.Evaluate());\n```\n\n**Evaluates .NET data types**\n\n```c#\nDebug.Assert(123456 == new Expression(\"123456\").Evaluate()); // integers\nDebug.Assert(new DateTime(2001, 01, 01) == new Expression(\"#01/01/2001#\").Evaluate()); // date and times\nDebug.Assert(123.456 == new Expression(\"123.456\").Evaluate()); // floating point numbers\nDebug.Assert(true == new Expression(\"true\").Evaluate()); // booleans\nDebug.Assert(\"azerty\" == new Expression(\"'azerty'\").Evaluate()); // strings\n```\n\n**Handles mathematical functional from System.Math**\n\n```c#\nDebug.Assert(0 == new Expression(\"Sin(0)\").Evaluate());\nDebug.Assert(2 == new Expression(\"Sqrt(4)\").Evaluate());\nDebug.Assert(0 == new Expression(\"Tan(0)\").Evaluate());\n```\n\n**Evaluates custom functions**\n\n```c#\nvar expression = new Expression(\"SecretOperation(3, 6)\");\nexpression.Functions[\"SecretOperation\"] = (args) =\u003e {\n    return (int)args[0].Evaluate() + (int)args[1].Evaluate();\n};\n\nDebug.Assert(9 == expression.Evaluate());\n```\n\n**Handles unicode characters**\n\n```c#\nDebug.Assert(\"経済協力開発機構\" == new Expression(\"'経済協力開発機構'\").Evaluate());\nDebug.Assert(\"Hello\" == new Expression(@\"'\\u0048\\u0065\\u006C\\u006C\\u006F'\").Evaluate());\nDebug.Assert(\"だ\" == new Expression(@\"'\\u3060'\").Evaluate());\nDebug.Assert(\"\\u0100\" == new Expression(@\"'\\u0100'\").Evaluate());\n```\n\n**Define parameters, even dynamic or expressions**\n\n```c#\nvar expression = new Expression(\"Round(Pow([Pi], 2) + Pow([Pi2], 2) + [X], 2)\");\n\nexpression.Parameters[\"Pi2\"] = new Expression(\"Pi * [Pi]\");\nexpression.Parameters[\"X\"] = 10;\n\nexpression.DynamicParameters[\"Pi\"] = _ =\u003e {\n    Console.WriteLine(\"I'm evaluating π!\");\n    return 3.14;\n};\n\nDebug.Assert(117.07 == expression.Evaluate());\n```\n\n**JSON Serialization**\n\nAt .NET 8+, NCalc have built-in support to polymorphic JSON serialization using [System.Text.Json](https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json).\n\n```c#\nconst string expressionString = \"{waterLevel} \u003e 4.0\";\n\nvar logicalExpression = LogicalExpressionFactory.Create(expressionString, ExpressionOptions.NoCache); //Created a BinaryExpression object.\n\nvar jsonExpression = JsonSerializer.Serialize(parsedExpression);\n\nvar deserializedLogicalExpression = JsonSerializer.Deserialize\u003cLogicalExpression\u003e(jsonExpression); //The object is still a BinaryExpression.\n\nvar expression = new Expression(deserializedLogicalExpression);\n\nexpression.Parameters = new Dictionary\u003cstring, object\u003e {\n    {\"waterLevel\", 4.0}\n};\n\nvar result = expression.Evaluate();\n```\n\n**Caching**\n\nNCalc automatically cache the parsing of strings using a [`ConcurrentDictionary`](https://learn.microsoft.com/pt-br/dotnet/api/system.collections.concurrent.concurrentdictionary-2).\nYou can also use our [Memory Cache plugin](https://ncalc.github.io/ncalc/articles/plugins/memory_cache.html).\n\n**Lambda Expressions**\n\n```cs\nvar expression = new Expression(\"1 + 2\");\nFunc\u003cint\u003e function = expression.ToLambda\u003cint\u003e();\nDebug.Assert(function()); //3\n```\n\n## Related projects\n\n### [Parlot](https://github.com/sebastienros/parlot)\n\nFast and lightweight parser creation tools by [Sébastien Ros](https://github.com/sebastienros) that NCalc uses at its\nparser.\n\n### [FastExpressionCompiler](https://github.com/dadhi/FastExpressionCompiler)\n\nFast Compiler for C# Expression Trees. Developed by [Maksim Volkov](https://github.com/dadhi)\n\n### [PanoramicData.NCalcExtensions](https://github.com/panoramicdata/PanoramicData.NCalcExtensions)\n\nExtension functions for NCalc to handle many general functions,  \nincluding string functions, switch, if, in, typeOf, cast etc.  \nDeveloped by David, Dan and all at [Panoramic Data](https://github.com/panoramicdata).\n\n### [Jint](https://github.com/sebastienros/jint)\n\nJavaScript Interpreter for .NET by [Sébastien Ros](https://github.com/sebastienros), the author of NCalc library.  \nRuns on any modern .NET platform as it supports .NET Standard 2.0 and .NET 4.6.1 targets (and up).\n\n### [NCalcJS](https://github.com/thomashambach/ncalcjs)\n\nA TypeScript/JavaScript port of NCalc.\n\n### [NCalc101](https://ncalc101.magicsuite.net)\n\nNCalc 101 is a simple web application that allows you to try out the NCalc expression evaluator, developed\nby [Panoramic Data](https://github.com/panoramicdata).\n\n### [JJMasterData](https://github.com/JJConsulting/JJMasterData/)\n\nJJMasterData is a runtime form generator from database metadata. It uses NCalc to evaluate expressions used in field\nvisibility and other dynamic behaviors.\n\n## NCalc versioning\n\nThe project uses [Nerdbank.GitVersioning](https://github.com/dotnet/Nerdbank.GitVersioning) tool to manage versions.  \nEach library build can be traced back to the original git commit.\nRead more about [versioning here.](https://ncalc.github.io/ncalc/articles/new_release.html)\n## Discord Server\n\nIf you want to talk with us, get support or just get the latest NCalc\nnews, [come to our discord server](https://discord.gg/TeJkmXbqFk).\n\n## Star History\n\n\u003ca href=\"https://star-history.com/#ncalc/ncalc\u0026Date\"\u003e\n \u003cpicture\u003e\n   \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://api.star-history.com/svg?repos=ncalc/ncalc\u0026type=Date\u0026theme=dark\" /\u003e\n   \u003csource media=\"(prefers-color-scheme: light)\" srcset=\"https://api.star-history.com/svg?repos=ncalc/ncalc\u0026type=Date\" /\u003e\n   \u003cimg alt=\"Star History Chart\" src=\"https://api.star-history.com/svg?repos=ncalc/ncalc\u0026type=Date\" /\u003e\n \u003c/picture\u003e\n\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fncalc%2Fncalc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fncalc%2Fncalc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fncalc%2Fncalc/lists"}