ben-ng / binomial-probability

Binomial probability calculator. Also does cumulative probability.
5 stars 1 forks source link

Doesn't work for numbers greater than 170 #1

Open EgorGumin opened 5 years ago

EgorGumin commented 5 years ago

For example. if you try binomialProbability( 171, 171, 0.5), you will get NaN. That's because combinations.js uses factorial function which doesnt't work for numbers greater than 170. You can use https://npmjs.com/package/big-factorial and build correct for big numbers combinations function, then use it in binomial-probability, or just type a warning in the Readme regarding the limitations (170 max)

EgorGumin commented 5 years ago

In case somebody will face the same issue: you can use cephes library bdtr method to calculate cumulative binomial probability like this cephes.bdtr(successful, trials, average). It works with big numbers and works fast