NeinMath 1.5.1
dotnet add package NeinMath --version 1.5.1
NuGet\Install-Package NeinMath -Version 1.5.1
<PackageReference Include="NeinMath" Version="1.5.1" />
paket add NeinMath --version 1.5.1
#r "nuget: NeinMath, 1.5.1"
// Install NeinMath as a Cake Addin #addin nuget:?package=NeinMath&version=1.5.1 // Install NeinMath as a Cake Tool #tool nuget:?package=NeinMath&version=1.5.1
NeinMath
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.
To install NeinMath, run the following command in the NuGet Package Manager Console.
PM> Install-Package NeinMath
It's generally based on the integer implementation of this work, but rewritten to not use pointer arithmetic and other fancy things. Thus, it's a bit slower albeit portable.
Note: starting with the new .NET Core this project becomes a bit obsolete, because the performance gains disappear since some improvements have been contributed. 🎉
Performance
Let's start with a simple comparison (time per 100 operations).
Operation | Length (bits) | BigInteger (.NET) | Integer (NeinMath) |
---|---|---|---|
log | 4,194,304 | 1306 ms | 0 ms |
add (+) | 4,194,304 | 40 ms | 17 ms |
sub (-) | 4,194,304 | 43 ms | 18 ms |
mul (*) | 65,536 | 980 ms | 116 ms |
squ (^2) | 65,536 | 980 ms | 82 ms |
div (/) | 65,536 | 555 ms | 231 ms |
mod (%) | 65,536 | 555 ms | 231 ms |
gcd | 65,536 | 730 ms | 532 ms |
modinv | 65,536 | N/A | 1,412 ms |
modpow | 16,384 | 5,124,600 ms | 652,900 ms |
Note: ensure you're running a 64-bit process. Handling this with just 32-bits is a huge impediment for both, BigInteger
and Integer
.
Note: these results are from "my machine". A basic (very basic) benchmark utility is included to verify / disprove them.
Integers
Like BigInteger 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.
To get an idea, this is an example for calculating the Greatest Common Divisor:
Integer Gcd(Integer left, Integer right)
{
var a = left.Abs();
var b = right.Abs();
while (b != 0)
{
var c = a % b;
a = b;
b = c;
}
return a;
}
Note: calling left.Gcd(right)
is much faster, since the internal implementation is based on a more sophisticated algorithm.
Rationals
Coming sometime... maybe... who knows?
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 was computed. 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. |
.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 | net40 is compatible. net403 was computed. net45 was computed. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. 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.0
- No dependencies.
-
.NETStandard 2.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on NeinMath:
Package | Downloads |
---|---|
PoseidonSharp
This is a Poseidon Hashing Library built for use with Loopring |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.5.1 | 939 | 1/7/2023 |
1.5.0 | 342 | 11/11/2022 |
1.4.0 | 440 | 11/8/2021 |
1.3.1 | 914 | 2/15/2019 |
1.3.0 | 1,027 | 9/12/2018 |
1.2.0 | 1,096 | 6/28/2018 |
1.1.1 | 1,164 | 1/4/2018 |
1.1.0 | 1,164 | 6/11/2017 |
1.0.1 | 1,598 | 6/28/2016 |
1.0.0 | 1,339 | 5/19/2016 |
0.2.5 | 1,561 | 12/6/2015 |
0.2.4 | 1,448 | 11/21/2015 |
0.2.3 | 1,440 | 9/13/2015 |
0.2.2 | 1,359 | 8/16/2015 |
0.2.1 | 1,274 | 4/11/2015 |
0.2.0 | 1,184 | 4/7/2015 |
0.1.1 | 1,207 | 4/1/2015 |
0.1.0 | 1,229 | 3/27/2015 |
Added current README.md to package contents.