GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - NullDev/mathlib: 🧮 Zero-dependency collection of mathematical functions using BigInts

BranchesTags
Open more actions menu

Latest commit

 

History

61 Commits
61 Commits

Folders and files

NameName
Last commit message
Last commit date
lib
lib
 
 
tests
tests
 
 
.editorconfig
.editorconfig
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
bun.lock
bun.lock
 
 
eslint.config.js
eslint.config.js
 
 
package.json
package.json
 
 
tsconfig.json
tsconfig.json
 
 

Repository files navigation

mathlib

License

Zero-dependency collection of advanced mathematical functions using BigInts.


✅ What this is

This is my personal zero-dependency collection of various mathematical functions using BigInts,
completely written from scratch.

Functions should be optimized for performance and accuracy, and should be safe for large numbers.
But I can give zero guarentees. If you're using this, you're on your own.
I do write tests for every single function implemented, but I can't guarentee, that the tests are sane either...
All functions are documented - and I tried to comment the code as well as the tests as good as possible.


⛔ What this isn't

This is not a fully fledge mathematical library like mathjs.
It's a collection of functions I re-use occasionally. And it's BigInt only!


📜 What's implemented:

  • abs - Absolute value of a BigInt
  • floorLog2 - Calculate the floor of the base-2 logarithm of a number
  • clamp - Clamp a BigInt to a given range
  • bitLength - Bit length of a BigInt
  • hammingWeight - Population count (number of set bits) of a BigInt
  • prodOdd - Calculate the product of all odd numbers in a given range
  • pow - Power of a BigInt (x^y)
  • nthRoot - nth root of a BigInt (x^(1/n))
  • sqrt - Square root of a BigInt
  • manhattanDist - Manhattan distance between two BigInts
  • euclideanDist - Euclidean distance between two BigInts
  • gcd - Greatest common divisor (2 inputs)
  • gcdMulti - Greatest common divisor of multiple numbers (variadic)
  • gcdExt - Extended Euclidean gcd algorithm for Bézout coefficients
  • lcm - Least common multiple (2 inputs)
  • lcmMulti - Least common multiple of multiple numbers (variadic)
  • mod - True modulo operation for BigInt (not remainder)
  • modPow - Modular exponentiation of a base raised to an exponent modulo a number
  • modInv - Modular inverse of a number using the Extended Euclidean algorithm
  • modDiv - Modular division of two numbers
  • modSqrt - Tonelli-Shanks square root mod an odd prime p
  • modNthRoot - Tonelli-Shanks nth root mod an odd prime p for gcd(k, p-1)=1 and gcd(k, p-1) > 1
  • primitiveRoot - Find any primitive root (generator) of the multiplicative group ℤp×
  • isPrime - Miller-Rabin primality test on 64-bit-size BigInts with deterministic base set
  • eulerCriterion - Euler's criterion for quadratic residues modulo a prime p
  • randomBigInt - Cryptographically-strong (hopefully) random bigint in given range
  • quadraticPoly - Quadratic polynomial f(x) = x² + c modulo n
  • pollardRho - Pollard's ρ algorithm for integer factorization using Brent's cycle detection
  • factor - Prime factorization using Pollard's rho
  • highestSetBit - Position of the highest set bit in a BigInt
  • fibPair - Calculate the nth Fibonacci number modulo m using iterative fast-doubling
  • fib - Calculate the nth Fibonacci number Fₙ for any integer n
  • primePisano - Pisano period π(p) for a prime p
  • pisanoPeriod - Pisano period π(n) for any positive integer n ≥ 1
  • totient - Euler's totient function φ(n)
  • jacobi - Calculate the Jacobi symbol (a | n) for any positive integer n ≥ 1
  • mobius - Möbius function μ(n) for positive integer n ≥ 1
  • factorial - Calculate the exact factorial n! of a number for bigint n ≥ 0
  • crt - Chinese Remainder Theorem solver for a system of congruences

... more to come


📋 To-Do

  • Test coverage overview / reporting
  • Build step & minification for browser
  • Better test setup (still figuring out bun:test)
  • Add more functions (only with tests)
  • NPM package maybe
  • Maybe split up mathlib into smaller related chunks

:octocat: Contributing

Don't really expect anyone to contribute but...

  • Bun is needed to run the tests
  • TypeScript only
  • Adhere to style guide (eslint)
  • Every function should have a test
  • Every function should be documented

About

🧮 Zero-dependency collection of mathematical functions using BigInts

Topics

librarymathmathematicsnulldevutils

Resources

Readme
MIT license
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.