How to use the config function from mathjs

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

mathjs.config is a method used to set and retrieve configuration options for the Math.js library.

126
127
128
129
130
131
132
133
134
135
// rendered (and therefore "enabled") child elements.
// Context is affected.
private renderChildren() {
  // Apply the random seed before rendering so we have deterministic
  // output when rendering the node's children.
  Math.config({randomSeed: this.ctx.seed});
  this.renderedChildren = [];
  for (let i = 0; i < this.elem.children().length; i++) {
    // TODO(scott): Parsing of text nodes using .contents().
    // We should should handle programmatic gotos, for instance.
fork icon25
star icon71
watch icon9

+ 2 other calls in file

26
27
28
29
30
31
32
33
34
35
    regex: /eval|import|parse|simplify|derivative|createUnit/gi
  };
  
  Object.freeze(this);
  Object.freeze(this.static);
  config({ number: 'BigNumber', precision: 64 });
}

async execute(msg, args) {
  let mess = await msg.channel.createMessage(this._localize(msg.author.locale.util.math.busy));
fork icon0
star icon1
watch icon1

+ 2 other calls in file

How does mathjs.config work?

mathjs.config is a function in the mathjs library that allows you to configure various settings and behavior of the library, such as changing the number format, setting the default type of numbers, changing the maximum number of digits, and more. When called, it returns the current configuration object, which can be modified and then re-applied to the library using mathjs.config(configObj).

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
const math = require("mathjs");

// Define an expression with 5 digits precision
const expr1 = math.evaluate("0.1 + 0.2", { precision: 5 });

// Change the precision to 3 digits
math.config({ precision: 3 });

// Evaluate the expression again with 3 digits precision
const expr2 = math.evaluate("0.1 + 0.2");

console.log(expr1); // 0.3
console.log(expr2); // 0.3

In the example above, math.config() is used to change the precision of math.js. The initial evaluation of the expression "0.1 + 0.2" returns 0.30000000000000004 due to the default precision of 16 digits. After changing the precision to 3 digits, the same expression now evaluates to 0.3.