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