mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-25 15:07:57 +00:00
merged random functions with develop
This commit is contained in:
commit
0084920875
39
Jakefile.js
39
Jakefile.js
@ -114,6 +114,45 @@ task('test', ['concat'], function () {
|
||||
console.log('Executed ' + files.length + ' test files successfully');
|
||||
});
|
||||
|
||||
/**
|
||||
* build task
|
||||
*/
|
||||
desc('Build the library using browserify');
|
||||
task('dist', {async: true}, function () {
|
||||
var browserify = require('browserify');
|
||||
var b = browserify();
|
||||
// TODO: make directory dist
|
||||
var dist = './dist/math.js';
|
||||
var distMin = './dist/math.min.js';
|
||||
b.add('./src/index.js');
|
||||
b.bundle({
|
||||
standalone: 'math'
|
||||
}, function (err, code) {
|
||||
if(err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
// add header and shim
|
||||
var lib = util.read('./src/header.js') + code + util.read('./src/shim.js');
|
||||
|
||||
// write bundled file
|
||||
util.write(dist, lib);
|
||||
|
||||
// update version number and stuff in the javascript files
|
||||
updateVersion(dist);
|
||||
|
||||
// minify
|
||||
var result = util.minify({
|
||||
src: dist,
|
||||
dest: distMin,
|
||||
header: util.read(HEADER)
|
||||
});
|
||||
updateVersion(distMin);
|
||||
|
||||
complete();
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Update version and date patterns in given file.
|
||||
* Patterns '@@date' and '@@version' will be replaced with current date and
|
||||
|
||||
12037
dist/math.js
vendored
12037
dist/math.js
vendored
File diff suppressed because it is too large
Load Diff
11
dist/math.min.js
vendored
11
dist/math.min.js
vendored
File diff suppressed because one or more lines are too long
2
index.js
2
index.js
@ -1 +1 @@
|
||||
exports = require ('./dist/math.js');
|
||||
module.exports = require('./src/index.js');
|
||||
@ -29,14 +29,15 @@
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"jake": ">= 0.5.9",
|
||||
"tap": ">= 0.4.3",
|
||||
"browserify": "2.x",
|
||||
"mocha": "1.x",
|
||||
"numbers" : "0.4.0",
|
||||
"uglify-js": ">= 2.2.5",
|
||||
"dateable": ">= 0.1.2",
|
||||
"underscore": "1.4.x"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "jake test --trace"
|
||||
"test": "mocha test --recursive --reporter spec"
|
||||
},
|
||||
"main": "./dist/math.js",
|
||||
"bin": {
|
||||
|
||||
@ -1,22 +1,23 @@
|
||||
/**
|
||||
* mathjs constants
|
||||
*/
|
||||
math.pi = Math.PI;
|
||||
math.e = Math.E;
|
||||
math.tau = Math.PI * 2;
|
||||
math.i = new Complex(0, 1);
|
||||
module.exports = function (math) {
|
||||
var Complex = require('./type/Complex.js');
|
||||
|
||||
math['Infinity']= Infinity;
|
||||
math['NaN'] = NaN;
|
||||
math['true'] = true;
|
||||
math['false'] = false;
|
||||
math.pi = Math.PI;
|
||||
math.e = Math.E;
|
||||
math.tau = Math.PI * 2;
|
||||
math.i = new Complex(0, 1);
|
||||
|
||||
// uppercase constants (for compatibility with built-in Math)
|
||||
math.E = Math.E;
|
||||
math.LN2 = Math.LN2;
|
||||
math.LN10 = Math.LN10;
|
||||
math.LOG2E = Math.LOG2E;
|
||||
math.LOG10E = Math.LOG10E;
|
||||
math.PI = Math.PI;
|
||||
math.SQRT1_2 = Math.SQRT1_2;
|
||||
math.SQRT2 = Math.SQRT2;
|
||||
math['Infinity'] = Infinity;
|
||||
math['NaN'] = NaN;
|
||||
math['true'] = true;
|
||||
math['false'] = false;
|
||||
|
||||
// uppercase constants (for compatibility with built-in Math)
|
||||
math.E = Math.E;
|
||||
math.LN2 = Math.LN2;
|
||||
math.LN10 = Math.LN10;
|
||||
math.LOG2E = Math.LOG2E;
|
||||
math.LOG10E = Math.LOG10E;
|
||||
math.PI = Math.PI;
|
||||
math.SQRT1_2 = Math.SQRT1_2;
|
||||
math.SQRT2 = Math.SQRT2;
|
||||
};
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs['Infinity'] = {
|
||||
module.exports = {
|
||||
'name': 'Infinity',
|
||||
'category': 'Constants',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.LN10 = {
|
||||
module.exports = {
|
||||
'name': 'LN10',
|
||||
'category': 'Constants',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.LN2 = {
|
||||
module.exports = {
|
||||
'name': 'LN2',
|
||||
'category': 'Constants',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.LOG10E = {
|
||||
module.exports = {
|
||||
'name': 'LOG10E',
|
||||
'category': 'Constants',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.LOG2E = {
|
||||
module.exports = {
|
||||
'name': 'LOG2E',
|
||||
'category': 'Constants',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs['NaN'] = {
|
||||
module.exports = {
|
||||
'name': 'NaN',
|
||||
'category': 'Constants',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.SQRT1_2 = {
|
||||
module.exports = {
|
||||
'name': 'SQRT1_2',
|
||||
'category': 'Constants',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.SQRT2 = {
|
||||
module.exports = {
|
||||
'name': 'SQRT2',
|
||||
'category': 'Constants',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.e = math.docs.E = {
|
||||
module.exports = {
|
||||
'name': 'e',
|
||||
'category': 'Constants',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs['false'] = {
|
||||
module.exports = {
|
||||
'name': 'false',
|
||||
'category': 'Constants',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.i = {
|
||||
module.exports = {
|
||||
'name': 'i',
|
||||
'category': 'Constants',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.pi = math.docs.PI = {
|
||||
module.exports = {
|
||||
'name': 'pi',
|
||||
'category': 'Constants',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.tau = {
|
||||
module.exports = {
|
||||
'name': 'tau',
|
||||
'category': 'Constants',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs['true'] = {
|
||||
module.exports = {
|
||||
'name': 'true',
|
||||
'category': 'Constants',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.abs = {
|
||||
module.exports = {
|
||||
'name': 'abs',
|
||||
'category': 'Arithmetic',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.add = {
|
||||
module.exports = {
|
||||
'name': 'add',
|
||||
'category': 'Operators',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.ceil = {
|
||||
module.exports = {
|
||||
'name': 'ceil',
|
||||
'category': 'Arithmetic',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.cube = {
|
||||
module.exports = {
|
||||
'name': 'cube',
|
||||
'category': 'Arithmetic',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.divide = {
|
||||
module.exports = {
|
||||
'name': 'divide',
|
||||
'category': 'Operators',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.edivide = {
|
||||
module.exports = {
|
||||
'name': 'edivide',
|
||||
'category': 'Operators',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.emultiply = {
|
||||
module.exports = {
|
||||
'name': 'emultiply',
|
||||
'category': 'Operators',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.epow = {
|
||||
module.exports = {
|
||||
'name': 'epow',
|
||||
'category': 'Operators',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.equal = {
|
||||
module.exports = {
|
||||
'name': 'equal',
|
||||
'category': 'Operators',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.exp = {
|
||||
module.exports = {
|
||||
'name': 'exp',
|
||||
'category': 'Arithmetic',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.fix = {
|
||||
module.exports = {
|
||||
'name': 'fix',
|
||||
'category': 'Arithmetic',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.floor = {
|
||||
module.exports = {
|
||||
'name': 'floor',
|
||||
'category': 'Arithmetic',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.gcd = {
|
||||
module.exports = {
|
||||
'name': 'gcd',
|
||||
'category': 'Arithmetic',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.larger = {
|
||||
module.exports = {
|
||||
'name': 'larger',
|
||||
'category': 'Operators',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.largereq = {
|
||||
module.exports = {
|
||||
'name': 'largereq',
|
||||
'category': 'Operators',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.lcm = {
|
||||
module.exports = {
|
||||
'name': 'lcm',
|
||||
'category': 'Arithmetic',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.log = {
|
||||
module.exports = {
|
||||
'name': 'log',
|
||||
'category': 'Arithmetic',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.log10 = {
|
||||
module.exports = {
|
||||
'name': 'log10',
|
||||
'category': 'Arithmetic',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.mod = {
|
||||
module.exports = {
|
||||
'name': 'mod',
|
||||
'category': 'Operators',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.multiply = {
|
||||
module.exports = {
|
||||
'name': 'multiply',
|
||||
'category': 'Operators',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.pow = {
|
||||
module.exports = {
|
||||
'name': 'pow',
|
||||
'category': 'Operators',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.round = {
|
||||
module.exports = {
|
||||
'name': 'round',
|
||||
'category': 'Arithmetic',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.sign = {
|
||||
module.exports = {
|
||||
'name': 'sign',
|
||||
'category': 'Arithmetic',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.smaller = {
|
||||
module.exports = {
|
||||
'name': 'smaller',
|
||||
'category': 'Operators',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.smallereq = {
|
||||
module.exports = {
|
||||
'name': 'smallereq',
|
||||
'category': 'Operators',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.sqrt = {
|
||||
module.exports = {
|
||||
'name': 'sqrt',
|
||||
'category': 'Arithmetic',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.square = {
|
||||
module.exports = {
|
||||
'name': 'square',
|
||||
'category': 'Arithmetic',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.subtract = {
|
||||
module.exports = {
|
||||
'name': 'subtract',
|
||||
'category': 'Operators',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.unary = {
|
||||
module.exports = {
|
||||
'name': 'unary',
|
||||
'category': 'Operators',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.unequal = {
|
||||
module.exports = {
|
||||
'name': 'unequal',
|
||||
'category': 'Operators',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.xgcd = {
|
||||
module.exports = {
|
||||
'name': 'xgcd',
|
||||
'category': 'Arithmetic',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.arg = {
|
||||
module.exports = {
|
||||
'name': 'arg',
|
||||
'category': 'Complex',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.conj = {
|
||||
module.exports = {
|
||||
'name': 'conj',
|
||||
'category': 'Complex',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.im = {
|
||||
module.exports = {
|
||||
'name': 'im',
|
||||
'category': 'Complex',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.re = {
|
||||
module.exports = {
|
||||
'name': 're',
|
||||
'category': 'Complex',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs['boolean'] = {
|
||||
module.exports = {
|
||||
'name': 'boolean',
|
||||
'category': 'Type',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.complex = {
|
||||
module.exports = {
|
||||
'name': 'complex',
|
||||
'category': 'Type',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.matrix = {
|
||||
module.exports = {
|
||||
'name': 'matrix',
|
||||
'category': 'Type',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.number = {
|
||||
module.exports = {
|
||||
'name': 'number',
|
||||
'category': 'Type',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.range = {
|
||||
module.exports = {
|
||||
'name': 'range',
|
||||
'category': 'Type',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.string = {
|
||||
module.exports = {
|
||||
'name': 'string',
|
||||
'category': 'Type',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.unit = {
|
||||
module.exports = {
|
||||
'name': 'unit',
|
||||
'category': 'Type',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.concat = {
|
||||
module.exports = {
|
||||
'name': 'concat',
|
||||
'category': 'Matrix',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.det = {
|
||||
module.exports = {
|
||||
'name': 'det',
|
||||
'category': 'Matrix',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.diag = {
|
||||
module.exports = {
|
||||
'name': 'diag',
|
||||
'category': 'Matrix',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.eye = {
|
||||
module.exports = {
|
||||
'name': 'eye',
|
||||
'category': 'Matrix',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.inv = {
|
||||
module.exports = {
|
||||
'name': 'inv',
|
||||
'category': 'Matrix',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.ones = {
|
||||
module.exports = {
|
||||
'name': 'ones',
|
||||
'category': 'Matrix',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.size = {
|
||||
module.exports = {
|
||||
'name': 'size',
|
||||
'category': 'Matrix',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.squeeze = {
|
||||
module.exports = {
|
||||
'name': 'squeeze',
|
||||
'category': 'Matrix',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.subset = {
|
||||
module.exports = {
|
||||
'name': 'subset',
|
||||
'category': 'Matrix',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.transpose = {
|
||||
module.exports = {
|
||||
'name': 'transpose',
|
||||
'category': 'Matrix',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.zeros = {
|
||||
module.exports = {
|
||||
'name': 'zeros',
|
||||
'category': 'Matrix',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.factorial = {
|
||||
module.exports = {
|
||||
'name': 'factorial',
|
||||
'category': 'Probability',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.random = {
|
||||
module.exports = {
|
||||
'name': 'random',
|
||||
'category': 'Probability',
|
||||
'syntax': [
|
||||
@ -11,17 +11,3 @@ math.docs.random = {
|
||||
],
|
||||
'seealso': []
|
||||
};
|
||||
|
||||
math.docs.randInt = {
|
||||
'name': 'randInt',
|
||||
'category': 'Probability',
|
||||
'syntax': [
|
||||
'randInt()'
|
||||
],
|
||||
'description':
|
||||
'Return a random number between 0 and 1.',
|
||||
'examples': [
|
||||
'randInt()'
|
||||
],
|
||||
'seealso': []
|
||||
};
|
||||
13
src/docs/function/probability/randomInt.js
Normal file
13
src/docs/function/probability/randomInt.js
Normal file
@ -0,0 +1,13 @@
|
||||
module.exports = {
|
||||
'name': 'randInt',
|
||||
'category': 'Probability',
|
||||
'syntax': [
|
||||
'randInt()'
|
||||
],
|
||||
'description':
|
||||
'Return a random number between 0 and 1.',
|
||||
'examples': [
|
||||
'randInt()'
|
||||
],
|
||||
'seealso': []
|
||||
};
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.max = {
|
||||
module.exports = {
|
||||
'name': 'max',
|
||||
'category': 'Statistics',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.min = {
|
||||
module.exports = {
|
||||
'name': 'min',
|
||||
'category': 'Statistics',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.acos = {
|
||||
module.exports = {
|
||||
'name': 'acos',
|
||||
'category': 'Trigonometry',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.asin = {
|
||||
module.exports = {
|
||||
'name': 'asin',
|
||||
'category': 'Trigonometry',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.atan = {
|
||||
module.exports = {
|
||||
'name': 'atan',
|
||||
'category': 'Trigonometry',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.atan2 = {
|
||||
module.exports = {
|
||||
'name': 'atan2',
|
||||
'category': 'Trigonometry',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.cos = {
|
||||
module.exports = {
|
||||
'name': 'cos',
|
||||
'category': 'Trigonometry',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.cot = {
|
||||
module.exports = {
|
||||
'name': 'cot',
|
||||
'category': 'Trigonometry',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.csc = {
|
||||
module.exports = {
|
||||
'name': 'csc',
|
||||
'category': 'Trigonometry',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.sec = {
|
||||
module.exports = {
|
||||
'name': 'sec',
|
||||
'category': 'Trigonometry',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.sin = {
|
||||
module.exports = {
|
||||
'name': 'sin',
|
||||
'category': 'Trigonometry',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.tan = {
|
||||
module.exports = {
|
||||
'name': 'tan',
|
||||
'category': 'Trigonometry',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs['in'] = {
|
||||
module.exports = {
|
||||
'name': 'in',
|
||||
'category': 'Units',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.clone = {
|
||||
module.exports = {
|
||||
'name': 'clone',
|
||||
'category': 'Utils',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs['eval'] = {
|
||||
module.exports = {
|
||||
'name': 'eval',
|
||||
'category': 'Utils',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.format = {
|
||||
module.exports = {
|
||||
'name': 'format',
|
||||
'category': 'Utils',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs.help = {
|
||||
module.exports = {
|
||||
'name': 'help',
|
||||
'category': 'Utils',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs['import'] = {
|
||||
module.exports = {
|
||||
'name': 'import',
|
||||
'category': 'Utils',
|
||||
'syntax': [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
math.docs['typeof'] = {
|
||||
module.exports = {
|
||||
'name': 'typeof',
|
||||
'category': 'Utils',
|
||||
'syntax': [
|
||||
|
||||
110
src/docs/index.js
Normal file
110
src/docs/index.js
Normal file
@ -0,0 +1,110 @@
|
||||
// constants
|
||||
exports.e = require('./constants/e.js');
|
||||
exports.E = require('./constants/e.js');
|
||||
exports['false'] = require('./constants/false.js');
|
||||
exports.i = require('./constants/i.js');
|
||||
exports['Infinity'] = require('./constants/Infinity.js');
|
||||
exports.LN2 = require('./constants/LN2.js');
|
||||
exports.LN10 = require('./constants/LN10.js');
|
||||
exports.LOG2E = require('./constants/LOG2E.js');
|
||||
exports.LOG10E = require('./constants/LOG10E.js');
|
||||
exports.NaN = require('./constants/NaN.js');
|
||||
exports.pi = require('./constants/pi.js');
|
||||
exports.PI = require('./constants/pi.js');
|
||||
exports.SQRT1_2 = require('./constants/SQRT1_2.js');
|
||||
exports.SQRT2 = require('./constants/SQRT2.js');
|
||||
exports.tau = require('./constants/tau.js');
|
||||
exports['true'] = require('./constants/true.js');
|
||||
|
||||
// functions - arithmetic
|
||||
exports.abs = require('./function/arithmetic/abs.js');
|
||||
exports.add = require('./function/arithmetic/add.js');
|
||||
exports.ceil = require('./function/arithmetic/ceil.js');
|
||||
exports.cube = require('./function/arithmetic/cube.js');
|
||||
exports.divide = require('./function/arithmetic/divide.js');
|
||||
exports.edivide = require('./function/arithmetic/edivide.js');
|
||||
exports.emultiply = require('./function/arithmetic/emultiply.js');
|
||||
exports.epow = require('./function/arithmetic/epow.js');
|
||||
exports.equal = require('./function/arithmetic/equal.js');
|
||||
exports.exp = require('./function/arithmetic/exp.js');
|
||||
exports.fix = require('./function/arithmetic/fix.js');
|
||||
exports.floor = require('./function/arithmetic/floor.js');
|
||||
exports.gcd = require('./function/arithmetic/gcd.js');
|
||||
exports.larger = require('./function/arithmetic/larger.js');
|
||||
exports.largereq = require('./function/arithmetic/largereq.js');
|
||||
exports.lcm = require('./function/arithmetic/lcm.js');
|
||||
exports.log = require('./function/arithmetic/log.js');
|
||||
exports.log10 = require('./function/arithmetic/log10.js');
|
||||
exports.mod = require('./function/arithmetic/mod.js');
|
||||
exports.multiply = require('./function/arithmetic/multiply.js');
|
||||
exports.pow = require('./function/arithmetic/pow.js');
|
||||
exports.round = require('./function/arithmetic/round.js');
|
||||
exports.sign = require('./function/arithmetic/sign.js');
|
||||
exports.smaller = require('./function/arithmetic/smaller.js');
|
||||
exports.smallereq = require('./function/arithmetic/smallereq.js');
|
||||
exports.sqrt = require('./function/arithmetic/sqrt.js');
|
||||
exports.square = require('./function/arithmetic/square.js');
|
||||
exports.subtract = require('./function/arithmetic/subtract.js');
|
||||
exports.unary = require('./function/arithmetic/unary.js');
|
||||
exports.unequal = require('./function/arithmetic/unequal.js');
|
||||
exports.xgcd = require('./function/arithmetic/xgcd.js');
|
||||
|
||||
// functions - complex
|
||||
exports.arg = require('./function/complex/arg.js');
|
||||
exports.conj = require('./function/complex/conj.js');
|
||||
exports.re = require('./function/complex/re.js');
|
||||
exports.im = require('./function/complex/im.js');
|
||||
|
||||
// functions - construction
|
||||
exports.boolean = require('./function/construction/boolean.js');
|
||||
exports.complex = require('./function/construction/complex.js');
|
||||
exports.matrix = require('./function/construction/matrix.js');
|
||||
exports.number = require('./function/construction/number.js');
|
||||
exports.range = require('./function/construction/range.js');
|
||||
exports.string = require('./function/construction/string.js');
|
||||
exports.unit = require('./function/construction/unit.js');
|
||||
|
||||
// functions - matrix
|
||||
exports.concat = require('./function/matrix/concat.js');
|
||||
exports.det = require('./function/matrix/det.js');
|
||||
exports.diag = require('./function/matrix/diag.js');
|
||||
exports.eye = require('./function/matrix/eye.js');
|
||||
exports.inv = require('./function/matrix/inv.js');
|
||||
exports.ones = require('./function/matrix/ones.js');
|
||||
exports.size = require('./function/matrix/size.js');
|
||||
exports.squeeze = require('./function/matrix/squeeze.js');
|
||||
exports.subset = require('./function/matrix/subset.js');
|
||||
exports.transpose = require('./function/matrix/transpose.js');
|
||||
exports.zeros = require('./function/matrix/zeros.js');
|
||||
|
||||
// functions - probability
|
||||
exports.factorial = require('./function/probability/factorial.js');
|
||||
exports.random = require('./function/probability/random.js');
|
||||
exports.randomInt = require('./function/probability/randomInt.js');
|
||||
|
||||
// functions - statistics
|
||||
exports.min = require('./function/statistics/min.js');
|
||||
exports.max = require('./function/statistics/max.js');
|
||||
|
||||
// functions - trigonometry
|
||||
exports.acos = require('./function/trigonometry/acos.js');
|
||||
exports.asin = require('./function/trigonometry/asin.js');
|
||||
exports.atan = require('./function/trigonometry/atan.js');
|
||||
exports.atan2 = require('./function/trigonometry/atan2.js');
|
||||
exports.cos = require('./function/trigonometry/cos.js');
|
||||
exports.cot = require('./function/trigonometry/cot.js');
|
||||
exports.csc = require('./function/trigonometry/csc.js');
|
||||
exports.sec = require('./function/trigonometry/sec.js');
|
||||
exports.sin = require('./function/trigonometry/sin.js');
|
||||
exports.tan = require('./function/trigonometry/tan.js');
|
||||
|
||||
// functions - units
|
||||
exports['in'] = require('./function/units/in.js');
|
||||
|
||||
// functions - utils
|
||||
exports.clone = require('./function/utils/clone.js');
|
||||
exports['eval'] = require('./function/utils/eval.js');
|
||||
exports.format = require('./function/utils/format.js');
|
||||
exports.help = require('./function/utils/help.js');
|
||||
exports['import'] = require('./function/utils/import.js');
|
||||
exports['typeof'] = require('./function/utils/typeof.js');
|
||||
@ -11,7 +11,7 @@ if (typeof exports !== 'undefined') {
|
||||
/**
|
||||
* AMD module exports
|
||||
*/
|
||||
if (typeof(require) != 'undefined' && typeof(define) != 'undefined') {
|
||||
if (typeof(require) !== 'undefined' && typeof(define) !== 'undefined') {
|
||||
define(function () {
|
||||
return math;
|
||||
});
|
||||
@ -20,9 +20,9 @@ if (typeof(require) != 'undefined' && typeof(define) != 'undefined') {
|
||||
/**
|
||||
* Browser exports
|
||||
*/
|
||||
if (typeof(window) != 'undefined') {
|
||||
if (typeof(window) !== 'undefined') {
|
||||
if (window['math']) {
|
||||
util.deepExtend(window['math'], math);
|
||||
object.deepExtend(window['math'], math);
|
||||
}
|
||||
else {
|
||||
window['math'] = math;
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
var math = require('../math.js'),
|
||||
Scope = require('./Scope.js');
|
||||
|
||||
/**
|
||||
* @constructor math.expr.Parser
|
||||
* @constructor Parser
|
||||
* Parser contains methods to evaluate or parse expressions, and has a number
|
||||
* of convenience methods to get, set, and remove variables from memory. Parser
|
||||
* keeps a scope containing variables in memory, which is used for all
|
||||
@ -19,7 +21,7 @@
|
||||
* var result = node.eval(); // evaluate a parsed node
|
||||
*
|
||||
* Example usage:
|
||||
* var parser = new math.expr.Parser();
|
||||
* var parser = new Parser();
|
||||
* // Note: there is a convenience method which can be used instead:
|
||||
* // var parser = new math.parser();
|
||||
*
|
||||
@ -49,14 +51,14 @@
|
||||
* // clear defined functions and variables
|
||||
* parser.clear();
|
||||
*/
|
||||
math.expr.Parser = function Parser() {
|
||||
if (!(this instanceof math.expr.Parser)) {
|
||||
function Parser() {
|
||||
if (!(this instanceof Parser)) {
|
||||
throw new SyntaxError(
|
||||
'Parser constructor must be called with the new operator');
|
||||
}
|
||||
|
||||
this.scope = new math.expr.Scope();
|
||||
};
|
||||
this.scope = new Scope();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse an expression end return the parsed function node.
|
||||
@ -65,7 +67,7 @@ math.expr.Parser = function Parser() {
|
||||
* @return {Node} node
|
||||
* @throws {Error}
|
||||
*/
|
||||
math.expr.Parser.prototype.parse = function (expr) {
|
||||
Parser.prototype.parse = function (expr) {
|
||||
return math.parse(expr, this.scope);
|
||||
};
|
||||
|
||||
@ -75,7 +77,7 @@ math.expr.Parser.prototype.parse = function (expr) {
|
||||
* @return {*} result The result, or undefined when the expression was empty
|
||||
* @throws {Error}
|
||||
*/
|
||||
math.expr.Parser.prototype.eval = function (expr) {
|
||||
Parser.prototype.eval = function (expr) {
|
||||
var node = math.parse(expr, this.scope);
|
||||
return node.eval();
|
||||
};
|
||||
@ -86,7 +88,7 @@ math.expr.Parser.prototype.eval = function (expr) {
|
||||
* @param {String} name
|
||||
* @return {* | undefined} value
|
||||
*/
|
||||
math.expr.Parser.prototype.get = function (name) {
|
||||
Parser.prototype.get = function (name) {
|
||||
return this.scope.get(name);
|
||||
};
|
||||
|
||||
@ -95,7 +97,7 @@ math.expr.Parser.prototype.get = function (name) {
|
||||
* @param {String} name
|
||||
* @param {* | undefined} value
|
||||
*/
|
||||
math.expr.Parser.prototype.set = function (name, value) {
|
||||
Parser.prototype.set = function (name, value) {
|
||||
this.scope.set(name, value);
|
||||
};
|
||||
|
||||
@ -103,13 +105,15 @@ math.expr.Parser.prototype.set = function (name, value) {
|
||||
* Remove a variable from the parsers scope
|
||||
* @param {String} name
|
||||
*/
|
||||
math.expr.Parser.prototype.remove = function (name) {
|
||||
Parser.prototype.remove = function (name) {
|
||||
this.scope.remove(name);
|
||||
};
|
||||
|
||||
/**
|
||||
* Clear the scope with variables and functions
|
||||
*/
|
||||
math.expr.Parser.prototype.clear = function () {
|
||||
Parser.prototype.clear = function () {
|
||||
this.scope.clear();
|
||||
};
|
||||
|
||||
module.exports = Parser;
|
||||
|
||||
@ -1,30 +1,32 @@
|
||||
var math = require('../math.js'),
|
||||
Unit = require('../type/Unit.js');
|
||||
|
||||
/**
|
||||
* Scope
|
||||
* A scope stores values of symbols: variables and functions.
|
||||
*
|
||||
* Syntax:
|
||||
* var scope = new math.expr.Scope();
|
||||
* var scope = new math.expr.Scope(parentScope);
|
||||
* var scope = new math.expr.Scope(symbols);
|
||||
* var scope = new math.expr.Scope(parentScope, symbols);
|
||||
* var scope = new Scope();
|
||||
* var scope = new Scope(parentScope);
|
||||
* var scope = new Scope(symbols);
|
||||
* var scope = new Scope(parentScope, symbols);
|
||||
*
|
||||
* Where:
|
||||
* {math.expr.Scope} parentScope Scope will be linked to a parent scope,
|
||||
* {Scope} parentScope Scope will be linked to a parent scope,
|
||||
* which is traversed when resolving
|
||||
* symbols.
|
||||
* {Object} symbols A custom object that will be used to
|
||||
* resolve and store variables.
|
||||
*
|
||||
* @constructor math.expr.Scope
|
||||
* @constructor Scope
|
||||
* @param {...} [args]
|
||||
*/
|
||||
math.expr.Scope = function Scope(args) {
|
||||
/** @type {math.expr.Scope} */
|
||||
function Scope(args) {
|
||||
/** @type {Scope} */
|
||||
this.parentScope = null;
|
||||
// TODO: rename parentScope to previousScope, add a nextScope, change Scope to a linked list node
|
||||
|
||||
/** @type {math.expr.Scope[]} */
|
||||
/** @type {Scope[]} */
|
||||
this.subScopes = null;
|
||||
// TODO: rename subScopes to childScopes (or childNodes?)
|
||||
|
||||
@ -38,7 +40,7 @@ math.expr.Scope = function Scope(args) {
|
||||
// read first argument (can be parentScope or symbols map)
|
||||
if (arguments.length > 0) {
|
||||
var arg0 = arguments[0];
|
||||
if (arg0 instanceof math.expr.Scope) {
|
||||
if (arg0 instanceof Scope) {
|
||||
this.parentScope = arg0;
|
||||
}
|
||||
else if (arg0 instanceof Object) {
|
||||
@ -53,16 +55,16 @@ math.expr.Scope = function Scope(args) {
|
||||
this.symbols = arg1;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
math.expr.Scope.prototype = {
|
||||
Scope.prototype = {
|
||||
/**
|
||||
* Create a sub scope
|
||||
* The variables in a sub scope are not accessible from the parent scope
|
||||
* @return {math.expr.Scope} subScope
|
||||
* @return {Scope} subScope
|
||||
*/
|
||||
createSubScope: function () {
|
||||
var subScope = new math.expr.Scope(this);
|
||||
var subScope = new Scope(this);
|
||||
if (!this.subScopes) {
|
||||
this.subScopes = [];
|
||||
}
|
||||
@ -177,3 +179,5 @@ math.expr.Scope.prototype = {
|
||||
this.cache = {};
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Scope;
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
var math = require('../math.js'),
|
||||
util = require('../util/index.js'),
|
||||
string = util.string;
|
||||
|
||||
/**
|
||||
* @constructor math.type.Selector
|
||||
* @constructor Selector
|
||||
* Wrap any value in a Selector, allowing to perform chained operations on
|
||||
* the value.
|
||||
*
|
||||
@ -20,21 +24,21 @@
|
||||
*
|
||||
* @param {*} [value]
|
||||
*/
|
||||
math.type.Selector = function Selector (value) {
|
||||
if (!(this instanceof math.type.Selector)) {
|
||||
function Selector (value) {
|
||||
if (!(this instanceof Selector)) {
|
||||
throw new SyntaxError(
|
||||
'Selector constructor must be called with the new operator');
|
||||
}
|
||||
|
||||
if (value instanceof math.type.Selector) {
|
||||
if (value instanceof Selector) {
|
||||
this.value = value.value;
|
||||
}
|
||||
else {
|
||||
this.value = value;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
math.type.Selector.prototype = {
|
||||
Selector.prototype = {
|
||||
/**
|
||||
* Close the selector. Returns the final value.
|
||||
* Does the same as method valueOf()
|
||||
@ -54,7 +58,7 @@ math.type.Selector.prototype = {
|
||||
throw Error('Selector value is undefined');
|
||||
}
|
||||
|
||||
return new math.type.Selector(math.subset(value, index));
|
||||
return new Selector(math.subset(value, index));
|
||||
},
|
||||
|
||||
/**
|
||||
@ -67,7 +71,7 @@ math.type.Selector.prototype = {
|
||||
throw Error('Selector value is undefined');
|
||||
}
|
||||
|
||||
return new math.type.Selector(math.subset(value, index, replacement));
|
||||
return new Selector(math.subset(value, index, replacement));
|
||||
},
|
||||
|
||||
/**
|
||||
@ -84,7 +88,7 @@ math.type.Selector.prototype = {
|
||||
* @returns {String}
|
||||
*/
|
||||
toString: function () {
|
||||
return math.format(this.value);
|
||||
return string.format(this.value);
|
||||
}
|
||||
};
|
||||
|
||||
@ -93,8 +97,7 @@ math.type.Selector.prototype = {
|
||||
* @param {String} name
|
||||
* @param {*} value The value or function to be proxied
|
||||
*/
|
||||
function createSelectorProxy(name, value) {
|
||||
var Selector = math.type.Selector;
|
||||
function createProxy(name, value) {
|
||||
var slice = Array.prototype.slice;
|
||||
if (typeof value === 'function') {
|
||||
// a function
|
||||
@ -108,3 +111,24 @@ function createSelectorProxy(name, value) {
|
||||
Selector.prototype[name] = new Selector(value);
|
||||
}
|
||||
}
|
||||
|
||||
Selector.createProxy = createProxy;
|
||||
|
||||
/**
|
||||
* initialise the Chain prototype with all functions and constants in math
|
||||
*/
|
||||
Selector.init = function init () {
|
||||
Selector.init = null; // delete, we are initialized
|
||||
|
||||
for (var prop in math) {
|
||||
if (math.hasOwnProperty(prop) && prop) {
|
||||
createProxy(prop, math[prop]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// exports
|
||||
module.exports = Selector;
|
||||
exports.init = Selector.init;
|
||||
|
||||
util.types.addType('selector', Selector);
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user