math.js 638 B

123456789101112
  1. module.exports = {
  2. // sum of integer / bignumber
  3. sum: (...args) => args.reduce((acc, n) => acc + n, 0),
  4. bigintSum: (...args) => args.reduce((acc, n) => acc + n, 0n),
  5. BNsum: (...args) => args.reduce((acc, n) => acc.add(n), web3.utils.toBN(0)),
  6. // min of integer / bignumber
  7. min: (...args) => args.slice(1).reduce((x, y) => (x < y ? x : y), args[0]),
  8. BNmin: (...args) => args.slice(1).reduce((x, y) => (x.lt(y) ? x : y), args[0]),
  9. // max of integer / bignumber
  10. max: (...args) => args.slice(1).reduce((x, y) => (x > y ? x : y), args[0]),
  11. BNmax: (...args) => args.slice(1).reduce((x, y) => (x.gt(y) ? x : y), args[0]),
  12. };