BigNumberRecursiveMod 1.1.0

dotnet add package BigNumberRecursiveMod --version 1.1.0
                    
NuGet\Install-Package BigNumberRecursiveMod -Version 1.1.0
                    
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="BigNumberRecursiveMod" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BigNumberRecursiveMod" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="BigNumberRecursiveMod" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BigNumberRecursiveMod --version 1.1.0
                    
#r "nuget: BigNumberRecursiveMod, 1.1.0"
                    
#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.
#:package BigNumberRecursiveMod@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=BigNumberRecursiveMod&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=BigNumberRecursiveMod&version=1.1.0
                    
Install as a Cake Tool

🧮 BigNumberRecursiveMod

NuGet Version NuGet Downloads License

A lightweight, zero-dependency C# library for recursively calculating modular arithmetic on very large integer sequences represented as strings — without converting them into BigIntegers.


📘 Overview

BigNumberRecursiveMod provides an efficient and recursive approach to compute the modulo (%) of extremely large numbers represented as string sequences — perfect for cases where numbers exceed Int64 or BigInteger parsing limits.

It operates recursively by:

  • Splitting the number sequence into manageable chunks
  • Recursively processing higher-order digits
  • Efficiently combining results using modular arithmetic

This approach mimics manual long division but is implemented with recursion for simplicity and clarity.


🧩 Why Use Recursive Modulo?

When dealing with very large integers, standard integer types (int, long, BigInteger) can be inefficient or impossible to use — especially if numbers are stored or streamed as strings (e.g., from JSON, logs, or APIs).

This library solves that by:

  • Working entirely on string-based numbers
  • Avoiding overflow
  • Remaining lightweight, pure C#, and dependency-free
  • Providing clear and testable logic via recursion

⚙️ Installation

dotnet add package BigNumberRecursiveMod

🚀 Quick Start

Example 1: Using a String Divider

using BigNumberRecursiveMod;

string numberSequence = "777635";
string divider = "32";

int mod = RecursiveMod.CalculateMod(numberSequence, divider);

Console.WriteLine(mod); // Output: 3

Example 2: Using an Integer Divider

using BigNumberRecursiveMod;

string numberSequence = "491984984";
int divider = 978;

int mod = RecursiveMod.CalculateMod(numberSequence, divider);

Console.WriteLine(mod); // Output: 128

Example 3: Extremely Large Numbers

using BigNumberRecursiveMod;

string numberSequence = "41646849849849161654198498498498498498498498465416515151564651189198484000084984987496874984984984894984984984984981";
string divider = "97";

int mod = RecursiveMod.CalculateMod(numberSequence, divider);

Console.WriteLine(mod); // Always less than 97

🧠 How It Works

private static int CalculateRecursive(string numberSequence, int divider, int n)
{
    if (numberSequence.Length <= n)
        return int.Parse(numberSequence) % divider;

    string head = numberSequence.Substring(0, numberSequence.Length - n);
    string tail = numberSequence.Substring(numberSequence.Length - n, n);

    int headMod = CalculateRecursive(head, divider, n);
    int combinedMod = (headMod * (int)Math.Pow(10, n) + int.Parse(tail)) % divider;

    return combinedMod;
}

🔍 Process Explanation

  1. Divide the number into smaller pieces (head and tail).

  2. Recursively compute the modulo of the head.

  3. Combine the results using modular arithmetic:

    combinedMod = (headMod * 10^n + tailInt) % divider
    
  4. Return the final modulo result.

This ensures correctness even when the number sequence exceeds numeric parsing limits.


✅ Unit Tests

[Fact]
public void LargeNumberTest()
{
    string numberSequence = "999999";
    string divider = "68";

    int mod = RecursiveMod.CalculateMod(numberSequence, divider);

    Assert.Equal(59, mod);
}

🧰 API Reference

RecursiveMod.CalculateMod(string numberSequence, string divider)

Calculates the modulo of a string-based number sequence with a string divider.

RecursiveMod.CalculateMod(string numberSequence, int divider)

Calculates the modulo of a string-based number sequence with an integer divider.


⚠️ Exception Handling

Exception Type Description
ArgumentException Thrown if divider is not a valid integer.
ArgumentException Thrown if numberSequence contains non-digit characters.

🧱 Project Structure

BigNumberRecursiveMod/
├── BigNumberRecursiveMod/
│   ├── RecursiveMod.cs
│   └── BigNumberRecursiveMod.csproj
├── TestRecursiveMod/
│   ├── RecursiveModTest.cs
│   └── TestRecursiveMod.csproj
├── README.md
└── LICENSE

📝 License

This project is licensed under the MIT License.


❤️ Contributing

Pull requests are welcome!
If you find a bug or have a suggestion:

  1. Fork the repo
  2. Create a new branch (feature/amazing-feature)
  3. Commit your changes
  4. Open a PR

👨‍💻 Author

Valadis Pitsas
GitHub: @cpitsas
NuGet: BigNumberRecursiveMod

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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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.1

    • 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
1.1.0 181 10/7/2025
1.0.1 190 10/6/2025
1.0.0 176 10/6/2025