TheSquid.Numerics.Extensions 0.7.35452.1

Prefix Reserved
dotnet add package TheSquid.Numerics.Extensions --version 0.7.35452.1                
NuGet\Install-Package TheSquid.Numerics.Extensions -Version 0.7.35452.1                
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.
<PackageReference Include="TheSquid.Numerics.Extensions" Version="0.7.35452.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TheSquid.Numerics.Extensions --version 0.7.35452.1                
#r "nuget: TheSquid.Numerics.Extensions, 0.7.35452.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TheSquid.Numerics.Extensions as a Cake Addin
#addin nuget:?package=TheSquid.Numerics.Extensions&version=0.7.35452.1

// Install TheSquid.Numerics.Extensions as a Cake Tool
#tool nuget:?package=TheSquid.Numerics.Extensions&version=0.7.35452.1                

TheSquid.Numerics.Extensions

GitHub Status NuGet Version

C# implementation of extension methods for BigInteger data type. Such as extracting an Nth root, generating a random value and exponentiation. By Nikolai TheSquid.

I will be glad to merge your pull requests for improve calculation performance. Even if the improvement affects only individual cases from the range of values.

To use these extensions you will need to add to your code following namespaces: System.Numerics and TheSquid.Numerics.Extensions.

NthRootExtension

C# implementation of an extension method to quickly calculate an Nth root (including square root) for BigInteger value.

How to use

Basicly you can copy class NthRootExtension from source repository to your project. Another option is to add the TheSquid.Numerics.Extensions package from the nuget repository to your project's dependencies.

Usage example:

var source = BigInteger.Parse(Console.ReadLine());
var exponent = int.Parse(Console.ReadLine());
var root = source.NthRoot(exponent, out var isExactResult);

How to test

You can start random NthRoot tests right after clone repository and build solution. You must run generate tests and rebuild solution before start speed Nth root tests.

How to understand

The extension method uses two root calculation algorithms: well-known Newton's method and digit-by-digit method. As the degree of the root increases, the calculation by the Newton method slows down, and the digit-by-digit method accelerates. With a root radicand value order of 100,000 decimal digits, the dependence of the calculation speed on the degree of the root is as follows:

root comparison

NextBigIntegerExtension

C# implementation of an extension method to generate random BigInteger value within the specified range.

How to use

Basicly you can copy class NextBigIntegerExtension from source repository to your project. Another option is to add the TheSquid.Numerics.Extensions package from the nuget repository to your project's dependencies.

Usage example:

var source = BigInteger.Parse(Console.ReadLine());
var exponent = int.Parse(Console.ReadLine());
var power = source.PowCached(exponent);

How to test

You can start random tests for NextBigInteger extension method using NextBigIntegerExtensionTests class from project TheSquid.Numerics.Extensions.Tests right after clone repository and build solution.

How to understand

Extension method for the system class Random. Method uses instance of Random class to generate an array of random bytes.

PowCachedExtension

C# implementation of an extension method for faster calculation of powers with repeated parameters using cache.

How to use

Basicly you can copy class PowCachedExtension from source repository to your project. Another option is to add the TheSquid.Numerics.Extensions package from the nuget repository to your project's dependencies.

Usage example:

var min = BigInteger.Parse(Console.ReadLine());
var max = BigInteger.Parse(Console.ReadLine());
var random = new Random(DateTime.Now.Millisecond).NextBigInteger(min, max);

Pow cache clears itself automatically. Firstly, if out of memory error occurs when calculating the power. Then the cache will be cleared completely. Secondly, if the number of elements in the cache reaches the number of int.MaxValue. Then the cache will be cleared by half. Additionally, you can check the number of elements in the cache and clear it manually, leaving a specified number of elements.

Usage example:

var available = PowCachedExtension.ItemsInCache;
var threshold = long.Parse(Console.ReadLine());
if (threshold < available) PowCachedExtension.ShrinkCacheData(threshold);

How to test

You can start random tests for PowCached extension method using PowCachedExtensionTests class from project TheSquid.Numerics.Extensions.Tests right after clone repository and build solution.

How to understand

Acceleration is achieved by memorizing results of computing degrees, as well as memorizing the intermediate results obtained in calculation progress. With random basement values in range from 0 to 1000, random exponent values in range from 0 to 1000 and iterations count up to 2000000, the dependence of the calculation speed on cache filling is as follows:

pow comparison

Product 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.7.35452.1 244 10/21/2023
0.6.20581.1 182 8/17/2023
0.5.25646.1 152 8/15/2023
0.4.20363.1 166 8/14/2023
0.3.17043.1 161 8/12/2023