function bigFactorial(n) {
    if (n.isZero()) {
      return new type.BigNumber(1); // 0! is per definition 1
    }

    var precision = config.precision + (Math.log(n.toNumber()) | 0);
    var Big = type.BigNumber.clone({
      precision: precision
    });
    var res = new Big(n);
    var value = n.toNumber() - 1; // number

    while (value > 1) {
      res = res.times(value);
      value--;
    }

    return new type.BigNumber(res.toPrecision(type.BigNumber.precision));
  }
Calculate factorial for a BigNumber
@param {BigNumber} n
@returns {BigNumber} Returns the factorial of n