Skip to content

fosterchild1/AptInt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

222 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lightweight, highest performance BigInteger library for Luau

AptInt is THE fastest luau implementation of BigInteger, designed for working with numbers over 10,000 digits long.

Overview

This library provides arbitrary precision arithmetic capabilities implemented in just Luau. It uses a 2^24 word size to store numbers and can easily be configured to your liking.

This library provides:

The implementations are as performant as possible, so they have no safety checks, with the exception of the metamethods.

Usage

Usage Documentation can be found here.
Algorithm choice can be found here.

What makes it so fast?

AptInt uses the Karatsuba and Toom-Cook3 algorithms for multiplication, Knuths algorithm D for division, Karatsuba sqrt for finding the square root and more. Alongside these algorithms, it uses many techniques to shave off hundreds of milliseconds of computing time.

It also utilizes the full power of native code generation to get even faster results.

Benchmarks

Note that these were done on an i7-10750H CPU. The benchmark script can be found in /bench/.
The results are updated every time the performance gets improved. They are also generally ~1.3x faster if running on the roblox server.
For division, we do a 2NxN division. (2N = digit count)

Raw

Digit count Addition Subtraction Multiplication Division Square root
1 1μs 1μs 1μs 2μs 29μs
50 1μs 3μs 4μs 11μs 31μs
100 2μs 7μs 6μs 15μs 73μs
500 5μs 9μs 56μs 28μs 250μs
1,000 7μs 13μs 173μs 58μs 357μs
5,000 23μs 30μs 1ms 195μs 796μs
10,000 57μs 74μs 4ms 1ms 2ms
50,000 209μs 243μs 46ms 38ms 35ms
100,000 389μs 396μs 137ms 114ms 89ms