0

I have a custom bundle for mathjs that looks something like so:

var core = require('mathjs/core');
var math = core.create();
math.import(require('mathjs/lib/type'));
math.import(require('mathjs/lib/function/arithmetic'));
math.import(require('mathjs/lib/function/trigonometry'));
math.import(require('mathjs/lib/expression'));

which I then export. If I then try math.eval('pi'), I get an Exception:

Exception: Error: Undefined symbol pi

I don't see this error if I import the entire mathjs library but, then, that rather defeats the purpose of the small custom bundle.

Question: What is the minimal import so that math.eval('pi') returns 3.14...?

Mark McClure
  • 4,862
  • 21
  • 34

1 Answers1

1
var core = require('mathjs/core');
var math = core.create();
math.import(require('mathjs/lib/type'));
math.import(require('mathjs/lib/expression'));
math.import(require('mathjs/lib/constants'));

console.log(math.eval('pi')) // 3.141592653589793

See the constants module in the github repository of mathjs.

The value of PI is taken from the standard, built-in Javascript object Math. See this.

turdus-merula
  • 8,546
  • 8
  • 38
  • 50