Configuration #

Math.js contains a number of configuration options. There are two ways to configure math.js:

The following configuration options are available:

Examples #

This section shows a number of configuration examples.

node.js #

// load the default instance of math.js
var math = require('mathjs');

// range will output a Matrix
math.range(0, 4);       // Matrix [0, 1, 2, 3]


// create a new instance configured to use Arrays
var math2 = math.create({
  matrix: 'Array'       // Choose 'Matrix' (default) or 'Array'
});

// range will output an Array 
math2.range(0, 4);      // Array [0, 1, 2, 3]

// change the configuration of math2 from Arrays to Matrices
math2.config({
  matrix: 'Matrix'      // Choose 'Matrix' (default) or 'Array'
});

// range will output a Matrix
math2.range(0, 4);      // Matrix [0, 1, 2, 3]


// create an instance of math.js with BigNumber configuration
var bigmath = math.create({
  number: 'BigNumber',  // Choose 'number' (default), 'BigNumber', or 'Fraction'
  precision: 32         // 64 by default, only applicable for BigNumbers
});

// parser will parse numbers as BigNumber now:
bigmath.eval('1 / 3');  // BigNumber, 0.33333333333333333333333333333333

browser #

<!DOCTYPE HTML>
<html>
<head>
  <script src="math.js" type="text/javascript"></script>
</head>
<body>
  <script type="text/javascript">
    // the default instance of math.js is available as 'math'
  
    // range will output a Matrix
    math.range(0, 4);       // Matrix [0, 1, 2, 3]
    
    // change the configuration of math from Matrices to Arrays
    math.config({
      matrix: 'Array'      // Choose 'Matrix' (default) or 'Array'
    });
    
    // range will output an Array 
    math.range(0, 4);       // Array [0, 1, 2, 3]
    
    // create a new instance of math.js with bignumber configuration
    var bigmath = math.create({
      number: 'BigNumber',  // Choose 'number' (default), 'BigNumber', or 'Fraction'
      precision: 32         // 64 by default, only applicable for BigNumbers
    });
    
    // parser will parse numbers as BigNumber now:
    bigmath.eval('1 / 3');  // BigNumber, 0.33333333333333333333333333333333
  </script>
</body>
</html>
Fork me on GitHub