peterolson / BigInteger.js

An arbitrary length integer library for Javascript
The Unlicense
1.12k stars 187 forks source link

Explanation of the BigInteger.js codebase? #229

Closed lancejpollard closed 2 years ago

lancejpollard commented 2 years ago

Hi there, I am digging into the codebase and wondering if you could do a quick breakdown of what the major parts are. For the first thing, what is the need for SmallInteger and Integer and NativeBigInt, as opposed to BigInteger?

peterolson commented 2 years ago

It uses different functions for calculating operations depending on the situation. If the environment supports BigInteger natively, then it will take advantage of that and use NativeBigInt. Otherwise, if the number is small enough to use native JavaScript numbers to perform the calculation, it will use SmallInteger. Otherwise it calculate with arrays of JavaScript numbers.