Fast TSN library for large numbers of X number of bits (unsigned and signed)
  • MQL5 95.2%
  • MQL4 4.8%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-08-26 22:31:33 -05:00
Src aun me falta cnumberutils lo dejare para mañan, la cosa es un To Bytes (numero normal para DER en rsa) eficiente template.. hay que pensar 2026-08-26 22:31:33 -05:00
Test 2026-08-25 19:48:27 -05:00
BigNumberByLeo.mqproj Generated by MQL5 Wizard 2026-08-13 21:04:32 -05:00
dependencies.json 2026-08-21 21:01:14 -05:00
LICENSE Añadir LICENSE 2026-08-14 13:58:49 +00:00
README.md 2026-08-25 19:48:27 -05:00

Arbitrary-precision unsigned integer library for MQL5.
Limb-based (ulong[]) arithmetic, ~90% complete.


Main Features

  • Arbitrary-precision BigUInteger: base type backed by a ulong[] limb array, construct from a long, a decimal string, raw bytes, or an existing limb array
  • Full arithmetic: +, -, *, /, % — each with both BigUInteger and long operands, plus in-place (+=, -=, etc.) variants
  • Bitwise operators: &, |, ^, ~, <<, >>, both in-place and returning a new value
  • Comparisons: >, >=, ==, !=, <, <=, plus IsZero() / IsNotZero()
  • Fast multiplication: schoolbook multiplication (working), with Karatsuba for large operands in progress
  • Modular exponentiation: PowMod(exp, mod)pending implementation
  • Primality testing: IsProbablePrime(rounds) (Miller-Rabin style) — pending implementation
  • GCD: standard Gdc() (working) and extended GCD (GdcExtendedRetX, for modular inverse) — pending implementation
  • Byte/string conversion: FromBytesLE/BE, ToBytesLE/BE, ToString
  • Random generation: InitRandom<TRandom>(limbs), pluggable with any RNG source
  • Low-level numeric utilities (CNumberUtils): 64x64→128 multiply, 128/64-bit division, hex string conversion

Usage examples

Basic arithmetic:

#include "Src\\Base\\Main.mqh"

ulong v[];
ArrayResize(v, 1);
v[0] = 64;
TSN::BigUInteger integer(v, 1);

integer /= 8;      // 8
integer %= 6;      // 2

Standard GCD:

TSN::BigUInteger a("123456789", 10);
ulong gcd = a.Gdc(987654321);

PowMod, IsProbablePrime and GdcExtendedRetX are declared in the API but not yet implemented — see Roadmap.


Repository Structure

BigNumberByLeo/
├── Src/
│   ├── Base/    # BigUInteger core (arithmetic, bitwise, comparisons, primality, GCD)
│   └── Utils/   # Low-level numeric helpers (CNumberUtils)
└── Test/        # Scripts covering ops, division, multiplication, misc

Requirements

See dependencies.json for the full list.

  • MetaTrader 5, build 5430+
  • Depends on TsnTables (public, installed automatically via tsndep)

Installation

cd "C:\Users\YOUR_USER\AppData\Roaming\MetaQuotes\Terminal\YOUR_ID\MQL5\Shared Projects"
tsndep install "https://forge.mql5.io/nique_372/BigNumberByLeo.git"

Requires the tsndep package, available on PyPI. It automatically downloads and installs all declared dependencies.


Quick Start

1. Include the library:

#include "..\\BigNumberByLeo\\Src\\Base\\Main.mqh"

2. Use it:

TSN::BigUInteger a("340282366920938463463374607431768211456", 10);
TSN::BigUInteger b(2);

TSN::BigUInteger c = a * b;

License

Read Full License By downloading or using this repository, you accept the license terms.


Contact


Roadmap

  • Core arithmetic, bitwise ops, comparisons, schoolbook multiplication, standard GCD, byte/string conversion [Complete]
  • Karatsuba multiplication for large operands [In progress]
  • PowMod (modular exponentiation) [Pending]
  • IsProbablePrime (Miller-Rabin) [Pending]
  • GdcExtendedRetX (extended GCD / modular inverse) [Pending]

Copyright © 2026 Niquel & Leo — TSN Ecosystem