improving factorial function

speed up factorial function for number
This commit is contained in:
Honeybar 2018-07-14 21:17:05 -07:00 committed by GitHub
parent 3d35d858b8
commit 77bd559b19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -178,10 +178,14 @@ function factory (type, config, load, typed) {
const precision = config.precision + (Math.log(n.toNumber()) | 0)
const Big = type.BigNumber.clone({precision: precision})
let bigN = new Big(n)
let one = new Big(1)
let two = new Big(2)
return new type.BigNumber(productBig(one, bigN, one, two).toPrecision(type.BigNumber.precision))
let res = new Big(n)
let value = n.toNumber() - 1 // number
while (value > 1) {
res = res.times(value)
value--
}
return new type.BigNumber(res.toPrecision(type.BigNumber.precision))
}
gamma.toTex = {1: `\\Gamma\\left(\${args[0]}\\right)`}