1 | 'use strict';
|
2 |
|
3 | var object = require('./utils/object');
|
4 | var bigConstants = require('./utils/bignumber/constants');
|
5 |
|
6 | function factory (type, config, load, typed, math) {
|
7 |
|
8 |
|
9 | math.on('config', function (curr, prev) {
|
10 | if (curr.number !== prev.number) {
|
11 | factory(type, config, load, typed, math);
|
12 | }
|
13 | });
|
14 |
|
15 | setConstant(math, 'true', true);
|
16 | setConstant(math, 'false', false);
|
17 | setConstant(math, 'null', null);
|
18 | setConstant(math, 'uninitialized', require('./utils/array').UNINITIALIZED);
|
19 |
|
20 | if (config.number === 'BigNumber') {
|
21 | setConstant(math, 'Infinity', new type.BigNumber(Infinity));
|
22 | setConstant(math, 'NaN', new type.BigNumber(NaN));
|
23 |
|
24 | setLazyConstant(math, 'pi', function () {return bigConstants.pi(type.BigNumber)});
|
25 | setLazyConstant(math, 'tau', function () {return bigConstants.tau(type.BigNumber)});
|
26 | setLazyConstant(math, 'e', function () {return bigConstants.e(type.BigNumber)});
|
27 | setLazyConstant(math, 'phi', function () {return bigConstants.phi(type.BigNumber)});
|
28 |
|
29 |
|
30 | setLazyConstant(math, 'E', function () {return math.e;});
|
31 | setLazyConstant(math, 'LN2', function () {return new type.BigNumber(2).ln();});
|
32 | setLazyConstant(math, 'LN10', function () {return new type.BigNumber(10).ln()});
|
33 | setLazyConstant(math, 'LOG2E', function () {return new type.BigNumber(1).div(new type.BigNumber(2).ln());});
|
34 | setLazyConstant(math, 'LOG10E', function () {return new type.BigNumber(1).div(new type.BigNumber(10).ln())});
|
35 | setLazyConstant(math, 'PI', function () {return math.pi});
|
36 | setLazyConstant(math, 'SQRT1_2', function () {return new type.BigNumber('0.5').sqrt()});
|
37 | setLazyConstant(math, 'SQRT2', function () {return new type.BigNumber(2).sqrt()});
|
38 | }
|
39 | else {
|
40 | setConstant(math, 'Infinity', Infinity);
|
41 | setConstant(math, 'NaN', NaN);
|
42 |
|
43 | setConstant(math, 'pi', Math.PI);
|
44 | setConstant(math, 'tau', Math.PI * 2);
|
45 | setConstant(math, 'e', Math.E);
|
46 | setConstant(math, 'phi', 1.61803398874989484820458683436563811772030917980576286213545);
|
47 |
|
48 |
|
49 | setConstant(math, 'E', math.e);
|
50 | setConstant(math, 'LN2', Math.LN2);
|
51 | setConstant(math, 'LN10', Math.LN10);
|
52 | setConstant(math, 'LOG2E', Math.LOG2E);
|
53 | setConstant(math, 'LOG10E', Math.LOG10E);
|
54 | setConstant(math, 'PI', math.pi);
|
55 | setConstant(math, 'SQRT1_2', Math.SQRT1_2);
|
56 | setConstant(math, 'SQRT2', Math.SQRT2);
|
57 | }
|
58 |
|
59 |
|
60 | setConstant(math, 'i', type.Complex.I);
|
61 |
|
62 |
|
63 | setConstant(math, 'version', require('./version'));
|
64 | }
|
65 |
|
66 |
|
67 | function setConstant(math, name, value) {
|
68 | math[name] = value;
|
69 | math.expression.mathWithTransform[name] = value;
|
70 | }
|
71 |
|
72 |
|
73 | function setLazyConstant (math, name, resolver) {
|
74 | object.lazy(math, name, resolver);
|
75 | object.lazy(math.expression.mathWithTransform, name, resolver);
|
76 | }
|
77 |
|
78 | exports.factory = factory;
|
79 | exports.lazy = false;
|
80 | exports.math = true; |
\ | No newline at end of file |