{"id":28201174,"url":"https://github.com/axelheer/nein-math","last_synced_at":"2025-06-12T18:31:05.218Z","repository":{"id":29471497,"uuid":"33008095","full_name":"axelheer/nein-math","owner":"axelheer","description":"NeinMath is playing around with arbitrary precision integers, written in pure managed code, not using any unsafe stuff, and a bit faster than the build-in .NET type for integers with a few thousand bits.","archived":false,"fork":false,"pushed_at":"2025-05-05T15:57:35.000Z","size":1116,"stargazers_count":16,"open_issues_count":0,"forks_count":7,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-16T22:15:54.717Z","etag":null,"topics":["biginteger","bignumber","c-sharp"],"latest_commit_sha":null,"homepage":"","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/axelheer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"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":{"custom":"paypal.me/axelheer"}},"created_at":"2015-03-27T20:39:15.000Z","updated_at":"2025-05-05T15:57:38.000Z","dependencies_parsed_at":"2024-02-14T20:31:21.620Z","dependency_job_id":"1f9a3711-8740-45bc-8d68-951a806968c3","html_url":"https://github.com/axelheer/nein-math","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/axelheer/nein-math","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axelheer%2Fnein-math","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axelheer%2Fnein-math/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axelheer%2Fnein-math/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axelheer%2Fnein-math/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/axelheer","download_url":"https://codeload.github.com/axelheer/nein-math/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axelheer%2Fnein-math/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259519177,"owners_count":22870324,"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":["biginteger","bignumber","c-sharp"],"created_at":"2025-05-16T22:16:06.679Z","updated_at":"2025-06-12T18:31:05.204Z","avatar_url":"https://github.com/axelheer.png","language":"C#","funding_links":["paypal.me/axelheer"],"categories":[],"sub_categories":[],"readme":"NeinMath\n========\n\n[![Latest package](https://img.shields.io/nuget/v/NeinMath.svg)](https://www.nuget.org/packages/NeinMath)\n[![Download tracker](https://img.shields.io/nuget/dt/NeinMath.svg)](https://www.nuget.org/packages/NeinMath)\n[![GitHub status](https://github.com/axelheer/nein-math/workflows/everything/badge.svg)](https://github.com/axelheer/nein-math/actions)\n[![Code coverage](https://codecov.io/gh/axelheer/nein-math/branch/main/graph/badge.svg)](https://codecov.io/gh/axelheer/nein-math)\n\n*NeinMath* is playing around with arbitrary precision integers, written in pure managed code, not using any unsafe stuff, and a bit faster than the build-in .NET type for integers with a few thousand bits.\n\nTo install *NeinMath*, run the following command in the [NuGet Package Manager Console](http://docs.nuget.org/docs/start-here/using-the-package-manager-console).\n\n```ps1\nPM\u003e Install-Package NeinMath\n```\n\nIt's generally based on the integer implementation of [this work][0], but rewritten to not use pointer arithmetic and other fancy things. Thus, it's a bit slower albeit portable.\n\n*Note:* starting with the new .NET Core this project becomes a bit obsolete, because the performance gains disappear since some improvements have been [contributed][2]. :tada:\n\nPerformance\n-----------\n\nLet's start with a simple comparison (time per 100 operations).\n\n| Operation | Length (bits) | BigInteger (.NET) | Integer (NeinMath) |\n|:----------|--------------:|------------------:|-------------------:|\n| log       |     4,194,304 |           1306 ms |               0 ms |\n| add (+)   |     4,194,304 |             40 ms |              17 ms |\n| sub (-)   |     4,194,304 |             43 ms |              18 ms |\n| mul (*)   |        65,536 |            980 ms |             116 ms |\n| squ (^2)  |        65,536 |            980 ms |              82 ms |\n| div (/)   |        65,536 |            555 ms |             231 ms |\n| mod (%)   |        65,536 |            555 ms |             231 ms |\n| gcd       |        65,536 |            730 ms |             532 ms |\n| modinv    |        65,536 |               N/A |           1,412 ms |\n| modpow    |        16,384 |      5,124,600 ms |         652,900 ms |\n\n*Note:* ensure you're running a 64-bit process. Handling this with just 32-bits is a huge impediment for both, `BigInteger` and `Integer`.\n\n*Note:* these results are from \"my machine\". A basic (very basic) benchmark utility is included to verify / disprove them.\n\nIntegers\n--------\n\nLike [BigInteger][1] a structure `Integer` provides all the operators you would expect from an integer, so it should be quite compatible to existing .NET code. In fact, there are tests based on `BigInteger` to ensure it computes correctly most of the time.\n\nTo get an idea, this is an example for calculating the *Greatest Common Divisor*:\n\n```csharp\nInteger Gcd(Integer left, Integer right)\n{\n    var a = left.Abs();\n    var b = right.Abs();\n\n    while (b != 0)\n    {\n        var c = a % b;\n        a = b;\n        b = c;\n    }\n\n    return a;\n}\n```\n\n*Note:* calling `left.Gcd(right)` is much faster, since the internal implementation is based on a more sophisticated algorithm.\n\nRationals\n---------\n\nComing sometime... maybe... who knows?\n\n[0]: http://axel.heer.eu/2011/02/05/big-integer-arithmetik/\n[1]: http://msdn.microsoft.com/library/system.numerics.biginteger\n[2]: http://github.com/dotnet/corefx/issues/1307\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faxelheer%2Fnein-math","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faxelheer%2Fnein-math","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faxelheer%2Fnein-math/lists"}