How to use the bignumber function from mathjs

Find comprehensive JavaScript mathjs.bignumber code examples handpicked from public code repositorys.

599
600
601
602
603
604
605
606
  var numPaths = Mathjs.divide(factorialTemp, 2);
  // The number of seconds is numPaths / 10 but we are now multiplying by 10 to prevent
  // rounding errors so return numPaths. This will be divided by 10 in calculateTimeUnits() when we
  // divide seconds by secondsInUnitOfTime (both are multiplied by 10).


  return Mathjs.bignumber(numPaths);
}
fork icon75
star icon325
watch icon0

28
29
30
31
32
33
34
35
36
37
38
 * Create math methods which automatically wraps
 * every provided arguments with math.bignumber.
 */
const math = extractMathJS.reduce((acc, method) => (
  (acc[method] = (...args) =>
    mathjs[method](...args.map(n => mathjs.bignumber(n)))
  ), acc
), {});


const { ceil, equal, larger, mod,pow, sqrt } = math;
fork icon1
star icon8
watch icon0

92
93
94
95
96
97
98
99
100
Another major feature of mathjs is a big number constructor.

```js
let math = require('mathjs');
 
let big = new math.bignumber('123456789876543217777777777777777771234444555666123');
 
console.log(big.toString());
```
fork icon0
star icon5
watch icon1

11
12
13
14
15
16
17
18
19
    throw new RangeError("ROUND_PRECISION must bee greater or equal to zero");
}

math.config(config);

const bignumber = math.bignumber;
const matrix = math.matrix;

//const TRIANGLE_UNIT_HEIGHT = math.divide(math.sqrt(bignumber("3")), bignumber("2"));
fork icon1
star icon0
watch icon1

27
28
29
30
31
32
33
34
35
36
    l_counts[l] += 1;
  }

  // convert to bignum
  for (const k in l_counts) {
    l_counts[k] = math.bignumber(l_counts[k])
  }

  return math.multinomial(Object.values(l_counts)).toFixed();
}
fork icon0
star icon0
watch icon0

9
10
11
12
13
14
15
16
17
18
const mnr = require('modified-newton-raphson');
const state = require('../../../../src/state.js');

const INTEGRAL_ERROR = 1e-8;
const DERIVATIVE_H = 1e-15;
const SMALL_NUMBER = math.bignumber('1e-15');
const OPTIMIZATION_INTERMEDIATE_RATIO = 0.3819660112501051517954;

const compileFuncFromString = (func, variable) => {
    let temp = math.parse(func).compile();
fork icon0
star icon0
watch icon5

+ 27 other calls in file

14
15
16
17
18
19
20
21
22
23
const continuousMCode = math.parse('m * log(1 + rm / m)').compile()
const mDurationCode = math.parse('waPvs / px / (1 + y / m)').compile()

function biggify(args) {
  if (Array.isArray(args)) {
    return args.map(arg => typeof arg === 'number' ? math.bignumber(arg) : arg)
  }

  Object.entries(args)
    .forEach(([key, val]) => {
fork icon0
star icon0
watch icon1

+ 7 other calls in file