dankogai / js-combinatorics

power set, combination, permutation and more in JavaScript
MIT License
742 stars 97 forks source link

C function return "float" number #63

Closed dsvictor94 closed 4 years ago

dsvictor94 commented 4 years ago

Combinatorics.C(25, 20) = 53129.99999999999

Expected: 53130

https://jsfiddle.net/27sf94k1/

dankogai commented 4 years ago

It's because C is defined as P(m, n) / P(n, n) and P(25,20) returns 1.2926008369442487e+23, too big for Number to keep its integral value (129,260,083,694,425,000,000,000). Time to add BigInt support?

dankogai commented 4 years ago

Version 0.6.0 (https://github.com/dankogai/js-combinatorics/commit/10374fc4e3f77fc05ee7eb765263adf311206885) now supports BigInt.

> Combinatorics.factorial(100)
9.332621544394418e+157
> Combinatorics.factorial(100n)
93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000n
>