mm_maths 1.1.9 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +156 -0
- package/index.js +6 -410
- package/lib/maths.js +429 -0
- package/package.json +42 -33
- package/tool/math/index.js +83 -0
- package/tool/math/tool.json +60 -0
- package/.gitattributes +0 -5
- package/convert/format_multiply/index.js +0 -40
- package/convert/format_multiply/test.js +0 -5
- package/convert/format_plus/index.js +0 -42
- package/convert/format_plus/test.js +0 -4
- package/convert/four_run/convert.json +0 -8
- package/convert/four_run/index.js +0 -20
- package/convert/four_run/test.js +0 -7
- package/convert/multiply_divide/index.js +0 -197
- package/convert/multiply_divide/test.js +0 -14
- package/convert/plus_subtract/index.js +0 -160
- package/convert/plus_subtract/test.js +0 -15
- package/convert/readme.md +0 -2
- package/doc/mm_math.doc +0 -0
- package/doc//345/207/275/346/225/260/347/254/246/345/217/267/344/270/200/350/247/210/350/241/250.xls +0 -0
- package/express/README.md +0 -2
- package/identities/chemistry/readme.md +0 -1
- package/identities/equation/readme.md +0 -2
- package/identities/geometry/readme.md +0 -1
- package/identities/geometry/rectangle/readme.md +0 -1
- package/identities/geometry/string/readme.md +0 -1
- package/identities/physics/readme.md +0 -1
- package/identities/readme.md +0 -2
- package/math/array/average/index.js +0 -10
- package/math/array/average/math.json +0 -8
- package/math/array/average/test.js +0 -3
- package/math/array/col/index.js +0 -17
- package/math/array/col/math.json +0 -8
- package/math/array/col/test.js +0 -4
- package/math/array/composite/index.js +0 -35
- package/math/array/composite/math.json +0 -8
- package/math/array/composite/test.js +0 -4
- package/math/array/deviations/index.js +0 -15
- package/math/array/deviations/math.json +0 -8
- package/math/array/deviations/test.js +0 -3
- package/math/array/difference/index.js +0 -9
- package/math/array/difference/math.json +0 -8
- package/math/array/difference/test.js +0 -7
- package/math/array/distinct/index.js +0 -20
- package/math/array/distinct/math.json +0 -8
- package/math/array/distinct/test.js +0 -8
- package/math/array/distributive/index.js +0 -24
- package/math/array/distributive/math.json +0 -8
- package/math/array/distributive/test.js +0 -3
- package/math/array/divisor/index.js +0 -17
- package/math/array/divisor/math.json +0 -8
- package/math/array/divisor/test.js +0 -6
- package/math/array/intersect/index.js +0 -9
- package/math/array/intersect/math.json +0 -8
- package/math/array/intersect/test.js +0 -7
- package/math/array/max/index.js +0 -17
- package/math/array/max/math.json +0 -8
- package/math/array/max/test.js +0 -8
- package/math/array/median/index.js +0 -34
- package/math/array/median/math.json +0 -8
- package/math/array/median/test.js +0 -4
- package/math/array/min/index.js +0 -16
- package/math/array/min/math.json +0 -8
- package/math/array/min/test.js +0 -8
- package/math/array/multiple/index.js +0 -17
- package/math/array/multiple/math.json +0 -8
- package/math/array/multiple/test.js +0 -7
- package/math/array/natural/index.js +0 -17
- package/math/array/natural/math.json +0 -8
- package/math/array/natural/test.js +0 -9
- package/math/array/pos/index.js +0 -21
- package/math/array/pos/math.json +0 -8
- package/math/array/pos/test.js +0 -41
- package/math/array/prime/index.js +0 -35
- package/math/array/prime/math.json +0 -8
- package/math/array/prime/test.js +0 -4
- package/math/array/readme.md +0 -5
- package/math/array/reduction/index.js +0 -57
- package/math/array/reduction/math.json +0 -8
- package/math/array/reduction/test.js +0 -42
- package/math/array/rising/index.js +0 -8
- package/math/array/rising/math.json +0 -8
- package/math/array/rising/test.js +0 -3
- package/math/array/row/index.js +0 -11
- package/math/array/row/math.json +0 -8
- package/math/array/row/test.js +0 -4
- package/math/array/square/index.js +0 -12
- package/math/array/square/math.json +0 -8
- package/math/array/square/test.js +0 -3
- package/math/array/stddev/index.js +0 -17
- package/math/array/stddev/math.json +0 -8
- package/math/array/stddev/test.js +0 -4
- package/math/array/sum/index.js +0 -13
- package/math/array/sum/math.json +0 -8
- package/math/array/sum/test.js +0 -3
- package/math/array/sumproduct/index.js +0 -13
- package/math/array/sumproduct/math.json +0 -8
- package/math/array/sumproduct/test.js +0 -3
- package/math/array/union/index.js +0 -11
- package/math/array/union/math.json +0 -8
- package/math/array/union/test.js +0 -7
- package/math/base/abs/index.js +0 -8
- package/math/base/abs/math.json +0 -8
- package/math/base/abs/test.js +0 -3
- package/math/base/ceil/index.js +0 -8
- package/math/base/ceil/math.json +0 -8
- package/math/base/ceil/test.js +0 -3
- package/math/base/denominator/index.js +0 -17
- package/math/base/denominator/math.json +0 -9
- package/math/base/denominator/test.js +0 -3
- package/math/base/diff/index.js +0 -9
- package/math/base/diff/math.json +0 -8
- package/math/base/diff/test.js +0 -6
- package/math/base/exp/index.js +0 -8
- package/math/base/exp/math.json +0 -8
- package/math/base/exp/test.js +0 -6
- package/math/base/floor/index.js +0 -8
- package/math/base/floor/math.json +0 -8
- package/math/base/floor/test.js +0 -3
- package/math/base/int/index.js +0 -8
- package/math/base/int/math.json +0 -8
- package/math/base/int/test.js +0 -2
- package/math/base/log/index.js +0 -8
- package/math/base/log/math.json +0 -8
- package/math/base/log/test.js +0 -4
- package/math/base/max_divisor/index.js +0 -10
- package/math/base/max_divisor/math.json +0 -9
- package/math/base/max_divisor/test.js +0 -3
- package/math/base/min_multiple/index.js +0 -11
- package/math/base/min_multiple/math.json +0 -9
- package/math/base/min_multiple/test.js +0 -3
- package/math/base/mod/index.js +0 -8
- package/math/base/mod/math.json +0 -8
- package/math/base/mod/test.js +0 -3
- package/math/base/pow/index.js +0 -9
- package/math/base/pow/math.json +0 -8
- package/math/base/pow/test.js +0 -3
- package/math/base/rand/index.js +0 -21
- package/math/base/rand/math.json +0 -8
- package/math/base/rand/test.js +0 -3
- package/math/base/random/index.js +0 -12
- package/math/base/random/math.json +0 -8
- package/math/base/random/test.js +0 -4
- package/math/base/readme.md +0 -1
- package/math/base/round/index.js +0 -14
- package/math/base/round/math.json +0 -8
- package/math/base/round/test.js +0 -4
- package/math/base/sqrt/index.js +0 -8
- package/math/base/sqrt/math.json +0 -8
- package/math/base/sqrt/test.js +0 -5
- package/math/readme.md +0 -1
- package/math/stock/AMOUNT/index.js +0 -7
- package/math/stock/AMOUNT/math.json +0 -8
- package/math/stock/AMOUNT/test.js +0 -4
- package/math/stock/AP/index.js +0 -20
- package/math/stock/AP/math.json +0 -8
- package/math/stock/AP/test.js +0 -5
- package/math/stock/AROON/index.js +0 -14
- package/math/stock/ARR/index.js +0 -10
- package/math/stock/ARR/math.json +0 -8
- package/math/stock/ARR/test.js +0 -45
- package/math/stock/ASTAR/index.js +0 -20
- package/math/stock/ASTAR/math.json +0 -8
- package/math/stock/ASTAR/test.js +0 -4
- package/math/stock/AVERAGE/index.js +0 -14
- package/math/stock/AVERAGE/math.json +0 -8
- package/math/stock/AVERAGE/test.js +0 -5
- package/math/stock/AYANG/index.js +0 -18
- package/math/stock/AYANG/math.json +0 -8
- package/math/stock/AYANG/test.js +0 -4
- package/math/stock/AYIN/index.js +0 -18
- package/math/stock/AYIN/math.json +0 -8
- package/math/stock/AYIN/test.js +0 -4
- package/math/stock/BBANDS/index.js +0 -0
- package/math/stock/BETWEEN/index.js +0 -24
- package/math/stock/BETWEEN/math.json +0 -8
- package/math/stock/BETWEEN/test.js +0 -4
- package/math/stock/CLOSE/c.js +0 -0
- package/math/stock/CLOSE/index.js +0 -11
- package/math/stock/CLOSE/math.json +0 -8
- package/math/stock/CLOSE/test.js +0 -45
- package/math/stock/CP/index.js +0 -35
- package/math/stock/CP/math.json +0 -8
- package/math/stock/CP/test.js +0 -5
- package/math/stock/CROSS/index.js +0 -29
- package/math/stock/CROSS/math.json +0 -8
- package/math/stock/CROSS/test.js +0 -6
- package/math/stock/DATE/index.js +0 -14
- package/math/stock/DATE/math.json +0 -8
- package/math/stock/DATE/test.js +0 -45
- package/math/stock/DOWN/index.js +0 -19
- package/math/stock/DOWN/math.json +0 -8
- package/math/stock/DOWN/test.js +0 -8
- package/math/stock/DOWNNDAY/index.js +0 -27
- package/math/stock/DOWNNDAY/math.json +0 -8
- package/math/stock/DOWNNDAY/test.js +0 -10
- package/math/stock/EMA/index.js +0 -30
- package/math/stock/EMA/math.json +0 -8
- package/math/stock/EMA/test.js +0 -4
- package/math/stock/HHV/index.js +0 -16
- package/math/stock/HHV/math.json +0 -8
- package/math/stock/HHV/test.js +0 -4
- package/math/stock/HIGH/h.js +0 -0
- package/math/stock/HIGH/index.js +0 -11
- package/math/stock/HIGH/math.json +0 -8
- package/math/stock/HIGH/test.js +0 -45
- package/math/stock/LEFT/index.js +0 -13
- package/math/stock/LEFT/math.json +0 -8
- package/math/stock/LEFT/test.js +0 -4
- package/math/stock/LLV/index.js +0 -16
- package/math/stock/LLV/math.json +0 -8
- package/math/stock/LLV/test.js +0 -4
- package/math/stock/LOW/index.js +0 -11
- package/math/stock/LOW/l.js +0 -0
- package/math/stock/LOW/math.json +0 -8
- package/math/stock/LOW/test.js +0 -47
- package/math/stock/MA/index.js +0 -30
- package/math/stock/MA/math.json +0 -8
- package/math/stock/MA/test.js +0 -5
- package/math/stock/MACD/index.js +0 -29
- package/math/stock/MACD/math.json +0 -8
- package/math/stock/MACD/test.js +0 -4
- package/math/stock/MFI/index.js +0 -33
- package/math/stock/NMA/index.js +0 -23
- package/math/stock/NMA/math.json +0 -8
- package/math/stock/NMA/test.js +0 -5
- package/math/stock/NOT/index.js +0 -7
- package/math/stock/NOT/math.json +0 -8
- package/math/stock/NOT/test.js +0 -10
- package/math/stock/OPEN/index.js +0 -11
- package/math/stock/OPEN/math.json +0 -8
- package/math/stock/OPEN/o.js +0 -0
- package/math/stock/OPEN/test.js +0 -45
- package/math/stock/PERCPRICEOSC/index.js +0 -19
- package/math/stock/REF/index.js +0 -15
- package/math/stock/REF/math.json +0 -8
- package/math/stock/REF/test.js +0 -5
- package/math/stock/RIGHT/index.js +0 -13
- package/math/stock/RIGHT/math.json +0 -8
- package/math/stock/RIGHT/test.js +0 -4
- package/math/stock/RSI/index.js +0 -36
- package/math/stock/SMA/index.js +0 -12
- package/math/stock/STAR/index.js +0 -19
- package/math/stock/STAR/math.json +0 -8
- package/math/stock/STAR/test.js +0 -4
- package/math/stock/STOCHRSI/index.js +0 -19
- package/math/stock/SUM/index.js +0 -19
- package/math/stock/SUM/math.json +0 -8
- package/math/stock/SUM/test.js +0 -7
- package/math/stock/TIME/index.js +0 -14
- package/math/stock/TIME/math.json +0 -8
- package/math/stock/TIME/test.js +0 -45
- package/math/stock/TRUERANGE/index.js +0 -19
- package/math/stock/UP/index.js +0 -19
- package/math/stock/UP/math.json +0 -8
- package/math/stock/UP/test.js +0 -9
- package/math/stock/UPNDAY/index.js +0 -28
- package/math/stock/UPNDAY/math.json +0 -8
- package/math/stock/UPNDAY/test.js +0 -10
- package/math/stock/VMA/index.js +0 -41
- package/math/stock/VMA/math.json +0 -8
- package/math/stock/VMA/test.js +0 -7
- package/math/stock/VOL/index.js +0 -11
- package/math/stock/VOL/math.json +0 -8
- package/math/stock/VOL/test.js +0 -45
- package/math/stock/WILLR/index.js +0 -22
- package/math/stock/YANG/index.js +0 -16
- package/math/stock/YANG/math.json +0 -8
- package/math/stock/YANG/test.js +0 -4
- package/math/stock/YIN/index.js +0 -16
- package/math/stock/YIN/math.json +0 -8
- package/math/stock/YIN/test.js +0 -4
- package/math/stock/readme.md +0 -294
- package/math/trigonometric/cos/index.js +0 -8
- package/math/trigonometric/cos/math.json +0 -20
- package/math/trigonometric/cot/index.js +0 -8
- package/math/trigonometric/cot/math.json +0 -17
- package/math/trigonometric/csc/index.js +0 -8
- package/math/trigonometric/csc/math.json +0 -20
- package/math/trigonometric/readme.md +0 -2
- package/math/trigonometric/sec/index.js +0 -8
- package/math/trigonometric/sec/math.json +0 -20
- package/math/trigonometric/sin/index.js +0 -8
- package/math/trigonometric/sin/math.json +0 -20
- package/math/trigonometric/tan/index.js +0 -8
- package/math/trigonometric/tan/math.json +0 -18
- package/symbol/brackets/index.js +0 -46
- package/symbol/brackets/symbol.json +0 -8
- package/symbol/brackets/test.js +0 -12
- package/symbol/decimal/index.js +0 -41
- package/symbol/decimal/symbol.json +0 -8
- package/symbol/decimal/test.js +0 -2
- package/symbol/percentage/index.js +0 -48
- package/symbol/percentage/symbol.json +0 -8
- package/symbol/percentage/test.js +0 -2
- package/symbol/pi/index.js +0 -20
- package/symbol/pi/symbol.json +0 -9
- package/symbol/pi/test.js +0 -2
- package/symbol/power/index.js +0 -111
- package/symbol/power/symbol.json +0 -8
- package/symbol/power/test.js +0 -10
- package/symbol/readme.md +0 -2
- package/test.js +0 -32
- package/test2.js +0 -47
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 公式的加法格式化
|
|
3
|
-
* @param {String} expression
|
|
4
|
-
* @return {String} 返回格式化后的公式
|
|
5
|
-
*/
|
|
6
|
-
module.exports = function format_plus(expression) {
|
|
7
|
-
var exp = expression.replace(/\^\-/g, '^@');
|
|
8
|
-
exp = exp.replace(/\+/g, ' +').replace(/\-/g, ' -');
|
|
9
|
-
exp = exp.replace(/\^@/g, '^-');
|
|
10
|
-
if (/[a-zA-Z]/.test(exp)) {
|
|
11
|
-
var left = "";
|
|
12
|
-
var between = "";
|
|
13
|
-
var right = "";
|
|
14
|
-
var value = "";
|
|
15
|
-
var vals = exp.split(' ');
|
|
16
|
-
var len = vals.length;
|
|
17
|
-
for (var i = 0; i < len; i++) {
|
|
18
|
-
var val = vals[i];
|
|
19
|
-
if (/[a-zA-Z]/.test(val)) {
|
|
20
|
-
if (val.indexOf('-') === -1) {
|
|
21
|
-
left += ' ' + val;
|
|
22
|
-
} else {
|
|
23
|
-
between += ' ' + val;
|
|
24
|
-
}
|
|
25
|
-
} else {
|
|
26
|
-
var k = val.replace(/\+/g, '').replace(/\-/g, '').replace(/\*/g, '');
|
|
27
|
-
if (/^[0-9.]+$/.test(k)) {
|
|
28
|
-
value += ' ' + val;
|
|
29
|
-
} else {
|
|
30
|
-
right += ' ' + val;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exp = left + ' +' + between + ' +' + right;
|
|
35
|
-
if (value) {
|
|
36
|
-
exp += ' +' + eval(value);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return exp.replace('+ +', '+').replace('+ +', '+').replace('+ -', '-').replace('+ -', '-');
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
// .replace(/\*/g, ' *')
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const multiply_divide = require('../multiply_divide');
|
|
2
|
-
const plus_subtract = require('../plus_subtract');
|
|
3
|
-
|
|
4
|
-
const decimal = require('../../symbol/decimal');
|
|
5
|
-
const percentage = require('../../symbol/percentage');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @description 四则运算
|
|
9
|
-
* @param {String} expression 公式
|
|
10
|
-
*/
|
|
11
|
-
module.exports = function four_run(expression) {
|
|
12
|
-
var express = decimal(expression);
|
|
13
|
-
express = percentage(express);
|
|
14
|
-
express = plus_subtract(express);
|
|
15
|
-
express = express.replace(/\^\-/g, '^@').replace(/\+/g, '+ ').replace(/\-/g, '- ').replace(/\^@/g, '^-');
|
|
16
|
-
if(express.indexOf('- ') == 0){
|
|
17
|
-
express = express.replace('- ', '-')
|
|
18
|
-
}
|
|
19
|
-
return express;
|
|
20
|
-
}
|
package/convert/four_run/test.js
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
require('mm_expand');
|
|
2
|
-
const power = require('../../symbol/power');
|
|
3
|
-
const denominator = require('../../math/base/denominator');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 乘除
|
|
7
|
-
* @param {String} expression 公式
|
|
8
|
-
*/
|
|
9
|
-
function multiply_divide(expression) {
|
|
10
|
-
var expres = power(expression);
|
|
11
|
-
expres = expres.replace(/ /g, '').replace(/\*/g, ' *').replace(/\//g, ' /');
|
|
12
|
-
var arr = expres.split(' ');
|
|
13
|
-
// 统计代数
|
|
14
|
-
var dict = {};
|
|
15
|
-
var exp = "";
|
|
16
|
-
// 乘*乘 / (除 * 除)
|
|
17
|
-
var multiply = 1;
|
|
18
|
-
var divide = 1;
|
|
19
|
-
// 统计代数个数
|
|
20
|
-
arr.map(function(str) {
|
|
21
|
-
var k = str.replace('*', '').replace('/', '');
|
|
22
|
-
k = k.left('^', true);
|
|
23
|
-
if (isNaN(k)) {
|
|
24
|
-
// 次方加减
|
|
25
|
-
if (str.indexOf('^') !== -1) {
|
|
26
|
-
var n = Number(str.right('^'));
|
|
27
|
-
var ar = k.match(/[a-zA-Z]/);
|
|
28
|
-
var len = ar.length;
|
|
29
|
-
for (var i = 0; i < len; i++) {
|
|
30
|
-
var ki = ar[i];
|
|
31
|
-
if (!dict.hasOwnProperty(ki)) {
|
|
32
|
-
dict[ki] += 0;
|
|
33
|
-
}
|
|
34
|
-
if (str.indexOf('/') !== -1) {
|
|
35
|
-
dict[ki] += -1;
|
|
36
|
-
} else {
|
|
37
|
-
dict[ki] += 1;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
var ar = k.split(/[a-zA-Z]+/);
|
|
41
|
-
const l = ar.length;
|
|
42
|
-
for (var i = 0; i < l; i++) {
|
|
43
|
-
var m = ar[i];
|
|
44
|
-
if (str.indexOf('/') !== -1) {
|
|
45
|
-
if (multiply % m === 0) {
|
|
46
|
-
multiply = multiply / m;
|
|
47
|
-
} else {
|
|
48
|
-
divide = divide * m;
|
|
49
|
-
}
|
|
50
|
-
} else {
|
|
51
|
-
multiply = multiply * m;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
} else {
|
|
55
|
-
if (k.indexOf('_') === -1) {
|
|
56
|
-
// console.log(k);
|
|
57
|
-
var ar = k.split(/[a-zA-Z]+/);
|
|
58
|
-
if (ar) {
|
|
59
|
-
var len = ar.length;
|
|
60
|
-
for (var i = 0; i < len; i++) {
|
|
61
|
-
var txt = ar[i];
|
|
62
|
-
if (txt) {
|
|
63
|
-
var m = Number(txt);
|
|
64
|
-
// 让乘数相乘,除数相乘
|
|
65
|
-
if (str.indexOf('/') !== -1) {
|
|
66
|
-
if (multiply % m === 0) {
|
|
67
|
-
multiply = multiply / m;
|
|
68
|
-
} else {
|
|
69
|
-
divide = divide * m;
|
|
70
|
-
}
|
|
71
|
-
} else {
|
|
72
|
-
multiply = multiply * m;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
var ar_k = k.match(/[a-zA-Z]/g, '');
|
|
78
|
-
if (ar_k) {
|
|
79
|
-
// 增减代数次方
|
|
80
|
-
for (var i = 0; i < ar_k.length; i++) {
|
|
81
|
-
var v = ar_k[i];
|
|
82
|
-
if (!dict.hasOwnProperty(v)) {
|
|
83
|
-
dict[v] = 0;
|
|
84
|
-
}
|
|
85
|
-
if (str.indexOf('/') !== -1) {
|
|
86
|
-
dict[v] -= 1;
|
|
87
|
-
} else {
|
|
88
|
-
dict[v] += 1;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
} else {
|
|
93
|
-
if (!dict.hasOwnProperty(k)) {
|
|
94
|
-
dict[k] = 0;
|
|
95
|
-
}
|
|
96
|
-
if (str.indexOf('/') !== -1) {
|
|
97
|
-
dict[k] -= 1;
|
|
98
|
-
} else {
|
|
99
|
-
dict[k] += 1;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
} else {
|
|
104
|
-
var m = 1;
|
|
105
|
-
if (str.indexOf('^') !== -1) {
|
|
106
|
-
var n = Number(str.right('^'));
|
|
107
|
-
var x = Number(k);
|
|
108
|
-
m = Math.pow(x, n);
|
|
109
|
-
} else {
|
|
110
|
-
m = Number(k);
|
|
111
|
-
}
|
|
112
|
-
if (str.indexOf('/') != -1) {
|
|
113
|
-
if (multiply % m === 0) {
|
|
114
|
-
multiply = multiply / m;
|
|
115
|
-
} else {
|
|
116
|
-
divide = divide * m;
|
|
117
|
-
}
|
|
118
|
-
} else {
|
|
119
|
-
multiply = multiply * m;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
if (multiply === 0 || divide === 0) {
|
|
124
|
-
return 0;
|
|
125
|
-
}
|
|
126
|
-
var bl = false;
|
|
127
|
-
var left = "";
|
|
128
|
-
if (multiply % divide === 0) {
|
|
129
|
-
var shan = (multiply / divide);
|
|
130
|
-
if (shan !== 1) {
|
|
131
|
-
left = shan + '';
|
|
132
|
-
}
|
|
133
|
-
bl = true;
|
|
134
|
-
} else {
|
|
135
|
-
var param = denominator(multiply, divide);
|
|
136
|
-
multiply = param.multiply;
|
|
137
|
-
divide = param.divide;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
var right = "";
|
|
141
|
-
// 合并公式
|
|
142
|
-
for (var k in dict) {
|
|
143
|
-
var val = dict[k];
|
|
144
|
-
if (val === 1) {
|
|
145
|
-
left += k
|
|
146
|
-
} else if (val !== 0) {
|
|
147
|
-
if (val > 0) {
|
|
148
|
-
left += " * " + k + '^' + val + " * "
|
|
149
|
-
} else {
|
|
150
|
-
var n = -val;
|
|
151
|
-
if (n === 1) {
|
|
152
|
-
right += k
|
|
153
|
-
} else {
|
|
154
|
-
right += " / " + k + '^' + n + " / "
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
if(left.startsWith(' * ')){
|
|
160
|
-
left = left.substring(3);
|
|
161
|
-
}
|
|
162
|
-
if(right.endWith(' / ')){
|
|
163
|
-
right = right.substring(0,right.length - 3);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
var result = "";
|
|
167
|
-
if (!bl) {
|
|
168
|
-
if (multiply !== 1) {
|
|
169
|
-
result = multiply + left;
|
|
170
|
-
} else {
|
|
171
|
-
result = left;
|
|
172
|
-
}
|
|
173
|
-
if (divide !== 1) {
|
|
174
|
-
result += '/' + divide + right;
|
|
175
|
-
} else {
|
|
176
|
-
result += '/' + right;
|
|
177
|
-
}
|
|
178
|
-
} else {
|
|
179
|
-
if (right) {
|
|
180
|
-
result = left + '/' + right;
|
|
181
|
-
} else {
|
|
182
|
-
result = left;
|
|
183
|
-
if (!result) {
|
|
184
|
-
result = "1";
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
if (result.indexOf('/') === 0) {
|
|
189
|
-
result = 1 + result;
|
|
190
|
-
}
|
|
191
|
-
if(result.endsWith(' * ')){
|
|
192
|
-
result = result.substring(0, result.length - 3);
|
|
193
|
-
}
|
|
194
|
-
return result.replace('* /', '/').replace(/\* \*/g, '*');
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
module.exports = multiply_divide;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
const multiply_divide = require('./index');
|
|
2
|
-
|
|
3
|
-
// console.log(multiply_divide('4*a/3*a/c/4*3*b'));
|
|
4
|
-
// console.log(multiply_divide('4*a/2*a/4/c'));
|
|
5
|
-
// console.log(multiply_divide('4*a/2*3*b/a*c/b*c/b*c^3'));
|
|
6
|
-
// console.log(multiply_divide('4^3*12/3a'));
|
|
7
|
-
|
|
8
|
-
// console.log(multiply_divide("ab/8a^2"));
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// console.log(multiply_divide("ab/8a^2/2b^-3"));
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
console.log(multiply_divide("ab/8a^2 * 2b^-3"));
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
const multiply_divide = require('../multiply_divide');
|
|
2
|
-
const denominator = require('../../math/base/denominator');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 加减
|
|
6
|
-
* @param {String} expression 公式
|
|
7
|
-
*/
|
|
8
|
-
module.exports = function plus_subtract(expression) {
|
|
9
|
-
var expres = expression.replace(/\^\-/g, '^~');
|
|
10
|
-
expres = expres.replace(/ /g, '').replace(/\+/g, ' +').replace(/\-/g, ' -');
|
|
11
|
-
expres = expres.replace(/\^~/g, '^-');
|
|
12
|
-
var arr = expres.split(' ');
|
|
13
|
-
|
|
14
|
-
var dict = {};
|
|
15
|
-
var exp = "";
|
|
16
|
-
var num = 0;
|
|
17
|
-
|
|
18
|
-
var multiply = 0;
|
|
19
|
-
var divide = 1;
|
|
20
|
-
|
|
21
|
-
var multiply_str = "";
|
|
22
|
-
var divide_str = "";
|
|
23
|
-
|
|
24
|
-
// 统计代数个数
|
|
25
|
-
arr.map(function(x) {
|
|
26
|
-
var exp = "";
|
|
27
|
-
|
|
28
|
-
if (x.indexOf('-') === 0) {
|
|
29
|
-
exp = " -" + multiply_divide(x.replace('-', '')) + "";
|
|
30
|
-
} else {
|
|
31
|
-
if (x.indexOf('+') === 0) {
|
|
32
|
-
exp = x.replace('+', '');
|
|
33
|
-
} else {
|
|
34
|
-
exp = x;
|
|
35
|
-
}
|
|
36
|
-
exp = multiply_divide(exp) + "";
|
|
37
|
-
}
|
|
38
|
-
if (/[a-zA-Z]/.test(exp)) {
|
|
39
|
-
if (exp.indexOf(' -') === 0) {
|
|
40
|
-
if (exp.indexOf('^') !== -1 || exp.indexOf('/') !== -1) {
|
|
41
|
-
var key = exp.replace(' -', '');
|
|
42
|
-
// 代数加减
|
|
43
|
-
if (!dict[key]) {
|
|
44
|
-
dict[key] = -1;
|
|
45
|
-
} else {
|
|
46
|
-
dict[key] -= 1;
|
|
47
|
-
}
|
|
48
|
-
} else {
|
|
49
|
-
var key = exp.match(/[a-zA-Z]+/)[0];
|
|
50
|
-
var str = exp.replace(key, '');
|
|
51
|
-
var n = 1;
|
|
52
|
-
if(str)
|
|
53
|
-
{
|
|
54
|
-
if(str.trim() == '-')
|
|
55
|
-
{
|
|
56
|
-
n = -1;
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
n = Number(str);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
// 代数加减
|
|
63
|
-
if (!dict[key]) {
|
|
64
|
-
dict[key] = n;
|
|
65
|
-
} else {
|
|
66
|
-
dict[key] += n;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
} else {
|
|
70
|
-
if (exp.indexOf('^') !== -1 || exp.indexOf('/') !== -1) {
|
|
71
|
-
var key = exp;
|
|
72
|
-
// 代数加减
|
|
73
|
-
if (!dict[key]) {
|
|
74
|
-
dict[key] = 1;
|
|
75
|
-
} else {
|
|
76
|
-
dict[key] += 1;
|
|
77
|
-
}
|
|
78
|
-
} else {
|
|
79
|
-
var key = exp.match(/[a-zA-Z]+/)[0];
|
|
80
|
-
var str = exp.replace(key, '');
|
|
81
|
-
var n = 1;
|
|
82
|
-
if(str)
|
|
83
|
-
{
|
|
84
|
-
if(str.trim() == '-')
|
|
85
|
-
{
|
|
86
|
-
n = -1;
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
n = Number(str);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
// 代数加减
|
|
93
|
-
if (!dict[key]) {
|
|
94
|
-
dict[key] = n;
|
|
95
|
-
} else {
|
|
96
|
-
dict[key] += n;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
} else {
|
|
101
|
-
// 代数加减
|
|
102
|
-
if (exp.indexOf("^") !== -1) {
|
|
103
|
-
var mh = exp.match(/[0-9]+\^[0-9]+/);
|
|
104
|
-
if (mh) {
|
|
105
|
-
var key = mh[0];
|
|
106
|
-
var left = key.left("^");
|
|
107
|
-
var ex = "";
|
|
108
|
-
var right = key.right("^");
|
|
109
|
-
var n = Number(right);
|
|
110
|
-
for (var i = 0; i < n; i++) {
|
|
111
|
-
ex += " * (" + left + ")";
|
|
112
|
-
}
|
|
113
|
-
var value = eval(ex.replace(' * ', ''));
|
|
114
|
-
exp = exp.replace(key, value);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
if (exp.indexOf("/") !== -1) {
|
|
118
|
-
var left = exp.left("/");
|
|
119
|
-
var right = exp.right("/");
|
|
120
|
-
var d = Number(right);
|
|
121
|
-
multiply = Number(left) * divide + multiply * d;
|
|
122
|
-
divide *= d;
|
|
123
|
-
} else {
|
|
124
|
-
num += Number(exp);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
var result = '';
|
|
130
|
-
// 合并公式
|
|
131
|
-
for (var k in dict) {
|
|
132
|
-
var val = dict[k];
|
|
133
|
-
if (val === 1) {
|
|
134
|
-
result += ' +' + k
|
|
135
|
-
} else if (val !== 0) {
|
|
136
|
-
if (val > 0) {
|
|
137
|
-
result += ' +' + val + k
|
|
138
|
-
} else {
|
|
139
|
-
if (-val === 1) {
|
|
140
|
-
result += ' -' + k
|
|
141
|
-
} else {
|
|
142
|
-
result += val + k
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
if (num > 0) {
|
|
148
|
-
result += ' +' + num
|
|
149
|
-
} else if (num < 0) {
|
|
150
|
-
result += num
|
|
151
|
-
}
|
|
152
|
-
if (multiply !== 0) {
|
|
153
|
-
var o = denominator(multiply, divide);
|
|
154
|
-
result += " +" + o.multiply + '/' + o.divide;
|
|
155
|
-
}
|
|
156
|
-
if (result.indexOf(' +') === 0) {
|
|
157
|
-
result = result.replace(' +', '');
|
|
158
|
-
}
|
|
159
|
-
return result.replace(/\+ \-/g, ' -');
|
|
160
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const plus_subtract = require('./index');
|
|
2
|
-
|
|
3
|
-
// console.log(plus_subtract('4+a+2-3+b+a+b-b'));
|
|
4
|
-
// console.log(plus_subtract('4*a/3-a/c/4+3*b'));
|
|
5
|
-
// console.log(plus_subtract('4+a/2*a+4/c'));
|
|
6
|
-
|
|
7
|
-
// console.log(plus_subtract('4+a/2a*2a/a'));
|
|
8
|
-
// console.log(plus_subtract('4+a/2a + 1/7 +1/7'));
|
|
9
|
-
// console.log(plus_subtract('4+a/7a + a/8a'));
|
|
10
|
-
// console.log(plus_subtract('4+a/7a + ab/8a'));
|
|
11
|
-
|
|
12
|
-
// console.log(plus_subtract('4 + 0 + 0.25 + 4^2 + 1/7 + 1/14'));
|
|
13
|
-
// console.log(plus_subtract('4+a/7a + ab/8a^2 + 4^2 + 1/7 + 1/14'));
|
|
14
|
-
|
|
15
|
-
console.log(plus_subtract('2a-3a + 4a'));
|
package/convert/readme.md
DELETED
package/doc/mm_math.doc
DELETED
|
Binary file
|
package/doc//345/207/275/346/225/260/347/254/246/345/217/267/344/270/200/350/247/210/350/241/250.xls
DELETED
|
Binary file
|
package/express/README.md
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# 化学恒等式
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# 几何恒等式
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# 矩形恒等式
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# 线性恒等式
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# 物理恒等式
|
package/identities/readme.md
DELETED
package/math/array/col/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 二维数组取列值
|
|
3
|
-
* @param {Array} arr 二维数组
|
|
4
|
-
* @param {Number} y 列
|
|
5
|
-
* @return {Array} 返回列值集合
|
|
6
|
-
*/
|
|
7
|
-
module.exports = function col(arr, y) {
|
|
8
|
-
var arr_new = [];
|
|
9
|
-
var len = arr.length;
|
|
10
|
-
for (var i = 0; i < len; i++) {
|
|
11
|
-
var arr_sub = arr[i];
|
|
12
|
-
if (arr_sub.length >= y) {
|
|
13
|
-
arr_new.push(arr_sub[y - 1]);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return arr_new;
|
|
17
|
-
};
|
package/math/array/col/math.json
DELETED
package/math/array/col/test.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
function isComposite(n) {
|
|
2
|
-
if (n == 0 || n == 1) {
|
|
3
|
-
return false;
|
|
4
|
-
}
|
|
5
|
-
if (n == 2) {
|
|
6
|
-
return false;
|
|
7
|
-
}
|
|
8
|
-
var times = Math.sqrt(n);
|
|
9
|
-
if (times == parseInt(times)) {
|
|
10
|
-
return true;
|
|
11
|
-
}
|
|
12
|
-
for (var i = 2; i < times; i++) {
|
|
13
|
-
if (n % i == 0) {
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* 取所有合数
|
|
22
|
-
* @param {Array} arr 数组
|
|
23
|
-
* @return {Array} 返回合数集合
|
|
24
|
-
*/
|
|
25
|
-
module.exports = function composite(arr) {
|
|
26
|
-
var arr_new = [];
|
|
27
|
-
var len = arr.length;
|
|
28
|
-
for (var i = 0; i < len; i++) {
|
|
29
|
-
var n = arr[i];
|
|
30
|
-
if (isComposite(n)) {
|
|
31
|
-
arr_new.push(n);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return arr_new;
|
|
35
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const average = require('../average');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 求偏差
|
|
5
|
-
* @param {Array} arr 数组
|
|
6
|
-
* @return {Number} 返回平均值
|
|
7
|
-
*/
|
|
8
|
-
module.exports = function deviations(arr) {
|
|
9
|
-
// 先求平均值
|
|
10
|
-
var value = average(arr);
|
|
11
|
-
// 用当前数值减去平均值,求出偏差值
|
|
12
|
-
return arr.map(function(x) {
|
|
13
|
-
return x - value;
|
|
14
|
-
});
|
|
15
|
-
};
|