From 4d0a679c87187d673e1789dbdc7f2c7c5dda9ac6 Mon Sep 17 00:00:00 2001 From: josdejong Date: Sun, 30 Mar 2014 21:19:54 +0200 Subject: [PATCH 01/48] Bumped version number to 0.20.0-SNAPSHOT --- bower.json | 2 +- misc/how_to_publish.md | 5 ++++- package.json | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/bower.json b/bower.json index 4a9f98acf..b5ec1006a 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "mathjs", - "version": "0.19.0", + "version": "0.20.0-SNAPSHOT", "main": "./dist/math.js", "ignore": [ "coverage", diff --git a/misc/how_to_publish.md b/misc/how_to_publish.md index 30637201b..301b0280d 100644 --- a/misc/how_to_publish.md +++ b/misc/how_to_publish.md @@ -73,8 +73,11 @@ select the new version and press the button. Publish at cdnjs: +*Auto update should be enabled since v0.19.0, if so, no need to publish at cdnjs +manually.* + - clone the cdnjs project -- pull changes: `git pull upstream` +- pull changes: `git pull upstream master` - add the new version of the library under /ajax/libs/mathjs/ - add new folder /x.y.z/ with the new library - update the version number in package.json diff --git a/package.json b/package.json index 4a2863f15..9c8cfd813 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mathjs", - "version": "0.19.0", + "version": "0.20.0-SNAPSHOT", "description": "Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser and offers an integrated solution to work with numbers, big numbers, complex numbers, units, and matrices.", "author": "Jos de Jong (https://github.com/josdejong)", "contributors": [ From 9f7dbbbc171b6411867ff0979370e190106bf59a Mon Sep 17 00:00:00 2001 From: josdejong Date: Mon, 31 Mar 2014 20:38:53 +0200 Subject: [PATCH 02/48] Updated contributors --- HISTORY.md | 27 ++++++++++++++------------- package.json | 10 ++++++++-- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 7ffaaba8c..958dc1eec 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -5,6 +5,7 @@ https://github.com/josdejong/mathjs ## 2014-03-30, version 0.19.0 - Implemented functions `compare`, `sum`, `prod`, `var`, `std`, `median`. +- Implemented function `ifElse` (thanks @mtraynham). - Minor bug fixes. @@ -12,7 +13,7 @@ https://github.com/josdejong/mathjs - Added unit `feet`. - Implemented function `compile` (shortcut for parsing and then compiling). -- Improved performance of function `pow` for matrices. Thanks hamadu. +- Improved performance of function `pow` for matrices. Thanks @hamadu. - Fixed broken auto completion in the command line interface. - Fixed an error in function `combinations` for large numbers, and improved performance of both functions `combinations` and `permutations`. @@ -28,12 +29,12 @@ https://github.com/josdejong/mathjs compiled into JavaScript, giving much better performance (easily 10x as fast). - Renamed unit conversion function and operator `in` to `to`. Operator `in` is still available in the expression parser as an alias for `to`. Added unit - `in`, an abbreviation for `inch`. Thanks Elijah Insua (tmpvar). + `in`, an abbreviation for `inch`. Thanks Elijah Insua (@tmpvar). - Added plurals and aliases for units. - Implemented an argument `includeEnd` for function `range` (false by default). - Ranges in the expression parser now support big numbers. - Implemented functions `permutations` and `combinations`. - Thanks Daniel Levin (daniel-levin). + Thanks Daniel Levin (@daniel-levin). - Added lower case abbreviation `l` for unit litre. @@ -105,11 +106,11 @@ https://github.com/josdejong/mathjs use `math.format(value [, precision])` instead. - Fixed formatting numbers as scientific notation in some cases returning a zero digit left from the decimal point. (like "0.33333e8" rather than - "3.3333e7"). Thanks husayt. + "3.3333e7"). Thanks @husayt. - Implemented a function `print` to interpolate values in a template string, this functionality was moved from the function `format`. - Implemented statistics function `mean`. Thanks Guillermo Indalecio Fernandez - (guillermobox). + (@guillermobox). - Extended and changed `max` and `min` for multi dimensional matrices: they now return the maximum and minimum of the flattened array. An optional second argument `dim` allows to calculate the `max` or `min` for specified dimension. @@ -139,7 +140,7 @@ https://github.com/josdejong/mathjs ## 2013-09-03, version 0.13.0 - Implemented support for booleans in all relevant functions. -- Implemented functions `map` and `forEach`. Thanks Sebastien Piquemal (sebpic). +- Implemented functions `map` and `forEach`. Thanks Sebastien Piquemal (@sebpic). - All construction functions can be used to convert the type of variables, also element-wise for all elements in an Array or Matrix. - Changed matrix indexes of the expression parser to one-based with the @@ -168,7 +169,7 @@ https://github.com/josdejong/mathjs ## 2013-08-22, version 0.12.0 - Implemented functions `random([min, max])`, `randomInt([min, max])`, - `pickRandom(array)`. Thanks Sebastien Piquemal (sebpic). + `pickRandom(array)`. Thanks Sebastien Piquemal (@sebpic). - Implemented function `distribution(name)`, generating a distribution object with functions `random`, `randomInt`, `pickRandom` for different distributions. Currently supporting `uniform` and `normal`. @@ -186,7 +187,7 @@ https://github.com/josdejong/mathjs for example `A[0, 0:3]`. - Removed the feature introduced in v0.10.0 to automatically convert a complex value with an imaginary part equal to zero to a number. -- Fixed zeros being formatted as null. Thanks TimKraft. +- Fixed zeros being formatted as null. Thanks @TimKraft. ## 2013-07-23, version 0.11.1 @@ -203,7 +204,7 @@ https://github.com/josdejong/mathjs - Added constants `true` and `false`. - Added constructor function `boolean`. - Fixed function `select` not accepting `0` as input. - Thanks Elijah Manor (elijahmanor). + Thanks Elijah Manor (@elijahmanor). - Parser now supports multiple unary minus operators after each other. - Fixed not accepting empty matrices like `[[], []]`. - Some fixes in the end user documentation. @@ -219,7 +220,7 @@ https://github.com/josdejong/mathjs - Implemented end user documentation and a new `help` function. - Functions `size` and `squeeze` now return a Matrix instead of an Array as output on Matrix input. -- Added a constant tau (2 * pi). Thanks Zak Zibrat (palimpsests). +- Added a constant tau (2 * pi). Thanks Zak Zibrat (@palimpsests). - Renamed function `unaryminus` to `unary`. - Fixed a bug in determining node dependencies in function assignments. @@ -246,7 +247,7 @@ https://github.com/josdejong/mathjs or other data types. - Implemented construction functions number and string (mainly useful inside the parser). -- Improved function `det`. Thanks Bryan Cuccioli (bcuccioli). +- Improved function `det`. Thanks Bryan Cuccioli (@bcuccioli). - Moved the parse code from prototype math.expr.Parser to function math.parse, simplified Parser a little bit. - Strongly simplified the code of Scope and Workspace. @@ -286,7 +287,7 @@ https://github.com/josdejong/mathjs ## 2013-05-04, version 0.7.2 - Fixed method unequal, which was checking for equality instead of inequality. - Thanks FJS2. + Thanks @FJS2. ## 2013-04-27, version 0.7.1 @@ -310,7 +311,7 @@ https://github.com/josdejong/mathjs - Implemented method `math.eval`, which uses a readonly parser to evaluate expressions. - Implemented method `xgcd` (extended eucledian algorithm). Thanks Bart Kiers - (bkiers). + (@bkiers). - Improved math.format, which now rounds values to a maximum number of digits instead of decimals (default is 5 digits, for example `math.format(math.pi)` returns `3.1416`). diff --git a/package.json b/package.json index 9c8cfd813..d34f2d3a6 100644 --- a/package.json +++ b/package.json @@ -7,12 +7,18 @@ "Sebastien Piquemal (https://github.com/sebpiq)", "Guillermo Indalecio Fernández (https://github.com/guillermobox)", "Huseyn Guliyev (https://github.com/husayt)", + "Daniel Levin (https://github.com/daniel-levin)", + "Fabrice Colas (https://github.com/fcolas6013)", + "Marcus Andre (https://github.com/marcusandre)", "Jim Garrison (https://github.com/garrison)", "Bart Kiers (https://github.com/bkiers)", - "Zak Zibrat (https://github.com/palimpsests)", "Bryan Cuccioli (https://github.com/bcuccioli)", + "Finn Pauls (https://github.com/finnp)", + "hamadu (https://github.com/hamadu)", + "Waldir Pimenta (https://github.com/waldir)", + "mtraynham (https://github.com/mtraynham)", "Elijah Insua (https://github.com/tmpvar)", - "Daniel Levin (https://github.com/daniel-levin)" + "Zach Zibrat (https://github.com/palimpsests)" ], "homepage": "http://mathjs.org", "repository": { From c74afb7dcbbd6e050d7e108a5456421015772dcb Mon Sep 17 00:00:00 2001 From: josdejong Date: Mon, 31 Mar 2014 21:24:46 +0200 Subject: [PATCH 03/48] Improved function `ifElse` --- HISTORY.md | 5 + lib/expression/docs/function/utils/ifElse.js | 8 +- lib/function/utils/ifElse.js | 118 +++++++++++++++++-- test/function/utils/ifElse.test.js | 102 ++++++++++------ 4 files changed, 189 insertions(+), 44 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 958dc1eec..c1d4d1a68 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,6 +2,11 @@ https://github.com/josdejong/mathjs +## not yet released, version 0.19.1 + +- Improved function `ifElse`, is now specified for special data types too. + + ## 2014-03-30, version 0.19.0 - Implemented functions `compare`, `sum`, `prod`, `var`, `std`, `median`. diff --git a/lib/expression/docs/function/utils/ifElse.js b/lib/expression/docs/function/utils/ifElse.js index fc584476f..53f09faf1 100644 --- a/lib/expression/docs/function/utils/ifElse.js +++ b/lib/expression/docs/function/utils/ifElse.js @@ -2,11 +2,13 @@ module.exports = { 'name': 'ifElse', 'category': 'Utils', 'syntax': [ - 'ifElse(conditionalExpr, trueExpr, falseExpr)' + 'ifElse(conditional, trueExpr, falseExpr)' ], - 'description': 'Executes a ternary operation.', + 'description': 'Executes a conditional operation.', 'examples': [ - 'ifElse(10 > 0, 10, 0)' + 'ifElse(10 > 0, 10, 0)', + 'ifElse("", true, false)', + 'ifElse([4, 6, 0, -1], true, false)' ], 'seealso': [] }; diff --git a/lib/function/utils/ifElse.js b/lib/function/utils/ifElse.js index 04bb969f7..0ed7fdcba 100644 --- a/lib/function/utils/ifElse.js +++ b/lib/function/utils/ifElse.js @@ -1,17 +1,121 @@ module.exports = function (math) { + var util = require('../../util/index'), + + BigNumber = require('bignumber.js'), + Matrix = require('../../type/Matrix'), + Complex = require('../../type/Complex'), + Unit = require('../../type/Unit'), + collection = require('../../type/collection'), + + deepEqual = util.object.deepEqual, + isNumber = util.number.isNumber, + isString = util.string.isString, + isBoolean = util['boolean'].isBoolean, + isComplex = Complex.isComplex, + isUnit = Unit.isUnit, + isCollection = collection.isCollection; /** - * Executes a ternary operation - * @param {*} conditionalExpr The conditional expression - * @param {*} trueExpr The true expression - * @param {*} falseExpr The false expression - * @return {*} The evaluated return expression + * Execute a conditional operation. + * + * In case of a matrix or array, the test is done element wise, the + * true and false part can be either a matrix/array with the same size + * of the condition, or a scalar value. + * + * @param {Number | Boolean | String | Complex | BigNumber | Unit | Matrix | Array} condition + * The conditional expression + * @param {*} trueExpr The true expression + * @param {*} falseExpr The false expression + * @return {*} The evaluated return expression */ - math.ifElse = function ifElse(conditionalExpr, trueExpr, falseExpr) { + math.ifElse = function ifElse(condition, trueExpr, falseExpr) { if (arguments.length != 3) { throw new math.error.ArgumentsError('ifElse', arguments.length, 3); } - return conditionalExpr ? trueExpr : falseExpr; + if (isNumber(condition) || isBoolean(condition)) { + return condition ? trueExpr : falseExpr; + } + + if (condition instanceof BigNumber) { + return condition.isZero() ? falseExpr : trueExpr; + } + + if (isString(condition)) { + return condition ? trueExpr : falseExpr; + } + + if (isComplex(condition)) { + return (condition.re || condition.im) ? trueExpr : falseExpr; + } + + if (isUnit(condition)) { + return condition.value ? trueExpr : falseExpr; + } + + if (condition === null || condition === undefined) { + return falseExpr; + } + + if (isCollection(condition)) { + return _ifElseCollection(condition, trueExpr, falseExpr); + } + + throw new math.error.UnsupportedTypeError('ifElse', condition); }; + + /** + * Execute the if-else condition element wise + * @param {Matrix | Array} condition + * @param {*} trueExpr + * @param {*} falseExpr + * @returns {*} + * @private + */ + function _ifElseCollection(condition, trueExpr, falseExpr) { + var asMatrix = (condition instanceof Matrix) || + (trueExpr instanceof Matrix) || + (falseExpr instanceof Matrix); + + // change an array into a matrix + if (!(condition instanceof Matrix)) condition = new Matrix(condition); + + // change the true expression into a matrix and check whether the size + // matches with the condition matrix + if (isCollection(trueExpr)) { + if (!(trueExpr instanceof Matrix)) trueExpr = new Matrix(trueExpr); + + if (!deepEqual(condition.size(), trueExpr.size())) { + throw new RangeError('Dimensions mismatch ([' + + condition.size().join(', ') + '] != [' + + trueExpr.size().join(', ') + + '])'); + } + } + + // change the false expression into a matrix and check whether the size + // matches with the condition matrix + if (isCollection(falseExpr)) { + if (!(falseExpr instanceof Matrix)) falseExpr = new Matrix(falseExpr); + + if (!deepEqual(condition.size(), falseExpr.size())) { + throw new RangeError('Dimensions mismatch ([' + + condition.size().join(', ') + '] != [' + + falseExpr.size().join(', ') + + '])'); + } + } + + // do the actual conditional test element wise + var trueIsMatrix = trueExpr instanceof Matrix, + falseIsMatrix = falseExpr instanceof Matrix; + var result = condition.map(function (value, index) { + return math.ifElse(value, + trueIsMatrix ? trueExpr.get(index) : trueExpr, + falseIsMatrix ? falseExpr.get(index) : falseExpr + ); + }); + + return asMatrix ? result : result.valueOf(); + } }; diff --git a/test/function/utils/ifElse.test.js b/test/function/utils/ifElse.test.js index 0f553fd1d..10f1cc2f0 100644 --- a/test/function/utils/ifElse.test.js +++ b/test/function/utils/ifElse.test.js @@ -1,47 +1,81 @@ // test format var assert = require('assert'), - math = require('../../../index')(); + math = require('../../../index')(), + ifElse = math.ifElse; describe('ifElse', function() { - it('should evaluate to true', function() { - assert.equal(math.ifElse(true, 1, 0), 1); - assert.equal(math.ifElse(1, 1, 0), 1); - assert.equal(math.ifElse({}, 1, 0), 1); - assert.equal(math.ifElse(1 > 0, 1, 0), 1); - assert.equal(math.ifElse('foo' == 'foo', 1, 0), 1); - assert.equal(math.ifElse(10 == 10, 1, 0), 1); - assert.equal(math.ifElse(5 == 2 + 3, 1, 0), 1); - assert.equal(math.ifElse(true, 'foo', 'bar'), 'foo'); - assert.equal(math.ifElse(1, 'foo', 'bar'), 'foo'); - assert.equal(math.ifElse({}, 'foo', 'bar'), 'foo'); - assert.equal(math.ifElse(1 > 0, 'foo', 'bar'), 'foo'); - assert.equal(math.ifElse('foo' == 'foo', 'foo', 'bar'), 'foo'); - assert.equal(math.ifElse(10 == 10, 'foo', 'bar'), 'foo'); - assert.equal(math.ifElse(5 == 2 + 3, 'foo', 'bar'), 'foo'); + it('should evaluate boolean conditions', function() { + assert.equal(ifElse(true, 1, 0), 1); + assert.equal(ifElse(false, 1, 0), 0); }); - it('should evaluate to false', function() { - assert.equal(math.ifElse(false, 1, 0), 0); - assert.equal(math.ifElse(0, 1, 0), 0); - assert.equal(math.ifElse(null, 1, 0), 0); - assert.equal(math.ifElse(0 > 1, 1, 0), 0); - assert.equal(math.ifElse('foo' != 'foo', 1, 0), 0); - assert.equal(math.ifElse(10 != 10, 1, 0), 0); - assert.equal(math.ifElse(5 != 2 + 3, 1, 0), 0); - assert.equal(math.ifElse(false, 'foo', 'bar'), 'bar'); - assert.equal(math.ifElse(0, 'foo', 'bar'), 'bar'); - assert.equal(math.ifElse(null, 'foo', 'bar'), 'bar'); - assert.equal(math.ifElse(0 > 1, 'foo', 'bar'), 'bar'); - assert.equal(math.ifElse('foo' != 'foo', 'foo', 'bar'), 'bar'); - assert.equal(math.ifElse(10 != 10, 'foo', 'bar'), 'bar'); - assert.equal(math.ifElse(5 != 2 + 3, 'foo', 'bar'), 'bar'); + it('should evaluate number conditions', function() { + assert.equal(ifElse(1, 1, 0), 1); + assert.equal(ifElse(4, 1, 0), 1); + assert.equal(ifElse(-1, 1, 0), 1); + assert.equal(ifElse(0, 1, 0), 0); + }); + + it('should evaluate bignumber conditions', function() { + assert.equal(ifElse(math.bignumber(1), 1, 0), 1); + assert.equal(ifElse(math.bignumber(4), 1, 0), 1); + assert.equal(ifElse(math.bignumber(-1), 1, 0), 1); + assert.equal(ifElse(math.bignumber(0), 1, 0), 0); + }); + + it('should evaluate string conditions', function() { + assert.equal(ifElse('hello', 1, 0), 1); + assert.equal(ifElse('', 1, 0), 0); + }); + + it('should evaluate unit conditions', function() { + assert.equal(ifElse(math.unit('5cm'), 1, 0), 1); + assert.equal(ifElse(math.unit('0 inch'), 1, 0), 0); + }); + + it('should evaluate null conditions', function() { + assert.equal(ifElse(null, 1, 0), 0); + }); + + it('should evaluate undefined conditions', function() { + assert.equal(ifElse(undefined, 1, 0), 0); + }); + + it('should evaluate array conditions', function() { + assert.deepEqual(ifElse([1, 0, 1], 1, 0), [1, 0, 1]); + assert.deepEqual(ifElse([[1, 0], [0, 0]], 1, 0), [[1, 0], [0, 0]]); + + assert.deepEqual(ifElse([[1, 1], [1, 1]], [[1,2],[3,4]], [[5,6],[7,8]]), [[1,2],[3,4]]); + assert.deepEqual(ifElse([[1, 0], [0, 1]], 123, [[5,6],[7,8]]), [[123,6],[7,123]]); + assert.deepEqual(ifElse([[1, 0], [0, 1]], [[1,2],[3,4]], 123), [[1,123],[123,4]]); + assert.deepEqual(ifElse([[0, 0], [0, 0]], [[1,2],[3,4]], [[5,6],[7,8]]), [[5,6],[7,8]]); + }); + + it('should evaluate matrix conditions', function() { + assert.deepEqual(ifElse(math.matrix([1, 0, 1]), 1, 0), math.matrix([1, 0, 1])); + assert.deepEqual(ifElse(math.matrix([[1, 0], [0, 0]]), 1, 0), + math.matrix([[1, 0], [0, 0]])); + + assert.deepEqual(ifElse(math.matrix([[1, 1], [1, 1]]), math.matrix([[1,2],[3,4]]), math.matrix([[5,6],[7,8]])), + math.matrix([[1,2],[3,4]])); + assert.deepEqual(ifElse(math.matrix([[1, 0], [0, 1]]), 123, [[5,6],[7,8]]), + math.matrix([[123,6],[7,123]])); + assert.deepEqual(ifElse(math.matrix([[1, 0], [0, 1]]), math.matrix([[1,2],[3,4]]), 123), + math.matrix([[1,123],[123,4]])); + assert.deepEqual(ifElse(math.matrix([[0, 0], [0, 0]]), math.matrix([[1,2],[3,4]]), math.matrix([[5,6],[7,8]])), + math.matrix([[5,6],[7,8]])); }); it('should throw an error if called with invalid number of arguments', function() { - assert.throws(function() { math.ifElse(true); }); - assert.throws(function() { math.ifElse(true, true); }); - assert.throws(function() { math.ifElse(true, true, true, true); }); + assert.throws(function() { ifElse(true); }); + assert.throws(function() { ifElse(true, true); }); + assert.throws(function() { ifElse(true, true, true, true); }); + }); + + it('should throw an error if called with invalid type of arguments', function() { + assert.throws(function() { ifElse(new Date()); }); + assert.throws(function() { ifElse(/regexp/); }); }); }); From b3ab923a69388697e6d19fe9d395637e17555dc3 Mon Sep 17 00:00:00 2001 From: josdejong Date: Tue, 1 Apr 2014 20:49:55 +0200 Subject: [PATCH 04/48] Implemented conditional operator `a ? b : c` in expression parser --- HISTORY.md | 1 + docs/expressions.md | 60 +++++------ docs/functions.md | 2 +- lib/expression/docs/function/utils/ifElse.js | 2 +- lib/expression/node/IndexNode.js | 3 + lib/expression/node/TernaryNode.js | 38 +++++++ lib/expression/node/index.js | 1 + lib/expression/parse.js | 58 +++++++---- lib/function/utils/ifElse.js | 2 +- test/expression/node/TernaryNode.test.js | 100 +++++++++++++++++++ test/expression/node/index.test.js | 28 ++++++ test/expression/parse.test.js | 19 ++++ 12 files changed, 263 insertions(+), 51 deletions(-) create mode 100644 lib/expression/node/TernaryNode.js create mode 100644 test/expression/node/TernaryNode.test.js create mode 100644 test/expression/node/index.test.js diff --git a/HISTORY.md b/HISTORY.md index c1d4d1a68..5da5335ea 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -4,6 +4,7 @@ https://github.com/josdejong/mathjs ## not yet released, version 0.19.1 +- Implemented conditional operator `a ? b : c` in expression parser. - Improved function `ifElse`, is now specified for special data types too. diff --git a/docs/expressions.md b/docs/expressions.md index 4935bfb49..57eb6925a 100644 --- a/docs/expressions.md +++ b/docs/expressions.md @@ -268,35 +268,36 @@ math.eval('(2 + 3) * 4'); // 20 The following operators are available: -Operator | Name | Syntax | Associativity | Example | Result ------------ | --------------------- | --------- | ------------- | --------------------- | --------------- -`(`, `)` | Parentheses | `(x)` | None | `2 * (3 + 4)` | `14` -`[`, `]` | Matrix, Index | `[...]` | None | `[[1,2],[3,4]]` | `[[1,2],[3,4]]` -`,` | Parameter separator | `x, y` | None | `max(2, 1, 5)` | `5` -`;` | Statement separator | `x; y` | Left to right | `a=2; b=3; a*b` | `[6]` -`;` | Row separator | `[x, y]` | Left to right | `[1,2;3,4]` | `[[1,2],[3,4]]` -`\n` | Statement separator | `x \n y` | Left to right | `a=2 \n b=3 \n a*b` | `[2,3,6]` -`+` | Add | `x + y` | Left to right | `4 + 5` | `9` -`-` | Subtract | `x - y` | Left to right | `7 - 3` | `4` -`*` | Multiply | `x * y` | Left to right | `2 * 3` | `6` -`.*` | Element-wise multiply | `x .* y` | Left to right | `[1,2,3] .* [1,2,3]` | `[1,4,9]` -`/` | Divide | `x / y` | Left to right | `6 / 2` | `3` -`./` | Element-wise divide | `x ./ y` | Left to right | `[9,6,4] ./ [3,2,2]` | `[3,3,2]` -`%`, `mod` | Modulus | `x % y` | Left to right | `8 % 3` | `2` -`^` | Power | `x ^ y` | Right to left | `2 ^ 3` | `8` -`.^` | Element-wise power | `x .^ y` | Right to left | `[2,3] .^ [3,3]` | `[9,27]` -`-` | Unary | `-y` | None | `-4` | `-4` -`'` | Transpose | `y'` | None | `[[1,2],[3,4]]'` | `[[1,3],[2,4]]` -`!` | Factorial | `y!` | None | `5!` | `120` -`=` | Assignment | `x = y` | Right to left | `a = 5` | `5` -`:` | Range | `x : y` | None | `1:4` | `[1,2,3,4]` -`to`, `in` | Unit conversion | `x to y` | Left to right | `2 inch to cm` | `5.08 cm` -`==` | Equal | `x == y` | Left to right | `2 == 4 - 2` | `true` -`!=` | Unequal | `x != y` | Left to right | `2 != 3` | `true` -`<` | Smaller | `x < y` | Left to right | `2 < 3` | `true` -`>` | Larger | `x > y` | Left to right | `2 > 3` | `false` -`<=` | Smallereq | `x <= y` | Left to right | `4 <= 3` | `false` -`>=` | Largereq | `x >= y` | Left to right | `2 + 4 >= 6` | `true` +Operator | Name | Syntax | Associativity | Example | Result +----------- | ----------------------- | ---------- | ------------- | --------------------- | --------------- +`(`, `)` | Parentheses | `(x)` | None | `2 * (3 + 4)` | `14` +`[`, `]` | Matrix, Index | `[...]` | None | `[[1,2],[3,4]]` | `[[1,2],[3,4]]` +`,` | Parameter separator | `x, y` | None | `max(2, 1, 5)` | `5` +`;` | Statement separator | `x; y` | Left to right | `a=2; b=3; a*b` | `[6]` +`;` | Row separator | `[x, y]` | Left to right | `[1,2;3,4]` | `[[1,2],[3,4]]` +`\n` | Statement separator | `x \n y` | Left to right | `a=2 \n b=3 \n a*b` | `[2,3,6]` +`+` | Add | `x + y` | Left to right | `4 + 5` | `9` +`-` | Subtract | `x - y` | Left to right | `7 - 3` | `4` +`*` | Multiply | `x * y` | Left to right | `2 * 3` | `6` +`.*` | Element-wise multiply | `x .* y` | Left to right | `[1,2,3] .* [1,2,3]` | `[1,4,9]` +`/` | Divide | `x / y` | Left to right | `6 / 2` | `3` +`./` | Element-wise divide | `x ./ y` | Left to right | `[9,6,4] ./ [3,2,2]` | `[3,3,2]` +`%`, `mod` | Modulus | `x % y` | Left to right | `8 % 3` | `2` +`^` | Power | `x ^ y` | Right to left | `2 ^ 3` | `8` +`.^` | Element-wise power | `x .^ y` | Right to left | `[2,3] .^ [3,3]` | `[9,27]` +`-` | Unary | `-y` | None | `-4` | `-4` +`'` | Transpose | `y'` | None | `[[1,2],[3,4]]'` | `[[1,3],[2,4]]` +`!` | Factorial | `y!` | None | `5!` | `120` +`=` | Assignment | `x = y` | Right to left | `a = 5` | `5` +`?` `:` | Conditional expression | `x ? y : z` | Right to left | `15 > 100 ? 1 : -1` | `-1` +`:` | Range | `x : y` | None | `1:4` | `[1,2,3,4]` +`to`, `in` | Unit conversion | `x to y` | Left to right | `2 inch to cm` | `5.08 cm` +`==` | Equal | `x == y` | Left to right | `2 == 4 - 2` | `true` +`!=` | Unequal | `x != y` | Left to right | `2 != 3` | `true` +`<` | Smaller | `x < y` | Left to right | `2 < 3` | `true` +`>` | Larger | `x > y` | Left to right | `2 > 3` | `false` +`<=` | Smallereq | `x <= y` | Left to right | `4 <= 3` | `false` +`>=` | Largereq | `x >= y` | Left to right | `2 + 4 >= 6` | `true` The operators have the following precedence, from highest to lowest: @@ -313,6 +314,7 @@ Operators | Description `:` | Range `==`, `!=`, `<`, `>`, `<=`, `>=` | Comparison `to`, `in` | Unit conversion +`?`, `:` | Conditional expression `=` | Assignment `,` | Parameter and column separator `;` | Row separator diff --git a/docs/functions.md b/docs/functions.md index 52ff19bf2..eb6f3830a 100644 --- a/docs/functions.md +++ b/docs/functions.md @@ -143,7 +143,7 @@ math.add('hello ', 'world!'); // String 'hello world!' - math.clone(x) - math.forEach(x, callback) - math.format(value [, precision]) -- math.ifElse(conditionalExpr, trueExpr, falseExpr) +- math.ifElse(condition, trueExpr, falseExpr) - math.import(filename | object, override) - math.map(x, callback) - math.print(template, values [, precision]) diff --git a/lib/expression/docs/function/utils/ifElse.js b/lib/expression/docs/function/utils/ifElse.js index 53f09faf1..4b2c46228 100644 --- a/lib/expression/docs/function/utils/ifElse.js +++ b/lib/expression/docs/function/utils/ifElse.js @@ -4,7 +4,7 @@ module.exports = { 'syntax': [ 'ifElse(conditional, trueExpr, falseExpr)' ], - 'description': 'Executes a conditional operation.', + 'description': 'Executes a conditional expression.', 'examples': [ 'ifElse(10 > 0, 10, 0)', 'ifElse("", true, false)', diff --git a/lib/expression/node/IndexNode.js b/lib/expression/node/IndexNode.js index b55c91ee0..837c85f81 100644 --- a/lib/expression/node/IndexNode.js +++ b/lib/expression/node/IndexNode.js @@ -14,7 +14,10 @@ var number= require('../../util/number.js'), /** * @constructor IndexNode + * @extends Node + * * get a subset of a matrix + * * @param {Node} object * @param {Node[]} ranges */ diff --git a/lib/expression/node/TernaryNode.js b/lib/expression/node/TernaryNode.js new file mode 100644 index 000000000..4fdf9517a --- /dev/null +++ b/lib/expression/node/TernaryNode.js @@ -0,0 +1,38 @@ +var OperatorNode = require('./OperatorNode'); + +/** + * @constructor TernaryNode + * @extends {OperatorNode} + * + * A conditional expression + * + * condition ? truePart : falsePart + * + * @param {String[]} ops The operator symbols, for example ['?', ':'] + * @param {String} fn The function name, for example 'ifElse' + * @param {Node[]} params The operator parameters, should contain three parameters. + */ +function TernaryNode (ops, fn, params) { + if (!(this instanceof TernaryNode)) { + throw new SyntaxError('Constructor must be called with the new operator'); + } + + // TODO: validate input + this.ops = ops; + this.fn = fn; + this.params = params; +} + +TernaryNode.prototype = new OperatorNode(); + +/** + * Get string representation + * @return {String} str + */ +TernaryNode.prototype.toString = function() { + return this.params[0] + ' ' + this.ops[0] + ' ' + + this.params[1] + ' ' + this.ops[1] + ' ' + + this.params[2]; +}; + +module.exports = TernaryNode; diff --git a/lib/expression/node/index.js b/lib/expression/node/index.js index 3ac696fe3..a9fb9124b 100644 --- a/lib/expression/node/index.js +++ b/lib/expression/node/index.js @@ -9,5 +9,6 @@ exports.OperatorNode = require('./OperatorNode'); exports.ParamsNode = require('./ParamsNode'); exports.RangeNode = require('./RangeNode'); exports.SymbolNode = require('./SymbolNode'); +exports.TernaryNode = require('./TernaryNode'); exports.UnitNode = require('./UnitNode'); exports.UpdateNode = require('./UpdateNode'); diff --git a/lib/expression/parse.js b/lib/expression/parse.js index f50f45b32..dd0f37ec7 100644 --- a/lib/expression/parse.js +++ b/lib/expression/parse.js @@ -22,6 +22,7 @@ var util = require('../util/index'), ParamsNode = require('./node/ParamsNode'), RangeNode = require('./node/RangeNode'), SymbolNode = require('./node/SymbolNode'), + TernaryNode = require('./node/TernaryNode'), UnitNode = require('./node/UnitNode'), UpdateNode = require('./node/UpdateNode'); @@ -117,6 +118,7 @@ var DELIMITERS = { '\'': true, '=': true, ':': true, + '?': true, '==': true, '!=': true, @@ -576,7 +578,7 @@ function parseRange () { * @private */ function parseBitwiseConditions () { - var node = parseComparison(); + var node = parseIfElse(); /* TODO: implement bitwise conditions var operators = { @@ -598,6 +600,35 @@ function parseBitwiseConditions () { return node; } +/** + * conditional operation + * + * condition ? truePart : falsePart + * + * Note: conditional operator is right-associative + * + * @return {Node} node + * @private + */ +function parseIfElse () { + var node = parseComparison(); + + while (token == '?') { + getToken(); + var params = [node]; + params.push(parseComparison()); + + if (token != ':') throw createSyntaxError('False part of conditional expression expected'); + getToken(); + + params.push(parseIfElse()); + + node = new TernaryNode(['?', ':'], 'ifElse', params); + } + + return node; +} + /** * comparison operators * @return {Node} node @@ -770,27 +801,16 @@ function parseUnary () { * @private */ function parsePow () { - var node, leftNode, nodes, ops, name, fn, params; + var node, name, fn, params; - nodes = [ - parseLeftHandOperators() - ]; - ops = []; + node = parseLeftHandOperators(); - // stack all operands of a chained power operator (like '2^3^3') - while (token == '^' || token == '.^') { - ops.push(token); - getToken(); - nodes.push(parseLeftHandOperators()); - } - - // evaluate the operands from right to left (right associative) - node = nodes.pop(); - while (nodes.length) { - leftNode = nodes.pop(); - name = ops.pop(); + if (token == '^' || token == '.^') { + name = token; fn = (name == '^') ? 'pow' : 'epow'; - params = [leftNode, node]; + + getToken(); + params = [node, parsePow()]; node = new OperatorNode(name, fn, params); } diff --git a/lib/function/utils/ifElse.js b/lib/function/utils/ifElse.js index 0ed7fdcba..88a5ae3f1 100644 --- a/lib/function/utils/ifElse.js +++ b/lib/function/utils/ifElse.js @@ -16,7 +16,7 @@ module.exports = function (math) { isCollection = collection.isCollection; /** - * Execute a conditional operation. + * Execute a conditional expression. * * In case of a matrix or array, the test is done element wise, the * true and false part can be either a matrix/array with the same size diff --git a/test/expression/node/TernaryNode.test.js b/test/expression/node/TernaryNode.test.js new file mode 100644 index 000000000..675ac8f23 --- /dev/null +++ b/test/expression/node/TernaryNode.test.js @@ -0,0 +1,100 @@ +// test IfElseNode +var assert = require('assert'), + approx = require('../../../tools/approx'), + math = require('../../../index')(), + Node = require('../../../lib/expression/node/Node'), + ConstantNode = require('../../../lib/expression/node/ConstantNode'), + SymbolNode = require('../../../lib/expression/node/SymbolNode'), + OperatorNode = require('../../../lib/expression/node/OperatorNode'), + TernaryNode = require('../../../lib/expression/node/TernaryNode'); + +describe('TernaryNode', function() { + + it ('should create a TernaryNode', function () { + var n = new TernaryNode('ifElse'); + assert(n instanceof TernaryNode); + assert(n instanceof Node); + }); + + it ('should throw an error when calling without new operator', function () { + var a = new ConstantNode('number', '2'); + var b = new ConstantNode('boolean', 'true'); + var c = new ConstantNode('boolean', 'false'); + assert.throws(function () {TernaryNode(['?', ':'], 'ifElse', [a, b, c])}, SyntaxError); + }); + + it ('should compile an TernaryNode', function () { + var a = new ConstantNode('number', '2'); + var b = new ConstantNode('boolean', 'true'); + var c = new ConstantNode('boolean', 'false'); + var n = new TernaryNode(['?', ':'], 'ifElse', [a, b, c]); + + var expr = n.compile(math); + + assert.equal(expr.eval(), true); + }); + + it ('should throw an error in case of unresolved operator function', function () { + var a = new ConstantNode('number', '2'); + var b = new ConstantNode('boolean', 'true'); + var c = new ConstantNode('boolean', 'false'); + var n = new TernaryNode(['?', ':'], 'ifElse', [a, b, c]); + + var emptyNamespace = {}; + + assert.throws(function () { + n.compile(emptyNamespace); + }, /Function ifElse missing in provided namespace/); + }); + + it ('should find a TernaryNode', function () { + var a = new ConstantNode('number', '2'); + var b = new ConstantNode('boolean', 'true'); + var c = new ConstantNode('boolean', 'false'); + var n = new TernaryNode(['?', ':'], 'ifElse', [a, b, c]); + + assert.deepEqual(n.find({type: TernaryNode}), [n]); + assert.deepEqual(n.find({type: SymbolNode}), []); + assert.deepEqual(n.find({type: ConstantNode}), [a, b, c]); + assert.deepEqual(n.find({type: ConstantNode, properties: {value: '2'}}), [a]); + assert.deepEqual(n.find({type: ConstantNode, properties: {value: '4'}}), []); + }); + + it ('should find an TernaryNode without contents', function () { + var n = new TernaryNode(); + + assert.deepEqual(n.find({type: TernaryNode}), [n]); + assert.deepEqual(n.find({type: SymbolNode}), []); + }); + + it ('should match a TernaryNode', function () { + var a = new TernaryNode(); + assert.equal(a.match({type: TernaryNode}), true); + assert.equal(a.match({type: ConstantNode}), false); + }); + + it ('should stringify a TernaryNode', function () { + var a = new ConstantNode('number', '2'); + var b = new ConstantNode('boolean', 'true'); + var c = new ConstantNode('boolean', 'false'); + var n = new TernaryNode(['?', ':'], 'ifElse', [a, b, c]); + + assert.equal(n.toString(), '2 ? true : false'); + }); + + it.skip ('should stringify a TernaryNode with nested operator nodes', function () { + var a = new ConstantNode('number', '2'); + var b = new ConstantNode('number', '3'); + var c = new ConstantNode('number', '4'); + var d = new ConstantNode('number', '5'); + + var n1 = new SymbolNode('a'); + var n2 = new OperatorNode('+', 'add', [a, b]); + var n3 = new OperatorNode('-', 'subtract', [c, d]); + + var n = new TernaryNode(['?', ':'], 'ifElse', [n1, n2, n3]); + + assert.equal(n.toString(), 'a ? 2 + 3 : 4 - 5'); + }); + +}); diff --git a/test/expression/node/index.test.js b/test/expression/node/index.test.js new file mode 100644 index 000000000..67e17bff6 --- /dev/null +++ b/test/expression/node/index.test.js @@ -0,0 +1,28 @@ +// test the contents of index.js +var assert = require('assert'), + index = require('../../../lib/expression/node/index'); + +describe('node/index', function() { + + it('should contain all nodes', function() { + assert.equal(Object.keys(index).length, 14); + + assert.equal(Object.keys(index).length, 14); + + assert.strictEqual(index.ArrayNode, require('../../../lib/expression/node/ArrayNode')); + assert.strictEqual(index.AssignmentNode, require('../../../lib/expression/node/AssignmentNode')); + assert.strictEqual(index.BlockNode, require('../../../lib/expression/node/BlockNode')); + assert.strictEqual(index.ConstantNode, require('../../../lib/expression/node/ConstantNode')); + assert.strictEqual(index.FunctionNode, require('../../../lib/expression/node/FunctionNode')); + assert.strictEqual(index.IndexNode, require('../../../lib/expression/node/IndexNode')); + assert.strictEqual(index.OperatorNode, require('../../../lib/expression/node/OperatorNode')); + assert.strictEqual(index.ParamsNode, require('../../../lib/expression/node/ParamsNode')); + assert.strictEqual(index.RangeNode, require('../../../lib/expression/node/RangeNode')); + assert.strictEqual(index.SymbolNode, require('../../../lib/expression/node/SymbolNode')); + assert.strictEqual(index.TernaryNode, require('../../../lib/expression/node/TernaryNode')); + assert.strictEqual(index.UnitNode, require('../../../lib/expression/node/UnitNode')); + assert.strictEqual(index.UpdateNode, require('../../../lib/expression/node/UpdateNode')); + }); + +}); + diff --git a/test/expression/parse.test.js b/test/expression/parse.test.js index d6bcaad2e..fd97b0ca3 100644 --- a/test/expression/parse.test.js +++ b/test/expression/parse.test.js @@ -679,6 +679,17 @@ describe('parse', function() { assert.equal(parseAndEval('2 != 2'), false); }); + it('should parse a ? b : c', function() { + assert.equal(parseAndEval('2 ? true : false'), true); + assert.equal(parseAndEval('0 ? true : false'), false); + assert.equal(parseAndEval('false ? true : false'), false); + + assert.equal(parseAndEval('2 > 0 ? 1 : 2 < 0 ? -1 : 0'), 1); + assert.equal(parseAndEval('(2 > 0 ? 1 : 2 < 0) ? -1 : 0'), -1); + assert.equal(parseAndEval('-2 > 0 ? 1 : -2 < 0 ? -1 : 0'), -1); + assert.equal(parseAndEval('0 > 0 ? 1 : 0 < 0 ? -1 : 0'), 0); + }); + it('should parse : (range)', function() { assert.ok(parseAndEval('2:5') instanceof Matrix); assert.deepEqual(parseAndEval('2:5'), new Matrix([2,3,4,5])); @@ -737,6 +748,14 @@ describe('parse', function() { assert.equal(parseAndEval('-4!'), -24); assert.equal(parseAndEval('3!+2'), 8); + assert.equal(parseAndEval('2 > 3 ? true : false'), false); + assert.equal(parseAndEval('2 == 3 ? true : false'), false); + assert.equal(parseAndEval('3 ? 2 + 4 : 2 - 1'), 6); + assert.deepEqual(parseAndEval('3 ? true : false; 22'), [22]); + assert.deepEqual(parseAndEval('3 ? 5cm to m : 5cm in mm'), new Unit(5, 'cm').to('m')); + assert.deepEqual(parseAndEval('2 == 4-2 ? [1,2] : false'), new Matrix([1,2])); + assert.deepEqual(parseAndEval('false ? 1:2:6'), new Matrix([2,3,4,5,6])); + // TODO: extensively test operator precedence }); From f568ae75c1ddac09f98ea593d0a18f100921ce60 Mon Sep 17 00:00:00 2001 From: josdejong Date: Thu, 3 Apr 2014 20:58:43 +0200 Subject: [PATCH 05/48] More unit tests added --- HISTORY.md | 1 + docs/datatypes/units.md | 10 +- examples/units.js | 2 +- lib/expression/node/SymbolNode.js | 2 +- lib/function/arithmetic/multiply.js | 8 +- lib/function/construction/unit.js | 2 +- lib/function/matrix/concat.js | 2 +- lib/function/utils/ifElse.js | 4 +- lib/type/Complex.js | 4 - lib/type/Help.js | 3 - lib/type/Index.js | 4 - lib/type/Matrix.js | 12 +- lib/type/Range.js | 4 - lib/type/Unit.js | 592 ++++++++++++++-------------- test/function/matrix/concat.test.js | 2 +- test/type/Matrix.test.js | 29 ++ test/type/Unit.test.js | 274 ++++++++++--- 17 files changed, 571 insertions(+), 384 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 5da5335ea..8c5d78e1f 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -6,6 +6,7 @@ https://github.com/josdejong/mathjs - Implemented conditional operator `a ? b : c` in expression parser. - Improved function `ifElse`, is now specified for special data types too. +- Minor bug fixes. ## 2014-03-30, version 0.19.0 diff --git a/docs/datatypes/units.md b/docs/datatypes/units.md index 822714304..03b0a98b8 100644 --- a/docs/datatypes/units.md +++ b/docs/datatypes/units.md @@ -15,7 +15,7 @@ full name and an abbreviation. The returned object is a `Unit`. Syntax: ```js -math.unit(value: number, plainUnit: string) : Unit +math.unit(value: number, name: string) : Unit math.unit(unit: string) : Unit math.unit(unit: Unit) : Unit ``` @@ -35,10 +35,10 @@ A `Unit` contains the following functions: length, mass, etc. - `equals(unit)`. Test whether a unit equals an other unit. Units are equal when they have the same base and same value when normalized to SI units. -- `to(plainUnit)`. Convert the unit to a specific prefix and unit. Returns - a clone of the unit with a fixed prefix and unit. -- `toNumber(plainUnit)`. Get the value of a unit when converted to the specified - plain unit (a unit with optional prefix but without value). +- `to(unitName)`. Convert the unit to a specific unit name. Returns a clone of + the unit with a fixed prefix and unit. +- `toNumber(unitName)`. Get the value of a unit when converted to the + specified unit (a unit with optional prefix but without value). - `format([precision])`. Get a string representation of the unit. The function will determine the best fitting prefix for the unit. If precision is defined, the units value will be rounded to the provided number of digits. diff --git a/examples/units.js b/examples/units.js index 4ee0fa84a..ab12b90a4 100644 --- a/examples/units.js +++ b/examples/units.js @@ -13,7 +13,7 @@ function print (value) { console.log(math.format(value, precision)); } -// units can be created by providing a value and plain unit, or by providing +// units can be created by providing a value and unit name, or by providing // a string with a valued unit. console.log('create units'); var a = math.unit(45, 'cm'); diff --git a/lib/expression/node/SymbolNode.js b/lib/expression/node/SymbolNode.js index 01b48f20c..cb05bf61e 100644 --- a/lib/expression/node/SymbolNode.js +++ b/lib/expression/node/SymbolNode.js @@ -39,7 +39,7 @@ SymbolNode.prototype._compile = function (defs) { return '(' + 'scope["' + this.name + '"] !== undefined ? scope["' + this.name + '"] : ' + 'math["' + this.name + '"] !== undefined ? math["' + this.name + '"] : ' + - (Unit.isPlainUnit(this.name) ? + (Unit.isValuelessUnit(this.name) ? 'new Unit(null, "' + this.name + '")' : 'undef("' + this.name + '")') + ')'; diff --git a/lib/function/arithmetic/multiply.js b/lib/function/arithmetic/multiply.js index 292d3f784..428bc49ba 100644 --- a/lib/function/arithmetic/multiply.js +++ b/lib/function/arithmetic/multiply.js @@ -109,7 +109,7 @@ module.exports = function(math) { if (sizeY.length == 1) { // vector * vector if (sizeX[0] != sizeY[0]) { - throw new RangeError('Dimensions mismatch in multiplication. ' + + throw new RangeError('Dimension mismatch in multiplication. ' + 'Length of A must match length of B ' + '(A is ' + sizeX[0] + ', B is ' + sizeY[0] + @@ -121,7 +121,7 @@ module.exports = function(math) { else if (sizeY.length == 2) { // vector * matrix if (sizeX[0] != sizeY[0]) { - throw new RangeError('Dimensions mismatch in multiplication. ' + + throw new RangeError('Dimension mismatch in multiplication. ' + 'Length of A must match rows of B ' + '(A is ' + sizeX[0] + ', B is ' + sizeY[0] + 'x' + sizeY[1] + ', ' + @@ -139,7 +139,7 @@ module.exports = function(math) { if (sizeY.length == 1) { // matrix * vector if (sizeX[1] != sizeY[0]) { - throw new RangeError('Dimensions mismatch in multiplication. ' + + throw new RangeError('Dimension mismatch in multiplication. ' + 'Columns of A must match length of B ' + '(A is ' + sizeX[0] + 'x' + sizeX[0] + ', B is ' + sizeY[0] + ', ' + @@ -151,7 +151,7 @@ module.exports = function(math) { else if (sizeY.length == 2) { // matrix * matrix if (sizeX[1] != sizeY[0]) { - throw new RangeError('Dimensions mismatch in multiplication. ' + + throw new RangeError('Dimension mismatch in multiplication. ' + 'Columns of A must match rows of B ' + '(A is ' + sizeX[0] + 'x' + sizeX[1] + ', B is ' + sizeY[0] + 'x' + sizeY[1] + ', ' + diff --git a/lib/function/construction/unit.js b/lib/function/construction/unit.js index 694ec671a..cfba18e68 100644 --- a/lib/function/construction/unit.js +++ b/lib/function/construction/unit.js @@ -38,7 +38,7 @@ module.exports = function (math) { } if (isString(arg)) { - if (Unit.isPlainUnit(arg)) { + if (Unit.isValuelessUnit(arg)) { return new Unit(null, arg); // a pure unit } diff --git a/lib/function/matrix/concat.js b/lib/function/matrix/concat.js index 81a0cabb7..59242fa60 100644 --- a/lib/function/matrix/concat.js +++ b/lib/function/matrix/concat.js @@ -98,7 +98,7 @@ module.exports = function (math) { if (dim < concatDim) { // recurse into next dimension if (a.length != b.length) { - throw new Error('Dimensions mismatch (' + a.length + ' != ' + b.length + ')'); + throw new Error('Dimension mismatch (' + a.length + ' != ' + b.length + ')'); } var c = []; diff --git a/lib/function/utils/ifElse.js b/lib/function/utils/ifElse.js index 88a5ae3f1..8bb7666c7 100644 --- a/lib/function/utils/ifElse.js +++ b/lib/function/utils/ifElse.js @@ -86,7 +86,7 @@ module.exports = function (math) { if (!(trueExpr instanceof Matrix)) trueExpr = new Matrix(trueExpr); if (!deepEqual(condition.size(), trueExpr.size())) { - throw new RangeError('Dimensions mismatch ([' + + throw new RangeError('Dimension mismatch ([' + condition.size().join(', ') + '] != [' + trueExpr.size().join(', ') + '])'); @@ -99,7 +99,7 @@ module.exports = function (math) { if (!(falseExpr instanceof Matrix)) falseExpr = new Matrix(falseExpr); if (!deepEqual(condition.size(), falseExpr.size())) { - throw new RangeError('Dimensions mismatch ([' + + throw new RangeError('Dimension mismatch ([' + condition.size().join(', ') + '] != [' + falseExpr.size().join(', ') + '])'); diff --git a/lib/type/Complex.js b/lib/type/Complex.js index 237cbd8dd..35f5e374a 100644 --- a/lib/type/Complex.js +++ b/lib/type/Complex.js @@ -354,7 +354,3 @@ Complex.prototype.toString = function toString () { // exports module.exports = Complex; - -// to trick my IDE which doesn't get it -exports.isComplex = Complex.isComplex; -exports.parse = Complex.parse; diff --git a/lib/type/Help.js b/lib/type/Help.js index 2a82e54e4..37fbf5b51 100644 --- a/lib/type/Help.js +++ b/lib/type/Help.js @@ -91,6 +91,3 @@ Help.prototype.toJSON = function () { // exports module.exports = Help; - -// to trick my IDE which doesn't get it -exports.isHelp = Help.isHelp; diff --git a/lib/type/Index.js b/lib/type/Index.js index 5327a6a1f..19817200d 100644 --- a/lib/type/Index.js +++ b/lib/type/Index.js @@ -262,7 +262,3 @@ Index.prototype.toString = function () { // exports module.exports = Index; - -// to trick my IDE which doesn't get it -exports.isIndex = Index.isIndex; -exports.create = Index.create; diff --git a/lib/type/Matrix.js b/lib/type/Matrix.js index 629614893..271f055a5 100644 --- a/lib/type/Matrix.js +++ b/lib/type/Matrix.js @@ -264,7 +264,8 @@ function _set (matrix, index, submatrix, defaultValue) { // check whether submatrix is a scalar if (sSize.length != 0) { - throw new TypeError('Scalar value expected'); + throw new RangeError('Dimension mismatch ' + + '(scalar expected, got a matrix)'); } matrix.set(index.min(), submatrix, defaultValue); @@ -286,7 +287,7 @@ function _set (matrix, index, submatrix, defaultValue) { // check whether the size of the submatrix matches the index size if (!object.deepEqual(iSize, sSize)) { - throw new RangeError('Dimensions mismatch ' + + throw new RangeError('Dimension mismatch ' + '(' + string.format(iSize) + ' != '+ string.format(sSize) + ')'); } @@ -359,10 +360,6 @@ Matrix.prototype.resize = function resize(size, defaultValue) { * @private */ function _fit(matrix, size, defaultValue) { - if (!isArray(size)) { - throw new Error('Array expected'); - } - var newSize = object.clone(matrix._size), changed = false; @@ -515,6 +512,3 @@ function preprocess(data) { // exports module.exports = Matrix; - -// to trick my IDE which doesn't get it -exports.isMatrix = Matrix.isMatrix; diff --git a/lib/type/Range.js b/lib/type/Range.js index f30b7c072..45de53f3c 100644 --- a/lib/type/Range.js +++ b/lib/type/Range.js @@ -265,7 +265,3 @@ Range.prototype.toString = function toString() { // exports module.exports = Range; - -// to trick my IDE which doesn't get it -exports.isRange = Range.isRange; -exports.parse = Range.parse; diff --git a/lib/type/Unit.js b/lib/type/Unit.js index ae547792c..479501a8c 100644 --- a/lib/type/Unit.js +++ b/lib/type/Unit.js @@ -9,8 +9,8 @@ var util = require('../util/index'), * @constructor Unit * * A unit can be constructed in the following ways: - * var a = new Unit(value, unit); - * var b = new Unit(null, unit); + * var a = new Unit(value, name); + * var b = new Unit(null, name); * var c = Unit.parse(str); * * Example usage: @@ -21,7 +21,7 @@ var util = require('../util/index'), * @param {Number} [value] A value like 5.2 * @param {String} [unit] A unit like "cm" or "inch" */ -function Unit(value, unit) { +function Unit(value, name) { if (!(this instanceof Unit)) { throw new Error('Constructor must be called with the new operator'); } @@ -29,15 +29,15 @@ function Unit(value, unit) { if (value != null && !isNumber(value)) { throw new TypeError('First parameter in Unit constructor must be a number'); } - if (unit != null && !isString(unit)) { + if (name != null && (!isString(name) || name == '')) { throw new TypeError('Second parameter in Unit constructor must be a string'); } - if (unit != null) { + if (name != null) { // find the unit and prefix from the string - var res = _findUnit(unit); + var res = _findUnit(name); if (!res) { - throw new SyntaxError('Unknown unit "' + unit + '"'); + throw new SyntaxError('Unknown unit "' + name + '"'); } this.unit = res.unit; this.prefix = res.prefix; @@ -155,15 +155,15 @@ function parseNumber () { } function parseUnit() { - var unit = ''; + var unitName = ''; skipWhitespace(); while (c && c != ' ' && c != '\t') { - unit += c; + unitName += c; next(); } - return unit || null; + return unitName || null; } /** @@ -184,9 +184,9 @@ Unit.parse = function parse(str) { next(); skipWhitespace(); var value = parseNumber(); - var unit; + var name; if (value) { - unit = parseUnit(); + name = parseUnit(); next(); skipWhitespace(); @@ -195,12 +195,16 @@ Unit.parse = function parse(str) { return null; } - if (value && unit) { - return new Unit(Number(value), unit); + if (value && name) { + try { + // constructor will throw an error when unit is not found + return new Unit(Number(value), name); + } + catch (err) {} } } else { - unit = parseUnit(); + name = parseUnit(); next(); skipWhitespace(); @@ -209,7 +213,13 @@ Unit.parse = function parse(str) { return null; } - return new Unit(null, unit) + if (name) { + try { + // constructor will throw an error when unit is not found + return new Unit(null, name); + } + catch (err) {} + } } return null; @@ -301,11 +311,12 @@ function _findUnit(str) { /** * Test if the given expression is a unit. * The unit can have a prefix but cannot have a value. - * @param {String} unit A plain unit without value. Can have prefix, like "cm" + * @param {String} name A string to be tested whether it is a value less unit. + * The unit can have prefix, like "cm" * @return {Boolean} true if the given string is a unit */ -Unit.isPlainUnit = function (unit) { - return (_findUnit(unit) != null); +Unit.isValuelessUnit = function (name) { + return (_findUnit(name) != null); }; /** @@ -313,9 +324,6 @@ Unit.isPlainUnit = function (unit) { * @param {BASE_UNITS | undefined} base */ Unit.prototype.hasBase = function(base) { - if (this.unit.base === undefined) { - return (base === undefined); - } return (this.unit.base === base); }; @@ -339,13 +347,13 @@ Unit.prototype.equals = function(other) { /** * Create a clone of this unit with a representation - * @param {String | Unit} plainUnit A plain unit, without value. Can have prefix, like "cm" + * @param {String | Unit} valuelessUnit A unit without value. Can have prefix, like "cm" * @returns {Unit} unit having fixed, specified unit */ -Unit.prototype.to = function (plainUnit) { +Unit.prototype.to = function (valuelessUnit) { var other; - if (isString(plainUnit)) { - other = new Unit(null, plainUnit); + if (isString(valuelessUnit)) { + other = new Unit(null, valuelessUnit); if (!this.equalBase(other)) { throw new Error('Units do not match'); @@ -354,18 +362,15 @@ Unit.prototype.to = function (plainUnit) { other.value = this.value; return other; } - else if (plainUnit instanceof Unit) { - if (!this.equalBase(plainUnit)) { + else if (valuelessUnit instanceof Unit) { + if (!this.equalBase(valuelessUnit)) { throw new Error('Units do not match'); } - if (plainUnit.value != null) { + if (valuelessUnit.value != null) { throw new Error('Cannot convert to a unit with a value'); } - if (plainUnit.unit == null) { - throw new Error('Unit expected on the right hand side of function in'); - } - other = plainUnit.clone(); + other = valuelessUnit.clone(); other.value = this.value; other.fixPrefix = true; return other; @@ -376,14 +381,13 @@ Unit.prototype.to = function (plainUnit) { }; /** - * Return the value of the unit when represented with given plain unit - * @param {String | Unit} plainUnit For example 'cm' or 'inch' + * Return the value of the unit when represented with given valueless unit + * @param {String | Unit} valuelessUnit For example 'cm' or 'inch' * @return {Number} value */ -Unit.prototype.toNumber = function (plainUnit) { - var other = this.to(plainUnit); - var prefix = this.fixPrefix ? other._bestPrefix() : other.prefix; - return other._unnormalize(other.value, prefix.value); +Unit.prototype.toNumber = function (valuelessUnit) { + var other = this.to(valuelessUnit); + return other._unnormalize(other.value, other.prefix.value); }; @@ -410,7 +414,7 @@ Unit.prototype.format = function format(options) { if (!this.fixPrefix) { var bestPrefix = this._bestPrefix(); value = this._unnormalize(this.value, bestPrefix.value); - str = (this.value != null) ? number.format(value, options) + ' ' : ''; + str = number.format(value, options) + ' '; str += bestPrefix.name + this.unit.name; } else { @@ -456,323 +460,323 @@ Unit.prototype._bestPrefix = function () { }; var PREFIXES = { - 'NONE': { - '': {'name': '', 'value': 1, 'scientific': true} + NONE: { + '': {name: '', value: 1, scientific: true} }, - 'SHORT': { - '': {'name': '', 'value': 1, 'scientific': true}, + SHORT: { + '': {name: '', value: 1, scientific: true}, - 'da': {'name': 'da', 'value': 1e1, 'scientific': false}, - 'h': {'name': 'h', 'value': 1e2, 'scientific': false}, - 'k': {'name': 'k', 'value': 1e3, 'scientific': true}, - 'M': {'name': 'M', 'value': 1e6, 'scientific': true}, - 'G': {'name': 'G', 'value': 1e9, 'scientific': true}, - 'T': {'name': 'T', 'value': 1e12, 'scientific': true}, - 'P': {'name': 'P', 'value': 1e15, 'scientific': true}, - 'E': {'name': 'E', 'value': 1e18, 'scientific': true}, - 'Z': {'name': 'Z', 'value': 1e21, 'scientific': true}, - 'Y': {'name': 'Y', 'value': 1e24, 'scientific': true}, + 'da': {name: 'da', value: 1e1, scientific: false}, + 'h': {name: 'h', value: 1e2, scientific: false}, + 'k': {name: 'k', value: 1e3, scientific: true}, + 'M': {name: 'M', value: 1e6, scientific: true}, + 'G': {name: 'G', value: 1e9, scientific: true}, + 'T': {name: 'T', value: 1e12, scientific: true}, + 'P': {name: 'P', value: 1e15, scientific: true}, + 'E': {name: 'E', value: 1e18, scientific: true}, + 'Z': {name: 'Z', value: 1e21, scientific: true}, + 'Y': {name: 'Y', value: 1e24, scientific: true}, - 'd': {'name': 'd', 'value': 1e-1, 'scientific': false}, - 'c': {'name': 'c', 'value': 1e-2, 'scientific': false}, - 'm': {'name': 'm', 'value': 1e-3, 'scientific': true}, - 'u': {'name': 'u', 'value': 1e-6, 'scientific': true}, - 'n': {'name': 'n', 'value': 1e-9, 'scientific': true}, - 'p': {'name': 'p', 'value': 1e-12, 'scientific': true}, - 'f': {'name': 'f', 'value': 1e-15, 'scientific': true}, - 'a': {'name': 'a', 'value': 1e-18, 'scientific': true}, - 'z': {'name': 'z', 'value': 1e-21, 'scientific': true}, - 'y': {'name': 'y', 'value': 1e-24, 'scientific': true} + 'd': {name: 'd', value: 1e-1, scientific: false}, + 'c': {name: 'c', value: 1e-2, scientific: false}, + 'm': {name: 'm', value: 1e-3, scientific: true}, + 'u': {name: 'u', value: 1e-6, scientific: true}, + 'n': {name: 'n', value: 1e-9, scientific: true}, + 'p': {name: 'p', value: 1e-12, scientific: true}, + 'f': {name: 'f', value: 1e-15, scientific: true}, + 'a': {name: 'a', value: 1e-18, scientific: true}, + 'z': {name: 'z', value: 1e-21, scientific: true}, + 'y': {name: 'y', value: 1e-24, scientific: true} }, - 'LONG': { - '': {'name': '', 'value': 1, 'scientific': true}, + LONG: { + '': {name: '', value: 1, scientific: true}, - 'deca': {'name': 'deca', 'value': 1e1, 'scientific': false}, - 'hecto': {'name': 'hecto', 'value': 1e2, 'scientific': false}, - 'kilo': {'name': 'kilo', 'value': 1e3, 'scientific': true}, - 'mega': {'name': 'mega', 'value': 1e6, 'scientific': true}, - 'giga': {'name': 'giga', 'value': 1e9, 'scientific': true}, - 'tera': {'name': 'tera', 'value': 1e12, 'scientific': true}, - 'peta': {'name': 'peta', 'value': 1e15, 'scientific': true}, - 'exa': {'name': 'exa', 'value': 1e18, 'scientific': true}, - 'zetta': {'name': 'zetta', 'value': 1e21, 'scientific': true}, - 'yotta': {'name': 'yotta', 'value': 1e24, 'scientific': true}, + 'deca': {name: 'deca', value: 1e1, scientific: false}, + 'hecto': {name: 'hecto', value: 1e2, scientific: false}, + 'kilo': {name: 'kilo', value: 1e3, scientific: true}, + 'mega': {name: 'mega', value: 1e6, scientific: true}, + 'giga': {name: 'giga', value: 1e9, scientific: true}, + 'tera': {name: 'tera', value: 1e12, scientific: true}, + 'peta': {name: 'peta', value: 1e15, scientific: true}, + 'exa': {name: 'exa', value: 1e18, scientific: true}, + 'zetta': {name: 'zetta', value: 1e21, scientific: true}, + 'yotta': {name: 'yotta', value: 1e24, scientific: true}, - 'deci': {'name': 'deci', 'value': 1e-1, 'scientific': false}, - 'centi': {'name': 'centi', 'value': 1e-2, 'scientific': false}, - 'milli': {'name': 'milli', 'value': 1e-3, 'scientific': true}, - 'micro': {'name': 'micro', 'value': 1e-6, 'scientific': true}, - 'nano': {'name': 'nano', 'value': 1e-9, 'scientific': true}, - 'pico': {'name': 'pico', 'value': 1e-12, 'scientific': true}, - 'femto': {'name': 'femto', 'value': 1e-15, 'scientific': true}, - 'atto': {'name': 'atto', 'value': 1e-18, 'scientific': true}, - 'zepto': {'name': 'zepto', 'value': 1e-21, 'scientific': true}, - 'yocto': {'name': 'yocto', 'value': 1e-24, 'scientific': true} + 'deci': {name: 'deci', value: 1e-1, scientific: false}, + 'centi': {name: 'centi', value: 1e-2, scientific: false}, + 'milli': {name: 'milli', value: 1e-3, scientific: true}, + 'micro': {name: 'micro', value: 1e-6, scientific: true}, + 'nano': {name: 'nano', value: 1e-9, scientific: true}, + 'pico': {name: 'pico', value: 1e-12, scientific: true}, + 'femto': {name: 'femto', value: 1e-15, scientific: true}, + 'atto': {name: 'atto', value: 1e-18, scientific: true}, + 'zepto': {name: 'zepto', value: 1e-21, scientific: true}, + 'yocto': {name: 'yocto', value: 1e-24, scientific: true} }, - 'SQUARED': { - '': {'name': '', 'value': 1, 'scientific': true}, + SQUARED: { + '': {name: '', value: 1, scientific: true}, - 'da': {'name': 'da', 'value': 1e2, 'scientific': false}, - 'h': {'name': 'h', 'value': 1e4, 'scientific': false}, - 'k': {'name': 'k', 'value': 1e6, 'scientific': true}, - 'M': {'name': 'M', 'value': 1e12, 'scientific': true}, - 'G': {'name': 'G', 'value': 1e18, 'scientific': true}, - 'T': {'name': 'T', 'value': 1e24, 'scientific': true}, - 'P': {'name': 'P', 'value': 1e30, 'scientific': true}, - 'E': {'name': 'E', 'value': 1e36, 'scientific': true}, - 'Z': {'name': 'Z', 'value': 1e42, 'scientific': true}, - 'Y': {'name': 'Y', 'value': 1e48, 'scientific': true}, + 'da': {name: 'da', value: 1e2, scientific: false}, + 'h': {name: 'h', value: 1e4, scientific: false}, + 'k': {name: 'k', value: 1e6, scientific: true}, + 'M': {name: 'M', value: 1e12, scientific: true}, + 'G': {name: 'G', value: 1e18, scientific: true}, + 'T': {name: 'T', value: 1e24, scientific: true}, + 'P': {name: 'P', value: 1e30, scientific: true}, + 'E': {name: 'E', value: 1e36, scientific: true}, + 'Z': {name: 'Z', value: 1e42, scientific: true}, + 'Y': {name: 'Y', value: 1e48, scientific: true}, - 'd': {'name': 'd', 'value': 1e-2, 'scientific': false}, - 'c': {'name': 'c', 'value': 1e-4, 'scientific': false}, - 'm': {'name': 'm', 'value': 1e-6, 'scientific': true}, - 'u': {'name': 'u', 'value': 1e-12, 'scientific': true}, - 'n': {'name': 'n', 'value': 1e-18, 'scientific': true}, - 'p': {'name': 'p', 'value': 1e-24, 'scientific': true}, - 'f': {'name': 'f', 'value': 1e-30, 'scientific': true}, - 'a': {'name': 'a', 'value': 1e-36, 'scientific': true}, - 'z': {'name': 'z', 'value': 1e-42, 'scientific': true}, - 'y': {'name': 'y', 'value': 1e-42, 'scientific': true} + 'd': {name: 'd', value: 1e-2, scientific: false}, + 'c': {name: 'c', value: 1e-4, scientific: false}, + 'm': {name: 'm', value: 1e-6, scientific: true}, + 'u': {name: 'u', value: 1e-12, scientific: true}, + 'n': {name: 'n', value: 1e-18, scientific: true}, + 'p': {name: 'p', value: 1e-24, scientific: true}, + 'f': {name: 'f', value: 1e-30, scientific: true}, + 'a': {name: 'a', value: 1e-36, scientific: true}, + 'z': {name: 'z', value: 1e-42, scientific: true}, + 'y': {name: 'y', value: 1e-42, scientific: true} }, - 'CUBIC': { - '': {'name': '', 'value': 1, 'scientific': true}, + CUBIC: { + '': {name: '', value: 1, scientific: true}, - 'da': {'name': 'da', 'value': 1e3, 'scientific': false}, - 'h': {'name': 'h', 'value': 1e6, 'scientific': false}, - 'k': {'name': 'k', 'value': 1e9, 'scientific': true}, - 'M': {'name': 'M', 'value': 1e18, 'scientific': true}, - 'G': {'name': 'G', 'value': 1e27, 'scientific': true}, - 'T': {'name': 'T', 'value': 1e36, 'scientific': true}, - 'P': {'name': 'P', 'value': 1e45, 'scientific': true}, - 'E': {'name': 'E', 'value': 1e54, 'scientific': true}, - 'Z': {'name': 'Z', 'value': 1e63, 'scientific': true}, - 'Y': {'name': 'Y', 'value': 1e72, 'scientific': true}, + 'da': {name: 'da', value: 1e3, scientific: false}, + 'h': {name: 'h', value: 1e6, scientific: false}, + 'k': {name: 'k', value: 1e9, scientific: true}, + 'M': {name: 'M', value: 1e18, scientific: true}, + 'G': {name: 'G', value: 1e27, scientific: true}, + 'T': {name: 'T', value: 1e36, scientific: true}, + 'P': {name: 'P', value: 1e45, scientific: true}, + 'E': {name: 'E', value: 1e54, scientific: true}, + 'Z': {name: 'Z', value: 1e63, scientific: true}, + 'Y': {name: 'Y', value: 1e72, scientific: true}, - 'd': {'name': 'd', 'value': 1e-3, 'scientific': false}, - 'c': {'name': 'c', 'value': 1e-6, 'scientific': false}, - 'm': {'name': 'm', 'value': 1e-9, 'scientific': true}, - 'u': {'name': 'u', 'value': 1e-18, 'scientific': true}, - 'n': {'name': 'n', 'value': 1e-27, 'scientific': true}, - 'p': {'name': 'p', 'value': 1e-36, 'scientific': true}, - 'f': {'name': 'f', 'value': 1e-45, 'scientific': true}, - 'a': {'name': 'a', 'value': 1e-54, 'scientific': true}, - 'z': {'name': 'z', 'value': 1e-63, 'scientific': true}, - 'y': {'name': 'y', 'value': 1e-72, 'scientific': true} + 'd': {name: 'd', value: 1e-3, scientific: false}, + 'c': {name: 'c', value: 1e-6, scientific: false}, + 'm': {name: 'm', value: 1e-9, scientific: true}, + 'u': {name: 'u', value: 1e-18, scientific: true}, + 'n': {name: 'n', value: 1e-27, scientific: true}, + 'p': {name: 'p', value: 1e-36, scientific: true}, + 'f': {name: 'f', value: 1e-45, scientific: true}, + 'a': {name: 'a', value: 1e-54, scientific: true}, + 'z': {name: 'z', value: 1e-63, scientific: true}, + 'y': {name: 'y', value: 1e-72, scientific: true} }, - 'BINARY_SHORT': { - '': {'name': '', 'value': 1, 'scientific': true}, - 'k': {'name': 'k', 'value': 1024, 'scientific': true}, - 'M': {'name': 'M', 'value': Math.pow(1024, 2), 'scientific': true}, - 'G': {'name': 'G', 'value': Math.pow(1024, 3), 'scientific': true}, - 'T': {'name': 'T', 'value': Math.pow(1024, 4), 'scientific': true}, - 'P': {'name': 'P', 'value': Math.pow(1024, 5), 'scientific': true}, - 'E': {'name': 'E', 'value': Math.pow(1024, 6), 'scientific': true}, - 'Z': {'name': 'Z', 'value': Math.pow(1024, 7), 'scientific': true}, - 'Y': {'name': 'Y', 'value': Math.pow(1024, 8), 'scientific': true}, + BINARY_SHORT: { + '': {name: '', value: 1, scientific: true}, + 'k': {name: 'k', value: 1024, scientific: true}, + 'M': {name: 'M', value: Math.pow(1024, 2), scientific: true}, + 'G': {name: 'G', value: Math.pow(1024, 3), scientific: true}, + 'T': {name: 'T', value: Math.pow(1024, 4), scientific: true}, + 'P': {name: 'P', value: Math.pow(1024, 5), scientific: true}, + 'E': {name: 'E', value: Math.pow(1024, 6), scientific: true}, + 'Z': {name: 'Z', value: Math.pow(1024, 7), scientific: true}, + 'Y': {name: 'Y', value: Math.pow(1024, 8), scientific: true}, - 'Ki': {'name': 'Ki', 'value': 1024, 'scientific': true}, - 'Mi': {'name': 'Mi', 'value': Math.pow(1024, 2), 'scientific': true}, - 'Gi': {'name': 'Gi', 'value': Math.pow(1024, 3), 'scientific': true}, - 'Ti': {'name': 'Ti', 'value': Math.pow(1024, 4), 'scientific': true}, - 'Pi': {'name': 'Pi', 'value': Math.pow(1024, 5), 'scientific': true}, - 'Ei': {'name': 'Ei', 'value': Math.pow(1024, 6), 'scientific': true}, - 'Zi': {'name': 'Zi', 'value': Math.pow(1024, 7), 'scientific': true}, - 'Yi': {'name': 'Yi', 'value': Math.pow(1024, 8), 'scientific': true} + 'Ki': {name: 'Ki', value: 1024, scientific: true}, + 'Mi': {name: 'Mi', value: Math.pow(1024, 2), scientific: true}, + 'Gi': {name: 'Gi', value: Math.pow(1024, 3), scientific: true}, + 'Ti': {name: 'Ti', value: Math.pow(1024, 4), scientific: true}, + 'Pi': {name: 'Pi', value: Math.pow(1024, 5), scientific: true}, + 'Ei': {name: 'Ei', value: Math.pow(1024, 6), scientific: true}, + 'Zi': {name: 'Zi', value: Math.pow(1024, 7), scientific: true}, + 'Yi': {name: 'Yi', value: Math.pow(1024, 8), scientific: true} }, - 'BINARY_LONG': { - '': {'name': '', 'value': 1, 'scientific': true}, - 'kilo': {'name': 'kilo', 'value': 1024, 'scientific': true}, - 'mega': {'name': 'mega', 'value': Math.pow(1024, 2), 'scientific': true}, - 'giga': {'name': 'giga', 'value': Math.pow(1024, 3), 'scientific': true}, - 'tera': {'name': 'tera', 'value': Math.pow(1024, 4), 'scientific': true}, - 'peta': {'name': 'peta', 'value': Math.pow(1024, 5), 'scientific': true}, - 'exa': {'name': 'exa', 'value': Math.pow(1024, 6), 'scientific': true}, - 'zetta': {'name': 'zetta', 'value': Math.pow(1024, 7), 'scientific': true}, - 'yotta': {'name': 'yotta', 'value': Math.pow(1024, 8), 'scientific': true}, + BINARY_LONG: { + '': {name: '', value: 1, scientific: true}, + 'kilo': {name: 'kilo', value: 1024, scientific: true}, + 'mega': {name: 'mega', value: Math.pow(1024, 2), scientific: true}, + 'giga': {name: 'giga', value: Math.pow(1024, 3), scientific: true}, + 'tera': {name: 'tera', value: Math.pow(1024, 4), scientific: true}, + 'peta': {name: 'peta', value: Math.pow(1024, 5), scientific: true}, + 'exa': {name: 'exa', value: Math.pow(1024, 6), scientific: true}, + 'zetta': {name: 'zetta', value: Math.pow(1024, 7), scientific: true}, + 'yotta': {name: 'yotta', value: Math.pow(1024, 8), scientific: true}, - 'kibi': {'name': 'kibi', 'value': 1024, 'scientific': true}, - 'mebi': {'name': 'mebi', 'value': Math.pow(1024, 2), 'scientific': true}, - 'gibi': {'name': 'gibi', 'value': Math.pow(1024, 3), 'scientific': true}, - 'tebi': {'name': 'tebi', 'value': Math.pow(1024, 4), 'scientific': true}, - 'pebi': {'name': 'pebi', 'value': Math.pow(1024, 5), 'scientific': true}, - 'exi': {'name': 'exi', 'value': Math.pow(1024, 6), 'scientific': true}, - 'zebi': {'name': 'zebi', 'value': Math.pow(1024, 7), 'scientific': true}, - 'yobi': {'name': 'yobi', 'value': Math.pow(1024, 8), 'scientific': true} + 'kibi': {name: 'kibi', value: 1024, scientific: true}, + 'mebi': {name: 'mebi', value: Math.pow(1024, 2), scientific: true}, + 'gibi': {name: 'gibi', value: Math.pow(1024, 3), scientific: true}, + 'tebi': {name: 'tebi', value: Math.pow(1024, 4), scientific: true}, + 'pebi': {name: 'pebi', value: Math.pow(1024, 5), scientific: true}, + 'exi': {name: 'exi', value: Math.pow(1024, 6), scientific: true}, + 'zebi': {name: 'zebi', value: Math.pow(1024, 7), scientific: true}, + 'yobi': {name: 'yobi', value: Math.pow(1024, 8), scientific: true} } }; -var PREFIX_NONE = {'name': '', 'value': 1, 'scientific': true}; +var PREFIX_NONE = {name: '', value: 1, scientific: true}; var BASE_UNITS = { - 'NONE': {}, + NONE: {}, - 'LENGTH': {}, // meter - 'MASS': {}, // kilogram - 'TIME': {}, // second - 'CURRENT': {}, // ampere - 'TEMPERATURE': {}, // kelvin - 'LUMINOUS_INTENSITY': {}, // candela - 'AMOUNT_OF_SUBSTANCE': {}, // mole + LENGTH: {}, // meter + MASS: {}, // kilogram + TIME: {}, // second + CURRENT: {}, // ampere + TEMPERATURE: {}, // kelvin + LUMINOUS_INTENSITY: {}, // candela + AMOUNT_OF_SUBSTANCE: {}, // mole - 'FORCE': {}, // Newton - 'SURFACE': {}, // m2 - 'VOLUME': {}, // m3 - 'ANGLE': {}, // rad - 'BIT': {} // bit (digital) + FORCE: {}, // Newton + SURFACE: {}, // m2 + VOLUME: {}, // m3 + ANGLE: {}, // rad + BIT: {} // bit (digital) }; BASE_UNIT_NONE = {}; -UNIT_NONE = {'name': '', 'base': BASE_UNIT_NONE, 'value': 1, 'offset': 0}; +UNIT_NONE = {name: '', base: BASE_UNIT_NONE, value: 1, offset: 0}; var UNITS = { // length - meter: {'name': 'meter', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.LONG, 'value': 1, 'offset': 0}, - inch: {'name': 'inch', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.NONE, 'value': 0.0254, 'offset': 0}, - foot: {'name': 'foot', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.NONE, 'value': 0.3048, 'offset': 0}, - yard: {'name': 'yard', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.NONE, 'value': 0.9144, 'offset': 0}, - mile: {'name': 'mile', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.NONE, 'value': 1609.344, 'offset': 0}, - link: {'name': 'link', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.NONE, 'value': 0.201168, 'offset': 0}, - rod: {'name': 'rod', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.NONE, 'value': 5.029210, 'offset': 0}, - chain: {'name': 'chain', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.NONE, 'value': 20.1168, 'offset': 0}, - angstrom: {'name': 'angstrom', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.NONE, 'value': 1e-10, 'offset': 0}, + meter: {name: 'meter', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.LONG, value: 1, offset: 0}, + inch: {name: 'inch', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.NONE, value: 0.0254, offset: 0}, + foot: {name: 'foot', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.NONE, value: 0.3048, offset: 0}, + yard: {name: 'yard', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.NONE, value: 0.9144, offset: 0}, + mile: {name: 'mile', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.NONE, value: 1609.344, offset: 0}, + link: {name: 'link', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.NONE, value: 0.201168, offset: 0}, + rod: {name: 'rod', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.NONE, value: 5.029210, offset: 0}, + chain: {name: 'chain', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.NONE, value: 20.1168, offset: 0}, + angstrom: {name: 'angstrom', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.NONE, value: 1e-10, offset: 0}, - m: {'name': 'm', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.SHORT, 'value': 1, 'offset': 0}, - 'in': {'name': 'in', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.NONE, 'value': 0.0254, 'offset': 0}, - ft: {'name': 'ft', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.NONE, 'value': 0.3048, 'offset': 0}, - yd: {'name': 'yd', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.NONE, 'value': 0.9144, 'offset': 0}, - mi: {'name': 'mi', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.NONE, 'value': 1609.344, 'offset': 0}, - li: {'name': 'li', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.NONE, 'value': 0.201168, 'offset': 0}, - rd: {'name': 'rd', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.NONE, 'value': 5.029210, 'offset': 0}, - ch: {'name': 'ch', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.NONE, 'value': 20.1168, 'offset': 0}, - mil: {'name': 'mil', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.NONE, 'value': 0.0000254, 'offset': 0}, // 1/1000 inch + m: {name: 'm', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.SHORT, value: 1, offset: 0}, + 'in': {name: 'in', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.NONE, value: 0.0254, offset: 0}, + ft: {name: 'ft', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.NONE, value: 0.3048, offset: 0}, + yd: {name: 'yd', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.NONE, value: 0.9144, offset: 0}, + mi: {name: 'mi', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.NONE, value: 1609.344, offset: 0}, + li: {name: 'li', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.NONE, value: 0.201168, offset: 0}, + rd: {name: 'rd', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.NONE, value: 5.029210, offset: 0}, + ch: {name: 'ch', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.NONE, value: 20.1168, offset: 0}, + mil: {name: 'mil', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.NONE, value: 0.0000254, offset: 0}, // 1/1000 inch // Surface - m2: {'name': 'm2', 'base': BASE_UNITS.SURFACE, 'prefixes': PREFIXES.SQUARED, 'value': 1, 'offset': 0}, - sqin: {'name': 'sqin', 'base': BASE_UNITS.SURFACE, 'prefixes': PREFIXES.NONE, 'value': 0.00064516, 'offset': 0}, // 645.16 mm2 - sqft: {'name': 'sqft', 'base': BASE_UNITS.SURFACE, 'prefixes': PREFIXES.NONE, 'value': 0.09290304, 'offset': 0}, // 0.09290304 m2 - sqyd: {'name': 'sqyd', 'base': BASE_UNITS.SURFACE, 'prefixes': PREFIXES.NONE, 'value': 0.83612736, 'offset': 0}, // 0.83612736 m2 - sqmi: {'name': 'sqmi', 'base': BASE_UNITS.SURFACE, 'prefixes': PREFIXES.NONE, 'value': 2589988.110336, 'offset': 0}, // 2.589988110336 km2 - sqrd: {'name': 'sqrd', 'base': BASE_UNITS.SURFACE, 'prefixes': PREFIXES.NONE, 'value': 25.29295, 'offset': 0}, // 25.29295 m2 - sqch: {'name': 'sqch', 'base': BASE_UNITS.SURFACE, 'prefixes': PREFIXES.NONE, 'value': 404.6873, 'offset': 0}, // 404.6873 m2 - sqmil: {'name': 'sqmil', 'base': BASE_UNITS.SURFACE, 'prefixes': PREFIXES.NONE, 'value': 6.4516e-10, 'offset': 0}, // 6.4516 * 10^-10 m2 + m2: {name: 'm2', base: BASE_UNITS.SURFACE, prefixes: PREFIXES.SQUARED, value: 1, offset: 0}, + sqin: {name: 'sqin', base: BASE_UNITS.SURFACE, prefixes: PREFIXES.NONE, value: 0.00064516, offset: 0}, // 645.16 mm2 + sqft: {name: 'sqft', base: BASE_UNITS.SURFACE, prefixes: PREFIXES.NONE, value: 0.09290304, offset: 0}, // 0.09290304 m2 + sqyd: {name: 'sqyd', base: BASE_UNITS.SURFACE, prefixes: PREFIXES.NONE, value: 0.83612736, offset: 0}, // 0.83612736 m2 + sqmi: {name: 'sqmi', base: BASE_UNITS.SURFACE, prefixes: PREFIXES.NONE, value: 2589988.110336, offset: 0}, // 2.589988110336 km2 + sqrd: {name: 'sqrd', base: BASE_UNITS.SURFACE, prefixes: PREFIXES.NONE, value: 25.29295, offset: 0}, // 25.29295 m2 + sqch: {name: 'sqch', base: BASE_UNITS.SURFACE, prefixes: PREFIXES.NONE, value: 404.6873, offset: 0}, // 404.6873 m2 + sqmil: {name: 'sqmil', base: BASE_UNITS.SURFACE, prefixes: PREFIXES.NONE, value: 6.4516e-10, offset: 0}, // 6.4516 * 10^-10 m2 // Volume - m3: {'name': 'm3', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.CUBIC, 'value': 1, 'offset': 0}, - L: {'name': 'L', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.SHORT, 'value': 0.001, 'offset': 0}, // litre - l: {'name': 'l', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.SHORT, 'value': 0.001, 'offset': 0}, // litre - litre: {'name': 'litre', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.LONG, 'value': 0.001, 'offset': 0}, - cuin: {'name': 'cuin', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 1.6387064e-5, 'offset': 0}, // 1.6387064e-5 m3 - cuft: {'name': 'cuft', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.028316846592, 'offset': 0}, // 28.316 846 592 L - cuyd: {'name': 'cuyd', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.764554857984, 'offset': 0}, // 764.554 857 984 L - teaspoon: {'name': 'teaspoon', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.000005, 'offset': 0}, // 5 mL - tablespoon: {'name': 'tablespoon', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.000015, 'offset': 0}, // 15 mL - //{'name': 'cup', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.000240, 'offset': 0}, // 240 mL // not possible, we have already another cup + m3: {name: 'm3', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.CUBIC, value: 1, offset: 0}, + L: {name: 'L', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.SHORT, value: 0.001, offset: 0}, // litre + l: {name: 'l', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.SHORT, value: 0.001, offset: 0}, // litre + litre: {name: 'litre', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.LONG, value: 0.001, offset: 0}, + cuin: {name: 'cuin', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 1.6387064e-5, offset: 0}, // 1.6387064e-5 m3 + cuft: {name: 'cuft', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.028316846592, offset: 0}, // 28.316 846 592 L + cuyd: {name: 'cuyd', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.764554857984, offset: 0}, // 764.554 857 984 L + teaspoon: {name: 'teaspoon', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.000005, offset: 0}, // 5 mL + tablespoon: {name: 'tablespoon', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.000015, offset: 0}, // 15 mL + //{name: 'cup', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.000240, offset: 0}, // 240 mL // not possible, we have already another cup // Liquid volume - minim: {'name': 'minim', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.00000006161152, 'offset': 0}, // 0.06161152 mL - fluiddram: {'name': 'fluiddram', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.0000036966911, 'offset': 0}, // 3.696691 mL - fluidounce: {'name': 'fluidounce', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.00002957353, 'offset': 0}, // 29.57353 mL - gill: {'name': 'gill', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.0001182941, 'offset': 0}, // 118.2941 mL - cc: {'name': 'cc', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 1e-6, 'offset': 0}, // 1e-6 L - cup: {'name': 'cup', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.0002365882, 'offset': 0}, // 236.5882 mL - pint: {'name': 'pint', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.0004731765, 'offset': 0}, // 473.1765 mL - quart: {'name': 'quart', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.0009463529, 'offset': 0}, // 946.3529 mL - gallon: {'name': 'gallon', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.003785412, 'offset': 0}, // 3.785412 L - beerbarrel: {'name': 'beerbarrel', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.1173478, 'offset': 0}, // 117.3478 L - oilbarrel: {'name': 'oilbarrel', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.1589873, 'offset': 0}, // 158.9873 L - hogshead: {'name': 'hogshead', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.2384810, 'offset': 0}, // 238.4810 L + minim: {name: 'minim', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.00000006161152, offset: 0}, // 0.06161152 mL + fluiddram: {name: 'fluiddram', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.0000036966911, offset: 0}, // 3.696691 mL + fluidounce: {name: 'fluidounce', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.00002957353, offset: 0}, // 29.57353 mL + gill: {name: 'gill', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.0001182941, offset: 0}, // 118.2941 mL + cc: {name: 'cc', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 1e-6, offset: 0}, // 1e-6 L + cup: {name: 'cup', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.0002365882, offset: 0}, // 236.5882 mL + pint: {name: 'pint', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.0004731765, offset: 0}, // 473.1765 mL + quart: {name: 'quart', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.0009463529, offset: 0}, // 946.3529 mL + gallon: {name: 'gallon', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.003785412, offset: 0}, // 3.785412 L + beerbarrel: {name: 'beerbarrel', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.1173478, offset: 0}, // 117.3478 L + oilbarrel: {name: 'oilbarrel', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.1589873, offset: 0}, // 158.9873 L + hogshead: {name: 'hogshead', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.2384810, offset: 0}, // 238.4810 L - //{'name': 'min', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.00000006161152, 'offset': 0}, // 0.06161152 mL // min is already in use as minute - fldr: {'name': 'fldr', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.0000036966911, 'offset': 0}, // 3.696691 mL - floz: {'name': 'floz', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.00002957353, 'offset': 0}, // 29.57353 mL - gi: {'name': 'gi', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.0001182941, 'offset': 0}, // 118.2941 mL - cp: {'name': 'cp', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.0002365882, 'offset': 0}, // 236.5882 mL - pt: {'name': 'pt', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.0004731765, 'offset': 0}, // 473.1765 mL - qt: {'name': 'qt', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.0009463529, 'offset': 0}, // 946.3529 mL - gal: {'name': 'gal', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.003785412, 'offset': 0}, // 3.785412 L - bbl: {'name': 'bbl', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.1173478, 'offset': 0}, // 117.3478 L - obl: {'name': 'obl', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.1589873, 'offset': 0}, // 158.9873 L - //{'name': 'hogshead', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.2384810, 'offset': 0}, // 238.4810 L // TODO: hh? + //{name: 'min', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.00000006161152, offset: 0}, // 0.06161152 mL // min is already in use as minute + fldr: {name: 'fldr', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.0000036966911, offset: 0}, // 3.696691 mL + floz: {name: 'floz', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.00002957353, offset: 0}, // 29.57353 mL + gi: {name: 'gi', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.0001182941, offset: 0}, // 118.2941 mL + cp: {name: 'cp', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.0002365882, offset: 0}, // 236.5882 mL + pt: {name: 'pt', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.0004731765, offset: 0}, // 473.1765 mL + qt: {name: 'qt', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.0009463529, offset: 0}, // 946.3529 mL + gal: {name: 'gal', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.003785412, offset: 0}, // 3.785412 L + bbl: {name: 'bbl', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.1173478, offset: 0}, // 117.3478 L + obl: {name: 'obl', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.1589873, offset: 0}, // 158.9873 L + //{name: 'hogshead', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.2384810, offset: 0}, // 238.4810 L // TODO: hh? // Mass - g: {'name': 'g', 'base': BASE_UNITS.MASS, 'prefixes': PREFIXES.SHORT, 'value': 0.001, 'offset': 0}, - gram: {'name': 'gram', 'base': BASE_UNITS.MASS, 'prefixes': PREFIXES.LONG, 'value': 0.001, 'offset': 0}, + g: {name: 'g', base: BASE_UNITS.MASS, prefixes: PREFIXES.SHORT, value: 0.001, offset: 0}, + gram: {name: 'gram', base: BASE_UNITS.MASS, prefixes: PREFIXES.LONG, value: 0.001, offset: 0}, - ton: {'name': 'ton', 'base': BASE_UNITS.MASS, 'prefixes': PREFIXES.SHORT, 'value': 907.18474, 'offset': 0}, - tonne: {'name': 'tonne', 'base': BASE_UNITS.MASS, 'prefixes': PREFIXES.SHORT, 'value': 1000, 'offset': 0}, + ton: {name: 'ton', base: BASE_UNITS.MASS, prefixes: PREFIXES.SHORT, value: 907.18474, offset: 0}, + tonne: {name: 'tonne', base: BASE_UNITS.MASS, prefixes: PREFIXES.SHORT, value: 1000, offset: 0}, - grain: {'name': 'grain', 'base': BASE_UNITS.MASS, 'prefixes': PREFIXES.NONE, 'value': 64.79891e-6, 'offset': 0}, - dram: {'name': 'dram', 'base': BASE_UNITS.MASS, 'prefixes': PREFIXES.NONE, 'value': 1.7718451953125e-3, 'offset': 0}, - ounce: {'name': 'ounce', 'base': BASE_UNITS.MASS, 'prefixes': PREFIXES.NONE, 'value': 28.349523125e-3, 'offset': 0}, - poundmass: {'name': 'poundmass', 'base': BASE_UNITS.MASS, 'prefixes': PREFIXES.NONE, 'value': 453.59237e-3, 'offset': 0}, - hundredweight: {'name': 'hundredweight', 'base': BASE_UNITS.MASS, 'prefixes': PREFIXES.NONE, 'value': 45.359237, 'offset': 0}, - stick: {'name': 'stick', 'base': BASE_UNITS.MASS, 'prefixes': PREFIXES.NONE, 'value': 115e-3, 'offset': 0}, + grain: {name: 'grain', base: BASE_UNITS.MASS, prefixes: PREFIXES.NONE, value: 64.79891e-6, offset: 0}, + dram: {name: 'dram', base: BASE_UNITS.MASS, prefixes: PREFIXES.NONE, value: 1.7718451953125e-3, offset: 0}, + ounce: {name: 'ounce', base: BASE_UNITS.MASS, prefixes: PREFIXES.NONE, value: 28.349523125e-3, offset: 0}, + poundmass: {name: 'poundmass', base: BASE_UNITS.MASS, prefixes: PREFIXES.NONE, value: 453.59237e-3, offset: 0}, + hundredweight: {name: 'hundredweight', base: BASE_UNITS.MASS, prefixes: PREFIXES.NONE, value: 45.359237, offset: 0}, + stick: {name: 'stick', base: BASE_UNITS.MASS, prefixes: PREFIXES.NONE, value: 115e-3, offset: 0}, - gr: {'name': 'gr', 'base': BASE_UNITS.MASS, 'prefixes': PREFIXES.NONE, 'value': 64.79891e-6, 'offset': 0}, - dr: {'name': 'dr', 'base': BASE_UNITS.MASS, 'prefixes': PREFIXES.NONE, 'value': 1.7718451953125e-3, 'offset': 0}, - oz: {'name': 'oz', 'base': BASE_UNITS.MASS, 'prefixes': PREFIXES.NONE, 'value': 28.349523125e-3, 'offset': 0}, - lbm: {'name': 'lbm', 'base': BASE_UNITS.MASS, 'prefixes': PREFIXES.NONE, 'value': 453.59237e-3, 'offset': 0}, - cwt: {'name': 'cwt', 'base': BASE_UNITS.MASS, 'prefixes': PREFIXES.NONE, 'value': 45.359237, 'offset': 0}, + gr: {name: 'gr', base: BASE_UNITS.MASS, prefixes: PREFIXES.NONE, value: 64.79891e-6, offset: 0}, + dr: {name: 'dr', base: BASE_UNITS.MASS, prefixes: PREFIXES.NONE, value: 1.7718451953125e-3, offset: 0}, + oz: {name: 'oz', base: BASE_UNITS.MASS, prefixes: PREFIXES.NONE, value: 28.349523125e-3, offset: 0}, + lbm: {name: 'lbm', base: BASE_UNITS.MASS, prefixes: PREFIXES.NONE, value: 453.59237e-3, offset: 0}, + cwt: {name: 'cwt', base: BASE_UNITS.MASS, prefixes: PREFIXES.NONE, value: 45.359237, offset: 0}, // Time - s: {'name': 's', 'base': BASE_UNITS.TIME, 'prefixes': PREFIXES.SHORT, 'value': 1, 'offset': 0}, - min: {'name': 'min', 'base': BASE_UNITS.TIME, 'prefixes': PREFIXES.NONE, 'value': 60, 'offset': 0}, - h: {'name': 'h', 'base': BASE_UNITS.TIME, 'prefixes': PREFIXES.NONE, 'value': 3600, 'offset': 0}, - second: {'name': 'second', 'base': BASE_UNITS.TIME, 'prefixes': PREFIXES.LONG, 'value': 1, 'offset': 0}, - sec: {'name': 'sec', 'base': BASE_UNITS.TIME, 'prefixes': PREFIXES.LONG, 'value': 1, 'offset': 0}, - minute: {'name': 'minute', 'base': BASE_UNITS.TIME, 'prefixes': PREFIXES.NONE, 'value': 60, 'offset': 0}, - hour: {'name': 'hour', 'base': BASE_UNITS.TIME, 'prefixes': PREFIXES.NONE, 'value': 3600, 'offset': 0}, - day: {'name': 'day', 'base': BASE_UNITS.TIME, 'prefixes': PREFIXES.NONE, 'value': 86400, 'offset': 0}, + s: {name: 's', base: BASE_UNITS.TIME, prefixes: PREFIXES.SHORT, value: 1, offset: 0}, + min: {name: 'min', base: BASE_UNITS.TIME, prefixes: PREFIXES.NONE, value: 60, offset: 0}, + h: {name: 'h', base: BASE_UNITS.TIME, prefixes: PREFIXES.NONE, value: 3600, offset: 0}, + second: {name: 'second', base: BASE_UNITS.TIME, prefixes: PREFIXES.LONG, value: 1, offset: 0}, + sec: {name: 'sec', base: BASE_UNITS.TIME, prefixes: PREFIXES.LONG, value: 1, offset: 0}, + minute: {name: 'minute', base: BASE_UNITS.TIME, prefixes: PREFIXES.NONE, value: 60, offset: 0}, + hour: {name: 'hour', base: BASE_UNITS.TIME, prefixes: PREFIXES.NONE, value: 3600, offset: 0}, + day: {name: 'day', base: BASE_UNITS.TIME, prefixes: PREFIXES.NONE, value: 86400, offset: 0}, // Angle - rad: {'name': 'rad', 'base': BASE_UNITS.ANGLE, 'prefixes': PREFIXES.NONE, 'value': 1, 'offset': 0}, + rad: {name: 'rad', base: BASE_UNITS.ANGLE, prefixes: PREFIXES.NONE, value: 1, offset: 0}, // deg = rad / (2*pi) * 360 = rad / 0.017453292519943295769236907684888 - deg: {'name': 'deg', 'base': BASE_UNITS.ANGLE, 'prefixes': PREFIXES.NONE, 'value': 0.017453292519943295769236907684888, 'offset': 0}, + deg: {name: 'deg', base: BASE_UNITS.ANGLE, prefixes: PREFIXES.NONE, value: 0.017453292519943295769236907684888, offset: 0}, // grad = rad / (2*pi) * 400 = rad / 0.015707963267948966192313216916399 - grad: {'name': 'grad', 'base': BASE_UNITS.ANGLE, 'prefixes': PREFIXES.NONE, 'value': 0.015707963267948966192313216916399, 'offset': 0}, + grad: {name: 'grad', base: BASE_UNITS.ANGLE, prefixes: PREFIXES.NONE, value: 0.015707963267948966192313216916399, offset: 0}, // cycle = rad / (2*pi) = rad / 6.2831853071795864769252867665793 - cycle: {'name': 'cycle', 'base': BASE_UNITS.ANGLE, 'prefixes': PREFIXES.NONE, 'value': 6.2831853071795864769252867665793, 'offset': 0}, + cycle: {name: 'cycle', base: BASE_UNITS.ANGLE, prefixes: PREFIXES.NONE, value: 6.2831853071795864769252867665793, offset: 0}, // Electric current - A: {'name': 'A', 'base': BASE_UNITS.CURRENT, 'prefixes': PREFIXES.SHORT, 'value': 1, 'offset': 0}, - ampere: {'name': 'ampere', 'base': BASE_UNITS.CURRENT, 'prefixes': PREFIXES.LONG, 'value': 1, 'offset': 0}, + A: {name: 'A', base: BASE_UNITS.CURRENT, prefixes: PREFIXES.SHORT, value: 1, offset: 0}, + ampere: {name: 'ampere', base: BASE_UNITS.CURRENT, prefixes: PREFIXES.LONG, value: 1, offset: 0}, // Temperature // K(C) = °C + 273.15 // K(F) = (°F + 459.67) / 1.8 // K(R) = °R / 1.8 - K: {'name': 'K', 'base': BASE_UNITS.TEMPERATURE, 'prefixes': PREFIXES.NONE, 'value': 1, 'offset': 0}, - degC: {'name': 'degC', 'base': BASE_UNITS.TEMPERATURE, 'prefixes': PREFIXES.NONE, 'value': 1, 'offset': 273.15}, - degF: {'name': 'degF', 'base': BASE_UNITS.TEMPERATURE, 'prefixes': PREFIXES.NONE, 'value': 1/1.8, 'offset': 459.67}, - degR: {'name': 'degR', 'base': BASE_UNITS.TEMPERATURE, 'prefixes': PREFIXES.NONE, 'value': 1/1.8, 'offset': 0}, - kelvin: {'name': 'kelvin', 'base': BASE_UNITS.TEMPERATURE, 'prefixes': PREFIXES.NONE, 'value': 1, 'offset': 0}, - celsius: {'name': 'celsius', 'base': BASE_UNITS.TEMPERATURE, 'prefixes': PREFIXES.NONE, 'value': 1, 'offset': 273.15}, - fahrenheit: {'name': 'fahrenheit', 'base': BASE_UNITS.TEMPERATURE, 'prefixes': PREFIXES.NONE, 'value': 1/1.8, 'offset': 459.67}, - rankine: {'name': 'rankine', 'base': BASE_UNITS.TEMPERATURE, 'prefixes': PREFIXES.NONE, 'value': 1/1.8, 'offset': 0}, + K: {name: 'K', base: BASE_UNITS.TEMPERATURE, prefixes: PREFIXES.NONE, value: 1, offset: 0}, + degC: {name: 'degC', base: BASE_UNITS.TEMPERATURE, prefixes: PREFIXES.NONE, value: 1, offset: 273.15}, + degF: {name: 'degF', base: BASE_UNITS.TEMPERATURE, prefixes: PREFIXES.NONE, value: 1/1.8, offset: 459.67}, + degR: {name: 'degR', base: BASE_UNITS.TEMPERATURE, prefixes: PREFIXES.NONE, value: 1/1.8, offset: 0}, + kelvin: {name: 'kelvin', base: BASE_UNITS.TEMPERATURE, prefixes: PREFIXES.NONE, value: 1, offset: 0}, + celsius: {name: 'celsius', base: BASE_UNITS.TEMPERATURE, prefixes: PREFIXES.NONE, value: 1, offset: 273.15}, + fahrenheit: {name: 'fahrenheit', base: BASE_UNITS.TEMPERATURE, prefixes: PREFIXES.NONE, value: 1/1.8, offset: 459.67}, + rankine: {name: 'rankine', base: BASE_UNITS.TEMPERATURE, prefixes: PREFIXES.NONE, value: 1/1.8, offset: 0}, // amount of substance - mol: {'name': 'mol', 'base': BASE_UNITS.AMOUNT_OF_SUBSTANCE, 'prefixes': PREFIXES.NONE, 'value': 1, 'offset': 0}, - mole: {'name': 'mole', 'base': BASE_UNITS.AMOUNT_OF_SUBSTANCE, 'prefixes': PREFIXES.NONE, 'value': 1, 'offset': 0}, + mol: {name: 'mol', base: BASE_UNITS.AMOUNT_OF_SUBSTANCE, prefixes: PREFIXES.NONE, value: 1, offset: 0}, + mole: {name: 'mole', base: BASE_UNITS.AMOUNT_OF_SUBSTANCE, prefixes: PREFIXES.NONE, value: 1, offset: 0}, // luminous intensity - cd: {'name': 'cd', 'base': BASE_UNITS.LUMINOUS_INTENSITY, 'prefixes': PREFIXES.NONE, 'value': 1, 'offset': 0}, - candela: {'name': 'candela', 'base': BASE_UNITS.LUMINOUS_INTENSITY, 'prefixes': PREFIXES.NONE, 'value': 1, 'offset': 0}, + cd: {name: 'cd', base: BASE_UNITS.LUMINOUS_INTENSITY, prefixes: PREFIXES.NONE, value: 1, offset: 0}, + candela: {name: 'candela', base: BASE_UNITS.LUMINOUS_INTENSITY, prefixes: PREFIXES.NONE, value: 1, offset: 0}, // TODO: units STERADIAN - //{'name': 'sr', 'base': BASE_UNITS.STERADIAN, 'prefixes': PREFIXES.NONE, 'value': 1, 'offset': 0}, - //{'name': 'steradian', 'base': BASE_UNITS.STERADIAN, 'prefixes': PREFIXES.NONE, 'value': 1, 'offset': 0}, + //{name: 'sr', base: BASE_UNITS.STERADIAN, prefixes: PREFIXES.NONE, value: 1, offset: 0}, + //{name: 'steradian', base: BASE_UNITS.STERADIAN, prefixes: PREFIXES.NONE, value: 1, offset: 0}, // Force - N: {'name': 'N', 'base': BASE_UNITS.FORCE, 'prefixes': PREFIXES.SHORT, 'value': 1, 'offset': 0}, - newton: {'name': 'newton', 'base': BASE_UNITS.FORCE, 'prefixes': PREFIXES.LONG, 'value': 1, 'offset': 0}, - lbf: {'name': 'lbf', 'base': BASE_UNITS.FORCE, 'prefixes': PREFIXES.NONE, 'value': 4.4482216152605, 'offset': 0}, - poundforce: {'name': 'poundforce', 'base': BASE_UNITS.FORCE, 'prefixes': PREFIXES.NONE, 'value': 4.4482216152605, 'offset': 0}, + N: {name: 'N', base: BASE_UNITS.FORCE, prefixes: PREFIXES.SHORT, value: 1, offset: 0}, + newton: {name: 'newton', base: BASE_UNITS.FORCE, prefixes: PREFIXES.LONG, value: 1, offset: 0}, + lbf: {name: 'lbf', base: BASE_UNITS.FORCE, prefixes: PREFIXES.NONE, value: 4.4482216152605, offset: 0}, + poundforce: {name: 'poundforce', base: BASE_UNITS.FORCE, prefixes: PREFIXES.NONE, value: 4.4482216152605, offset: 0}, // Binary - b: {'name': 'b', 'base': BASE_UNITS.BIT, 'prefixes': PREFIXES.BINARY_SHORT, 'value': 1, 'offset': 0}, - bits: {'name': 'bits', 'base': BASE_UNITS.BIT, 'prefixes': PREFIXES.BINARY_LONG, 'value': 1, 'offset': 0}, - B: {'name': 'B', 'base': BASE_UNITS.BIT, 'prefixes': PREFIXES.BINARY_SHORT, 'value': 8, 'offset': 0}, - bytes: {'name': 'bytes', 'base': BASE_UNITS.BIT, 'prefixes': PREFIXES.BINARY_LONG, 'value': 8, 'offset': 0} + b: {name: 'b', base: BASE_UNITS.BIT, prefixes: PREFIXES.BINARY_SHORT, value: 1, offset: 0}, + bits: {name: 'bits', base: BASE_UNITS.BIT, prefixes: PREFIXES.BINARY_LONG, value: 1, offset: 0}, + B: {name: 'B', base: BASE_UNITS.BIT, prefixes: PREFIXES.BINARY_SHORT, value: 8, offset: 0}, + bytes: {name: 'bytes', base: BASE_UNITS.BIT, prefixes: PREFIXES.BINARY_LONG, value: 8, offset: 0} }; // plurals @@ -827,6 +831,7 @@ var PLURALS = { }; for (var name in PLURALS) { + /* istanbul ignore next (we cannot really test next statement) */ if (PLURALS.hasOwnProperty(name)) { var unit = UNITS[PLURALS[name]]; var plural = Object.create(unit); @@ -851,8 +856,3 @@ Unit.UNITS = UNITS; // exports module.exports = Unit; - -// to trick my IDE which doesn't get it -exports.isUnit = Unit.isUnit; -exports.isPlainUnit = Unit.isPlainUnit; -exports.parse = Unit.parse; diff --git a/test/function/matrix/concat.test.js b/test/function/matrix/concat.test.js index 239f6cc5f..369eaf382 100644 --- a/test/function/matrix/concat.test.js +++ b/test/function/matrix/concat.test.js @@ -84,7 +84,7 @@ describe('concat', function() { it('should throw an error in case dimension mismatch', function() { assert.throws(function () {math.concat([1, 2], [[1,2], [3,4]])}, RangeError); - assert.throws(function () {math.concat([[1, 2]], [[1,2], [3,4]])}, /Dimensions mismatch/); + assert.throws(function () {math.concat([[1, 2]], [[1,2], [3,4]])}, /Dimension mismatch/); }); it('should throw an error in case of invalid type of argument', function() { diff --git a/test/type/Matrix.test.js b/test/type/Matrix.test.js index 36838df6f..d9defa710 100644 --- a/test/type/Matrix.test.js +++ b/test/type/Matrix.test.js @@ -107,6 +107,10 @@ describe('matrix', function() { assert.throws(function () {m.get([])}); }); + it('should throw an error in case of dimension mismatch', function() { + assert.throws(function () {m.get([0,2,0,2,0,2])}, /Dimension mismatch/); + }); + it('should throw an error when getting a value given a invalid index', function() { assert.throws(function () {m.get([1.2, 2])}); assert.throws(function () {m.get([1,-2])}); @@ -192,6 +196,17 @@ describe('matrix', function() { assert.throws(function () { m.subset([1]); }); }); + it('should throw an error in case of wrong number of arguments', function() { + var m = new Matrix(); + assert.throws(function () { m.subset();}, /Wrong number of arguments/); + assert.throws(function () { m.subset(1,2,3,4); }, /Wrong number of arguments/); + }); + + it('should throw an error in case of dimension mismatch', function() { + var m = new Matrix([[1,2,3],[4,5,6]]); + assert.throws(function () {m.subset(index([0,2]))}, /Dimension mismatch/); + }); + }); describe('set subset', function() { @@ -288,6 +303,20 @@ describe('matrix', function() { assert.deepEqual(m, res); }); + it ('should throw an error in case of wrong type of index', function () { + assert.throws(function () {new Matrix().subset('no index', 2)}, /Invalid index/) + }); + + it ('should throw an error in case of wrong size of submatrix', function () { + assert.throws(function () {new Matrix().subset(index(0), [2,3])}, /Dimension mismatch/) + }); + + it('should throw an error in case of dimension mismatch', function() { + var m = new Matrix([[1,2,3],[4,5,6]]); + assert.throws(function () {m.subset(index([0,2]), [100,100])}, /Dimension mismatch/); + assert.throws(function () {m.subset(index([0,2], [0,2]), [100,100])}, /Dimension mismatch/); + }); + }); describe('map', function() { diff --git a/test/type/Unit.test.js b/test/type/Unit.test.js index 348c231b8..9b6c8526c 100644 --- a/test/type/Unit.test.js +++ b/test/type/Unit.test.js @@ -1,91 +1,220 @@ var assert = require('assert'), approx = require('../../tools/approx'), - math = require('../../index')(); + Unit = require('../../lib/type/Unit'); describe('unit', function() { describe('constructor', function() { it('should create unit correctly', function() { - var unit1 = math.unit(5000, 'cm'); + var unit1 = new Unit(5000, 'cm'); assert.equal(unit1.value, 50); assert.equal(unit1.unit.name, 'm'); - unit1 = math.unit(5, 'kg'); + unit1 = new Unit(5, 'kg'); assert.equal(unit1.value, 5); assert.equal(unit1.unit.name, 'g'); - unit1 = math.unit(null, 'kg'); + unit1 = new Unit(null, 'kg'); assert.equal(unit1.value, null); assert.equal(unit1.unit.name, 'g'); }); it('should create square meter correctly', function() { - var unit1 = math.unit(0.000001, 'km2'); + var unit1 = new Unit(0.000001, 'km2'); assert.equal(unit1.value, 1); assert.equal(unit1.unit.name, 'm2'); }); it('should create cubic meter correctly', function() { - var unit1 = math.unit(0.000000001, 'km3'); + var unit1 = new Unit(0.000000001, 'km3'); assert.equal(unit1.value, 1); assert.equal(unit1.unit.name, 'm3'); }); - it('should throw an error if called with wrong arguments', function() { - assert.throws(function () { Unit(2, 'inch'); }); + it('should ignore properties on Object.prototype', function() { + Object.prototype.foo = Unit.UNITS['meter']; + + assert.throws(function () {new Unit(1, 'foo')}, /Unknown unit/); + + delete Object.prototype.foo; + }); + + it('should throw an error if called without new keyword', function() { + assert.throws(function () { + Unit(2, 'inch'); + }); + }); + + it('should throw an error if called with wrong type of arguments', function() { assert.throws(function () { new Unit('24', 'inch'); }); assert.throws(function () { new Unit(0, 'bla'); }); + assert.throws(function () { new Unit(4, ''); }); assert.throws(function () { new Unit(0, 3); }); }); }); - describe('isPlainUnit', function() { + describe('isValuelessUnit', function() { it('should return true if the string is a plain unit', function() { - assert.equal(math.type.Unit.isPlainUnit('cm'), true); - assert.equal(math.type.Unit.isPlainUnit('inch'), true); - assert.equal(math.type.Unit.isPlainUnit('kb'), true); + assert.equal(Unit.isValuelessUnit('cm'), true); + assert.equal(Unit.isValuelessUnit('inch'), true); + assert.equal(Unit.isValuelessUnit('kb'), true); }); it('should return false if the unit is not a plain unit', function() { - assert.equal(math.type.Unit.isPlainUnit('bla'), false); - assert.equal(math.type.Unit.isPlainUnit('5cm'), false); + assert.equal(Unit.isValuelessUnit('bla'), false); + assert.equal(Unit.isValuelessUnit('5cm'), false); + }); + + }); + + describe('isUnit', function() { + + it('should test whether a variable is a unit', function() { + assert.equal(Unit.isUnit(new Date()), false); + assert.equal(Unit.isUnit('string'), false); + assert.equal(Unit.isUnit(new Unit(2, 'km')), true); + assert.equal(Unit.isUnit(new Unit(null, 'km')), true); + }); + + }); + + describe('hasBase', function() { + + it('should test whether a unit has a certain base unit', function() { + assert.equal(new Unit(5, 'cm').hasBase(Unit.BASE_UNITS.ANGLE), false); + assert.equal(new Unit(5, 'cm').hasBase(Unit.BASE_UNITS.LENGTH), true); + }); + + }); + + describe('equalBase', function() { + + it('should test whether two units have the same base unit', function() { + assert.equal(new Unit(5, 'cm').equalBase(new Unit(10, 'm')), true); + assert.equal(new Unit(5, 'cm').equalBase(new Unit(10, 'kg')), false); + }); + + }); + + describe('equals', function() { + + it('should test whether two units are equal', function() { + assert.equal(new Unit(100, 'cm').equals(new Unit(1, 'm')), true); + assert.equal(new Unit(100, 'cm').equals(new Unit(2, 'm')), false); + assert.equal(new Unit(100, 'cm').equals(new Unit(1, 'kg')), false); + }); + + }); + + describe('clone', function() { + + it('should clone a unit', function() { + var u1 = new Unit(100, 'cm'); + var u2 = u1.clone(); + assert(u1 !== u2); + assert.deepEqual(u1, u2); + + var u3 = new Unit(100, 'cm').to('inch'); + var u4 = u3.clone(); + assert(u3 !== u4); + assert.deepEqual(u3, u4); + + var u5 = new Unit(null, 'cm').to('inch'); + var u6 = u5.clone(); + assert(u5 !== u6); + assert.deepEqual(u5, u6); + }); }); describe('toNumber', function() { - it ('convert a unit to a number', function () { - var u = math.unit(5000, 'cm'); + it ('should convert a unit to a number', function () { + var u = new Unit(5000, 'cm'); approx.equal(u.toNumber('mm'), 50000); - approx.equal(math.unit('5.08 cm').toNumber('inch'), 2); + approx.equal(new Unit(5.08, 'cm').toNumber('inch'), 2); + }); + + it ('should convert a unit with fixed prefix to a number', function () { + var u1 = new Unit(5000, 'cm'); + var u2 = u1.to('km'); + approx.equal(u2.toNumber('mm'), 50000); + }); + }); + + describe('to', function() { + + it ('should convert a unit to a fixed unitName', function () { + var u1 = new Unit(5000, 'cm'); + assert.equal(u1.value, 50); + assert.equal(u1.unit.name, 'm'); + assert.equal(u1.prefix.name, 'c'); + assert.equal(u1.fixPrefix, false); + + var u2 = u1.to('inch'); + assert.notStrictEqual(u1, u2); // u2 must be a clone + assert.equal(u2.value, 50); + assert.equal(u2.unit.name, 'inch'); + assert.equal(u2.prefix.name, ''); + assert.equal(u2.fixPrefix, true); + }); + + it ('should convert a unit to a fixed unit', function () { + var u1 = new Unit(5000, 'cm'); + assert.equal(u1.value, 50); + assert.equal(u1.unit.name, 'm'); + assert.equal(u1.prefix.name, 'c'); + assert.equal(u1.fixPrefix, false); + + var u2 = u1.to(new Unit(null, 'km')); + assert.notStrictEqual(u1, u2); // u2 must be a clone + assert.equal(u2.value, 50); + assert.equal(u2.unit.name, 'm'); + assert.equal(u2.prefix.name, 'k'); + assert.equal(u2.fixPrefix, true); + }); + + it ('should throw an error when converting to an incompatible unit', function () { + var u1 = new Unit(5000, 'cm'); + assert.throws(function () {u1.to('kg')}, /Units do not match/); + }); + + it ('should throw an error when converting to a unit having a value', function () { + var u1 = new Unit(5000, 'cm'); + assert.throws(function () {u1.to(new Unit(4, 'm'))}, /Cannot convert to a unit with a value/); + }); + + it ('should throw an error when converting to an unsupported type of argument', function () { + var u1 = new Unit(5000, 'cm'); + assert.throws(function () {u1.to(new Date())}, /String or Unit expected as parameter/); }); }); describe('toString', function() { it('should convert to string properly', function() { - assert.equal(math.unit(5000, 'cm').toString(), '50 m'); - assert.equal(math.unit(5, 'kg').toString(), '5 kg'); - assert.equal(math.unit(2/3, 'm').toString(), '0.6666666666666666 m'); + assert.equal(new Unit(5000, 'cm').toString(), '50 m'); + assert.equal(new Unit(5, 'kg').toString(), '5 kg'); + assert.equal(new Unit(2/3, 'm').toString(), '0.6666666666666666 m'); }); it('should render with the best prefix', function() { - assert.equal(math.unit('0.001m').toString(), '1 mm'); - assert.equal(math.unit('0.01m').toString(), '10 mm'); - assert.equal(math.unit('0.1m').toString(), '100 mm'); - assert.equal(math.unit('0.5m').toString(), '500 mm'); - assert.equal(math.unit('0.6m').toString(), '0.6 m'); - assert.equal(math.unit('1m').toString(), '1 m'); - assert.equal(math.unit('10m').toString(), '10 m'); - assert.equal(math.unit('100m').toString(), '100 m'); - assert.equal(math.unit('300m').toString(), '300 m'); - assert.equal(math.unit('500m').toString(), '500 m'); - assert.equal(math.unit('600m').toString(), '0.6 km'); - assert.equal(math.unit('1000m').toString(), '1 km'); + assert.equal(new Unit(0.001 ,'m').toString(), '1 mm'); + assert.equal(new Unit(0.01 ,'m').toString(), '10 mm'); + assert.equal(new Unit(0.1 ,'m').toString(), '100 mm'); + assert.equal(new Unit(0.5 ,'m').toString(), '500 mm'); + assert.equal(new Unit(0.6 ,'m').toString(), '0.6 m'); + assert.equal(new Unit(1 ,'m').toString(), '1 m'); + assert.equal(new Unit(10 ,'m').toString(), '10 m'); + assert.equal(new Unit(100 ,'m').toString(), '100 m'); + assert.equal(new Unit(300 ,'m').toString(), '300 m'); + assert.equal(new Unit(500 ,'m').toString(), '500 m'); + assert.equal(new Unit(600 ,'m').toString(), '0.6 km'); + assert.equal(new Unit(1000 ,'m').toString(), '1 km'); }); }); @@ -93,9 +222,27 @@ describe('unit', function() { describe('format', function () { it('should format units with given precision', function() { - assert.equal(math.unit(2/3, 'm').format(3), '0.667 m'); - assert.equal(math.unit(2/3, 'm').format(4), '0.6667 m'); - assert.equal(math.unit(2/3, 'm').format(), '0.6666666666666666 m'); + assert.equal(new Unit(2/3, 'm').format(3), '0.667 m'); + assert.equal(new Unit(2/3, 'm').format(4), '0.6667 m'); + assert.equal(new Unit(2/3, 'm').format(), '0.6666666666666666 m'); + }); + + it('should format a unit without value', function() { + assert.equal(new Unit(null, 'cm').format(), 'cm'); + assert.equal(new Unit(null, 'm').format(), 'm'); + }); + + it('should format a unit with fixed prefix and without value', function() { + assert.equal(new Unit(null, 'cm').to('km').format(), 'km'); + assert.equal(new Unit(null, 'cm').to('inch').format(), 'inch'); + }); + + it('should ignore properties in Object.prototype when finding the best prefix', function() { + Object.prototype.foo = 'bar'; + + assert.equal(new Unit(5e5, 'cm').format(), '5 km'); + + delete Object.prototype.foo; }); }); @@ -105,59 +252,90 @@ describe('unit', function() { it('should parse units correctly', function() { var unit1; - unit1 = math.unit('5kg'); + unit1 = Unit.parse('5kg'); assert.equal(unit1.value, 5); assert.equal(unit1.unit.name, 'g'); assert.equal(unit1.prefix.name, 'k'); - unit1 = math.unit('5 kg'); + unit1 = Unit.parse('5 kg'); assert.equal(unit1.value, 5); assert.equal(unit1.unit.name, 'g'); assert.equal(unit1.prefix.name, 'k'); - unit1 = math.unit(' 5 kg '); + unit1 = Unit.parse(' 5 kg '); assert.equal(unit1.value, 5); assert.equal(unit1.unit.name, 'g'); assert.equal(unit1.prefix.name, 'k'); - unit1 = math.unit('5e-3kg'); + unit1 = Unit.parse('5e-3kg'); assert.equal(unit1.value, 0.005); assert.equal(unit1.unit.name, 'g'); assert.equal(unit1.prefix.name, 'k'); - unit1 = math.unit('5e+3kg'); + unit1 = Unit.parse('5e+3kg'); assert.equal(unit1.value, 5000); assert.equal(unit1.unit.name, 'g'); assert.equal(unit1.prefix.name, 'k'); - unit1 = math.unit('-5kg'); + unit1 = Unit.parse('5e3kg'); + assert.equal(unit1.value, 5000); + assert.equal(unit1.unit.name, 'g'); + assert.equal(unit1.prefix.name, 'k'); + + unit1 = Unit.parse('-5kg'); assert.equal(unit1.value, -5); assert.equal(unit1.unit.name, 'g'); assert.equal(unit1.prefix.name, 'k'); - unit1 = math.unit('-5mg'); + unit1 = Unit.parse('+5kg'); + assert.equal(unit1.value, 5); + assert.equal(unit1.unit.name, 'g'); + assert.equal(unit1.prefix.name, 'k'); + + unit1 = Unit.parse('.5kg'); + assert.equal(unit1.value, .5); + assert.equal(unit1.unit.name, 'g'); + assert.equal(unit1.prefix.name, 'k'); + + unit1 = Unit.parse('-5mg'); assert.equal(unit1.value, -0.000005); assert.equal(unit1.unit.name, 'g'); assert.equal(unit1.prefix.name, 'm'); + unit1 = Unit.parse('5.2mg'); + approx.equal(unit1.value, 0.0000052); + assert.equal(unit1.unit.name, 'g'); + assert.equal(unit1.prefix.name, 'm'); }); + it('should return null when parsing an invalid unit', function() { + assert.equal(Unit.parse('.meter'), null); + assert.equal(Unit.parse('5e'), null); + assert.equal(Unit.parse('5e. meter'), null); + assert.equal(Unit.parse('5e1.3 meter'), null); + assert.equal(Unit.parse('5'), null); + assert.equal(Unit.parse(''), null); + }); + + it('should return null when parsing an invalid type of argument', function() { + assert.equal(Unit.parse(123), null); + }); }); describe('plurals', function() { it('should support plurals', function () { - var unit1 = math.unit('5 meters'); + var unit1 = new Unit(5, 'meters'); assert.equal(unit1.value, 5); assert.equal(unit1.unit.name, 'meters'); assert.equal(unit1.prefix.name, ''); - var unit2 = math.unit('5 kilometers'); + var unit2 = new Unit(5, 'kilometers'); assert.equal(unit2.value, 5000); assert.equal(unit2.unit.name, 'meters'); assert.equal(unit2.prefix.name, 'kilo'); - var unit3 = math.unit('5 inches'); + var unit3 = new Unit(5, 'inches'); approx.equal(unit3.value, 0.127); assert.equal(unit3.unit.name, 'inches'); assert.equal(unit3.prefix.name, ''); @@ -168,17 +346,17 @@ describe('unit', function() { describe('aliases', function() { it('should support aliases', function () { - var unit1 = math.unit('5 lt'); + var unit1 = new Unit(5, 'lt'); assert.equal(unit1.value, 5e-3); assert.equal(unit1.unit.name, 'l'); assert.equal(unit1.prefix.name, ''); - var unit2 = math.unit('1 lb'); + var unit2 = new Unit(1, 'lb'); assert.equal(unit2.value, 453.59237e-3); assert.equal(unit2.unit.name, 'lbm'); assert.equal(unit2.prefix.name, ''); }); }); - // TODO: extensively test Unit + // TODO: test the value of each of the available units... }); \ No newline at end of file From 721f21574e1f10eb4c86eef5b10f165cbf29abfe Mon Sep 17 00:00:00 2001 From: josdejong Date: Thu, 3 Apr 2014 22:23:35 +0200 Subject: [PATCH 06/48] Some more unit tests --- lib/function/arithmetic/mod.js | 8 ++++---- test/expression/parse.test.js | 6 +++++- test/function/arithmetic/compare.test.js | 2 +- test/function/arithmetic/mod.test.js | 14 ++++++++++++++ test/function/utils/ifElse.test.js | 23 +++++++++++++++++++++-- test/function/utils/import.test.js | 1 - 6 files changed, 45 insertions(+), 9 deletions(-) diff --git a/lib/function/arithmetic/mod.js b/lib/function/arithmetic/mod.js index e3ed2f477..4c6a18d82 100644 --- a/lib/function/arithmetic/mod.js +++ b/lib/function/arithmetic/mod.js @@ -46,10 +46,10 @@ module.exports = function (math) { } if (y instanceof BigNumber) { - return x.mod(y); + return y.isZero() ? x : x.mod(y); } - // downgrade to Number + // downgrade x to Number return mod(toNumber(x), y); } if (y instanceof BigNumber) { @@ -62,10 +62,10 @@ module.exports = function (math) { } if (x instanceof BigNumber) { - return x.mod(y) + return y.isZero() ? x : x.mod(y); } - // downgrade to Number + // downgrade y to Number return mod(x, toNumber(y)); } diff --git a/test/expression/parse.test.js b/test/expression/parse.test.js index fd97b0ca3..0f45f7997 100644 --- a/test/expression/parse.test.js +++ b/test/expression/parse.test.js @@ -679,7 +679,7 @@ describe('parse', function() { assert.equal(parseAndEval('2 != 2'), false); }); - it('should parse a ? b : c', function() { + it('should parse contitional expression a ? b : c', function() { assert.equal(parseAndEval('2 ? true : false'), true); assert.equal(parseAndEval('0 ? true : false'), false); assert.equal(parseAndEval('false ? true : false'), false); @@ -690,6 +690,10 @@ describe('parse', function() { assert.equal(parseAndEval('0 > 0 ? 1 : 0 < 0 ? -1 : 0'), 0); }); + it('should throw an error when false part of contitional expression is missing', function() { + assert.throws(function() {parseAndEval('2 ? true')}, /False part of conditional expression expected/); + }); + it('should parse : (range)', function() { assert.ok(parseAndEval('2:5') instanceof Matrix); assert.deepEqual(parseAndEval('2:5'), new Matrix([2,3,4,5])); diff --git a/test/function/arithmetic/compare.test.js b/test/function/arithmetic/compare.test.js index 55d905da3..e6ecabe6c 100644 --- a/test/function/arithmetic/compare.test.js +++ b/test/function/arithmetic/compare.test.js @@ -56,7 +56,7 @@ describe('compare', function() { it('should add two measures of the same unit', function() { assert.equal(compare(unit('100cm'), unit('10inch')), 1); assert.equal(compare(unit('99cm'), unit('1m')), -1); - //assert.equal(compare(unit('100cm'), unit('1m')), bignumber(0)); // dangerous, round-off errors + assert.equal(compare(unit('1m'), unit('1m')), bignumber(0)); assert.equal(compare(unit('101cm'), unit('1m')), 1); }); diff --git a/test/function/arithmetic/mod.test.js b/test/function/arithmetic/mod.test.js index 2f4d7be58..20ec49a07 100644 --- a/test/function/arithmetic/mod.test.js +++ b/test/function/arithmetic/mod.test.js @@ -20,6 +20,7 @@ describe('mod', function() { assert.equal(mod(0, 1), 0); assert.equal(mod(1, 0), 1); assert.equal(mod(0, 0), 0); + assert.equal(mod(7, 0), 7); approx.equal(mod(7, 2), 1); approx.equal(mod(9, 3), 0); @@ -39,8 +40,15 @@ describe('mod', function() { assert.throws(function () {mod(1,2,3)}, math.error.ArgumentsError); }); + it('should throw an error if used with wrong type of arguments', function() { + assert.throws(function () {mod(1, 'string')}, math.error.UnsupportedTypeError); + assert.throws(function () {mod('string', bignumber(2))}, math.error.UnsupportedTypeError); + }); + it('should calculate the modulus of bignumbers', function() { assert.deepEqual(mod(bignumber(7), bignumber(2)), bignumber(1)); + assert.deepEqual(mod(bignumber(7), bignumber(0)), bignumber(7)); + assert.deepEqual(mod(bignumber(0), bignumber(3)), bignumber(0)); assert.deepEqual(mod(bignumber(7), bignumber(2)), bignumber(1)); assert.deepEqual(mod(bignumber(8), bignumber(3)).valueOf(), bignumber(2).valueOf()); }); @@ -55,7 +63,11 @@ describe('mod', function() { it('should calculate the modulus of mixed numbers and bignumbers', function() { assert.deepEqual(mod(bignumber(7), 2), bignumber(1)); + assert.deepEqual(mod(bignumber(7), 0), bignumber(7)); assert.deepEqual(mod(8, bignumber(3)), bignumber(2)); + assert.deepEqual(mod(7, bignumber(0)), bignumber(7)); + assert.deepEqual(mod(bignumber(0), 3), bignumber(0)); + assert.deepEqual(mod(bignumber(7), 0), bignumber(7)); approx.equal(mod(7/3, bignumber(2)), 1/3); approx.equal(mod(7/3, 1/3), 0); @@ -64,7 +76,9 @@ describe('mod', function() { it('should calculate the modulus of mixed booleans and bignumbers', function() { assert.deepEqual(mod(bignumber(7), true), bignumber(0)); + assert.deepEqual(mod(bignumber(7), false), bignumber(7)); assert.deepEqual(mod(true, bignumber(3)), bignumber(1)); + assert.deepEqual(mod(false, bignumber(3)), bignumber(0)); }); it('should throw an error if used on complex numbers', function() { diff --git a/test/function/utils/ifElse.test.js b/test/function/utils/ifElse.test.js index 10f1cc2f0..2aa3954e4 100644 --- a/test/function/utils/ifElse.test.js +++ b/test/function/utils/ifElse.test.js @@ -24,6 +24,13 @@ describe('ifElse', function() { assert.equal(ifElse(math.bignumber(0), 1, 0), 0); }); + it('should evaluate complex number conditions', function() { + assert.equal(ifElse(math.complex(2, 3), 1, 0), 1); + assert.equal(ifElse(math.complex(2, 0), 1, 0), 1); + assert.equal(ifElse(math.complex(0, 3), 1, 0), 1); + assert.equal(ifElse(math.complex(0, 0), 1, 0), 0); + }); + it('should evaluate string conditions', function() { assert.equal(ifElse('hello', 1, 0), 1); assert.equal(ifElse('', 1, 0), 0); @@ -67,6 +74,18 @@ describe('ifElse', function() { math.matrix([[5,6],[7,8]])); }); + it('should throw an error when matrix dimensions mismatch', function() { + assert.throws(function () { + ifElse(math.matrix([[1, 1], [1, 1]]), math.matrix([[1,2,3],[4,5,6]]), 1); + }); + assert.throws(function () { + ifElse(math.matrix([[1, 1], [1, 1]]), 1, math.matrix([[1,2,3],[4,5,6]])); + }); + assert.throws(function () { + ifElse(math.matrix([[1, 1], [1, 1]]), 1, math.matrix([1,2])); + }); + }); + it('should throw an error if called with invalid number of arguments', function() { assert.throws(function() { ifElse(true); }); assert.throws(function() { ifElse(true, true); }); @@ -74,8 +93,8 @@ describe('ifElse', function() { }); it('should throw an error if called with invalid type of arguments', function() { - assert.throws(function() { ifElse(new Date()); }); - assert.throws(function() { ifElse(/regexp/); }); + assert.throws(function() { ifElse(new Date(), 1, 0); }, math.type.UnsupportedTypeError); + assert.throws(function() { ifElse(/regexp/, 1, 0); }, math.type.UnsupportedTypeError); }); }); diff --git a/test/function/utils/import.test.js b/test/function/utils/import.test.js index 6ad72c64c..8d5194e1f 100644 --- a/test/function/utils/import.test.js +++ b/test/function/utils/import.test.js @@ -102,7 +102,6 @@ describe('import', function() { }); it.skip('should throw an error when trying to load a module when no module loader is available', function () { - // TODO: how to temporarily override the global function require? var orig = require; require = undefined; From 754b33b983db59363ebd2c4d49d1b2d4ce5ee4d2 Mon Sep 17 00:00:00 2001 From: Finn Date: Fri, 4 Apr 2014 01:21:08 +0200 Subject: [PATCH 07/48] Add fromPolar and math.complex with polar input #76 --- lib/function/construction/complex.js | 5 ++++ lib/type/Complex.js | 31 ++++++++++++++++++++++ test/function/construction/complex.test.js | 5 ++++ test/type/Complex.test.js | 31 +++++++++++++++++++++- 4 files changed, 71 insertions(+), 1 deletion(-) diff --git a/lib/function/construction/complex.js b/lib/function/construction/complex.js index 74dafb0e3..9db363b54 100644 --- a/lib/function/construction/complex.js +++ b/lib/function/construction/complex.js @@ -76,6 +76,11 @@ module.exports = function (math) { return collection.deepMap(arg, complex); } + if(typeof arg === 'object' && 'r' in arg && 'phi' in arg) { + // polar coordinates + return Complex.fromPolar(arg.r, arg.phi); + } + throw new TypeError('Two numbers or a single string expected in function complex'); case 2: diff --git a/lib/type/Complex.js b/lib/type/Complex.js index 35f5e374a..34138b57c 100644 --- a/lib/type/Complex.js +++ b/lib/type/Complex.js @@ -1,7 +1,9 @@ var util = require('../util/index'), + Unit = require('./Unit'), number = util.number, isNumber = util.number.isNumber, + isUnit = Unit.isUnit, isString = util.string.isString; /** @@ -272,6 +274,35 @@ Complex.parse = function parse (str) { return null; }; +/** + * Create a complex number from polar coordinates + * @return {Complex} + */ +Complex.fromPolar = function fromPolar(args) { + switch (arguments.length) { + case 1: + var arg = arguments[0]; + if(typeof arg === 'object') { + return Complex.fromPolar(arg.r, arg.phi); + } + throw new TypeError('Input has to be an object with r and phi keys.'); + case 2: + var r = arguments[0], + phi = arguments[1]; + if(isNumber(r)) { + if(isNumber(phi) || (isUnit(phi) && phi.hasBase(Unit.BASE_UNITS.ANGLE))) { + return new Complex(r * math.cos(phi), r * math.sin(phi)); + } else { + throw new TypeError('Phi is not a number nor an angle unit.'); + } + } else { + throw new TypeError('Radius r is not a number.'); + } + default: + throw new math.error.ArgumentsError('fromPolar', arguments.length, 1, 2); + } +} + /** * Create a copy of the complex value * @return {Complex} clone diff --git a/test/function/construction/complex.test.js b/test/function/construction/complex.test.js index 82e9a781e..c25b9c3b1 100644 --- a/test/function/construction/complex.test.js +++ b/test/function/construction/complex.test.js @@ -39,6 +39,11 @@ describe('complex', function() { assert.deepEqual(complex([2, 1, complex(2, 3)]), result); }); + it('should accept polar coordinates as input', function() { + var polar = complex({r: 1, phi: 1}); + assert.deepEqual(polar, new math.type.Complex.fromPolar(1, 1)); + }); + it('should throw an error if called with a string', function() { assert.throws(function () {complex('no valid complex number')}, SyntaxError); }); diff --git a/test/type/Complex.test.js b/test/type/Complex.test.js index 760109db6..c46575705 100644 --- a/test/type/Complex.test.js +++ b/test/type/Complex.test.js @@ -1,7 +1,8 @@ // test data type Complex var assert = require('assert'), - Complex = require('../../lib/type/Complex'); + Complex = require('../../lib/type/Complex'), + math = require('../../index')(); describe('Complex', function () { @@ -182,4 +183,32 @@ describe('Complex', function () { }); + describe('fromPolar', function() { + it('should save polar coordinates input correctly', function() { + var complex1 = Complex.fromPolar({r: 0, phi: 4}); + var complex2 = Complex.fromPolar({r: 5, phi: 0}); + var complex3 = Complex.fromPolar({r: 1, phi: math.pi}); + var complex4 = Complex.fromPolar({r: 3, phi: math.pi / 2}); + assertComplex(complex1, 0, 0); + assertComplex(complex2, 5, 0); + assert.equal(complex3.re, -1); + assert.equal(complex4.im, 3); + }); + + it('should have the same value for the different import ways', function() { + var way1 = Complex.fromPolar(1, 1); + var way2 = Complex.fromPolar({r: 1, phi: 1}); + assert(way1.equals(way2)); + }); + + it('should accept angle units for phi properly', function() { + var fromDeg = Complex.fromPolar(1, math.unit('90deg')), + fromRad = Complex.fromPolar(1, math.unit('0rad')), + fromGrad = Complex.fromPolar(1, math.unit('100grad')); + assert.equal(fromDeg.im, 1); + assert.equal(fromGrad.im, 1); + assert.equal(fromRad.im, 0); + + }); + }); }); \ No newline at end of file From d19e7ea570133afa841a31319684e8eceaccbc86 Mon Sep 17 00:00:00 2001 From: josdejong Date: Fri, 4 Apr 2014 21:08:33 +0200 Subject: [PATCH 08/48] Switched to module `decimal.js` for BigNumber support, instead of `bignumber.js`. --- HISTORY.md | 4 +- docs/configuration.md | 15 +-- docs/datatypes/bignumbers.md | 40 ++++---- docs/datatypes/index.md | 2 +- docs/datatypes/numbers.md | 6 +- docs/expressions.md | 6 +- docs/index.md | 2 +- examples/bignumbers.js | 16 ++-- lib/expression/node/ConstantNode.js | 2 +- lib/expression/node/IndexNode.js | 12 +-- lib/expression/node/ParamsNode.js | 2 +- lib/expression/node/RangeNode.js | 2 +- lib/expression/node/UnitNode.js | 2 +- lib/expression/node/UpdateNode.js | 2 +- lib/function/arithmetic/abs.js | 2 +- lib/function/arithmetic/add.js | 2 +- lib/function/arithmetic/ceil.js | 2 +- lib/function/arithmetic/compare.js | 2 +- lib/function/arithmetic/cube.js | 2 +- lib/function/arithmetic/divide.js | 2 +- lib/function/arithmetic/equal.js | 2 +- lib/function/arithmetic/exp.js | 2 +- lib/function/arithmetic/fix.js | 2 +- lib/function/arithmetic/floor.js | 2 +- lib/function/arithmetic/gcd.js | 2 +- lib/function/arithmetic/larger.js | 2 +- lib/function/arithmetic/largereq.js | 2 +- lib/function/arithmetic/lcm.js | 2 +- lib/function/arithmetic/log.js | 2 +- lib/function/arithmetic/log10.js | 2 +- lib/function/arithmetic/mod.js | 2 +- lib/function/arithmetic/multiply.js | 2 +- lib/function/arithmetic/pow.js | 2 +- lib/function/arithmetic/round.js | 6 +- lib/function/arithmetic/sign.js | 2 +- lib/function/arithmetic/smaller.js | 2 +- lib/function/arithmetic/smallereq.js | 2 +- lib/function/arithmetic/sqrt.js | 2 +- lib/function/arithmetic/square.js | 2 +- lib/function/arithmetic/subtract.js | 2 +- lib/function/arithmetic/unary.js | 2 +- lib/function/arithmetic/unequal.js | 2 +- lib/function/arithmetic/xgcd.js | 2 +- lib/function/complex/arg.js | 2 +- lib/function/complex/conj.js | 2 +- lib/function/complex/im.js | 2 +- lib/function/complex/re.js | 2 +- lib/function/construction/bignumber.js | 3 +- lib/function/construction/boolean.js | 2 +- lib/function/construction/complex.js | 2 +- lib/function/construction/index.js | 2 +- lib/function/construction/number.js | 2 +- lib/function/construction/unit.js | 2 +- lib/function/matrix/eye.js | 2 +- lib/function/matrix/ones.js | 2 +- lib/function/matrix/range.js | 2 +- lib/function/matrix/resize.js | 2 +- lib/function/matrix/size.js | 2 +- lib/function/matrix/zeros.js | 2 +- lib/function/probability/combinations.js | 4 +- lib/function/probability/factorial.js | 4 +- lib/function/probability/permutations.js | 4 +- lib/function/statistics/median.js | 2 +- lib/function/statistics/var.js | 2 +- lib/function/trigonometry/acos.js | 2 +- lib/function/trigonometry/asin.js | 2 +- lib/function/trigonometry/atan.js | 2 +- lib/function/trigonometry/atan2.js | 2 +- lib/function/trigonometry/cos.js | 2 +- lib/function/trigonometry/cot.js | 2 +- lib/function/trigonometry/csc.js | 2 +- lib/function/trigonometry/sec.js | 2 +- lib/function/trigonometry/sin.js | 2 +- lib/function/trigonometry/tan.js | 2 +- lib/function/utils/ifElse.js | 2 +- lib/function/utils/typeof.js | 2 +- lib/math.js | 15 +-- lib/type/BigNumber.js | 1 + lib/util/number.js | 16 ++-- lib/util/string.js | 2 +- package.json | 2 +- test/expression/node/ConstantNode.test.js | 2 +- test/function/arithmetic/ceil.test.js | 20 ++-- test/function/arithmetic/fix.test.js | 20 ++-- test/function/arithmetic/floor.test.js | 20 ++-- test/function/construction/bignumber.test.js | 2 +- test/function/utils/format.test.js | 7 +- test/util/number.test.js | 98 +++++++++----------- 88 files changed, 219 insertions(+), 234 deletions(-) create mode 100644 lib/type/BigNumber.js diff --git a/HISTORY.md b/HISTORY.md index 8c5d78e1f..da104c5d8 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,8 +2,10 @@ https://github.com/josdejong/mathjs -## not yet released, version 0.19.1 +## not yet released, version 0.20.0 +- Switched to module `decimal.js` for BigNumber support, instead of + `bignumber.js`. - Implemented conditional operator `a ? b : c` in expression parser. - Improved function `ifElse`, is now specified for special data types too. - Minor bug fixes. diff --git a/docs/configuration.md b/docs/configuration.md index eb7da5f40..bcecc4303 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -16,19 +16,14 @@ Available configuration settings are: like `eval `which cannot determine the correct type of output from the functions input. For most functions though, the type of output is determined from the the input: a number as input will return a number as output, - a bignumber as input returns a bignumber as output. + a BigNumber as input returns a BigNumber as output. Available values are: `'number'` (default) or `'bignumber'`. - Big numbers have higher precision than the default numbers of JavaScript. + BigNumbers have higher precision than the default numbers of JavaScript. - `decimals`. The maximum number of decimal places behind the decimal - point (not the number of significant digits). Only applies to big numbers, + point (not the number of significant digits). Only applies to BigNumbers, not to numbers. Default value is 20. - *Important: This setting is applied application wide to all BigNumbers. - Behind the scenes, this setting is applied as the global `DECIMAL_PLACES` - setting of the [bignumber.js](https://github.com/MikeMcl/bignumber.js) - library used by math.js.* - ## Examples @@ -72,13 +67,13 @@ math2.config({ math2.range(0, 4); // Matrix [0, 1, 2, 3] ``` -### Configuration for big numbers +### Configuration for BigNumbers ```js // load the library var mathjs = require('mathjs'); -// use big numbers by default +// use BigNumbers by default var math3 = mathjs({ number: 'bignumber', decimals: 32 diff --git a/docs/datatypes/bignumbers.md b/docs/datatypes/bignumbers.md index 07b6537f6..7f8c015ef 100644 --- a/docs/datatypes/bignumbers.md +++ b/docs/datatypes/bignumbers.md @@ -1,33 +1,36 @@ -# Big Numbers +# BigNumbers -For calculations with an arbitrary precision, math.js supports BigNumber. -BigNumber is powered by the the library -[bignumber.js](https://github.com/MikeMcl/bignumber.js/). +For calculations with an arbitrary precision, math.js supports a `BigNumber` +data type. BigNumber support is powered by +[decimal.js](https://github.com/MikeMcl/decimal.js/). -A big number can be created using the function `bignumber`: +A BigNumber can be created using the function `bignumber`: ```js math.bignumber('2.3e+500'); // BigNumber, 2.3e+500 ``` Most functions can determine the type of output from the type of input: -a number as input will return a number as output, a bignumber as input returns -a bignumber as output. Functions which cannot determine the type of output +a number as input will return a number as output, a BigNumber as input returns +a BigNumber as output. Functions which cannot determine the type of output from the input (for example `math.eval`) use the default number type `number`, -which can be configured when instantiating math.js. To configure the use of big -numbers instead of [numbers](numbers.md) by default, configure math.js like: +which can be configured when instantiating math.js. To configure the use of +BigNumbers instead of [numbers](numbers.md) by default, configure math.js like: ```js var mathjs = require('mathjs'), math = mathjs({ number: 'bignumber', // Default type of number: 'number' (default) or 'bignumber' - decimals: 20 // Number decimal places behind the dot for big numbers + decimals: 20 // Number of decimal places behind the dot for BigNumbers }); // use math math.eval('0.1 + 0.2'); // BigNumber, 0.3 ``` +The default precision for BigNumber is 20 digits, and can be configured with +the option `decimals`. + *Important: BigNumber is not supported by the following functions: exp, gcd, lcm, log, log10, xgcd, @@ -45,29 +48,18 @@ precision, it is less likely that round-off errors occur: math.add(0.1, 0.2); // Number, 0.30000000000000004 math.divide(0.3, 0.2); // Number, 1.4999999999999998 -// no round-off errors with big numbers :) +// no round-off errors with BigNumbers :) math.add(math.bignumber(0.1), math.bignumber(0.2)); // BigNumber, 0.3 math.divide(math.bignumber(0.3), math.bignumber(0.2)); // BigNumber, 1.5 ``` -The default precision for BigNumber is 20 digits. This is a global setting -in the [underlying BigNumber library](https://github.com/MikeMcl/bignumber.js/), -which can be changed by configuring BigNumber: - -```js -BigNumber.config({DECIMAL_PLACES: 32}); -``` - -*Important: To work with small numbers, `DECIMAL_PLACES` must be configured -sufficiently large.* - -Big numbers can be converted to numbers and vice versa using the functions +BigNumbers can be converted to numbers and vice versa using the functions `number` and `bignumber`. When converting a BigNumber to a Number, the high precision of the BigNumber will be lost. When a BigNumber is too large to be represented as Number, it will be initialized as `Infinity`. ```js -// converting numbers and bignumbers +// converting numbers and BigNumbers var a = math.number(0.3); // Number, 0.3 var b = math.bignumber(a); // BigNumber, 0.3 var c = math.number(b); // Number, 0.3 diff --git a/docs/datatypes/index.md b/docs/datatypes/index.md index 72509ea9e..13e5b64c7 100644 --- a/docs/datatypes/index.md +++ b/docs/datatypes/index.md @@ -24,7 +24,7 @@ math.subtract(7.1, 2.3); // 4.8 math.round(math.pi, 3); // 3.142 math.sqrt(4.41e2); // 21 -// use big numbers +// use BigNumbers math.add(math.bignumber(0.1), math.bignumber(0.2)); // BigNumber, 0.3 // use strings diff --git a/docs/datatypes/numbers.md b/docs/datatypes/numbers.md index d734e9339..256d0fdb3 100644 --- a/docs/datatypes/numbers.md +++ b/docs/datatypes/numbers.md @@ -4,11 +4,11 @@ Math.js supports two types of numbers: - Number for fast floating point arithmetic, described on this page. - BigNumber for arbitrary precision arithmetic, describe on the page - [Big Numbers](bignumbers.md). + [BigNumbers](bignumbers.md). Most functions can determine the type of output from the type of input: -a number as input will return a number as output, a bignumber as input returns -a bignumber as output. Functions which cannot determine the type of output +a number as input will return a number as output, a BigNumber as input returns +a BigNumber as output. Functions which cannot determine the type of output from the input (for example `math.eval`) use the default number type, which can be configured when instantiating math.js: diff --git a/docs/expressions.md b/docs/expressions.md index 57eb6925a..db839eb96 100644 --- a/docs/expressions.md +++ b/docs/expressions.md @@ -456,9 +456,9 @@ math.format(ans, {precision: 14}); // "0.3" ``` -#### Big numbers +#### BigNumbers -Math.js supports big numbers for calculations with an arbitrary precision. +Math.js supports BigNumbers for calculations with an arbitrary precision. The pros and cons of Number and BigNumber are explained in detail on the page [Numbers](datatypes/numbers.md). @@ -484,7 +484,7 @@ var mathjs = require('mathjs'), math.eval('0.1 + 0.2'); // BigNumber, 0.3 ``` -Big numbers can be converted to numbers and vice versa using the functions +BigNumbers can be converted to numbers and vice versa using the functions `number` and `bignumber`. When converting a BigNumber to a Number, the high precision of the BigNumber will be lost. When a BigNumber is too large to be represented as Number, it will be initialized as `Infinity`. diff --git a/docs/index.md b/docs/index.md index 5460b93cc..b26e6a95a 100644 --- a/docs/index.md +++ b/docs/index.md @@ -7,7 +7,7 @@ - [Chained Operations](chained_operations.md) - [Data Types](datatypes/index.md) - [Numbers](datatypes/numbers.md) - - [Big Numbers](datatypes/bignumbers.md) + - [BigNumbers](datatypes/bignumbers.md) - [Complex Numbers](datatypes/complex_numbers.md) - [Matrices](datatypes/matrices.md) - [Units](datatypes/units.md) diff --git a/examples/bignumbers.js b/examples/bignumbers.js index e5f2a5725..a163657e0 100644 --- a/examples/bignumbers.js +++ b/examples/bignumbers.js @@ -1,11 +1,11 @@ -// big numbers +// BigNumbers // load math.js and create an instance -// the default type of numbers is configured as big numbers +// the default type of numbers is configured as BigNumbers var mathjs = require('../index'), math = mathjs({ number: 'bignumber', // Default type of number: 'number' (default) or 'bignumber' - decimals: 20 // number decimal places behind the dot for big numbers + decimals: 20 // number of decimal places behind the dot for BigNumbers }); /** @@ -21,19 +21,19 @@ print(math.add(0.1, 0.2)); // Number, 0.30000000000000004 print(math.divide(0.3, 0.2)); // Number, 1.4999999999999998 console.log(); -console.log('no round-off errors with big numbers'); +console.log('no round-off errors with BigNumbers'); print(math.add(math.bignumber(0.1), math.bignumber(0.2))); // BigNumber, 0.3 print(math.divide(math.bignumber(0.3), math.bignumber(0.2))); // BigNumber, 1.5 console.log(); -console.log('create big numbers from strings when exceeding the range of a number'); +console.log('create BigNumbers from strings when exceeding the range of a number'); print(math.bignumber(1.2e+500)); // BigNumber, Infinity WRONG print(math.bignumber('1.2e+500')); // BigNumber, 1.2e+500 console.log(); -// one can work conveniently with big numbers using the expression parser. -// note though that big numbers are only supported in arithmetic functions -console.log('use big numbers in the expression parser'); +// one can work conveniently with BigNumbers using the expression parser. +// note though that BigNumbers are only supported in arithmetic functions +console.log('use BigNumbers in the expression parser'); print(math.eval('0.1 + 0.2')); // BigNumber, 0.3 print(math.eval('0.3 / 0.2')); // BigNumber, 1.5 console.log(); diff --git a/lib/expression/node/ConstantNode.js b/lib/expression/node/ConstantNode.js index 51dd0ceae..261081516 100644 --- a/lib/expression/node/ConstantNode.js +++ b/lib/expression/node/ConstantNode.js @@ -1,6 +1,6 @@ var Node = require('./Node'), Complex = require('../../type/Complex'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), string = require('../../util/string'), isString = string.isString; diff --git a/lib/expression/node/IndexNode.js b/lib/expression/node/IndexNode.js index 837c85f81..0c9f642b1 100644 --- a/lib/expression/node/IndexNode.js +++ b/lib/expression/node/IndexNode.js @@ -1,12 +1,12 @@ -var number= require('../../util/number.js'), +var number= require('../../util/number'), Node = require('./Node.js'), - RangeNode = require('./RangeNode.js'), - SymbolNode = require('./SymbolNode.js'), + RangeNode = require('./RangeNode'), + SymbolNode = require('./SymbolNode'), - BigNumber = require('bignumber.js'), - Index = require('../../type/Index.js'), - Range = require('../../type/Range.js'), + BigNumber = require('../../type/BigNumber'), + Index = require('../../type/Index'), + Range = require('../../type/Range'), isNumber = number.isNumber, toNumber = number.toNumber, diff --git a/lib/expression/node/ParamsNode.js b/lib/expression/node/ParamsNode.js index be1481925..aabb92a73 100644 --- a/lib/expression/node/ParamsNode.js +++ b/lib/expression/node/ParamsNode.js @@ -4,7 +4,7 @@ var number= require('../../util/number'), RangeNode = require('./RangeNode'), SymbolNode = require('./SymbolNode'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Index = require('../../type/Index'), Range = require('../../type/Range'), diff --git a/lib/expression/node/RangeNode.js b/lib/expression/node/RangeNode.js index befea2fc0..84561150f 100644 --- a/lib/expression/node/RangeNode.js +++ b/lib/expression/node/RangeNode.js @@ -1,7 +1,7 @@ var number = require('../../util/number'), Node = require('./Node'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Range = require('../../type/Range'), Matrix = require('../../type/Matrix'), diff --git a/lib/expression/node/UnitNode.js b/lib/expression/node/UnitNode.js index a0533deb2..145179e92 100644 --- a/lib/expression/node/UnitNode.js +++ b/lib/expression/node/UnitNode.js @@ -1,6 +1,6 @@ var Node = require('./Node'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), diff --git a/lib/expression/node/UpdateNode.js b/lib/expression/node/UpdateNode.js index 1b8cdca8d..b6c942ea2 100644 --- a/lib/expression/node/UpdateNode.js +++ b/lib/expression/node/UpdateNode.js @@ -5,7 +5,7 @@ var number= require('../../util/number'), IndexNode = require('./IndexNode'), SymbolNode = require('./SymbolNode'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Index = require('../../type/Index'), Range = require('../../type/Range'), diff --git a/lib/function/arithmetic/abs.js b/lib/function/arithmetic/abs.js index 92714cbee..91129d3da 100644 --- a/lib/function/arithmetic/abs.js +++ b/lib/function/arithmetic/abs.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), Matrix = require('../../type/Matrix'), collection = require('../../type/collection'), diff --git a/lib/function/arithmetic/add.js b/lib/function/arithmetic/add.js index 46e2a743a..4be5bf42c 100644 --- a/lib/function/arithmetic/add.js +++ b/lib/function/arithmetic/add.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), Matrix = require('../../type/Matrix'), Unit = require('../../type/Unit'), diff --git a/lib/function/arithmetic/ceil.js b/lib/function/arithmetic/ceil.js index daf5b7106..8e8c9890a 100644 --- a/lib/function/arithmetic/ceil.js +++ b/lib/function/arithmetic/ceil.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), collection = require('../../type/collection'), diff --git a/lib/function/arithmetic/compare.js b/lib/function/arithmetic/compare.js index dc3524bb6..935ef66aa 100644 --- a/lib/function/arithmetic/compare.js +++ b/lib/function/arithmetic/compare.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), collection = require('../../type/collection'), diff --git a/lib/function/arithmetic/cube.js b/lib/function/arithmetic/cube.js index bb8b37b2b..9dd048b64 100644 --- a/lib/function/arithmetic/cube.js +++ b/lib/function/arithmetic/cube.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), collection = require('../../type/collection'), diff --git a/lib/function/arithmetic/divide.js b/lib/function/arithmetic/divide.js index 9cec46cab..9bb7fe5cd 100644 --- a/lib/function/arithmetic/divide.js +++ b/lib/function/arithmetic/divide.js @@ -1,7 +1,7 @@ module.exports = function(math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), Matrix = require('../../type/Matrix'), Unit = require('../../type/Unit'), diff --git a/lib/function/arithmetic/equal.js b/lib/function/arithmetic/equal.js index 933763998..cfb13811d 100644 --- a/lib/function/arithmetic/equal.js +++ b/lib/function/arithmetic/equal.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), collection = require('../../type/collection'), diff --git a/lib/function/arithmetic/exp.js b/lib/function/arithmetic/exp.js index 4697e89d8..9bde185b9 100644 --- a/lib/function/arithmetic/exp.js +++ b/lib/function/arithmetic/exp.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), Matrix = require('../../type/Matrix'), collection = require('../../type/collection'), diff --git a/lib/function/arithmetic/fix.js b/lib/function/arithmetic/fix.js index 11a9f9067..54a8e7fb8 100644 --- a/lib/function/arithmetic/fix.js +++ b/lib/function/arithmetic/fix.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), collection = require('../../type/collection'), diff --git a/lib/function/arithmetic/floor.js b/lib/function/arithmetic/floor.js index 6028d4b39..83e00b3e2 100644 --- a/lib/function/arithmetic/floor.js +++ b/lib/function/arithmetic/floor.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), collection = require('../../type/collection'), diff --git a/lib/function/arithmetic/gcd.js b/lib/function/arithmetic/gcd.js index 34a03603d..1f5b4a886 100644 --- a/lib/function/arithmetic/gcd.js +++ b/lib/function/arithmetic/gcd.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), collection = require('../../type/collection'), isNumber = util.number.isNumber, diff --git a/lib/function/arithmetic/larger.js b/lib/function/arithmetic/larger.js index 899f1e533..314a49421 100644 --- a/lib/function/arithmetic/larger.js +++ b/lib/function/arithmetic/larger.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), collection = require('../../type/collection'), diff --git a/lib/function/arithmetic/largereq.js b/lib/function/arithmetic/largereq.js index a88263002..82ca9cac9 100644 --- a/lib/function/arithmetic/largereq.js +++ b/lib/function/arithmetic/largereq.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), collection = require('../../type/collection'), diff --git a/lib/function/arithmetic/lcm.js b/lib/function/arithmetic/lcm.js index 31f2e273c..22438bd6f 100644 --- a/lib/function/arithmetic/lcm.js +++ b/lib/function/arithmetic/lcm.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), collection = require('../../type/collection'), isNumber = util.number.isNumber, diff --git a/lib/function/arithmetic/log.js b/lib/function/arithmetic/log.js index d881c6990..f84f81bdf 100644 --- a/lib/function/arithmetic/log.js +++ b/lib/function/arithmetic/log.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), collection = require('../../type/collection'), diff --git a/lib/function/arithmetic/log10.js b/lib/function/arithmetic/log10.js index 9d4b31cc8..916a1c1de 100644 --- a/lib/function/arithmetic/log10.js +++ b/lib/function/arithmetic/log10.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), collection = require('../../type/collection'), diff --git a/lib/function/arithmetic/mod.js b/lib/function/arithmetic/mod.js index 4c6a18d82..f1cadaef0 100644 --- a/lib/function/arithmetic/mod.js +++ b/lib/function/arithmetic/mod.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), collection = require('../../type/collection'), isNumber = util.number.isNumber, diff --git a/lib/function/arithmetic/multiply.js b/lib/function/arithmetic/multiply.js index 428bc49ba..5ede71f12 100644 --- a/lib/function/arithmetic/multiply.js +++ b/lib/function/arithmetic/multiply.js @@ -1,7 +1,7 @@ module.exports = function(math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), Matrix = require('../../type/Matrix'), Unit = require('../../type/Unit'), diff --git a/lib/function/arithmetic/pow.js b/lib/function/arithmetic/pow.js index d1d7ebc06..a6f9b2987 100644 --- a/lib/function/arithmetic/pow.js +++ b/lib/function/arithmetic/pow.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), Matrix = require('../../type/Matrix'), collection = require('../../type/collection'), diff --git a/lib/function/arithmetic/round.js b/lib/function/arithmetic/round.js index 61be56258..f9894dc2e 100644 --- a/lib/function/arithmetic/round.js +++ b/lib/function/arithmetic/round.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), collection = require('../../type/collection'), @@ -43,7 +43,7 @@ module.exports = function (math) { } if (x instanceof BigNumber) { - return x.round(); + return x.toDecimalPlaces(0); } if (isCollection(x)) { @@ -85,7 +85,7 @@ module.exports = function (math) { } if (x instanceof BigNumber) { - return x.round(n); + return x.toDecimalPlaces(n); } if (isCollection(x) || isCollection(n)) { diff --git a/lib/function/arithmetic/sign.js b/lib/function/arithmetic/sign.js index 518bdb3f8..5333fc7b9 100644 --- a/lib/function/arithmetic/sign.js +++ b/lib/function/arithmetic/sign.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), collection = require('../../type/collection'), diff --git a/lib/function/arithmetic/smaller.js b/lib/function/arithmetic/smaller.js index 1c1cfe036..c1ef6648d 100644 --- a/lib/function/arithmetic/smaller.js +++ b/lib/function/arithmetic/smaller.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), collection = require('../../type/collection'), diff --git a/lib/function/arithmetic/smallereq.js b/lib/function/arithmetic/smallereq.js index 223f62231..436847197 100644 --- a/lib/function/arithmetic/smallereq.js +++ b/lib/function/arithmetic/smallereq.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), collection = require('../../type/collection'), diff --git a/lib/function/arithmetic/sqrt.js b/lib/function/arithmetic/sqrt.js index 2c5fc8831..7f7aa18c9 100644 --- a/lib/function/arithmetic/sqrt.js +++ b/lib/function/arithmetic/sqrt.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), collection = require('../../type/collection'), diff --git a/lib/function/arithmetic/square.js b/lib/function/arithmetic/square.js index 603fb569e..1077682cb 100644 --- a/lib/function/arithmetic/square.js +++ b/lib/function/arithmetic/square.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), collection = require('../../type/collection'), diff --git a/lib/function/arithmetic/subtract.js b/lib/function/arithmetic/subtract.js index 155d75845..e00cc2bc3 100644 --- a/lib/function/arithmetic/subtract.js +++ b/lib/function/arithmetic/subtract.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), Matrix = require('../../type/Matrix'), Unit = require('../../type/Unit'), diff --git a/lib/function/arithmetic/unary.js b/lib/function/arithmetic/unary.js index 939f22208..a55be06aa 100644 --- a/lib/function/arithmetic/unary.js +++ b/lib/function/arithmetic/unary.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), collection = require('../../type/collection'), diff --git a/lib/function/arithmetic/unequal.js b/lib/function/arithmetic/unequal.js index d94507e7b..0c7c0c397 100644 --- a/lib/function/arithmetic/unequal.js +++ b/lib/function/arithmetic/unequal.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), collection = require('../../type/collection'), diff --git a/lib/function/arithmetic/xgcd.js b/lib/function/arithmetic/xgcd.js index 3f17f0877..d00c13506 100644 --- a/lib/function/arithmetic/xgcd.js +++ b/lib/function/arithmetic/xgcd.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), toNumber = util.number.toNumber, isNumber = util.number.isNumber, diff --git a/lib/function/complex/arg.js b/lib/function/complex/arg.js index 115671910..695cc1b78 100644 --- a/lib/function/complex/arg.js +++ b/lib/function/complex/arg.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), collection = require('../../type/collection'), diff --git a/lib/function/complex/conj.js b/lib/function/complex/conj.js index be4b855a1..3d151a213 100644 --- a/lib/function/complex/conj.js +++ b/lib/function/complex/conj.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), collection = require('../../type/collection'), diff --git a/lib/function/complex/im.js b/lib/function/complex/im.js index 6e8aa4bd3..a059e45fc 100644 --- a/lib/function/complex/im.js +++ b/lib/function/complex/im.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), collection = require('../../type/collection'), diff --git a/lib/function/complex/re.js b/lib/function/complex/re.js index c16c8cd9f..37c6d3b0d 100644 --- a/lib/function/complex/re.js +++ b/lib/function/complex/re.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), collection = require('../../type/collection'), diff --git a/lib/function/construction/bignumber.js b/lib/function/construction/bignumber.js index 0631d58f6..5e83f59c1 100644 --- a/lib/function/construction/bignumber.js +++ b/lib/function/construction/bignumber.js @@ -1,7 +1,8 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + // create a non-global instance of BigNumber + BigNumber = require('../../type/BigNumber'), collection = require('../../type/collection'), isCollection = collection.isCollection, diff --git a/lib/function/construction/boolean.js b/lib/function/construction/boolean.js index 12e95ed2e..62dd5ee68 100644 --- a/lib/function/construction/boolean.js +++ b/lib/function/construction/boolean.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), collection = require('../../type/collection'), isCollection = collection.isCollection, diff --git a/lib/function/construction/complex.js b/lib/function/construction/complex.js index 74dafb0e3..4270e66f2 100644 --- a/lib/function/construction/complex.js +++ b/lib/function/construction/complex.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), collection = require('../../type/collection'), diff --git a/lib/function/construction/index.js b/lib/function/construction/index.js index fd8d6b710..52da4ba4e 100644 --- a/lib/function/construction/index.js +++ b/lib/function/construction/index.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Index = require('../../type/Index'), toNumber = util.number.toNumber; diff --git a/lib/function/construction/number.js b/lib/function/construction/number.js index 63f4c5933..a06cd2b29 100644 --- a/lib/function/construction/number.js +++ b/lib/function/construction/number.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), collection = require('../../type/collection'), isCollection = collection.isCollection, diff --git a/lib/function/construction/unit.js b/lib/function/construction/unit.js index cfba18e68..585a192eb 100644 --- a/lib/function/construction/unit.js +++ b/lib/function/construction/unit.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Unit = require('../../type/Unit'), collection = require('../../type/collection'), diff --git a/lib/function/matrix/eye.js b/lib/function/matrix/eye.js index dcc23c765..fc2090b30 100644 --- a/lib/function/matrix/eye.js +++ b/lib/function/matrix/eye.js @@ -1,7 +1,7 @@ module.exports = function (math, settings) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Matrix = require('../../type/Matrix'), collection = require('../../type/collection'), diff --git a/lib/function/matrix/ones.js b/lib/function/matrix/ones.js index 2882c9af9..ade4aa3ea 100644 --- a/lib/function/matrix/ones.js +++ b/lib/function/matrix/ones.js @@ -1,7 +1,7 @@ module.exports = function (math, settings) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Matrix = require('../../type/Matrix'), collection = require('../../type/collection'), diff --git a/lib/function/matrix/range.js b/lib/function/matrix/range.js index 456a38241..b5b45d645 100644 --- a/lib/function/matrix/range.js +++ b/lib/function/matrix/range.js @@ -1,7 +1,7 @@ module.exports = function (math, settings) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Matrix = require('../../type/Matrix'), collection = require('../../type/collection'), diff --git a/lib/function/matrix/resize.js b/lib/function/matrix/resize.js index 6c01455a7..962867445 100644 --- a/lib/function/matrix/resize.js +++ b/lib/function/matrix/resize.js @@ -1,7 +1,7 @@ module.exports = function (math, settings) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Matrix = require('../../type/Matrix'), array = util.array, diff --git a/lib/function/matrix/size.js b/lib/function/matrix/size.js index 75d21c69e..f7f323beb 100644 --- a/lib/function/matrix/size.js +++ b/lib/function/matrix/size.js @@ -1,7 +1,7 @@ module.exports = function (math, settings) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), Matrix = require('../../type/Matrix'), diff --git a/lib/function/matrix/zeros.js b/lib/function/matrix/zeros.js index dbddb0952..50c1eeb85 100644 --- a/lib/function/matrix/zeros.js +++ b/lib/function/matrix/zeros.js @@ -1,7 +1,7 @@ module.exports = function (math, settings) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Matrix = require('../../type/Matrix'), collection = require('../../type/collection'), diff --git a/lib/function/probability/combinations.js b/lib/function/probability/combinations.js index 509aa18ae..69aee7a75 100644 --- a/lib/function/probability/combinations.js +++ b/lib/function/probability/combinations.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), collection = require('../../type/collection'), isNumber = util.number.isNumber, @@ -74,6 +74,6 @@ module.exports = function (math) { * @returns {boolean} isPositiveInteger */ var isPositiveInteger = function(n) { - return n.round().equals(n) && n.gte(0); + return n.isInteger() && n.gte(0); }; }; diff --git a/lib/function/probability/factorial.js b/lib/function/probability/factorial.js index 96a8ef242..6b58b4ecc 100644 --- a/lib/function/probability/factorial.js +++ b/lib/function/probability/factorial.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), collection = require('../../type/collection'), isNumber = util.number.isNumber, @@ -85,6 +85,6 @@ module.exports = function (math) { * @returns {boolean} isPositiveInteger */ var isPositiveInteger = function(n) { - return n.round().equals(n) && n.gte(0); + return n.isInteger() && n.gte(0); }; }; diff --git a/lib/function/probability/permutations.js b/lib/function/probability/permutations.js index 6ea976c30..def2d2a12 100644 --- a/lib/function/probability/permutations.js +++ b/lib/function/probability/permutations.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), isNumber = util.number.isNumber, isInteger = util.number.isInteger, @@ -89,6 +89,6 @@ module.exports = function (math) { * @returns {boolean} isPositiveInteger */ var isPositiveInteger = function(n) { - return n.round().equals(n) && n.gte(0); + return n.isInteger() && n.gte(0); }; }; diff --git a/lib/function/statistics/median.js b/lib/function/statistics/median.js index e9dc39770..f500ab918 100644 --- a/lib/function/statistics/median.js +++ b/lib/function/statistics/median.js @@ -1,7 +1,7 @@ module.exports = function (math) { var Matrix = require('../../type/Matrix'), Unit = require('../../type/Unit'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), collection = require('../../type/collection'), isNumber = require('../../util/number').isNumber, diff --git a/lib/function/statistics/var.js b/lib/function/statistics/var.js index ae0605876..a4511fb1a 100644 --- a/lib/function/statistics/var.js +++ b/lib/function/statistics/var.js @@ -1,6 +1,6 @@ module.exports = function (math) { var Matrix = require('../../type/Matrix'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), collection = require('../../type/collection'), isCollection = collection.isCollection, diff --git a/lib/function/trigonometry/acos.js b/lib/function/trigonometry/acos.js index 457da16ac..608c02460 100644 --- a/lib/function/trigonometry/acos.js +++ b/lib/function/trigonometry/acos.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), collection = require('../../type/collection'), diff --git a/lib/function/trigonometry/asin.js b/lib/function/trigonometry/asin.js index 36781d32e..ff28c856b 100644 --- a/lib/function/trigonometry/asin.js +++ b/lib/function/trigonometry/asin.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), collection = require('../../type/collection'), diff --git a/lib/function/trigonometry/atan.js b/lib/function/trigonometry/atan.js index 4f35506f6..26ceee5b1 100644 --- a/lib/function/trigonometry/atan.js +++ b/lib/function/trigonometry/atan.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), collection = require('../../type/collection'), diff --git a/lib/function/trigonometry/atan2.js b/lib/function/trigonometry/atan2.js index d872d636a..1f62d80c9 100644 --- a/lib/function/trigonometry/atan2.js +++ b/lib/function/trigonometry/atan2.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), collection = require('../../type/collection'), diff --git a/lib/function/trigonometry/cos.js b/lib/function/trigonometry/cos.js index ed384ef2c..9c3ea2103 100644 --- a/lib/function/trigonometry/cos.js +++ b/lib/function/trigonometry/cos.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), collection = require('../../type/collection'), diff --git a/lib/function/trigonometry/cot.js b/lib/function/trigonometry/cot.js index 087bf8f6e..76313d830 100644 --- a/lib/function/trigonometry/cot.js +++ b/lib/function/trigonometry/cot.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), collection = require('../../type/collection'), diff --git a/lib/function/trigonometry/csc.js b/lib/function/trigonometry/csc.js index f70cc1a79..7f6f0ec89 100644 --- a/lib/function/trigonometry/csc.js +++ b/lib/function/trigonometry/csc.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), collection = require('../../type/collection'), diff --git a/lib/function/trigonometry/sec.js b/lib/function/trigonometry/sec.js index 4c9f366be..96e020316 100644 --- a/lib/function/trigonometry/sec.js +++ b/lib/function/trigonometry/sec.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), collection = require('../../type/collection'), diff --git a/lib/function/trigonometry/sin.js b/lib/function/trigonometry/sin.js index 3f299174c..4252153ea 100644 --- a/lib/function/trigonometry/sin.js +++ b/lib/function/trigonometry/sin.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), collection = require('../../type/collection'), diff --git a/lib/function/trigonometry/tan.js b/lib/function/trigonometry/tan.js index 8a9e20c7d..f2cf77c12 100644 --- a/lib/function/trigonometry/tan.js +++ b/lib/function/trigonometry/tan.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), collection = require('../../type/collection'), diff --git a/lib/function/utils/ifElse.js b/lib/function/utils/ifElse.js index 8bb7666c7..35ce578e7 100644 --- a/lib/function/utils/ifElse.js +++ b/lib/function/utils/ifElse.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Matrix = require('../../type/Matrix'), Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), diff --git a/lib/function/utils/typeof.js b/lib/function/utils/typeof.js index 51d990be8..fe1fc7a09 100644 --- a/lib/function/utils/typeof.js +++ b/lib/function/utils/typeof.js @@ -1,7 +1,7 @@ module.exports = function (math) { var types = require('../../util/types'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../type/BigNumber'), Complex = require('../../type/Complex'), Matrix = require('../../type/Matrix'), Unit = require('../../type/Unit'), diff --git a/lib/math.js b/lib/math.js index 941ed3737..ef9286a60 100644 --- a/lib/math.js +++ b/lib/math.js @@ -33,7 +33,10 @@ function mathjs (settings) { matrix: 'matrix', // type of default number output. Choose 'number' (default) or 'bignumber' - number: 'number' + number: 'number', + + // number of significant digits in bignumbers + decimals: 20 }; /** @@ -49,7 +52,7 @@ function mathjs (settings) { * @return {Object} settings The currently applied settings */ math.config = function config (settings) { - var BigNumber = require('bignumber.js'); + var BigNumber = require('./type/BigNumber'); if (settings) { // merge settings @@ -57,7 +60,7 @@ function mathjs (settings) { if (settings.decimals) { BigNumber.config({ - DECIMAL_PLACES: settings.decimals + precision: settings.decimals // TODO: rename decimals to precision }); } @@ -87,9 +90,7 @@ function mathjs (settings) { } // return a clone of the settings - var current = object.clone(_settings); - current.decimals = BigNumber.config().DECIMAL_PLACES; - return current; + return object.clone(_settings); }; // apply provided configuration settings @@ -107,7 +108,7 @@ function mathjs (settings) { // types (Matrix, Complex, Unit, ...) math.type = {}; - math.type.BigNumber = require('bignumber.js'); + math.type.BigNumber = require('./type/BigNumber').constructor(); // create a new Decimal factory for this instance of math.js math.type.Complex = require('./type/Complex'); math.type.Range = require('./type/Range'); math.type.Index = require('./type/Index'); diff --git a/lib/type/BigNumber.js b/lib/type/BigNumber.js new file mode 100644 index 000000000..b66d4c71a --- /dev/null +++ b/lib/type/BigNumber.js @@ -0,0 +1 @@ +module.exports = require('decimal.js'); diff --git a/lib/util/number.js b/lib/util/number.js index df2ed3dd7..a90e0ac33 100644 --- a/lib/util/number.js +++ b/lib/util/number.js @@ -1,4 +1,4 @@ -var BigNumber = require('bignumber.js'); +var BigNumber = require('../type/BigNumber'); /** * Test whether value is a Number @@ -166,16 +166,14 @@ exports.format = function format(value, options) { throw new Error('options.scientific is deprecated, use options.exponential instead.'); } - // adjust BigNumber configuration + // create a clone of the bignumber with the desired configuration var isBigNumber = value instanceof BigNumber; if (isBigNumber) { - var oldScientific = BigNumber.config().EXPONENTIAL_AT; - BigNumber.config({ - EXPONENTIAL_AT: [ - Math.round(Math.log(lower) / Math.LN10), - Math.round(Math.log(upper) / Math.LN10) - ] + var BN = BigNumber.config({ + toExpNeg: Math.round(Math.log(lower) / Math.LN10), + toExpPos: Math.round(Math.log(upper) / Math.LN10) }); + value = new BN(value); } // handle special case zero @@ -203,10 +201,12 @@ exports.format = function format(value, options) { str = exports.toExponential(value, precision); } + /* TODO: cleanup // restore BigNumber configuration if (isBigNumber) { BigNumber.config({EXPONENTIAL_AT: oldScientific}); } + */ // remove trailing zeros after the decimal point return str.replace(/((\.\d*?)(0+))($|e)/, function () { diff --git a/lib/util/string.js b/lib/util/string.js index 5160da4c4..ca5a6eec0 100644 --- a/lib/util/string.js +++ b/lib/util/string.js @@ -1,5 +1,5 @@ var number = require('./number'), - BigNumber = require('bignumber.js'); + BigNumber = require('../type/BigNumber'); /** * Test whether value is a String diff --git a/package.json b/package.json index d34f2d3a6..00b80d34c 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "unit" ], "dependencies": { - "bignumber.js": "^1.3.0" + "decimal.js": "^1.0.0" }, "devDependencies": { "webpack": "latest", diff --git a/test/expression/node/ConstantNode.test.js b/test/expression/node/ConstantNode.test.js index f5cb492e0..03c6775f8 100644 --- a/test/expression/node/ConstantNode.test.js +++ b/test/expression/node/ConstantNode.test.js @@ -4,7 +4,7 @@ var assert = require('assert'), math = require('../../../index')(), bigmath = require('../../../index')({number: 'bignumber'}), Complex = require('../../../lib/type/Complex'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../../lib/type/BigNumber'), Node = require('../../../lib/expression/node/Node'), ConstantNode = require('../../../lib/expression/node/ConstantNode'), SymbolNode = require('../../../lib/expression/node/SymbolNode'); diff --git a/test/function/arithmetic/ceil.test.js b/test/function/arithmetic/ceil.test.js index 85005d00f..a62eef0ee 100644 --- a/test/function/arithmetic/ceil.test.js +++ b/test/function/arithmetic/ceil.test.js @@ -30,16 +30,16 @@ describe('ceil', function() { }); it('should return the ceil of a big number', function () { - approx.deepEqual(ceil(bignumber(0)), bignumber(0)); - approx.deepEqual(ceil(bignumber(1)), bignumber(1)); - approx.deepEqual(ceil(bignumber(1.3)), bignumber(2)); - approx.deepEqual(ceil(bignumber(1.8)), bignumber(2)); - approx.deepEqual(ceil(bignumber(2)), bignumber(2)); - approx.deepEqual(ceil(bignumber(-1)), bignumber(-1)); - approx.deepEqual(ceil(bignumber(-1.3)), bignumber(-1)); - approx.deepEqual(ceil(bignumber(-1.8)), bignumber(-1)); - approx.deepEqual(ceil(bignumber(-2)), bignumber(-2)); - approx.deepEqual(ceil(bignumber(-2.1)), bignumber(-2)); + assert.deepEqual(ceil(bignumber(0)), bignumber(0)); + assert.deepEqual(ceil(bignumber(1)), bignumber(1)); + assert.deepEqual(ceil(bignumber(1.3)), bignumber(2)); + assert.deepEqual(ceil(bignumber(1.8)), bignumber(2)); + assert.deepEqual(ceil(bignumber(2)), bignumber(2)); + assert.deepEqual(ceil(bignumber(-1)), bignumber(-1)); + assert.deepEqual(ceil(bignumber(-1.3)), bignumber(-1)); + assert.deepEqual(ceil(bignumber(-1.8)), bignumber(-1)); + assert.deepEqual(ceil(bignumber(-2)), bignumber(-2)); + assert.deepEqual(ceil(bignumber(-2.1)), bignumber(-2)); }); it('should return the ceil of real and imag part of a complex', function() { diff --git a/test/function/arithmetic/fix.test.js b/test/function/arithmetic/fix.test.js index ebbd6a437..d4b083c52 100644 --- a/test/function/arithmetic/fix.test.js +++ b/test/function/arithmetic/fix.test.js @@ -30,16 +30,16 @@ describe('fix', function() { }); it('should round big numbers correctly', function() { - approx.deepEqual(fix(bignumber(0)), bignumber(0)); - approx.deepEqual(fix(bignumber(1)), bignumber(1)); - approx.deepEqual(fix(bignumber(1.3)), bignumber(1)); - approx.deepEqual(fix(bignumber(1.8)), bignumber(1)); - approx.deepEqual(fix(bignumber(2)), bignumber(2)); - approx.deepEqual(fix(bignumber(-1)), bignumber(-1)); - approx.deepEqual(fix(bignumber(-1.3)), bignumber(-1)); - approx.deepEqual(fix(bignumber(-1.8)), bignumber(-1)); - approx.deepEqual(fix(bignumber(-2)), bignumber(-2)); - approx.deepEqual(fix(bignumber(-2.1)), bignumber(-2)); + assert.deepEqual(fix(bignumber(0)), bignumber(0)); + assert.deepEqual(fix(bignumber(1)), bignumber(1)); + assert.deepEqual(fix(bignumber(1.3)), bignumber(1)); + assert.deepEqual(fix(bignumber(1.8)), bignumber(1)); + assert.deepEqual(fix(bignumber(2)), bignumber(2)); + assert.deepEqual(fix(bignumber(-1)), bignumber(-1)); + assert.deepEqual(fix(bignumber(-1.3)), bignumber(-1)); + assert.deepEqual(fix(bignumber(-1.8)), bignumber(-1)); + assert.deepEqual(fix(bignumber(-2)), bignumber(-2)); + assert.deepEqual(fix(bignumber(-2.1)), bignumber(-2)); }); it('should round complex numbers correctly', function() { diff --git a/test/function/arithmetic/floor.test.js b/test/function/arithmetic/floor.test.js index ac4339328..5bbab81d9 100644 --- a/test/function/arithmetic/floor.test.js +++ b/test/function/arithmetic/floor.test.js @@ -30,16 +30,16 @@ describe('floor', function() { }); it('should floor big numbers correctly', function() { - approx.deepEqual(floor(bignumber(0)), bignumber(0)); - approx.deepEqual(floor(bignumber(1)), bignumber(1)); - approx.deepEqual(floor(bignumber(1.3)), bignumber(1)); - approx.deepEqual(floor(bignumber(1.8)), bignumber(1)); - approx.deepEqual(floor(bignumber(2)), bignumber(2)); - approx.deepEqual(floor(bignumber(-1)), bignumber(-1)); - approx.deepEqual(floor(bignumber(-1.3)), bignumber(-2)); - approx.deepEqual(floor(bignumber(-1.8)), bignumber(-2)); - approx.deepEqual(floor(bignumber(-2)), bignumber(-2)); - approx.deepEqual(floor(bignumber(-2.1)), bignumber(-3)); + assert.deepEqual(floor(bignumber(0)), bignumber(0)); + assert.deepEqual(floor(bignumber(1)), bignumber(1)); + assert.deepEqual(floor(bignumber(1.3)), bignumber(1)); + assert.deepEqual(floor(bignumber(1.8)), bignumber(1)); + assert.deepEqual(floor(bignumber(2)), bignumber(2)); + assert.deepEqual(floor(bignumber(-1)), bignumber(-1)); + assert.deepEqual(floor(bignumber(-1.3)), bignumber(-2)); + assert.deepEqual(floor(bignumber(-1.8)), bignumber(-2)); + assert.deepEqual(floor(bignumber(-2)), bignumber(-2)); + assert.deepEqual(floor(bignumber(-2.1)), bignumber(-3)); }); it('should floor complex numbers correctly', function() { diff --git a/test/function/construction/bignumber.test.js b/test/function/construction/bignumber.test.js index eeb405daa..4c5999e50 100644 --- a/test/function/construction/bignumber.test.js +++ b/test/function/construction/bignumber.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../../lib/type/BigNumber'), mathjs = require('../../../index'), math = mathjs(), bignumber = math.bignumber; diff --git a/test/function/utils/format.test.js b/test/function/utils/format.test.js index 374187e81..4bdd559c2 100644 --- a/test/function/utils/format.test.js +++ b/test/function/utils/format.test.js @@ -1,6 +1,7 @@ // test format var assert = require('assert'), - math = require('../../../index')(); + mathjs = require('../../../index'); + math = mathjs(); describe('format', function() { @@ -60,9 +61,7 @@ describe('format', function() { }); describe('bignumber', function () { - before (function () { - math.type.BigNumber.config(20); // ensure the precision is 20 digits, the default - }); + var math = mathjs({decimals: 20}); // ensure the precision is 20 digits, the default it('should format big numbers', function() { assert.equal(math.format(math.bignumber(2).dividedBy(7)), '0.28571428571428571429'); diff --git a/test/util/number.test.js b/test/util/number.test.js index baba3ac2a..0c15aba63 100644 --- a/test/util/number.test.js +++ b/test/util/number.test.js @@ -1,7 +1,7 @@ // test number utils var assert = require('assert'), approx = require('../../tools/approx'), - BigNumber = require('bignumber.js'), + BigNumber = require('../../lib/type/BigNumber'), number = require('../../lib/util/number'); describe('number', function() { @@ -75,18 +75,15 @@ describe('number', function() { }); it('should format a bignumber using toFixed', function() { - var DECIMAL_PLACES = BigNumber.config().DECIMAL_PLACES; - BigNumber.config(100); + var Big = BigNumber.constructor(); + Big.config({decimals: 100}); - assert.equal(number.toFixed(new BigNumber(2.34)), '2'); - assert.equal(number.toFixed(new BigNumber(2.34), 1), '2.3'); - assert.equal(number.toFixed(new BigNumber(2), 20), '2.00000000000000000000'); - assert.equal(number.toFixed(new BigNumber(2), 21), '2.000000000000000000000'); - assert.equal(number.toFixed(new BigNumber(2), 22), '2.0000000000000000000000'); - assert.equal(number.toFixed(new BigNumber(2), 30), '2.000000000000000000000000000000'); - - // restore global bignumber configuration - BigNumber.config(DECIMAL_PLACES); + assert.equal(number.toFixed(new Big(2.34)), '2'); + assert.equal(number.toFixed(new Big(2.34), 1), '2.3'); + assert.equal(number.toFixed(new Big(2), 20), '2.00000000000000000000'); + assert.equal(number.toFixed(new Big(2), 21), '2.000000000000000000000'); + assert.equal(number.toFixed(new Big(2), 22), '2.0000000000000000000000'); + assert.equal(number.toFixed(new Big(2), 30), '2.000000000000000000000000000000'); }); it('should format a number using toExponential', function() { @@ -101,22 +98,19 @@ describe('number', function() { }); it('should format a bignumber using toExponential', function() { - var DECIMAL_PLACES = BigNumber.config().DECIMAL_PLACES; - BigNumber.config(100); + var Big = BigNumber.constructor(); + Big.config({decimals: 100}); - assert.equal(number.toExponential(new BigNumber(2.34)), '2.34e+0'); - assert.equal(number.toExponential(new BigNumber(2.34e+3)), '2.34e+3'); - assert.equal(number.toExponential(new BigNumber(2.34e-3)), '2.34e-3'); - assert.equal(number.toExponential(new BigNumber(2.34e+3), 2), '2.3e+3'); - assert.equal(number.toExponential(new BigNumber(2e+3), 20), '2.0000000000000000000e+3'); - assert.equal(number.toExponential(new BigNumber(2e+3), 21), '2.00000000000000000000e+3'); - assert.equal(number.toExponential(new BigNumber(2e+3), 22), '2.000000000000000000000e+3'); - assert.equal(number.toExponential(new BigNumber(2e+3), 30), '2.00000000000000000000000000000e+3'); - assert.equal(number.toExponential(new BigNumber('2e+300'), 30), '2.00000000000000000000000000000e+300'); - assert.equal(number.toExponential(new BigNumber('2e-300'), 30), '2.00000000000000000000000000000e-300'); - - // restore global bignumber configuration - BigNumber.config(DECIMAL_PLACES); + assert.equal(number.toExponential(new Big(2.34)), '2.34e+0'); + assert.equal(number.toExponential(new Big(2.34e+3)), '2.34e+3'); + assert.equal(number.toExponential(new Big(2.34e-3)), '2.34e-3'); + assert.equal(number.toExponential(new Big(2.34e+3), 2), '2.3e+3'); + assert.equal(number.toExponential(new Big(2e+3), 20), '2.0000000000000000000e+3'); + assert.equal(number.toExponential(new Big(2e+3), 21), '2.00000000000000000000e+3'); + assert.equal(number.toExponential(new Big(2e+3), 22), '2.000000000000000000000e+3'); + assert.equal(number.toExponential(new Big(2e+3), 30), '2.00000000000000000000000000000e+3'); + assert.equal(number.toExponential(new Big('2e+300'), 30), '2.00000000000000000000000000000e+300'); + assert.equal(number.toExponential(new Big('2e-300'), 30), '2.00000000000000000000000000000e-300'); }); it('should convert a number into a bignumber (when possible)', function() { @@ -334,39 +328,42 @@ describe('number', function() { }); describe('bignumber', function () { + var B = null; + before (function () { - BigNumber.config(20); // ensure the precision is 20 digits, the default + B = BigNumber.constructor(); + B.config({precision: 20}); // ensure the precision is 20 digits, the default }); it('should format big numbers', function() { - assert.deepEqual(number.format(new BigNumber('2.3')), '2.3'); - assert.deepEqual(number.format(new BigNumber('0.00000003')), '3e-8'); - assert.deepEqual(number.format(new BigNumber('12345678')), '1.2345678e+7'); + assert.deepEqual(number.format(new B('2.3')), '2.3'); + assert.deepEqual(number.format(new B('0.00000003')), '3e-8'); + assert.deepEqual(number.format(new B('12345678')), '1.2345678e+7'); }); it('should format big numbers with given precision', function() { - assert.deepEqual(number.format(new BigNumber('1.23456'), 3), '1.23'); - assert.deepEqual(number.format(new BigNumber('12345678'), 4), '1.235e+7'); + assert.deepEqual(number.format(new B('1.23456'), 3), '1.23'); + assert.deepEqual(number.format(new B('12345678'), 4), '1.235e+7'); }); it('should format big numbers in exponential notation', function() { var options = { notation: 'exponential' }; - assert.deepEqual(number.format(new BigNumber('1.23456'), options), '1.23456e+0'); - assert.deepEqual(number.format(new BigNumber('12345678'), options), '1.2345678e+7'); - assert.deepEqual(number.format(new BigNumber('2.3e+30'), options), '2.3e+30'); - assert.deepEqual(number.format(new BigNumber('0.23e+30'), options), '2.3e+29'); - assert.deepEqual(number.format(new BigNumber('2.3e-30'), options), '2.3e-30'); - assert.deepEqual(number.format(new BigNumber('0.23e-30'), options), '2.3e-31'); + assert.deepEqual(number.format(new B('1.23456'), options), '1.23456e+0'); + assert.deepEqual(number.format(new B('12345678'), options), '1.2345678e+7'); + assert.deepEqual(number.format(new B('2.3e+30'), options), '2.3e+30'); + assert.deepEqual(number.format(new B('0.23e+30'), options), '2.3e+29'); + assert.deepEqual(number.format(new B('2.3e-30'), options), '2.3e-30'); + assert.deepEqual(number.format(new B('0.23e-30'), options), '2.3e-31'); options.precision = 18; - assert.deepEqual(number.format(new BigNumber(1).div(3), options), '3.33333333333333333e-1'); + assert.deepEqual(number.format(new B(1).div(3), options), '3.33333333333333333e-1'); }); - it.skip('sould format big numbers with custom precision, lower, and upper bound', function() { - var oldPrecision = BigNumber.config().DECIMAL_PLACES; - BigNumber.config({DECIMAL_PLACES: 100}); + it('should format big numbers with custom precision, lower, and upper bound', function() { + var Big = BigNumber.constructor(); + Big.config({precision: 100}); var options = { notation: 'auto', @@ -377,16 +374,13 @@ describe('number', function() { } }; - assert.deepEqual(number.format(new BigNumber(5).div(3), options), '1.6666666666666666666666666666666666666666666666667'); - assert.deepEqual(number.format(new BigNumber(5e+40).div(3), options), '16666666666666666666666666666666666666666.666666667'); - assert.deepEqual(number.format(new BigNumber(5e-40).div(3), options), + assert.deepEqual(number.format(new Big(5).div(3), options), '1.6666666666666666666666666666666666666666666666667'); + assert.deepEqual(number.format(new Big(5e+40).div(3), options), '16666666666666666666666666666666666666666.666666667'); + assert.deepEqual(number.format(new Big(5e-40).div(3), options), '0.00000000000000000000000000000000000000016666666666666666666666666666666666666666666666667'); - assert.deepEqual(number.format(new BigNumber(5e+60).div(3), options), '1.6666666666666666666666666666666666666666666666667e+60'); - assert.deepEqual(number.format(new BigNumber(5e-60).div(3), options), '1.6666666666666666666666666666666666666666666666667e-60'); - assert.deepEqual(number.format(new BigNumber(5e-80).div(3), options), '1.6666666666666666666666666666666666666666666666667e-80'); - - // restore old precision - BigNumber.config({DECIMAL_PLACES: oldPrecision}); + assert.deepEqual(number.format(new Big(5e+60).div(3), options), '1.6666666666666666666666666666666666666666666666667e+60'); + assert.deepEqual(number.format(new Big(5e-60).div(3), options), '1.6666666666666666666666666666666666666666666666667e-60'); + assert.deepEqual(number.format(new Big(5e-80).div(3), options), '1.6666666666666666666666666666666666666666666666667e-80'); }); it('should format big numbers in fixed notation', function() { From 7b32c7fb00546435dfd577834e1424140ea6882d Mon Sep 17 00:00:00 2001 From: Finn Date: Sat, 5 Apr 2014 01:07:55 +0200 Subject: [PATCH 09/48] Add toPolar method #76 --- lib/type/Complex.js | 12 ++++++++++++ test/type/Complex.test.js | 25 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/lib/type/Complex.js b/lib/type/Complex.js index 34138b57c..4a0ea8d87 100644 --- a/lib/type/Complex.js +++ b/lib/type/Complex.js @@ -303,6 +303,18 @@ Complex.fromPolar = function fromPolar(args) { } } +/* + * Return the value of the complex number in polar notation + * The angle phi will be set in the interval of [-pi, pi]. + * @return {Object} Object with r and phi keys. + */ +Complex.prototype.toPolar = function() { + var polar = {}; + polar.r = math.sqrt(math.add(math.square(this.re), math.square(this.im))); + polar.phi = math.atan2(this.im, this.re); + return polar; +}; + /** * Create a copy of the complex value * @return {Complex} clone diff --git a/test/type/Complex.test.js b/test/type/Complex.test.js index c46575705..3cec08309 100644 --- a/test/type/Complex.test.js +++ b/test/type/Complex.test.js @@ -189,10 +189,12 @@ describe('Complex', function () { var complex2 = Complex.fromPolar({r: 5, phi: 0}); var complex3 = Complex.fromPolar({r: 1, phi: math.pi}); var complex4 = Complex.fromPolar({r: 3, phi: math.pi / 2}); + var complex5 = Complex.fromPolar({r: 3, phi: -math.pi / 2}); assertComplex(complex1, 0, 0); assertComplex(complex2, 5, 0); assert.equal(complex3.re, -1); assert.equal(complex4.im, 3); + assert.equal(complex5.im, -3); }); it('should have the same value for the different import ways', function() { @@ -211,4 +213,27 @@ describe('Complex', function () { }); }); + + describe('toPolar', function() { + it('should return polar coordinates properly', function() { + var polar0 = (new Complex(0, 0)).toPolar(); + var polar1 = (new Complex(3, 4)).toPolar(); + var polar2 = (new Complex(-3, 4)).toPolar(); + var polar3 = (new Complex(3, -4)).toPolar(); + var polar4 = (new Complex(-3, -4)).toPolar(); + var polar5 = (new Complex(0, -1)).toPolar(); + assert.equal(polar0.r, 0); + assert.equal(polar1.r, 5); + assert.equal(polar2.r, 5); + assert.equal(polar3.r, 5); + assert.equal(polar4.r, 5); + assert.equal(polar5.r, 1); + assert.equal(polar0.phi, 0); + assert.equal(polar1.phi, 0.9272952180016122); + assert.equal(polar2.phi, 2.214297435588181); + assert.equal(polar3.phi, -0.9272952180016122); + assert.equal(polar4.phi, -2.214297435588181); + assert.equal(polar5.phi, -1.5707963267948966); + }); + }); }); \ No newline at end of file From 333f881c4d9a46b2b2f2a5192b90ad6d5338dd76 Mon Sep 17 00:00:00 2001 From: Finn Date: Sat, 5 Apr 2014 02:14:14 +0200 Subject: [PATCH 10/48] Add constructor support for polar and {re:..,im:..} Fixes #76 --- lib/function/construction/complex.js | 17 +++++++++----- lib/type/Complex.js | 21 +++++++++++++++-- test/function/construction/complex.test.js | 4 ++++ test/type/Complex.test.js | 26 ++++++++++++++++++++++ 4 files changed, 61 insertions(+), 7 deletions(-) diff --git a/lib/function/construction/complex.js b/lib/function/construction/complex.js index 9db363b54..14069c5ec 100644 --- a/lib/function/construction/complex.js +++ b/lib/function/construction/complex.js @@ -26,6 +26,10 @@ module.exports = function (math) { * complex(array : Array) converts the elements of the array * or matrix element wise into a * complex value. + * complex({re: number, im: number}) creates a complex value with provided + * values for real an imaginary part. + * complex({r: number, phi: number}) creates a complex value with provided + * polar coordinates * * Example usage: * var a = math.complex(3, -4); // 3 - 4i @@ -76,12 +80,15 @@ module.exports = function (math) { return collection.deepMap(arg, complex); } - if(typeof arg === 'object' && 'r' in arg && 'phi' in arg) { - // polar coordinates - return Complex.fromPolar(arg.r, arg.phi); - } + if (typeof arg === 'object') { + if('re' in arg && 'im' in arg) { + return new Complex(arg.re, arg.im); + } else if ('r' in arg && 'phi' in arg) { + return Complex.fromPolar(arg.r, arg.phi); + } + } - throw new TypeError('Two numbers or a single string expected in function complex'); + throw new TypeError('Two numbers, single string or an fitting object expected in function complex'); case 2: // re and im provided diff --git a/lib/type/Complex.js b/lib/type/Complex.js index 4a0ea8d87..b656177e2 100644 --- a/lib/type/Complex.js +++ b/lib/type/Complex.js @@ -36,6 +36,23 @@ function Complex(re, im) { this.im = 0; break; + case 1: + var arg = arguments[0]; + if (typeof arg === 'object') { + if('re' in arg && 'im' in arg) { + var construct = new Complex(arg.re, arg.im); // pass on input validation + this.re = construct.re; + this.im = construct.im; + break; + } else if ('r' in arg && 'phi' in arg) { + var construct = Complex.fromPolar(arg.r, arg.phi); + this.re = construct.re; + this.im = construct.im; + break; + } + } + throw new SyntaxError('Object with the re and im or r and phi properties expected.'); + case 2: if (!isNumber(re) || !isNumber(im)) { throw new TypeError('Two numbers expected in Complex constructor'); @@ -45,7 +62,7 @@ function Complex(re, im) { break; default: - throw new SyntaxError('Two or zero arguments expected in Complex constructor'); + throw new SyntaxError('One, two or three arguments expected in Complex constructor'); } } @@ -311,7 +328,7 @@ Complex.fromPolar = function fromPolar(args) { Complex.prototype.toPolar = function() { var polar = {}; polar.r = math.sqrt(math.add(math.square(this.re), math.square(this.im))); - polar.phi = math.atan2(this.im, this.re); + polar.phi = math.arg(this); return polar; }; diff --git a/test/function/construction/complex.test.js b/test/function/construction/complex.test.js index c25b9c3b1..ceeeae8e9 100644 --- a/test/function/construction/complex.test.js +++ b/test/function/construction/complex.test.js @@ -44,6 +44,10 @@ describe('complex', function() { assert.deepEqual(polar, new math.type.Complex.fromPolar(1, 1)); }); + it('should accept an object with im and re as keys', function() { + assert.deepEqual(complex({re: 1, im: 2}), new math.type.Complex(1, 2)); + }); + it('should throw an error if called with a string', function() { assert.throws(function () {complex('no valid complex number')}, SyntaxError); }); diff --git a/test/type/Complex.test.js b/test/type/Complex.test.js index 3cec08309..0167193b4 100644 --- a/test/type/Complex.test.js +++ b/test/type/Complex.test.js @@ -36,6 +36,14 @@ describe('Complex', function () { assert.throws(function () { Complex(3, -4); }); }); + it('should accept an object with im and re as keys', function() { + assertComplex(new Complex({re: 1, im: 2}), 1, 2); + }); + + it('should accept an object with polar coordinates like fromPolar', function() { + assert.deepEqual(new Complex({r: 3, phi: 4}), Complex.fromPolar(3, 4)); + }); + }); describe('toString', function() { @@ -210,7 +218,25 @@ describe('Complex', function () { assert.equal(fromDeg.im, 1); assert.equal(fromGrad.im, 1); assert.equal(fromRad.im, 0); + }); + it('should only accept an object with r and phi keys for 1 argument', function() { + assert.throws(function() { Complex.fromPolar({}) }, TypeError); + assert.throws(function() { Complex.fromPolar({r: 1}) }, TypeError); + assert.throws(function() { Complex.fromPolar({phi: 1}) }, TypeError); + assert.throws(function() { Complex.fromPolar("") }, TypeError); + }); + + it('should only accept a number as r', function() { + assert.throws(function() { Complex.fromPolar("1", 0); }); + assert.throws(function() { Complex.fromPolar(true, 0); }); + assert.throws(function() { Complex.fromPolar({}, 0); }); + }); + + it('should only accept units and numbers as phi', function() { + assert.throws(function() { Complex.fromPolar(1, "1")}); + assert.throws(function() { Complex.fromPolar(1, true)}); + assert.throws(function() { Complex.fromPolar(1, {})}); }); }); From ad554ef1f7029835ef6f070b583dbc020bb912cb Mon Sep 17 00:00:00 2001 From: josdejong Date: Sat, 5 Apr 2014 22:42:03 +0200 Subject: [PATCH 11/48] Updates and fixes to work with a different BigNumber instance per math.js instance --- lib/expression/node/ArrayNode.js | 1 - lib/expression/node/ConstantNode.js | 2 - lib/expression/node/IndexNode.js | 10 +- lib/expression/node/ParamsNode.js | 12 +- lib/expression/node/RangeNode.js | 11 +- lib/expression/node/UnitNode.js | 3 - lib/expression/node/UpdateNode.js | 15 +- lib/expression/parse.js | 1 - lib/function/arithmetic/abs.js | 2 +- lib/function/arithmetic/add.js | 12 +- lib/function/arithmetic/ceil.js | 2 +- lib/function/arithmetic/compare.js | 12 +- lib/function/arithmetic/cube.js | 2 +- lib/function/arithmetic/divide.js | 12 +- lib/function/arithmetic/equal.js | 12 +- lib/function/arithmetic/exp.js | 4 +- lib/function/arithmetic/fix.js | 2 +- lib/function/arithmetic/floor.js | 2 +- lib/function/arithmetic/gcd.js | 7 +- lib/function/arithmetic/larger.js | 12 +- lib/function/arithmetic/largereq.js | 12 +- lib/function/arithmetic/lcm.js | 7 +- lib/function/arithmetic/log.js | 4 +- lib/function/arithmetic/log10.js | 4 +- lib/function/arithmetic/mod.js | 12 +- lib/function/arithmetic/multiply.js | 12 +- lib/function/arithmetic/pow.js | 12 +- lib/function/arithmetic/round.js | 2 +- lib/function/arithmetic/sign.js | 2 +- lib/function/arithmetic/smaller.js | 12 +- lib/function/arithmetic/smallereq.js | 12 +- lib/function/arithmetic/sqrt.js | 2 +- lib/function/arithmetic/square.js | 2 +- lib/function/arithmetic/subtract.js | 12 +- lib/function/arithmetic/unary.js | 2 +- lib/function/arithmetic/unequal.js | 12 +- lib/function/arithmetic/xgcd.js | 7 +- lib/function/complex/arg.js | 4 +- lib/function/complex/conj.js | 2 +- lib/function/complex/im.js | 2 +- lib/function/complex/re.js | 2 +- lib/function/construction/bignumber.js | 15 +- lib/function/construction/boolean.js | 2 +- lib/function/construction/complex.js | 9 +- lib/function/construction/index.js | 10 +- lib/function/construction/number.js | 5 +- lib/function/construction/unit.js | 5 +- lib/function/matrix/eye.js | 27 +- lib/function/matrix/ones.js | 20 +- lib/function/matrix/range.js | 24 +- lib/function/matrix/resize.js | 7 +- lib/function/matrix/size.js | 2 +- lib/function/matrix/zeros.js | 20 +- lib/function/probability/combinations.js | 7 +- lib/function/probability/factorial.js | 2 +- lib/function/probability/permutations.js | 7 +- lib/function/statistics/median.js | 2 +- lib/function/statistics/var.js | 2 +- lib/function/trigonometry/acos.js | 4 +- lib/function/trigonometry/asin.js | 4 +- lib/function/trigonometry/atan.js | 4 +- lib/function/trigonometry/atan2.js | 7 +- lib/function/trigonometry/cos.js | 4 +- lib/function/trigonometry/cot.js | 4 +- lib/function/trigonometry/csc.js | 4 +- lib/function/trigonometry/sec.js | 4 +- lib/function/trigonometry/sin.js | 4 +- lib/function/trigonometry/tan.js | 4 +- lib/function/utils/ifElse.js | 2 +- lib/function/utils/typeof.js | 2 +- lib/math.js | 68 +++-- lib/type/BigNumber.js | 1 - lib/util/bignumber.js | 206 +++++++++++++++ lib/util/index.js | 1 + lib/util/number.js | 126 ++-------- lib/util/string.js | 9 +- test/expression/node/ConstantNode.test.js | 3 +- test/expression/node/UpdateNode.test.js | 4 +- test/expression/parse.test.js | 3 +- test/function/construction/bignumber.test.js | 4 +- test/function/matrix/range.test.js | 1 + test/math.test.js | 17 ++ test/util/bignumber.test.js | 251 +++++++++++++++++++ test/util/number.test.js | 137 +--------- test/util/string.test.js | 8 + 85 files changed, 780 insertions(+), 546 deletions(-) delete mode 100644 lib/type/BigNumber.js create mode 100644 lib/util/bignumber.js create mode 100644 test/util/bignumber.test.js diff --git a/lib/expression/node/ArrayNode.js b/lib/expression/node/ArrayNode.js index d013b4940..6fbc27ec4 100644 --- a/lib/expression/node/ArrayNode.js +++ b/lib/expression/node/ArrayNode.js @@ -2,7 +2,6 @@ var Node = require('./Node'), object = require('../../util/object'), string = require('../../util/string'), collection = require('../../type/collection'), - Matrix = require('../../type/Matrix'), util = require('../../util/index'), isArray = Array.isArray, diff --git a/lib/expression/node/ConstantNode.js b/lib/expression/node/ConstantNode.js index 261081516..c9d84eede 100644 --- a/lib/expression/node/ConstantNode.js +++ b/lib/expression/node/ConstantNode.js @@ -1,6 +1,4 @@ var Node = require('./Node'), - Complex = require('../../type/Complex'), - BigNumber = require('../../type/BigNumber'), string = require('../../util/string'), isString = string.isString; diff --git a/lib/expression/node/IndexNode.js b/lib/expression/node/IndexNode.js index 0c9f642b1..f890f5330 100644 --- a/lib/expression/node/IndexNode.js +++ b/lib/expression/node/IndexNode.js @@ -1,15 +1,7 @@ -var number= require('../../util/number'), - - Node = require('./Node.js'), +var Node = require('./Node.js'), RangeNode = require('./RangeNode'), SymbolNode = require('./SymbolNode'), - BigNumber = require('../../type/BigNumber'), - Index = require('../../type/Index'), - Range = require('../../type/Range'), - - isNumber = number.isNumber, - toNumber = number.toNumber, isNode = Node.isNode; /** diff --git a/lib/expression/node/ParamsNode.js b/lib/expression/node/ParamsNode.js index aabb92a73..86b2485e3 100644 --- a/lib/expression/node/ParamsNode.js +++ b/lib/expression/node/ParamsNode.js @@ -1,15 +1,5 @@ -var number= require('../../util/number'), +var Node = require('./Node'), - Node = require('./Node'), - RangeNode = require('./RangeNode'), - SymbolNode = require('./SymbolNode'), - - BigNumber = require('../../type/BigNumber'), - Index = require('../../type/Index'), - Range = require('../../type/Range'), - - isNumber = number.isNumber, - toNumber = number.toNumber, isNode = Node.isNode; /** diff --git a/lib/expression/node/RangeNode.js b/lib/expression/node/RangeNode.js index 84561150f..c2dd5328c 100644 --- a/lib/expression/node/RangeNode.js +++ b/lib/expression/node/RangeNode.js @@ -1,12 +1,5 @@ -var number = require('../../util/number'), - Node = require('./Node'), +var Node = require('./Node'), - BigNumber = require('../../type/BigNumber'), - Range = require('../../type/Range'), - Matrix = require('../../type/Matrix'), - - toNumber = number.toNumber, - isArray = Array.isArray; isNode = Node.isNode; /** @@ -21,7 +14,7 @@ function RangeNode (params) { } // validate inputs - if (!isArray(params) || + if (!Array.isArray(params) || (params.length != 2 && params.length != 3) || !params.every(isNode)) { throw new TypeError('Expected an Array containing 2 or 3 Nodes as parameter "params"'); diff --git a/lib/expression/node/UnitNode.js b/lib/expression/node/UnitNode.js index 145179e92..2aa2e371d 100644 --- a/lib/expression/node/UnitNode.js +++ b/lib/expression/node/UnitNode.js @@ -1,10 +1,7 @@ var Node = require('./Node'), - BigNumber = require('../../type/BigNumber'), - Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), - toNumber = require('../../util/number').toNumber, isString = require('../../util/string').isString; /** diff --git a/lib/expression/node/UpdateNode.js b/lib/expression/node/UpdateNode.js index b6c942ea2..3fb678275 100644 --- a/lib/expression/node/UpdateNode.js +++ b/lib/expression/node/UpdateNode.js @@ -1,16 +1,5 @@ -var number= require('../../util/number'), - - Node = require('./Node'), - RangeNode = require('./RangeNode'), - IndexNode = require('./IndexNode'), - SymbolNode = require('./SymbolNode'), - - BigNumber = require('../../type/BigNumber'), - Index = require('../../type/Index'), - Range = require('../../type/Range'), - - isNumber = number.isNumber, - toNumber = number.toNumber; +var Node = require('./Node'), + IndexNode = require('./IndexNode'); /** * @constructor UpdateNode diff --git a/lib/expression/parse.js b/lib/expression/parse.js index dd0f37ec7..5db576005 100644 --- a/lib/expression/parse.js +++ b/lib/expression/parse.js @@ -1,6 +1,5 @@ var util = require('../util/index'), - toNumber = util.number.toNumber, isString = util.string.isString, isArray = Array.isArray, type = util.types.type, diff --git a/lib/function/arithmetic/abs.js b/lib/function/arithmetic/abs.js index 91129d3da..fa1973401 100644 --- a/lib/function/arithmetic/abs.js +++ b/lib/function/arithmetic/abs.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), Matrix = require('../../type/Matrix'), collection = require('../../type/collection'), diff --git a/lib/function/arithmetic/add.js b/lib/function/arithmetic/add.js index 4be5bf42c..9f543416a 100644 --- a/lib/function/arithmetic/add.js +++ b/lib/function/arithmetic/add.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), Matrix = require('../../type/Matrix'), Unit = require('../../type/Unit'), @@ -9,8 +9,6 @@ module.exports = function (math) { isBoolean = util['boolean'].isBoolean, isNumber = util.number.isNumber, - toNumber = util.number.toNumber, - toBigNumber = util.number.toBigNumber, isString = util.string.isString, isComplex = Complex.isComplex, isUnit = Unit.isUnit, @@ -88,7 +86,7 @@ module.exports = function (math) { if (x instanceof BigNumber) { // try to convert to big number if (isNumber(y)) { - y = toBigNumber(y); + y = BigNumber.convert(y); } else if (isBoolean(y)) { y = new BigNumber(y ? 1 : 0); @@ -99,12 +97,12 @@ module.exports = function (math) { } // downgrade to Number - return add(toNumber(x), y); + return add(x.toNumber(), y); } if (y instanceof BigNumber) { // try to convert to big number if (isNumber(x)) { - x = toBigNumber(x); + x = BigNumber.convert(x); } else if (isBoolean(x)) { x = new BigNumber(x ? 1 : 0); @@ -115,7 +113,7 @@ module.exports = function (math) { } // downgrade to Number - return add(x, toNumber(y)); + return add(x, y.toNumber()); } if (isString(x) || isString(y)) { diff --git a/lib/function/arithmetic/ceil.js b/lib/function/arithmetic/ceil.js index 8e8c9890a..94a26936b 100644 --- a/lib/function/arithmetic/ceil.js +++ b/lib/function/arithmetic/ceil.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), collection = require('../../type/collection'), diff --git a/lib/function/arithmetic/compare.js b/lib/function/arithmetic/compare.js index 935ef66aa..13ab46007 100644 --- a/lib/function/arithmetic/compare.js +++ b/lib/function/arithmetic/compare.js @@ -1,14 +1,12 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), collection = require('../../type/collection'), isNumber = util.number.isNumber, - toNumber = util.number.toNumber, - toBigNumber = util.number.toBigNumber, isBoolean = util['boolean'].isBoolean, isString = util.string.isString, isComplex = Complex.isComplex, @@ -37,7 +35,7 @@ module.exports = function (math) { if (x instanceof BigNumber) { // try to convert to big number if (isNumber(y)) { - y = toBigNumber(y); + y = BigNumber.convert(y); } else if (isBoolean(y)) { y = new BigNumber(y ? 1 : 0); @@ -48,12 +46,12 @@ module.exports = function (math) { } // downgrade to Number - return compare(toNumber(x), y); + return compare(x.toNumber(), y); } if (y instanceof BigNumber) { // try to convert to big number if (isNumber(x)) { - x = toBigNumber(x); + x = BigNumber.convert(x); } else if (isBoolean(x)) { x = new BigNumber(x ? 1 : 0); @@ -64,7 +62,7 @@ module.exports = function (math) { } // downgrade to Number - return compare(x, toNumber(y)); + return compare(x, y.toNumber()); } if ((isUnit(x)) && (isUnit(y))) { diff --git a/lib/function/arithmetic/cube.js b/lib/function/arithmetic/cube.js index 9dd048b64..7379cba3a 100644 --- a/lib/function/arithmetic/cube.js +++ b/lib/function/arithmetic/cube.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), collection = require('../../type/collection'), diff --git a/lib/function/arithmetic/divide.js b/lib/function/arithmetic/divide.js index 9bb7fe5cd..7c04f5e5c 100644 --- a/lib/function/arithmetic/divide.js +++ b/lib/function/arithmetic/divide.js @@ -1,15 +1,13 @@ module.exports = function(math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), Matrix = require('../../type/Matrix'), Unit = require('../../type/Unit'), collection = require('../../type/collection'), isNumber = util.number.isNumber, - toNumber = util.number.toNumber, - toBigNumber = util.number.toBigNumber, isBoolean = util['boolean'].isBoolean, isComplex = Complex.isComplex, isUnit = Unit.isUnit, @@ -55,7 +53,7 @@ module.exports = function(math) { if (x instanceof BigNumber) { // try to convert to big number if (isNumber(y)) { - y = toBigNumber(y); + y = BigNumber.convert(y); } else if (isBoolean(y)) { y = new BigNumber(y ? 1 : 0); @@ -66,12 +64,12 @@ module.exports = function(math) { } // downgrade to Number - return divide(toNumber(x), y); + return divide(x.toNumber(), y); } if (y instanceof BigNumber) { // try to convert to big number if (isNumber(x)) { - x = toBigNumber(x); + x = BigNumber.convert(x); } else if (isBoolean(x)) { x = new BigNumber(x ? 1 : 0); @@ -82,7 +80,7 @@ module.exports = function(math) { } // downgrade to Number - return divide(x, toNumber(y)); + return divide(x, y.toNumber()); } if (isUnit(x)) { diff --git a/lib/function/arithmetic/equal.js b/lib/function/arithmetic/equal.js index cfb13811d..6da60016d 100644 --- a/lib/function/arithmetic/equal.js +++ b/lib/function/arithmetic/equal.js @@ -1,14 +1,12 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), collection = require('../../type/collection'), isNumber = util.number.isNumber, - toNumber = util.number.toNumber, - toBigNumber = util.number.toBigNumber, isBoolean = util['boolean'].isBoolean, isString = util.string.isString, isComplex = Complex.isComplex, @@ -54,7 +52,7 @@ module.exports = function (math) { if (x instanceof BigNumber) { // try to convert to big number if (isNumber(y)) { - y = toBigNumber(y); + y = BigNumber.convert(y); } else if (isBoolean(y)) { y = new BigNumber(y ? 1 : 0); @@ -65,12 +63,12 @@ module.exports = function (math) { } // downgrade to Number - return equal(toNumber(x), y); + return equal(x.toNumber(), y); } if (y instanceof BigNumber) { // try to convert to big number if (isNumber(x)) { - x = toBigNumber(x); + x = BigNumber.convert(x); } else if (isBoolean(x)) { x = new BigNumber(x ? 1 : 0); @@ -81,7 +79,7 @@ module.exports = function (math) { } // downgrade to Number - return equal(x, toNumber(y)); + return equal(x, y.toNumber()); } if ((isUnit(x)) && (isUnit(y))) { diff --git a/lib/function/arithmetic/exp.js b/lib/function/arithmetic/exp.js index 9bde185b9..95400fffd 100644 --- a/lib/function/arithmetic/exp.js +++ b/lib/function/arithmetic/exp.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), Matrix = require('../../type/Matrix'), collection = require('../../type/collection'), @@ -41,7 +41,7 @@ module.exports = function (math) { if (x instanceof BigNumber) { // TODO: implement BigNumber support // downgrade to Number - return exp(util.number.toNumber(x)); + return exp(x.toNumber()); } if (isCollection(x)) { diff --git a/lib/function/arithmetic/fix.js b/lib/function/arithmetic/fix.js index 54a8e7fb8..97f630d2a 100644 --- a/lib/function/arithmetic/fix.js +++ b/lib/function/arithmetic/fix.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), collection = require('../../type/collection'), diff --git a/lib/function/arithmetic/floor.js b/lib/function/arithmetic/floor.js index 83e00b3e2..668bcbcd4 100644 --- a/lib/function/arithmetic/floor.js +++ b/lib/function/arithmetic/floor.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), collection = require('../../type/collection'), diff --git a/lib/function/arithmetic/gcd.js b/lib/function/arithmetic/gcd.js index 1f5b4a886..470b8562d 100644 --- a/lib/function/arithmetic/gcd.js +++ b/lib/function/arithmetic/gcd.js @@ -1,11 +1,10 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, collection = require('../../type/collection'), isNumber = util.number.isNumber, - toNumber = util.number.toNumber, isBoolean = util['boolean'].isBoolean, isInteger = util.number.isInteger, isCollection = collection.isCollection; @@ -51,10 +50,10 @@ module.exports = function (math) { // downgrade bignumbers to numbers if (a instanceof BigNumber) { - return gcd(toNumber(a), b); + return gcd(a.toNumber(), b); } if (b instanceof BigNumber) { - return gcd(a, toNumber(b)); + return gcd(a, b.toNumber()); } if (isBoolean(a)) { diff --git a/lib/function/arithmetic/larger.js b/lib/function/arithmetic/larger.js index 314a49421..f3ace49f8 100644 --- a/lib/function/arithmetic/larger.js +++ b/lib/function/arithmetic/larger.js @@ -1,14 +1,12 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), collection = require('../../type/collection'), isNumber = util.number.isNumber, - toNumber = util.number.toNumber, - toBigNumber = util.number.toBigNumber, isBoolean = util['boolean'].isBoolean, isString = util.string.isString, isComplex = Complex.isComplex, @@ -39,7 +37,7 @@ module.exports = function (math) { if (x instanceof BigNumber) { // try to convert to big number if (isNumber(y)) { - y = toBigNumber(y); + y = BigNumber.convert(y); } else if (isBoolean(y)) { y = new BigNumber(y ? 1 : 0); @@ -50,12 +48,12 @@ module.exports = function (math) { } // downgrade to Number - return larger(toNumber(x), y); + return larger(x.toNumber(), y); } if (y instanceof BigNumber) { // try to convert to big number if (isNumber(x)) { - x = toBigNumber(x); + x = BigNumber.convert(x); } else if (isBoolean(x)) { x = new BigNumber(x ? 1 : 0); @@ -66,7 +64,7 @@ module.exports = function (math) { } // downgrade to Number - return larger(x, toNumber(y)); + return larger(x, y.toNumber()); } if ((isUnit(x)) && (isUnit(y))) { diff --git a/lib/function/arithmetic/largereq.js b/lib/function/arithmetic/largereq.js index 82ca9cac9..2910021aa 100644 --- a/lib/function/arithmetic/largereq.js +++ b/lib/function/arithmetic/largereq.js @@ -1,14 +1,12 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), collection = require('../../type/collection'), isNumber = util.number.isNumber, - toNumber = util.number.toNumber, - toBigNumber = util.number.toBigNumber, isBoolean = util['boolean'].isBoolean, isString = util.string.isString, isComplex = Complex.isComplex, @@ -39,7 +37,7 @@ module.exports = function (math) { if (x instanceof BigNumber) { // try to convert to big number if (isNumber(y)) { - y = toBigNumber(y); + y = BigNumber.convert(y); } else if (isBoolean(y)) { y = new BigNumber(y ? 1 : 0); @@ -50,12 +48,12 @@ module.exports = function (math) { } // downgrade to Number - return largereq(toNumber(x), y); + return largereq(x.toNumber(), y); } if (y instanceof BigNumber) { // try to convert to big number if (isNumber(x)) { - x = toBigNumber(x); + x = BigNumber.convert(x); } else if (isBoolean(x)) { x = new BigNumber(x ? 1 : 0); @@ -66,7 +64,7 @@ module.exports = function (math) { } // downgrade to Number - return largereq(x, toNumber(y)); + return largereq(x, y.toNumber()); } if ((isUnit(x)) && (isUnit(y))) { diff --git a/lib/function/arithmetic/lcm.js b/lib/function/arithmetic/lcm.js index 22438bd6f..f74e2ff60 100644 --- a/lib/function/arithmetic/lcm.js +++ b/lib/function/arithmetic/lcm.js @@ -1,11 +1,10 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, collection = require('../../type/collection'), isNumber = util.number.isNumber, - toNumber = util.number.toNumber, isBoolean = util['boolean'].isBoolean, isInteger = util.number.isInteger, isCollection = collection.isCollection; @@ -67,10 +66,10 @@ module.exports = function (math) { // downgrade bignumbers to numbers if (a instanceof BigNumber) { - return lcm(toNumber(a), b); + return lcm(a.toNumber(), b); } if (b instanceof BigNumber) { - return lcm(a, toNumber(b)); + return lcm(a, b.toNumber()); } throw new math.error.UnsupportedTypeError('lcm', a, b); diff --git a/lib/function/arithmetic/log.js b/lib/function/arithmetic/log.js index f84f81bdf..5c7dd39cb 100644 --- a/lib/function/arithmetic/log.js +++ b/lib/function/arithmetic/log.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), collection = require('../../type/collection'), @@ -46,7 +46,7 @@ module.exports = function (math) { if (x instanceof BigNumber) { // TODO: implement BigNumber support // downgrade to Number - return log(util.number.toNumber(x)); + return log(x.toNumber()); } if (isCollection(x)) { diff --git a/lib/function/arithmetic/log10.js b/lib/function/arithmetic/log10.js index 916a1c1de..637eedf9b 100644 --- a/lib/function/arithmetic/log10.js +++ b/lib/function/arithmetic/log10.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), collection = require('../../type/collection'), @@ -38,7 +38,7 @@ module.exports = function (math) { if (x instanceof BigNumber) { // TODO: implement BigNumber support // downgrade to Number - return log10(util.number.toNumber(x)); + return log10(x.toNumber()); } if (isComplex(x)) { diff --git a/lib/function/arithmetic/mod.js b/lib/function/arithmetic/mod.js index f1cadaef0..636a13a08 100644 --- a/lib/function/arithmetic/mod.js +++ b/lib/function/arithmetic/mod.js @@ -1,12 +1,10 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, collection = require('../../type/collection'), isNumber = util.number.isNumber, - toNumber = util.number.toNumber, - toBigNumber = util.number.toBigNumber, isBoolean = util['boolean'].isBoolean, isCollection = collection.isCollection; @@ -39,7 +37,7 @@ module.exports = function (math) { if (x instanceof BigNumber) { // try to convert to big number if (isNumber(y)) { - y = toBigNumber(y); + y = BigNumber.convert(y); } else if (isBoolean(y)) { y = new BigNumber(y ? 1 : 0); @@ -50,12 +48,12 @@ module.exports = function (math) { } // downgrade x to Number - return mod(toNumber(x), y); + return mod(x.toNumber(), y); } if (y instanceof BigNumber) { // try to convert to big number if (isNumber(x)) { - x = toBigNumber(x); + x = BigNumber.convert(x); } else if (isBoolean(x)) { x = new BigNumber(x ? 1 : 0); @@ -66,7 +64,7 @@ module.exports = function (math) { } // downgrade y to Number - return mod(x, toNumber(y)); + return mod(x, y.toNumber()); } // TODO: implement mod for complex values diff --git a/lib/function/arithmetic/multiply.js b/lib/function/arithmetic/multiply.js index 5ede71f12..b64697951 100644 --- a/lib/function/arithmetic/multiply.js +++ b/lib/function/arithmetic/multiply.js @@ -1,7 +1,7 @@ module.exports = function(math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), Matrix = require('../../type/Matrix'), Unit = require('../../type/Unit'), @@ -9,8 +9,6 @@ module.exports = function(math) { array = util.array, isNumber = util.number.isNumber, - toNumber = util.number.toNumber, - toBigNumber = util.number.toBigNumber, isBoolean = util['boolean'].isBoolean, isComplex = Complex.isComplex, isArray = Array.isArray, @@ -61,7 +59,7 @@ module.exports = function(math) { if (x instanceof BigNumber) { // try to convert to big number if (isNumber(y)) { - y = toBigNumber(y); + y = BigNumber.convert(y); } else if (isBoolean(y)) { y = new BigNumber(y ? 1 : 0); @@ -72,12 +70,12 @@ module.exports = function(math) { } // downgrade to Number - return multiply(toNumber(x), y); + return multiply(x.toNumber(), y); } if (y instanceof BigNumber) { // try to convert to big number if (isNumber(x)) { - x = toBigNumber(x); + x = BigNumber.convert(x); } else if (isBoolean(x)) { x = new BigNumber(x ? 1 : 0); @@ -88,7 +86,7 @@ module.exports = function(math) { } // downgrade to Number - return multiply(x, toNumber(y)); + return multiply(x, y.toNumber()); } if (isUnit(x)) { diff --git a/lib/function/arithmetic/pow.js b/lib/function/arithmetic/pow.js index a6f9b2987..6239725d8 100644 --- a/lib/function/arithmetic/pow.js +++ b/lib/function/arithmetic/pow.js @@ -1,15 +1,13 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), Matrix = require('../../type/Matrix'), collection = require('../../type/collection'), array = util.array, isNumber = util.number.isNumber, - toNumber = util.number.toNumber, - toBigNumber = util.number.toBigNumber, isBoolean = util['boolean'].isBoolean, isArray = Array.isArray, isInteger = util.number.isInteger, @@ -59,7 +57,7 @@ module.exports = function (math) { if (x instanceof BigNumber) { // try to convert to big number if (isNumber(y)) { - y = toBigNumber(y); + y = BigNumber.convert(y); } else if (isBoolean(y)) { y = new BigNumber(y ? 1 : 0); @@ -70,12 +68,12 @@ module.exports = function (math) { } // downgrade to Number - return pow(toNumber(x), y); + return pow(x.toNumber(), y); } if (y instanceof BigNumber) { // try to convert to big number if (isNumber(x)) { - x = toBigNumber(x); + x = BigNumber.convert(x); } else if (isBoolean(x)) { x = new BigNumber(x ? 1 : 0); @@ -86,7 +84,7 @@ module.exports = function (math) { } // downgrade to Number - return pow(x, toNumber(y)); + return pow(x, y.toNumber()); } diff --git a/lib/function/arithmetic/round.js b/lib/function/arithmetic/round.js index f9894dc2e..19953c655 100644 --- a/lib/function/arithmetic/round.js +++ b/lib/function/arithmetic/round.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), collection = require('../../type/collection'), diff --git a/lib/function/arithmetic/sign.js b/lib/function/arithmetic/sign.js index 5333fc7b9..919009353 100644 --- a/lib/function/arithmetic/sign.js +++ b/lib/function/arithmetic/sign.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), collection = require('../../type/collection'), diff --git a/lib/function/arithmetic/smaller.js b/lib/function/arithmetic/smaller.js index c1ef6648d..e6cad4550 100644 --- a/lib/function/arithmetic/smaller.js +++ b/lib/function/arithmetic/smaller.js @@ -1,14 +1,12 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), collection = require('../../type/collection'), isNumber = util.number.isNumber, - toNumber = util.number.toNumber, - toBigNumber = util.number.toBigNumber, isBoolean = util['boolean'].isBoolean, isString = util.string.isString, isComplex = Complex.isComplex, @@ -39,7 +37,7 @@ module.exports = function (math) { if (x instanceof BigNumber) { // try to convert to big number if (isNumber(y)) { - y = toBigNumber(y); + y = BigNumber.convert(y); } else if (isBoolean(y)) { y = new BigNumber(y ? 1 : 0); @@ -50,12 +48,12 @@ module.exports = function (math) { } // downgrade to Number - return smaller(toNumber(x), y); + return smaller(x.toNumber(), y); } if (y instanceof BigNumber) { // try to convert to big number if (isNumber(x)) { - x = toBigNumber(x); + x = BigNumber.convert(x); } else if (isBoolean(x)) { x = new BigNumber(x ? 1 : 0); @@ -66,7 +64,7 @@ module.exports = function (math) { } // downgrade to Number - return smaller(x, toNumber(y)); + return smaller(x, y.toNumber()); } if ((isUnit(x)) && (isUnit(y))) { diff --git a/lib/function/arithmetic/smallereq.js b/lib/function/arithmetic/smallereq.js index 436847197..c627b664d 100644 --- a/lib/function/arithmetic/smallereq.js +++ b/lib/function/arithmetic/smallereq.js @@ -1,14 +1,12 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), collection = require('../../type/collection'), isNumber = util.number.isNumber, - toNumber = util.number.toNumber, - toBigNumber = util.number.toBigNumber, isBoolean = util['boolean'].isBoolean, isString = util.string.isString, isComplex = Complex.isComplex, @@ -39,7 +37,7 @@ module.exports = function (math) { if (x instanceof BigNumber) { // try to convert to big number if (isNumber(y)) { - y = toBigNumber(y); + y = BigNumber.convert(y); } else if (isBoolean(y)) { y = new BigNumber(y ? 1 : 0); @@ -50,12 +48,12 @@ module.exports = function (math) { } // downgrade to Number - return smallereq(toNumber(x), y); + return smallereq(x.toNumber(), y); } if (y instanceof BigNumber) { // try to convert to big number if (isNumber(x)) { - x = toBigNumber(x); + x = BigNumber.convert(x); } else if (isBoolean(x)) { x = new BigNumber(x ? 1 : 0); @@ -66,7 +64,7 @@ module.exports = function (math) { } // downgrade to Number - return smallereq(x, toNumber(y)); + return smallereq(x, y.toNumber()); } if ((isUnit(x)) && (isUnit(y))) { diff --git a/lib/function/arithmetic/sqrt.js b/lib/function/arithmetic/sqrt.js index 7f7aa18c9..06d20af4c 100644 --- a/lib/function/arithmetic/sqrt.js +++ b/lib/function/arithmetic/sqrt.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), collection = require('../../type/collection'), diff --git a/lib/function/arithmetic/square.js b/lib/function/arithmetic/square.js index 1077682cb..487101034 100644 --- a/lib/function/arithmetic/square.js +++ b/lib/function/arithmetic/square.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), collection = require('../../type/collection'), diff --git a/lib/function/arithmetic/subtract.js b/lib/function/arithmetic/subtract.js index e00cc2bc3..90c9094c3 100644 --- a/lib/function/arithmetic/subtract.js +++ b/lib/function/arithmetic/subtract.js @@ -1,14 +1,12 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), Matrix = require('../../type/Matrix'), Unit = require('../../type/Unit'), collection = require('../../type/collection'), - toNumber = util.number.toNumber, - toBigNumber = util.number.toBigNumber, isBoolean = util['boolean'].isBoolean, isNumber = util.number.isNumber, isComplex = Complex.isComplex, @@ -65,7 +63,7 @@ module.exports = function (math) { if (x instanceof BigNumber) { // try to convert to big number if (isNumber(y)) { - y = toBigNumber(y); + y = BigNumber.convert(y); } else if (isBoolean(y)) { y = new BigNumber(y ? 1 : 0); @@ -76,12 +74,12 @@ module.exports = function (math) { } // downgrade to Number - return subtract(toNumber(x), y); + return subtract(x.toNumber(), y); } if (y instanceof BigNumber) { // try to convert to big number if (isNumber(x)) { - x = toBigNumber(x); + x = BigNumber.convert(x); } else if (isBoolean(x)) { x = new BigNumber(x ? 1 : 0); @@ -92,7 +90,7 @@ module.exports = function (math) { } // downgrade to Number - return subtract(x, toNumber(y)); + return subtract(x, y.toNumber()); } if (isUnit(x)) { diff --git a/lib/function/arithmetic/unary.js b/lib/function/arithmetic/unary.js index a55be06aa..fc5144755 100644 --- a/lib/function/arithmetic/unary.js +++ b/lib/function/arithmetic/unary.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), collection = require('../../type/collection'), diff --git a/lib/function/arithmetic/unequal.js b/lib/function/arithmetic/unequal.js index 0c7c0c397..f46fb71ec 100644 --- a/lib/function/arithmetic/unequal.js +++ b/lib/function/arithmetic/unequal.js @@ -1,14 +1,12 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), collection = require('../../type/collection'), isNumber = util.number.isNumber, - toNumber = util.number.toNumber, - toBigNumber = util.number.toBigNumber, isBoolean = util['boolean'].isBoolean, isString = util.string.isString, isComplex = Complex.isComplex, @@ -48,7 +46,7 @@ module.exports = function (math) { if (x instanceof BigNumber) { // try to convert to big number if (isNumber(y)) { - y = toBigNumber(y); + y = BigNumber.convert(y); } else if (isBoolean(y)) { y = new BigNumber(y ? 1 : 0); @@ -59,12 +57,12 @@ module.exports = function (math) { } // downgrade to Number - return unequal(toNumber(x), y); + return unequal(x.toNumber(), y); } if (y instanceof BigNumber) { // try to convert to big number if (isNumber(x)) { - x = toBigNumber(x); + x = BigNumber.convert(x); } else if (isBoolean(x)) { x = new BigNumber(x ? 1 : 0); @@ -75,7 +73,7 @@ module.exports = function (math) { } // downgrade to Number - return unequal(x, toNumber(y)); + return unequal(x, y.toNumber()); } if ((isUnit(x)) && (isUnit(y))) { diff --git a/lib/function/arithmetic/xgcd.js b/lib/function/arithmetic/xgcd.js index d00c13506..86200c1c7 100644 --- a/lib/function/arithmetic/xgcd.js +++ b/lib/function/arithmetic/xgcd.js @@ -1,9 +1,8 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, - toNumber = util.number.toNumber, isNumber = util.number.isNumber, isBoolean = util['boolean'].isBoolean, isInteger = util.number.isInteger; @@ -35,10 +34,10 @@ module.exports = function (math) { // downgrade bignumbers to numbers if (a instanceof BigNumber) { - return xgcd(toNumber(a), b); + return xgcd(a.toNumber(), b); } if (b instanceof BigNumber) { - return xgcd(a, toNumber(b)); + return xgcd(a, b.toNumber()); } if (isBoolean(a)) { diff --git a/lib/function/complex/arg.js b/lib/function/complex/arg.js index 695cc1b78..53518acd6 100644 --- a/lib/function/complex/arg.js +++ b/lib/function/complex/arg.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), collection = require('../../type/collection'), @@ -45,7 +45,7 @@ module.exports = function (math) { if (x instanceof BigNumber) { // downgrade to Number // TODO: implement BigNumber support - return arg(util.number.toNumber(x)); + return arg(x.toNumber()); } throw new math.error.UnsupportedTypeError('arg', x); diff --git a/lib/function/complex/conj.js b/lib/function/complex/conj.js index 3d151a213..fd6125ede 100644 --- a/lib/function/complex/conj.js +++ b/lib/function/complex/conj.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), collection = require('../../type/collection'), diff --git a/lib/function/complex/im.js b/lib/function/complex/im.js index a059e45fc..39c83f9ab 100644 --- a/lib/function/complex/im.js +++ b/lib/function/complex/im.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), collection = require('../../type/collection'), diff --git a/lib/function/complex/re.js b/lib/function/complex/re.js index 37c6d3b0d..461da7d07 100644 --- a/lib/function/complex/re.js +++ b/lib/function/complex/re.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), collection = require('../../type/collection'), diff --git a/lib/function/construction/bignumber.js b/lib/function/construction/bignumber.js index 5e83f59c1..c413f2c37 100644 --- a/lib/function/construction/bignumber.js +++ b/lib/function/construction/bignumber.js @@ -1,8 +1,8 @@ module.exports = function (math) { var util = require('../../util/index'), - // create a non-global instance of BigNumber - BigNumber = require('../../type/BigNumber'), + // take the BigNumber instance the provided math.js instance + BigNumber = math.type.BigNumber, collection = require('../../type/collection'), isCollection = collection.isCollection, @@ -10,17 +10,6 @@ module.exports = function (math) { isString = util.string.isString, isBoolean = util['boolean'].isBoolean; - // extend BigNumber with a function clone - if (typeof BigNumber.prototype.clone !== 'function') { - /** - * Clone a bignumber - * @return {BigNumber} clone - */ - BigNumber.prototype.clone = function clone () { - return new BigNumber(this); - }; - } - /** * Create a big number, which can store numbers with higher precision than * a JavaScript Number. diff --git a/lib/function/construction/boolean.js b/lib/function/construction/boolean.js index 62dd5ee68..3bdab0f52 100644 --- a/lib/function/construction/boolean.js +++ b/lib/function/construction/boolean.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, collection = require('../../type/collection'), isCollection = collection.isCollection, diff --git a/lib/function/construction/complex.js b/lib/function/construction/complex.js index 4270e66f2..c40adcfba 100644 --- a/lib/function/construction/complex.js +++ b/lib/function/construction/complex.js @@ -1,13 +1,12 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), collection = require('../../type/collection'), isCollection = collection.isCollection, isNumber = util.number.isNumber, - toNumber = util.number.toNumber, isString = util.string.isString, isComplex = Complex.isComplex; @@ -54,7 +53,7 @@ module.exports = function (math) { if (arg instanceof BigNumber) { // convert to Number - return new Complex(toNumber(arg), 0); + return new Complex(arg.toNumber(), 0); } if (isComplex(arg)) { @@ -85,12 +84,12 @@ module.exports = function (math) { // convert re to number if (re instanceof BigNumber) { - re = toNumber(re); + re = re.toNumber(); } // convert im to number if (im instanceof BigNumber) { - im = toNumber(im); + im = im.toNumber(); } if (isNumber(re) && isNumber(im)) { diff --git a/lib/function/construction/index.js b/lib/function/construction/index.js index 52da4ba4e..97d36a0aa 100644 --- a/lib/function/construction/index.js +++ b/lib/function/construction/index.js @@ -1,10 +1,8 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), - Index = require('../../type/Index'), - - toNumber = util.number.toNumber; + BigNumber = math.type.BigNumber, + Index = require('../../type/Index'); /** * Create an index. An Index can store ranges having start, step, and end @@ -30,11 +28,11 @@ module.exports = function (math) { // downgrade BigNumber to Number var args = Array.prototype.slice.apply(arguments).map(function (arg) { if (arg instanceof BigNumber) { - return toNumber(arg); + return arg.toNumber(); } else if (Array.isArray(arg)) { return arg.map(function (elem) { - return (elem instanceof BigNumber) ? toNumber (elem) : elem; + return (elem instanceof BigNumber) ? elem.toNumber() : elem; }); } else { diff --git a/lib/function/construction/number.js b/lib/function/construction/number.js index a06cd2b29..8935f2862 100644 --- a/lib/function/construction/number.js +++ b/lib/function/construction/number.js @@ -1,11 +1,10 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, collection = require('../../type/collection'), isCollection = collection.isCollection, - toNumber = util.number.toNumber, isNumber = util.number.isNumber, isBoolean = util['boolean'].isBoolean, isString = util.string.isString; @@ -27,7 +26,7 @@ module.exports = function (math) { } if (value instanceof BigNumber) { - return toNumber(value); + return value.toNumber(); } if (isString(value)) { diff --git a/lib/function/construction/unit.js b/lib/function/construction/unit.js index 585a192eb..a4e2e3cb6 100644 --- a/lib/function/construction/unit.js +++ b/lib/function/construction/unit.js @@ -1,12 +1,11 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Unit = require('../../type/Unit'), collection = require('../../type/collection'), isCollection = collection.isCollection, - toNumber = util.number.toNumber, isString = util.string.isString; /** @@ -61,7 +60,7 @@ module.exports = function (math) { if (arguments[0] instanceof BigNumber) { // convert value to number - return new Unit(toNumber(arguments[0]), arguments[1]); + return new Unit(arguments[0].toNumber(), arguments[1]); } else { return new Unit(arguments[0], arguments[1]); diff --git a/lib/function/matrix/eye.js b/lib/function/matrix/eye.js index fc2090b30..359ebd8bc 100644 --- a/lib/function/matrix/eye.js +++ b/lib/function/matrix/eye.js @@ -1,11 +1,10 @@ module.exports = function (math, settings) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Matrix = require('../../type/Matrix'), collection = require('../../type/collection'), - toNumber = util.number.toNumber, isNumber = util.number.isNumber, isInteger = util.number.isInteger, isArray = Array.isArray; @@ -41,16 +40,11 @@ module.exports = function (math, settings) { throw new math.error.ArgumentsError('eye', args.length, 0, 2); } - var asBigNumber = args[0] instanceof BigNumber, - rows = args[0], + var rows = args[0], cols = args[1]; - if (rows instanceof BigNumber) { - rows = toNumber(rows); - } - if (cols instanceof BigNumber) { - cols = toNumber(cols); - } + if (rows instanceof BigNumber) rows = rows.toNumber(); + if (cols instanceof BigNumber) cols = cols.toNumber(); if (!isNumber(rows) || !isInteger(rows) || rows < 1) { throw new Error('Parameters in function eye must be positive integers'); @@ -59,11 +53,22 @@ module.exports = function (math, settings) { throw new Error('Parameters in function eye must be positive integers'); } + // convert arguments from bignumber to numbers if needed + var asBigNumber = false; + args = args.map(function (value) { + if (value instanceof BigNumber) { + asBigNumber = true; + return value.toNumber(); + } else { + return value; + } + }); + // create the matrix var matrix = new Matrix(); var one = asBigNumber ? new BigNumber(1) : 1; var defaultValue = asBigNumber ? new BigNumber(0) : 0; - matrix.resize(args.map(toNumber), defaultValue); + matrix.resize(args, defaultValue); // fill in ones on the diagonal var minimum = math.min(args); diff --git a/lib/function/matrix/ones.js b/lib/function/matrix/ones.js index ade4aa3ea..37fda95df 100644 --- a/lib/function/matrix/ones.js +++ b/lib/function/matrix/ones.js @@ -1,13 +1,12 @@ module.exports = function (math, settings) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Matrix = require('../../type/Matrix'), collection = require('../../type/collection'), array = util.array, - toNumber = util.number.toNumber, isArray = Array.isArray; /** @@ -32,9 +31,22 @@ module.exports = function (math, settings) { } else { // output an array or matrix + + // convert arguments from bignumber to numbers if needed + var asBigNumber = false; + args = args.map(function (value) { + if (value instanceof BigNumber) { + asBigNumber = true; + return value.toNumber(); + } else { + return value; + } + }); + + // resize the matrix var res = []; - var defaultValue = (args[0] instanceof BigNumber) ? new BigNumber(1) : 1; - res = array.resize(res, args.map(toNumber), defaultValue); + var defaultValue = asBigNumber ? new BigNumber(1) : 1; + res = array.resize(res, args, defaultValue); return asMatrix ? new Matrix(res) : res; } diff --git a/lib/function/matrix/range.js b/lib/function/matrix/range.js index b5b45d645..a29a9cf21 100644 --- a/lib/function/matrix/range.js +++ b/lib/function/matrix/range.js @@ -1,15 +1,13 @@ module.exports = function (math, settings) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Matrix = require('../../type/Matrix'), collection = require('../../type/collection'), isBoolean = util['boolean'].isBoolean, isString = util.string.isString, - isNumber = util.number.isNumber, - toNumber = util.number.toNumber, - toBigNumber = util.number.toBigNumber; + isNumber = util.number.isNumber; /** * Create an array from a range. @@ -115,23 +113,17 @@ module.exports = function (math, settings) { var asBigNumber = true; // convert start, end, step to BigNumber - if (!(start instanceof BigNumber)) { - start = toBigNumber(start); - } - if (!(end instanceof BigNumber)) { - end = toBigNumber(end); - } - if (!(step instanceof BigNumber)) { - step = toBigNumber(step); - } + if (!(start instanceof BigNumber)) start = BigNumber.convert(start); + if (!(end instanceof BigNumber)) end = BigNumber.convert(end); + if (!(step instanceof BigNumber)) step = BigNumber.convert(step); if (!(start instanceof BigNumber) || !(end instanceof BigNumber) || !(step instanceof BigNumber)) { // not all values can be converted to big number :( // fall back to numbers asBigNumber = false; - start = toNumber(start); - end = toNumber(end); - step = toNumber(step); + if (start instanceof BigNumber) start = start.toNumber(); + if (end instanceof BigNumber) end = end.toNumber(); + if (step instanceof BigNumber) step = step.toNumber(); } } diff --git a/lib/function/matrix/resize.js b/lib/function/matrix/resize.js index 962867445..50da4b4e2 100644 --- a/lib/function/matrix/resize.js +++ b/lib/function/matrix/resize.js @@ -1,14 +1,13 @@ module.exports = function (math, settings) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Matrix = require('../../type/Matrix'), array = util.array, clone = util.object.clone, string = util.string, isString = util.string.isString, - toNumber = util.number.toNumber, isNumber = util.number.isNumber, isInteger = util.number.isInteger, isArray = array.isArray; @@ -42,7 +41,9 @@ module.exports = function (math, settings) { if (size.length && size[0] instanceof BigNumber) { // convert bignumbers to numbers - size = size.map(toNumber); + size = size.map(function (value) { + return (value instanceof BigNumber) ? value.toNumber() : value; + }); } if (isString(x)) { diff --git a/lib/function/matrix/size.js b/lib/function/matrix/size.js index f7f323beb..41161f936 100644 --- a/lib/function/matrix/size.js +++ b/lib/function/matrix/size.js @@ -1,7 +1,7 @@ module.exports = function (math, settings) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), Matrix = require('../../type/Matrix'), diff --git a/lib/function/matrix/zeros.js b/lib/function/matrix/zeros.js index 50c1eeb85..ffcfadcce 100644 --- a/lib/function/matrix/zeros.js +++ b/lib/function/matrix/zeros.js @@ -1,12 +1,11 @@ module.exports = function (math, settings) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Matrix = require('../../type/Matrix'), collection = require('../../type/collection'), array = util.array, - toNumber = util.number.toNumber, isArray = Array.isArray; /** @@ -31,9 +30,22 @@ module.exports = function (math, settings) { } else { // output an array or matrix + + // convert arguments from bignumber to numbers if needed + var asBigNumber = false; + args = args.map(function (value) { + if (value instanceof BigNumber) { + asBigNumber = true; + return value.toNumber(); + } else { + return value; + } + }); + + // resize the matrix var res = []; - var defaultValue = (args[0] instanceof BigNumber) ? new BigNumber(0) : 0; - res = array.resize(res, args.map(toNumber), defaultValue); + var defaultValue = asBigNumber ? new BigNumber(0) : 0; + res = array.resize(res, args, defaultValue); return asMatrix ? new Matrix(res) : res; } diff --git a/lib/function/probability/combinations.js b/lib/function/probability/combinations.js index 69aee7a75..237e9caec 100644 --- a/lib/function/probability/combinations.js +++ b/lib/function/probability/combinations.js @@ -1,12 +1,11 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, collection = require('../../type/collection'), isNumber = util.number.isNumber, - isInteger = util.number.isInteger, - toBigNumber = util.number.toBigNumber; + isInteger = util.number.isInteger; /** * Compute the number of combinations of n items taken k at a time @@ -47,7 +46,7 @@ module.exports = function (math) { if (n instanceof BigNumber) { // make sure k is a BigNumber as well // not all numbers can be converted to BigNumber - k = toBigNumber(k); + k = BigNumber.convert(k); if (!(k instanceof BigNumber) || !isPositiveInteger(n) || !isPositiveInteger(k)) { throw new TypeError('Positive integer value expected in function combinations'); diff --git a/lib/function/probability/factorial.js b/lib/function/probability/factorial.js index 6b58b4ecc..221ac272d 100644 --- a/lib/function/probability/factorial.js +++ b/lib/function/probability/factorial.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, collection = require('../../type/collection'), isNumber = util.number.isNumber, diff --git a/lib/function/probability/permutations.js b/lib/function/probability/permutations.js index def2d2a12..c19ab92e5 100644 --- a/lib/function/probability/permutations.js +++ b/lib/function/probability/permutations.js @@ -1,11 +1,10 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, isNumber = util.number.isNumber, - isInteger = util.number.isInteger, - toBigNumber = util.number.toBigNumber; + isInteger = util.number.isInteger; /** * Compute the number of permutations of n items taken k at a time @@ -64,7 +63,7 @@ module.exports = function (math) { // make sure k is a BigNumber as well // not all numbers can be converted to BigNumber - k = toBigNumber(k); + k = BigNumber.convert(k); if (!(k instanceof BigNumber) || !isPositiveInteger(n) || !isPositiveInteger(k)) { throw new TypeError('Positive integer value expected in function permutations'); diff --git a/lib/function/statistics/median.js b/lib/function/statistics/median.js index f500ab918..cf1e4dff6 100644 --- a/lib/function/statistics/median.js +++ b/lib/function/statistics/median.js @@ -1,7 +1,7 @@ module.exports = function (math) { var Matrix = require('../../type/Matrix'), Unit = require('../../type/Unit'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, collection = require('../../type/collection'), isNumber = require('../../util/number').isNumber, diff --git a/lib/function/statistics/var.js b/lib/function/statistics/var.js index a4511fb1a..e04289ff7 100644 --- a/lib/function/statistics/var.js +++ b/lib/function/statistics/var.js @@ -1,6 +1,6 @@ module.exports = function (math) { var Matrix = require('../../type/Matrix'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, collection = require('../../type/collection'), isCollection = collection.isCollection, diff --git a/lib/function/trigonometry/acos.js b/lib/function/trigonometry/acos.js index 608c02460..3d94211a1 100644 --- a/lib/function/trigonometry/acos.js +++ b/lib/function/trigonometry/acos.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), collection = require('../../type/collection'), @@ -67,7 +67,7 @@ module.exports = function (math) { if (x instanceof BigNumber) { // TODO: implement BigNumber support // downgrade to Number - return acos(util.number.toNumber(x)); + return acos(x.toNumber()); } throw new math.error.UnsupportedTypeError('acos', x); diff --git a/lib/function/trigonometry/asin.js b/lib/function/trigonometry/asin.js index ff28c856b..419e4bfc4 100644 --- a/lib/function/trigonometry/asin.js +++ b/lib/function/trigonometry/asin.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), collection = require('../../type/collection'), @@ -65,7 +65,7 @@ module.exports = function (math) { if (x instanceof BigNumber) { // TODO: implement BigNumber support // downgrade to Number - return asin(util.number.toNumber(x)); + return asin(x.toNumber()); } throw new math.error.UnsupportedTypeError('asin', x); diff --git a/lib/function/trigonometry/atan.js b/lib/function/trigonometry/atan.js index 26ceee5b1..12602304a 100644 --- a/lib/function/trigonometry/atan.js +++ b/lib/function/trigonometry/atan.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), collection = require('../../type/collection'), @@ -60,7 +60,7 @@ module.exports = function (math) { if (x instanceof BigNumber) { // TODO: implement BigNumber support // downgrade to Number - return atan(util.number.toNumber(x)); + return atan(x.toNumber()); } throw new math.error.UnsupportedTypeError('atan', x); diff --git a/lib/function/trigonometry/atan2.js b/lib/function/trigonometry/atan2.js index 1f62d80c9..e1daf18c8 100644 --- a/lib/function/trigonometry/atan2.js +++ b/lib/function/trigonometry/atan2.js @@ -1,11 +1,10 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), collection = require('../../type/collection'), - toNumber = util.number.toNumber, isNumber = util.number.isNumber, isBoolean = util['boolean'].isBoolean, isComplex = Complex.isComplex, @@ -50,10 +49,10 @@ module.exports = function (math) { // TODO: implement bignumber support if (y instanceof BigNumber) { - return atan2(toNumber(y), x); + return atan2(y.toNumber(), x); } if (x instanceof BigNumber) { - return atan2(y, toNumber(x)); + return atan2(y, x.toNumber()); } throw new math.error.UnsupportedTypeError('atan2', y, x); diff --git a/lib/function/trigonometry/cos.js b/lib/function/trigonometry/cos.js index 9c3ea2103..21b941731 100644 --- a/lib/function/trigonometry/cos.js +++ b/lib/function/trigonometry/cos.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), collection = require('../../type/collection'), @@ -59,7 +59,7 @@ module.exports = function (math) { if (x instanceof BigNumber) { // TODO: implement BigNumber support // downgrade to Number - return cos(util.number.toNumber(x)); + return cos(x.toNumber()); } throw new math.error.UnsupportedTypeError('cos', x); diff --git a/lib/function/trigonometry/cot.js b/lib/function/trigonometry/cot.js index 76313d830..53fd01ec4 100644 --- a/lib/function/trigonometry/cot.js +++ b/lib/function/trigonometry/cot.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), collection = require('../../type/collection'), @@ -59,7 +59,7 @@ module.exports = function (math) { if (x instanceof BigNumber) { // TODO: implement BigNumber support // downgrade to Number - return cot(util.number.toNumber(x)); + return cot(x.toNumber()); } throw new math.error.UnsupportedTypeError('cot', x); diff --git a/lib/function/trigonometry/csc.js b/lib/function/trigonometry/csc.js index 7f6f0ec89..b8c2c787c 100644 --- a/lib/function/trigonometry/csc.js +++ b/lib/function/trigonometry/csc.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), collection = require('../../type/collection'), @@ -60,7 +60,7 @@ module.exports = function (math) { if (x instanceof BigNumber) { // TODO: implement BigNumber support // downgrade to Number - return csc(util.number.toNumber(x)); + return csc(x.toNumber()); } throw new math.error.UnsupportedTypeError('csc', x); diff --git a/lib/function/trigonometry/sec.js b/lib/function/trigonometry/sec.js index 96e020316..2aa362b20 100644 --- a/lib/function/trigonometry/sec.js +++ b/lib/function/trigonometry/sec.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), collection = require('../../type/collection'), @@ -60,7 +60,7 @@ module.exports = function (math) { if (x instanceof BigNumber) { // TODO: implement BigNumber support // downgrade to Number - return sec(util.number.toNumber(x)); + return sec(x.toNumber()); } throw new math.error.UnsupportedTypeError('sec', x); diff --git a/lib/function/trigonometry/sin.js b/lib/function/trigonometry/sin.js index 4252153ea..12856cdb1 100644 --- a/lib/function/trigonometry/sin.js +++ b/lib/function/trigonometry/sin.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), collection = require('../../type/collection'), @@ -58,7 +58,7 @@ module.exports = function (math) { if (x instanceof BigNumber) { // TODO: implement BigNumber support // downgrade to Number - return sin(util.number.toNumber(x)); + return sin(x.toNumber()); } throw new math.error.UnsupportedTypeError('sin', x); diff --git a/lib/function/trigonometry/tan.js b/lib/function/trigonometry/tan.js index f2cf77c12..54f6dfc38 100644 --- a/lib/function/trigonometry/tan.js +++ b/lib/function/trigonometry/tan.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), collection = require('../../type/collection'), @@ -62,7 +62,7 @@ module.exports = function (math) { if (x instanceof BigNumber) { // TODO: implement BigNumber support // downgrade to Number - return tan(util.number.toNumber(x)); + return tan(x.toNumber()); } throw new math.error.UnsupportedTypeError('tan', x); diff --git a/lib/function/utils/ifElse.js b/lib/function/utils/ifElse.js index 35ce578e7..356d2eda7 100644 --- a/lib/function/utils/ifElse.js +++ b/lib/function/utils/ifElse.js @@ -1,7 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Matrix = require('../../type/Matrix'), Complex = require('../../type/Complex'), Unit = require('../../type/Unit'), diff --git a/lib/function/utils/typeof.js b/lib/function/utils/typeof.js index fe1fc7a09..a602e4cd9 100644 --- a/lib/function/utils/typeof.js +++ b/lib/function/utils/typeof.js @@ -1,7 +1,7 @@ module.exports = function (math) { var types = require('../../util/types'), - BigNumber = require('../../type/BigNumber'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), Matrix = require('../../type/Matrix'), Unit = require('../../type/Unit'), diff --git a/lib/math.js b/lib/math.js index ef9286a60..055ba4282 100644 --- a/lib/math.js +++ b/lib/math.js @@ -52,14 +52,12 @@ function mathjs (settings) { * @return {Object} settings The currently applied settings */ math.config = function config (settings) { - var BigNumber = require('./type/BigNumber'); - if (settings) { // merge settings object.deepExtend(_settings, settings); if (settings.decimals) { - BigNumber.config({ + math.type.BigNumber.config({ precision: settings.decimals // TODO: rename decimals to precision }); } @@ -93,8 +91,53 @@ function mathjs (settings) { return object.clone(_settings); }; - // apply provided configuration settings - math.config(settings); + // create a new BigNumber factory for this instance of math.js + var BigNumber = require('decimal.js').constructor(); + + // extend BigNumber with a function clone + if (typeof BigNumber.prototype.clone !== 'function') { + /** + * Clone a bignumber + * @return {BigNumber} clone + */ + BigNumber.prototype.clone = function clone () { + return new BigNumber(this); + }; + } + + // extend BigNumber with a function convert + if (typeof BigNumber.convert !== 'function') { + /** + * Try to convert a Number in to a BigNumber. + * If the number has 15 or mor significant digits, the Number cannot be + * converted to BigNumber and will return the original number. + * @param {Number} number + * @return {BigNumber | Number} bignumber + */ + BigNumber.convert = function convert(number) { + if (digits(number) > 15) { + return number; + } + else { + return new BigNumber(number); + } + }; + } + else { + throw new Error('Cannot add function convert to BigNumber: function already exists'); + } + + // types (Matrix, Complex, Unit, ...) + math.type = {}; + math.type.Complex = require('./type/Complex'); + math.type.Range = require('./type/Range'); + math.type.Index = require('./type/Index'); + math.type.Matrix = require('./type/Matrix'); + math.type.Unit = require('./type/Unit'); + math.type.Help = require('./type/Help'); + math.type.BigNumber = BigNumber; + + math.collection = require('./type/collection'); // expression (parse, Parser, nodes, docs) math.expression = {}; @@ -106,18 +149,6 @@ function mathjs (settings) { math.expression.Parser = require('./expression/Parser.js'); math.expression.docs = require('./expression/docs/index.js'); - // types (Matrix, Complex, Unit, ...) - math.type = {}; - math.type.BigNumber = require('./type/BigNumber').constructor(); // create a new Decimal factory for this instance of math.js - math.type.Complex = require('./type/Complex'); - math.type.Range = require('./type/Range'); - math.type.Index = require('./type/Index'); - math.type.Matrix = require('./type/Matrix'); - math.type.Unit = require('./type/Unit'); - math.type.Help = require('./type/Help'); - - math.collection = require('./type/collection'); - // error utility functions require('./type/error')(math); @@ -242,6 +273,9 @@ function mathjs (settings) { math.chaining = {}; math.chaining.Selector = require('./chaining/Selector.js')(math, _settings); + // apply provided configuration settings + math.config(settings); + // return the new instance return math; } diff --git a/lib/type/BigNumber.js b/lib/type/BigNumber.js deleted file mode 100644 index b66d4c71a..000000000 --- a/lib/type/BigNumber.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('decimal.js'); diff --git a/lib/util/bignumber.js b/lib/util/bignumber.js new file mode 100644 index 000000000..786f296ce --- /dev/null +++ b/lib/util/bignumber.js @@ -0,0 +1,206 @@ +var BigNumber = require('decimal.js'), + isNumber = require('./number').isNumber; + digits = require('./number').digits; + +/** + * Test whether value is a BigNumber + * @param {*} value + * @return {Boolean} isBigNumber + */ +exports.isBigNumber = function isBigNumber(value) { + return (value instanceof BigNumber); +}; + +/** + * Convert a number to a formatted string representation. + * + * Syntax: + * + * format(value) + * format(value, options) + * format(value, precision) + * format(value, fn) + * + * Where: + * + * {Number} value The value to be formatted + * {Object} options An object with formatting options. Available options: + * {String} notation + * Number notation. Choose from: + * 'fixed' Always use regular number notation. + * For example '123.40' and '14000000' + * 'exponential' Always use exponential notation. + * For example '1.234e+2' and '1.4e+7' + * 'auto' (default) Regular number notation for numbers + * having an absolute value between + * `lower` and `upper` bounds, and uses + * exponential notation elsewhere. + * Lower bound is included, upper bound + * is excluded. + * For example '123.4' and '1.4e7'. + * {Number} precision A number between 0 and 16 to round + * the digits of the number. + * In case of notations 'exponential' and + * 'auto', `precision` defines the total + * number of significant digits returned + * and is undefined by default. + * In case of notation 'fixed', + * `precision` defines the number of + * significant digits after the decimal + * point, and is 0 by default. + * {Object} exponential An object containing two parameters, + * {Number} lower and {Number} upper, + * used by notation 'auto' to determine + * when to return exponential notation. + * Default values are `lower=1e-3` and + * `upper=1e5`. + * Only applicable for notation `auto`. + * {Function} fn A custom formatting function. Can be used to override the + * built-in notations. Function `fn` is called with `value` as + * parameter and must return a string. Is useful for example to + * format all values inside a matrix in a particular way. + * + * Examples: + * + * format(6.4); // '6.4' + * format(1240000); // '1.24e6' + * format(1/3); // '0.3333333333333333' + * format(1/3, 3); // '0.333' + * format(21385, 2); // '21000' + * format(12.071, {notation: 'fixed'}); // '12' + * format(2.3, {notation: 'fixed', precision: 2}); // '2.30' + * format(52.8, {notation: 'exponential'}); // '5.28e+1' + * + * @param {BigNumber} value + * @param {Object | Function | Number} [options] + * @return {String} str The formatted value + */ +exports.format = function format(value, options) { + if (typeof options === 'function') { + // handle format(value, fn) + return options(value); + } + + // handle special cases + if (!value.isFinite()) { + return value.isNaN() ? 'NaN' : (value.gt(0) ? 'Infinity' : '-Infinity'); + } + + // default values for options + var notation = 'auto'; + var precision = undefined; + + if (options !== undefined) { + // determine notation from options + if (options.notation) { + notation = options.notation; + } + + // determine precision from options + if (isNumber(options)) { + precision = options; + } + else if (options.precision) { + precision = options.precision; + } + } + + // handle the various notations + switch (notation) { + case 'fixed': + return exports.toFixed(value, precision); + + // TODO: notation 'scientific' is deprecated since version 0.16.0, remove this some day + case 'scientific': + throw new Error('Format notation "scientific" is deprecated. Use "exponential" instead.'); + + case 'exponential': + return exports.toExponential(value, precision); + + case 'auto': + // determine lower and upper bound for exponential notation. + // TODO: implement support for upper and lower to be BigNumbers themselves + var lower = 1e-3; + var upper = 1e5; + if (options && options.exponential) { + if (options.exponential.lower !== undefined) { + lower = options.exponential.lower; + } + if (options.exponential.upper !== undefined) { + upper = options.exponential.upper; + } + } + else if (options && options.scientific) { + // TODO: 'options.scientific' is deprecated since version 0.16.0, remove this some day + throw new Error('options.scientific is deprecated, use options.exponential instead.'); + } + + // adjust the configuration of the BigNumber constructor (yeah, this is quite tricky...) + var oldConfig = value.constructor.config({}); + oldConfig = { + toExpNeg: oldConfig.toExpNeg, + toExpPos: oldConfig.toExpPos + }; + + value.constructor.config({ + toExpNeg: Math.round(Math.log(lower) / Math.LN10), + toExpPos: Math.round(Math.log(upper) / Math.LN10) + }); + + // handle special case zero + if (value.isZero()) return '0'; + + // determine whether or not to output exponential notation + var str; + var abs = value.abs(); + if (abs.gte(lower) && abs.lt(upper)) { + // normal number notation + // Note: in bignumber.js, function round rounds to significant digits + str = value.round(precision).toFixed(); + } + else { + // exponential notation + str = exports.toExponential(value, precision); + } + + // remove trailing zeros after the decimal point + return str.replace(/((\.\d*?)(0+))($|e)/, function () { + var digits = arguments[2]; + var e = arguments[4]; + return (digits !== '.') ? digits + e : e; + }); + + default: + throw new Error('Unknown notation "' + notation + '". ' + + 'Choose "auto", "exponential", or "fixed".'); + } +}; + +/** + * Format a number in exponential notation. Like '1.23e+5', '2.3e+0', '3.500e-3' + * @param {BigNumber} value + * @param {Number} [precision] Number of digits in formatted output. + * If not provided, the maximum available digits + * is used. + * @returns {string} str + */ +exports.toExponential = function toExponential (value, precision) { + if (precision !== undefined) { + return value.toExponential(precision - 1); // Note the offset of one + } + else { + return value.toExponential(); + } +}; + +/** + * Format a number with fixed notation. + * @param {BigNumber} value + * @param {Number} [precision=0] Optional number of decimals after the + * decimal point. Zero by default. + */ +exports.toFixed = function toFixed (value, precision) { + return value.toFixed(precision || 0); + // Note: the (precision || 0) is needed as the toFixed of BigNumber has an + // undefined default precision instead of 0. +}; diff --git a/lib/util/index.js b/lib/util/index.js index 48f179f60..87193dfff 100644 --- a/lib/util/index.js +++ b/lib/util/index.js @@ -1,6 +1,7 @@ exports.array = require('./array'); exports['boolean'] = require('./boolean'); exports.number = require('./number'); +exports.bignumber = require('./bignumber'); exports.object = require('./object'); exports.string = require('./string'); exports.types = require('./types'); diff --git a/lib/util/number.js b/lib/util/number.js index a90e0ac33..32c0145bf 100644 --- a/lib/util/number.js +++ b/lib/util/number.js @@ -1,5 +1,3 @@ -var BigNumber = require('../type/BigNumber'); - /** * Test whether value is a Number * @param {*} value @@ -96,7 +94,7 @@ exports.sign = function sign (x) { * format(2.3, {notation: 'fixed', precision: 2}); // '2.30' * format(52.8, {notation: 'exponential'}); // '5.28e+1' * - * @param {Number | BigNumber} value + * @param {Number} value * @param {Object | Function | Number} [options] * @return {String} str The formatted value */ @@ -166,48 +164,25 @@ exports.format = function format(value, options) { throw new Error('options.scientific is deprecated, use options.exponential instead.'); } - // create a clone of the bignumber with the desired configuration - var isBigNumber = value instanceof BigNumber; - if (isBigNumber) { - var BN = BigNumber.config({ - toExpNeg: Math.round(Math.log(lower) / Math.LN10), - toExpPos: Math.round(Math.log(upper) / Math.LN10) - }); - value = new BN(value); - } - // handle special case zero - if (_isZero(value)) { - return '0'; - } + if (value === 0) return '0'; // determine whether or not to output exponential notation var str; - if (_isBetween(value, lower, upper)) { + var abs = Math.abs(value); + if (abs >= lower && abs < upper) { // normal number notation - if (isBigNumber) { - str = new BigNumber(value.toPrecision(precision)).toString(); - } - else { // Number - // Note: IE7 does not allow value.toPrecision(undefined) - var valueStr = precision ? - value.toPrecision(Math.min(precision, 21)) : - value.toPrecision(); - str = parseFloat(valueStr) + ''; - } + // Note: IE7 does not allow value.toPrecision(undefined) + var valueStr = precision ? + value.toPrecision(Math.min(precision, 21)) : + value.toPrecision(); + str = parseFloat(valueStr) + ''; } else { // exponential notation str = exports.toExponential(value, precision); } - /* TODO: cleanup - // restore BigNumber configuration - if (isBigNumber) { - BigNumber.config({EXPONENTIAL_AT: oldScientific}); - } - */ - // remove trailing zeros after the decimal point return str.replace(/((\.\d*?)(0+))($|e)/, function () { var digits = arguments[2]; @@ -221,42 +196,9 @@ exports.format = function format(value, options) { } }; -/** - * Test whether a value is zero - * @param {Number | BigNumber} value - * @return {boolean} isZero - * @private - */ -function _isZero (value) { - return (value instanceof BigNumber) ? value.isZero() : (value === 0); -} - -/** - * Test whether a value is inside a range: - * - * lower >= value < upper - * - * @param {Number | BigNumber} value - * @param {Number} lower Included lower bound - * @param {Number} upper Excluded upper bound - * @return {boolean} isBetween - * @private - */ -function _isBetween(value, lower, upper) { - var abs; - if (value instanceof BigNumber) { - abs = value.abs(); - return (abs.gte(lower) && abs.lt(upper)); - } - else { - abs = Math.abs(value); - return (abs >= lower && abs < upper); - } -} - /** * Format a number in exponential notation. Like '1.23e+5', '2.3e+0', '3.500e-3' - * @param {Number | BigNumber} value + * @param {Number} value * @param {Number} [precision] Number of digits in formatted output. * If not provided, the maximum available digits * is used. @@ -264,12 +206,7 @@ function _isBetween(value, lower, upper) { */ exports.toExponential = function toExponential (value, precision) { if (precision !== undefined) { - if (value instanceof BigNumber) { - return value.toExponential(precision - 1); - } - else { // Number - return value.toExponential(Math.min(precision - 1, 20)); - } + return value.toExponential(Math.min(precision - 1, 20)); } else { return value.toExponential(); @@ -278,19 +215,12 @@ exports.toExponential = function toExponential (value, precision) { /** * Format a number with fixed notation. - * @param {Number | BigNumber} value + * @param {Number} value * @param {Number} [precision=0] Optional number of decimals after the * decimal point. Zero by default. */ exports.toFixed = function toFixed (value, precision) { - if (value instanceof BigNumber) { - return value.toFixed(precision || 0); - // Note: the (precision || 0) is needed as the toFixed of BigNumber has an - // undefined default precision instead of 0. - } - else { // Number - return value.toFixed(Math.min(precision, 20)); - } + return value.toFixed(Math.min(precision, 20)); }; /** @@ -299,7 +229,7 @@ exports.toFixed = function toFixed (value, precision) { * For example: * 2.34 returns 3 * 0.0034 returns 2 - * 120.5e+3 returns 4 + * 120.5e+30 returns 4 * * @param {Number} value * @return {Number} digits Number of significant digits @@ -308,32 +238,6 @@ exports.digits = function digits (value) { return value .toExponential() .replace(/e[\+\-0-9]*$/, '') // remove exponential notation - .replace( /^0\.0*|\./, '') // remove decimal point and leading zeros + .replace( /^0\.?0*|\./, '') // remove decimal point and leading zeros .length }; - -/** - * Convert a Number in to a BigNumber. If the number has 15 or mor significant - * digits, the Number cannot be converted to BigNumber and will return the - * original number. - * @param {Number} number - * @return {BigNumber | Number} bignumber - */ -exports.toBigNumber = function toBigNumber (number) { - if (exports.digits(number) > 15) { - return number; - } - else { - return new BigNumber(number); - } -}; - -/** - * Convert a BigNumber into a Number. If the number is out of range, it will - * get the value Infinity or 0. - * @param {BigNumber} bignumber - * @return {Number} number - */ -exports.toNumber = function toNumber (bignumber) { - return parseFloat(bignumber.valueOf()); -}; diff --git a/lib/util/string.js b/lib/util/string.js index ca5a6eec0..f163f50f5 100644 --- a/lib/util/string.js +++ b/lib/util/string.js @@ -1,5 +1,6 @@ var number = require('./number'), - BigNumber = require('../type/BigNumber'); + bignumber = require('./bignumber'), + BigNumber = require('decimal.js'); /** * Test whether value is a String @@ -45,10 +46,14 @@ exports.endsWith = function endsWith(text, search) { * @return {String} str */ exports.format = function format(value, options) { - if (number.isNumber(value) || value instanceof BigNumber) { + if (number.isNumber(value)) { return number.format(value, options); } + if (value instanceof BigNumber) { + return bignumber.format(value, options); + } + if (Array.isArray(value)) { return formatArray(value, options); } diff --git a/test/expression/node/ConstantNode.test.js b/test/expression/node/ConstantNode.test.js index 03c6775f8..058561940 100644 --- a/test/expression/node/ConstantNode.test.js +++ b/test/expression/node/ConstantNode.test.js @@ -4,7 +4,6 @@ var assert = require('assert'), math = require('../../../index')(), bigmath = require('../../../index')({number: 'bignumber'}), Complex = require('../../../lib/type/Complex'), - BigNumber = require('../../../lib/type/BigNumber'), Node = require('../../../lib/expression/node/Node'), ConstantNode = require('../../../lib/expression/node/ConstantNode'), SymbolNode = require('../../../lib/expression/node/SymbolNode'); @@ -56,7 +55,7 @@ describe('ConstantNode', function() { it ('should compile a ConstantNode with bigmath', function () { var expr = new ConstantNode('number', '2.3').compile(bigmath); - assert.deepEqual(expr.eval(), new BigNumber(2.3)); + assert.deepEqual(expr.eval(), new bigmath.type.BigNumber(2.3)); }); it ('should find a ConstantNode', function () { diff --git a/test/expression/node/UpdateNode.test.js b/test/expression/node/UpdateNode.test.js index 3c9161faa..49b5bddaa 100644 --- a/test/expression/node/UpdateNode.test.js +++ b/test/expression/node/UpdateNode.test.js @@ -128,9 +128,9 @@ describe('UpdateNode', function() { var scope = { a: [[0, 0], [0, 0]] }; - assert.deepEqual(expr.eval(scope), [[0, 0], [math.bignumber(5), 0]]); + assert.deepEqual(expr.eval(scope), [[0, 0], [bigmath.bignumber(5), 0]]); assert.deepEqual(scope, { - a: [[0, 0], [math.bignumber(5), 0]] + a: [[0, 0], [bigmath.bignumber(5), 0]] }); }); diff --git a/test/expression/parse.test.js b/test/expression/parse.test.js index 0f45f7997..489c443db 100644 --- a/test/expression/parse.test.js +++ b/test/expression/parse.test.js @@ -4,7 +4,6 @@ var assert = require('assert'), mathjs = require('../../index'), parse = require('../../lib/expression/parse'), math = mathjs(), - BigNumber = math.type.BigNumber, Complex = math.type.Complex, Matrix = math.type.Matrix, Unit = math.type.Unit; @@ -784,8 +783,10 @@ describe('parse', function() { var bigmath = mathjs({ number: 'bignumber' }); + var BigNumber = bigmath.type.BigNumber; it('should parse numbers as bignumber', function() { + assert.deepEqual(bigmath.bignumber('2.3'), new BigNumber('2.3')); assert.deepEqual(bigmath.eval('2.3'), new BigNumber('2.3')); assert.deepEqual(bigmath.eval('2.3e+500'), new BigNumber('2.3e+500')); }); diff --git a/test/function/construction/bignumber.test.js b/test/function/construction/bignumber.test.js index 4c5999e50..e47e014e2 100644 --- a/test/function/construction/bignumber.test.js +++ b/test/function/construction/bignumber.test.js @@ -1,8 +1,8 @@ var assert = require('assert'), - BigNumber = require('../../../lib/type/BigNumber'), mathjs = require('../../../index'), math = mathjs(), - bignumber = math.bignumber; + bignumber = math.bignumber, + BigNumber = math.type.BigNumber; describe('bignumber', function() { diff --git a/test/function/matrix/range.test.js b/test/function/matrix/range.test.js index 1958df0e8..d80c6821b 100644 --- a/test/function/matrix/range.test.js +++ b/test/function/matrix/range.test.js @@ -80,6 +80,7 @@ describe('range', function() { it('should parse a range with bignumbers', function() { var bigmath = mathjs({number: 'bignumber'}); + var bignumber = bigmath.bignumber; assert.deepEqual(bigmath.range('1:3'), matrix([bignumber(1),bignumber(2)])); assert.deepEqual(bigmath.range('3:-1:0'), matrix([bignumber(3),bignumber(2),bignumber(1)])); }); diff --git a/test/math.test.js b/test/math.test.js index fa7194da3..52e43fbe4 100644 --- a/test/math.test.js +++ b/test/math.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + approx = require('../tools/approx'), mathjs = require('../index'); describe('factory', function() { @@ -69,6 +70,22 @@ describe('factory', function() { math.config(config); }); + + it('should convert a number into a bignumber (when possible)', function() { + var BigNumber = math.type.BigNumber; + + assert.deepEqual(BigNumber.convert(2.34), new BigNumber(2.34)); + assert.deepEqual(BigNumber.convert(0), new BigNumber(0)); + assert.deepEqual(BigNumber.convert(2.3e-3), new BigNumber(2.3e-3)); + assert.deepEqual(BigNumber.convert(2.3e+3), new BigNumber(2.3e+3)); + + // The following values can't represented as bignumber + approx.equal(BigNumber.convert(Math.PI), Math.PI); + approx.equal(BigNumber.convert(1/3), 1/3); + }); + + // TODO: test whether two instances of mathjs do not influence each others (BigNumber) settings + it('should throw an error when ES5 is not supported', function() { var create = Object.create; Object.create = undefined; // fake missing Object.create function diff --git a/test/util/bignumber.test.js b/test/util/bignumber.test.js new file mode 100644 index 000000000..fca41550a --- /dev/null +++ b/test/util/bignumber.test.js @@ -0,0 +1,251 @@ +// test bignumber utils +var assert = require('assert'), + approx = require('../../tools/approx'), + BigNumber = require('decimal.js'), // FIXME: don't use the global BigNumber + bignumber = require('../../lib/util/bignumber'); + +describe('bignumber', function() { + + it('should format a bignumber using toFixed', function() { + var Big = BigNumber.constructor(); + Big.config({decimals: 100}); + + assert.equal(bignumber.toFixed(new Big(2.34)), '2'); + assert.equal(bignumber.toFixed(new Big(2.34), 1), '2.3'); + assert.equal(bignumber.toFixed(new Big(2), 20), '2.00000000000000000000'); + assert.equal(bignumber.toFixed(new Big(2), 21), '2.000000000000000000000'); + assert.equal(bignumber.toFixed(new Big(2), 22), '2.0000000000000000000000'); + assert.equal(bignumber.toFixed(new Big(2), 30), '2.000000000000000000000000000000'); + }); + + it('should format a bignumber using toExponential', function() { + var Big = BigNumber.constructor(); + Big.config({decimals: 100}); + + assert.equal(bignumber.toExponential(new Big(2.34)), '2.34e+0'); + assert.equal(bignumber.toExponential(new Big(2.34e+3)), '2.34e+3'); + assert.equal(bignumber.toExponential(new Big(2.34e-3)), '2.34e-3'); + assert.equal(bignumber.toExponential(new Big(2.34e+3), 2), '2.3e+3'); + assert.equal(bignumber.toExponential(new Big(2e+3), 20), '2.0000000000000000000e+3'); + assert.equal(bignumber.toExponential(new Big(2e+3), 21), '2.00000000000000000000e+3'); + assert.equal(bignumber.toExponential(new Big(2e+3), 22), '2.000000000000000000000e+3'); + assert.equal(bignumber.toExponential(new Big(2e+3), 30), '2.00000000000000000000000000000e+3'); + assert.equal(bignumber.toExponential(new Big('2e+300'), 30), '2.00000000000000000000000000000e+300'); + assert.equal(bignumber.toExponential(new Big('2e-300'), 30), '2.00000000000000000000000000000e-300'); + }); + + describe('format', function () { + + var B = null; + + before (function () { + B = BigNumber.constructor(); + B.config({precision: 20}); // ensure the precision is 20 digits, the default + }); + + it ('should format special values Infinity, NaN', function () { + assert.equal(bignumber.format(new BigNumber(Infinity)), 'Infinity'); + assert.equal(bignumber.format(new BigNumber(-Infinity)), '-Infinity'); + assert.equal(bignumber.format(new BigNumber(NaN)), 'NaN'); + }); + + it('auto notation', function () { + assert.equal(bignumber.format(new B(2).dividedBy(7)), '0.28571428571428571429'); + assert.equal(bignumber.format(new B(0.10400)), '0.104'); + assert.equal(bignumber.format(new B(1000)), '1000'); + + assert.equal(bignumber.format(new B(0)), '0'); + + assert.equal(bignumber.format(new B(2.4e-7)), '2.4e-7'); + assert.equal(bignumber.format(new B(2.4e-6)), '2.4e-6'); + assert.equal(bignumber.format(new B(2.4e-5)), '2.4e-5'); + assert.equal(bignumber.format(new B(2.4e-4)), '2.4e-4'); + assert.equal(bignumber.format(new B(2.3e-3)), '0.0023'); + assert.equal(bignumber.format(new B(2.3456e-3)), '0.0023456'); + assert.equal(bignumber.format(new B(2.3e-2)), '0.023'); + assert.equal(bignumber.format(new B(2.3e-1)), '0.23'); + assert.equal(bignumber.format(new B(2.3)), '2.3'); + assert.equal(bignumber.format(new B(2.3e+1)), '23'); + assert.equal(bignumber.format(new B(2.3e+2)), '230'); + assert.equal(bignumber.format(new B(2.3e+3)), '2300'); + assert.equal(bignumber.format(new B(2.3e+4)), '23000'); + assert.equal(bignumber.format(new B(2.3e+5)), '2.3e+5'); + assert.equal(bignumber.format(new B(2.3e+6)), '2.3e+6'); + + assert.equal(bignumber.format(new B(1.000000012)), '1.000000012'); + assert.equal(bignumber.format(new B(1000000012)), '1.000000012e+9'); + + assert.equal(bignumber.format(new B(1234567)), '1.234567e+6'); + assert.equal(bignumber.format(new B(123456789123456)), '1.23456789123456e+14'); + assert.equal(bignumber.format(new B(123456789123456e-14)), '1.23456789123456'); + assert.equal(bignumber.format(new B('123456789123456789')), '1.23456789123456789e+17'); + assert.equal(bignumber.format(new B('123456789123456789123456789')), '1.23456789123456789123456789e+26'); + + assert.equal(bignumber.format(new B(0.1111e+6)), '1.111e+5'); + assert.equal(bignumber.format(new B(0.3333e+6)), '3.333e+5'); + assert.equal(bignumber.format(new B(0.6666e+6)), '6.666e+5'); + assert.equal(bignumber.format(new B(0.9999e+6)), '9.999e+5'); + assert.equal(bignumber.format(new B(1.111e+6)), '1.111e+6'); + }); + + it('auto notation with precision as second parameter', function() { + assert.deepEqual(bignumber.format(new B('1.23456'), 3), '1.23'); + assert.deepEqual(bignumber.format(new B('12345678'), 4), '1.235e+7'); + + assert.equal(bignumber.format(new B(1).dividedBy(3)), '0.33333333333333333333'); + assert.equal(bignumber.format(new B(1).dividedBy(3), 5), '0.33333'); + assert.equal(bignumber.format(new B(1).dividedBy(3), 3), '0.333'); + assert.equal(bignumber.format(new B(2).dividedBy(3), 3), '0.667'); + }); + + describe('should apply options', function () { + + it('auto notation with precision', function () { + assert.equal(bignumber.format(new B(1).div(3)), '0.33333333333333333333'); + assert.equal(bignumber.format(new B(1).div(3), {precision: 3}), '0.333'); + assert.equal(bignumber.format(new B(1).div(3), {precision: 4}), '0.3333'); + assert.equal(bignumber.format(new B(1).div(3), {precision: 5}), '0.33333'); + + assert.equal(bignumber.format(new B(1000.000), {precision: 5}), '1000'); + assert.equal(bignumber.format(new B(1000.0010), {precision: 5}), '1000'); // rounded off at 5 digits + assert.equal(bignumber.format(new B(1234), {precision: 3}), '1230'); + assert.equal(bignumber.format(new B(123.4), {precision: 6}), '123.4'); + assert.equal(bignumber.format(new B(0.001234), {precision: 3}), '0.00123'); + + assert.equal(bignumber.format(new B(1234567), {precision: 4}), '1.235e+6'); + assert.equal(bignumber.format(new B(1234567), {precision: 2}), '1.2e+6'); + assert.equal(bignumber.format(new B(123e-6), {precision: 2}), '1.2e-4'); + assert.equal(bignumber.format(new B(123e-6), {precision: 8}), '1.23e-4'); // should remove trailing zeros + assert.equal(bignumber.format(new B(3e+6), {precision: 8}), '3e+6'); // should remove trailing zeros + assert.equal(bignumber.format(new B(1234), {precision: 2}), '1200'); + + // overflow the maximum precision of 20 + assert.equal(bignumber.format(new B(2.3), {precision: 30}), '2.3'); + }); + + it('auto notation with custom lower and upper bound', function () { + var options = { + exponential: { + lower: 1e-6, + upper: 1e+9 + } + }; + assert.equal(bignumber.format(new B(0), options), '0'); + assert.equal(bignumber.format(new B(1234567), options), '1234567'); + assert.equal(bignumber.format(new B(1e+9), options), '1e+9'); + assert.equal(bignumber.format(new B(1e+9-1), options), '999999999'); + assert.equal(bignumber.format(new B(1e-6), options), '0.000001'); + assert.equal(bignumber.format(new B(0.999e-6), options), '9.99e-7'); + assert.equal(bignumber.format(new B(123456789123), options), '1.23456789123e+11'); + }); + + }); + + it('should format bignumbers with a custom formatting function', function() { + function asCurrency (value) { + return '$' + value.toFixed(2); + } + + assert.equal(bignumber.format(new BigNumber(12.4264), asCurrency), '$12.43'); + assert.equal(bignumber.format(new BigNumber(0.1), asCurrency), '$0.10'); + assert.equal(bignumber.format(new BigNumber(1.2e+6), asCurrency), '$1200000.00'); + }); + + it('should format bignumbers in exponential notation', function() { + var options = { + notation: 'exponential' + }; + assert.deepEqual(bignumber.format(new B('1.23456'), options), '1.23456e+0'); + assert.deepEqual(bignumber.format(new B('12345678'), options), '1.2345678e+7'); + assert.deepEqual(bignumber.format(new B('2.3e+30'), options), '2.3e+30'); + assert.deepEqual(bignumber.format(new B('0.23e+30'), options), '2.3e+29'); + assert.deepEqual(bignumber.format(new B('2.3e-30'), options), '2.3e-30'); + assert.deepEqual(bignumber.format(new B('0.23e-30'), options), '2.3e-31'); + }); + + it('should format bignumbers in exponential notation with precision', function() { + var options = { + notation: 'exponential', + precision: 18 + }; + assert.deepEqual(bignumber.format(new B(1).div(3), options), '3.33333333333333333e-1'); + }); + + it('should format bignumbers with custom precision, lower, and upper bound', function() { + var Big = BigNumber.constructor(); + Big.config({precision: 100}); + + var options = { + notation: 'auto', + precision : 50, + exponential: { + lower: 1e-50, + upper: 1e+50 + } + }; + + assert.deepEqual(bignumber.format(new Big(5).div(3), options), '1.6666666666666666666666666666666666666666666666667'); + assert.deepEqual(bignumber.format(new Big(5e+40).div(3), options), '16666666666666666666666666666666666666666.666666667'); + assert.deepEqual(bignumber.format(new Big(5e-40).div(3), options), + '0.00000000000000000000000000000000000000016666666666666666666666666666666666666666666666667'); + assert.deepEqual(bignumber.format(new Big(5e+60).div(3), options), '1.6666666666666666666666666666666666666666666666667e+60'); + assert.deepEqual(bignumber.format(new Big(5e-60).div(3), options), '1.6666666666666666666666666666666666666666666666667e-60'); + assert.deepEqual(bignumber.format(new Big(5e-80).div(3), options), '1.6666666666666666666666666666666666666666666666667e-80'); + }); + + it('auto notation with custom lower bound', function () { + var options = { + exponential: { + lower: 1e-6 + } + }; + assert.equal(bignumber.format(new BigNumber(0), options), '0'); + assert.equal(bignumber.format(new BigNumber(1e-5), options), '0.00001'); + assert.equal(bignumber.format(new BigNumber(1e-6), options), '0.000001'); + assert.equal(bignumber.format(new BigNumber(0.999e-6), options), '9.99e-7'); + assert.equal(bignumber.format(new BigNumber(1e-7), options), '1e-7'); + }); + + it('auto notation with custom upper bound', function () { + var options = { + exponential: { + upper: 1e+9 + } + }; + assert.equal(bignumber.format(new BigNumber(1e+9), options), '1e+9'); + assert.equal(bignumber.format(new BigNumber(1e+9-1), options), '999999999'); + }); + + it('should format bignumbers in fixed notation', function() { + var options = { + notation: 'fixed' + }; + + assert.deepEqual(bignumber.format(new BigNumber('1.23456'), options), '1'); + assert.deepEqual(bignumber.format(new BigNumber('1.7'), options), '2'); + assert.deepEqual(bignumber.format(new BigNumber('12345678'), options), '12345678'); + assert.deepEqual(bignumber.format(new BigNumber('12e18'), options), '12000000000000000000'); + assert.deepEqual(bignumber.format(new BigNumber('12e30'), options), '12000000000000000000000000000000'); + }); + + + it('should format bignumbers in fixed notation with precision', function() { + options = { + notation: 'fixed', + precision: 2 + }; + assert.deepEqual(bignumber.format(new BigNumber('1.23456'), options), '1.23'); + assert.deepEqual(bignumber.format(new BigNumber('12345678'), options), '12345678.00'); + assert.deepEqual(bignumber.format(new BigNumber('12e18'), options), '12000000000000000000.00'); + assert.deepEqual(bignumber.format(new BigNumber('12e30'), options), '12000000000000000000000000000000.00'); + }); + + it('should throw an error on unknown notation', function () { + assert.throws(function () { + bignumber.format(new BigNumber(123), {notation: 'non existing'}) + }); + }); + + }); + +}); diff --git a/test/util/number.test.js b/test/util/number.test.js index 0c15aba63..84592495b 100644 --- a/test/util/number.test.js +++ b/test/util/number.test.js @@ -1,7 +1,6 @@ // test number utils var assert = require('assert'), approx = require('../../tools/approx'), - BigNumber = require('../../lib/type/BigNumber'), number = require('../../lib/util/number'); describe('number', function() { @@ -55,12 +54,16 @@ describe('number', function() { }); it('should count the number of significant digits of a number', function() { - assert.equal(number.digits(2.34), 3); + assert.equal(number.digits(0), 0); assert.equal(number.digits(2), 1); - assert.equal(number.digits(0), 1); + assert.equal(number.digits(1234), 4); + assert.equal(number.digits(2.34), 3); + assert.equal(number.digits(3000), 1); assert.equal(number.digits(0.0034), 2); - assert.equal(number.digits(3000.000), 1); assert.equal(number.digits(120.5e50), 4); + assert.equal(number.digits(1120.5e+50), 5); + assert.equal(number.digits(120.52e-50), 5); + assert.equal(number.digits(Math.PI), 16); }); it('should format a number using toFixed', function() { @@ -74,18 +77,6 @@ describe('number', function() { assert.equal(number.toFixed(2, 30), '2.00000000000000000000'); }); - it('should format a bignumber using toFixed', function() { - var Big = BigNumber.constructor(); - Big.config({decimals: 100}); - - assert.equal(number.toFixed(new Big(2.34)), '2'); - assert.equal(number.toFixed(new Big(2.34), 1), '2.3'); - assert.equal(number.toFixed(new Big(2), 20), '2.00000000000000000000'); - assert.equal(number.toFixed(new Big(2), 21), '2.000000000000000000000'); - assert.equal(number.toFixed(new Big(2), 22), '2.0000000000000000000000'); - assert.equal(number.toFixed(new Big(2), 30), '2.000000000000000000000000000000'); - }); - it('should format a number using toExponential', function() { assert.equal(number.toExponential(2.34), '2.34e+0'); assert.equal(number.toExponential(2.34e+3), '2.34e+3'); @@ -97,42 +88,6 @@ describe('number', function() { assert.equal(number.toExponential(2e+3, 30), '2.00000000000000000000e+3'); }); - it('should format a bignumber using toExponential', function() { - var Big = BigNumber.constructor(); - Big.config({decimals: 100}); - - assert.equal(number.toExponential(new Big(2.34)), '2.34e+0'); - assert.equal(number.toExponential(new Big(2.34e+3)), '2.34e+3'); - assert.equal(number.toExponential(new Big(2.34e-3)), '2.34e-3'); - assert.equal(number.toExponential(new Big(2.34e+3), 2), '2.3e+3'); - assert.equal(number.toExponential(new Big(2e+3), 20), '2.0000000000000000000e+3'); - assert.equal(number.toExponential(new Big(2e+3), 21), '2.00000000000000000000e+3'); - assert.equal(number.toExponential(new Big(2e+3), 22), '2.000000000000000000000e+3'); - assert.equal(number.toExponential(new Big(2e+3), 30), '2.00000000000000000000000000000e+3'); - assert.equal(number.toExponential(new Big('2e+300'), 30), '2.00000000000000000000000000000e+300'); - assert.equal(number.toExponential(new Big('2e-300'), 30), '2.00000000000000000000000000000e-300'); - }); - - it('should convert a number into a bignumber (when possible)', function() { - assert.deepEqual(number.toBigNumber(2.34), new BigNumber(2.34)); - assert.deepEqual(number.toBigNumber(0), new BigNumber(0)); - assert.deepEqual(number.toBigNumber(2.3e-3), new BigNumber(2.3e-3)); - assert.deepEqual(number.toBigNumber(2.3e+3), new BigNumber(2.3e+3)); - - approx.equal(number.toBigNumber(Math.PI), Math.PI); - approx.equal(number.toBigNumber(1/3), 1/3); - }); - - it('should convert a bignumber into a number', function () { - assert.deepEqual(number.toNumber(new BigNumber('2.34')), 2.34); - assert.deepEqual(number.toNumber(new BigNumber('0')), 0); - assert.deepEqual(number.toNumber(new BigNumber('2.3e-3')), 2.3e-3); - assert.deepEqual(number.toNumber(new BigNumber('2.3e+3')), 2.3e+3); - - assert.deepEqual(number.toNumber(new BigNumber('2.3e+500')), Infinity); - assert.deepEqual(number.toNumber(new BigNumber('2.3e-500')), 0); - }); - describe('format', function () { it ('should format special values Infinity, NaN', function () { @@ -327,84 +282,6 @@ describe('number', function() { assert.equal(number.format(1.2e+6, asCurrency), '$1200000.00'); }); - describe('bignumber', function () { - var B = null; - - before (function () { - B = BigNumber.constructor(); - B.config({precision: 20}); // ensure the precision is 20 digits, the default - }); - - it('should format big numbers', function() { - assert.deepEqual(number.format(new B('2.3')), '2.3'); - assert.deepEqual(number.format(new B('0.00000003')), '3e-8'); - assert.deepEqual(number.format(new B('12345678')), '1.2345678e+7'); - }); - - it('should format big numbers with given precision', function() { - assert.deepEqual(number.format(new B('1.23456'), 3), '1.23'); - assert.deepEqual(number.format(new B('12345678'), 4), '1.235e+7'); - }); - - it('should format big numbers in exponential notation', function() { - var options = { - notation: 'exponential' - }; - assert.deepEqual(number.format(new B('1.23456'), options), '1.23456e+0'); - assert.deepEqual(number.format(new B('12345678'), options), '1.2345678e+7'); - assert.deepEqual(number.format(new B('2.3e+30'), options), '2.3e+30'); - assert.deepEqual(number.format(new B('0.23e+30'), options), '2.3e+29'); - assert.deepEqual(number.format(new B('2.3e-30'), options), '2.3e-30'); - assert.deepEqual(number.format(new B('0.23e-30'), options), '2.3e-31'); - - options.precision = 18; - assert.deepEqual(number.format(new B(1).div(3), options), '3.33333333333333333e-1'); - }); - - it('should format big numbers with custom precision, lower, and upper bound', function() { - var Big = BigNumber.constructor(); - Big.config({precision: 100}); - - var options = { - notation: 'auto', - precision : 50, - exponential: { - lower: 1e-50, - upper: 1e+50 - } - }; - - assert.deepEqual(number.format(new Big(5).div(3), options), '1.6666666666666666666666666666666666666666666666667'); - assert.deepEqual(number.format(new Big(5e+40).div(3), options), '16666666666666666666666666666666666666666.666666667'); - assert.deepEqual(number.format(new Big(5e-40).div(3), options), - '0.00000000000000000000000000000000000000016666666666666666666666666666666666666666666666667'); - assert.deepEqual(number.format(new Big(5e+60).div(3), options), '1.6666666666666666666666666666666666666666666666667e+60'); - assert.deepEqual(number.format(new Big(5e-60).div(3), options), '1.6666666666666666666666666666666666666666666666667e-60'); - assert.deepEqual(number.format(new Big(5e-80).div(3), options), '1.6666666666666666666666666666666666666666666666667e-80'); - }); - - it('should format big numbers in fixed notation', function() { - var options = { - notation: 'fixed' - }; - - assert.deepEqual(number.format(new BigNumber('1.23456'), options), '1'); - assert.deepEqual(number.format(new BigNumber('1.7'), options), '2'); - assert.deepEqual(number.format(new BigNumber('12345678'), options), '12345678'); - assert.deepEqual(number.format(new BigNumber('12e18'), options), '12000000000000000000'); - assert.deepEqual(number.format(new BigNumber('12e30'), options), '12000000000000000000000000000000'); - - options = { - notation: 'fixed', - precision: 2 - }; - assert.deepEqual(number.format(new BigNumber('1.23456'), options), '1.23'); - assert.deepEqual(number.format(new BigNumber('12345678'), options), '12345678.00'); - assert.deepEqual(number.format(new BigNumber('12e18'), options), '12000000000000000000.00'); - assert.deepEqual(number.format(new BigNumber('12e30'), options), '12000000000000000000000000000000.00'); - }); - }); - }); }); diff --git a/test/util/string.test.js b/test/util/string.test.js index 03dbba6c6..9d590bc5e 100644 --- a/test/util/string.test.js +++ b/test/util/string.test.js @@ -1,6 +1,7 @@ // test string utils var assert = require('assert'), approx = require('../../tools/approx'), + BigNumber = require('decimal.js'), string = require('../../lib/util/string'); describe ('string', function () { @@ -31,6 +32,13 @@ describe ('string', function () { assert.equal(string.format(2.3), '2.3'); }); + it ('should format a bignumber', function () { + var B = BigNumber.config({ + precision: 20 + }); + assert.equal(string.format(new B(1).div(3)), '0.33333333333333333333'); + }); + it ('should format a number with configuration', function () { assert.equal(string.format(1.23456, 3), '1.23'); assert.equal(string.format(1.23456, {precision: 3}), '1.23'); From 268c40e4805f3ff444ca22a1350ef479d8bbba77 Mon Sep 17 00:00:00 2001 From: josdejong Date: Sat, 5 Apr 2014 22:51:47 +0200 Subject: [PATCH 12/48] Simplification of function digits --- lib/util/number.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/util/number.js b/lib/util/number.js index 32c0145bf..789cb2293 100644 --- a/lib/util/number.js +++ b/lib/util/number.js @@ -237,7 +237,7 @@ exports.toFixed = function toFixed (value, precision) { exports.digits = function digits (value) { return value .toExponential() - .replace(/e[\+\-0-9]*$/, '') // remove exponential notation + .replace(/e.*$/, '') // remove exponential notation .replace( /^0\.?0*|\./, '') // remove decimal point and leading zeros .length }; From 42748689a121f7ed4adfda1dad27ae29f105508c Mon Sep 17 00:00:00 2001 From: josdejong Date: Sat, 5 Apr 2014 22:53:38 +0200 Subject: [PATCH 13/48] Removed preliminary rounding of results of `det` --- lib/function/matrix/det.js | 4 ++-- test/function/matrix/det.test.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/function/matrix/det.js b/lib/function/matrix/det.js index 686c2c0d4..4e860f3c0 100644 --- a/lib/function/matrix/det.js +++ b/lib/function/matrix/det.js @@ -108,7 +108,7 @@ module.exports = function (math) { if (lead == cols) { // We found the last pivot. if (object.deepEqual(matrix, math.eye(rows).valueOf())) { - return math.round(d, 6); // FIXME: should d be rounded to 6 here? + return d; } else { return 0; } @@ -145,7 +145,7 @@ module.exports = function (math) { // If reduction did not result in the identity, the matrix is singular. if (object.deepEqual(matrix, math.eye(rows).valueOf())) { - return math.round(d, 6); // FIXME: should d be rounded to 6 here? + return d; } else { return 0; } diff --git a/test/function/matrix/det.test.js b/test/function/matrix/det.test.js index a329f18f3..542198999 100644 --- a/test/function/matrix/det.test.js +++ b/test/function/matrix/det.test.js @@ -7,24 +7,24 @@ describe('det', function() { assert.equal(math.det([5]), 5); assert.equal(math.det([[1,2],[3,4]]), -2); assert.equal(math.det(math.matrix([[1,2],[3,4]])), -2); - assert.equal(math.det([ + approx.equal(math.det([ [-2, 2, 3], [-1, 1, 3], [ 2, 0, -1] ]), 6); - assert.equal(math.det([ + approx.equal(math.det([ [ 1, 4, 7], [ 3, 0, 5], [-1, 9, 11] ]), -8); - assert.equal(math.det([ + approx.equal(math.det([ [1,7,4,3,7], [0,7,0,3,7], [0,7,4,3,0], [1,7,5,9,7], [2,7,4,3,7] ]), -1176); - assert.equal(math.det(math.diag([4,-5,6])), -120); + approx.equal(math.det(math.diag([4,-5,6])), -120); }); it('should return 1 for the identity matrix',function() { From 0ea333351c40a9d62059871c239d087c44dc3d35 Mon Sep 17 00:00:00 2001 From: josdejong Date: Sat, 5 Apr 2014 22:55:49 +0200 Subject: [PATCH 14/48] Fixed broken unit test --- test/function/matrix/det.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/function/matrix/det.test.js b/test/function/matrix/det.test.js index 542198999..cd6cc40d9 100644 --- a/test/function/matrix/det.test.js +++ b/test/function/matrix/det.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + approx = require('../../../tools/approx'), math = require('../../../index')(); describe('det', function() { From c7c17c6f64b71bb5d2724518e2ea193a49d8eccb Mon Sep 17 00:00:00 2001 From: josdejong Date: Sat, 5 Apr 2014 23:21:38 +0200 Subject: [PATCH 15/48] Removed dependency on global `math` from `Complex` --- HISTORY.md | 4 +++- lib/type/Complex.js | 27 +++++++++++++++++---------- test/type/Complex.test.js | 16 ++++++++-------- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index da104c5d8..b29d386fe 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -6,6 +6,8 @@ https://github.com/josdejong/mathjs - Switched to module `decimal.js` for BigNumber support, instead of `bignumber.js`. +- Implemented support for polar coordinates to the `Complex` datatype. + Thanks Finn Pauls (@finnp). - Implemented conditional operator `a ? b : c` in expression parser. - Improved function `ifElse`, is now specified for special data types too. - Minor bug fixes. @@ -14,7 +16,7 @@ https://github.com/josdejong/mathjs ## 2014-03-30, version 0.19.0 - Implemented functions `compare`, `sum`, `prod`, `var`, `std`, `median`. -- Implemented function `ifElse` (thanks @mtraynham). +- Implemented function `ifElse` Thanks @mtraynham. - Minor bug fixes. diff --git a/lib/type/Complex.js b/lib/type/Complex.js index b656177e2..a27c4ab28 100644 --- a/lib/type/Complex.js +++ b/lib/type/Complex.js @@ -303,22 +303,29 @@ Complex.fromPolar = function fromPolar(args) { return Complex.fromPolar(arg.r, arg.phi); } throw new TypeError('Input has to be an object with r and phi keys.'); + case 2: var r = arguments[0], phi = arguments[1]; if(isNumber(r)) { - if(isNumber(phi) || (isUnit(phi) && phi.hasBase(Unit.BASE_UNITS.ANGLE))) { - return new Complex(r * math.cos(phi), r * math.sin(phi)); - } else { - throw new TypeError('Phi is not a number nor an angle unit.'); + if (isUnit(phi) && phi.hasBase(Unit.BASE_UNITS.ANGLE)) { + // convert unit to a number in radians + phi = phi.toNumber('rad'); } + + if(isNumber(phi)) { + return new Complex(r * Math.cos(phi), r * Math.sin(phi)); + } + + throw new TypeError('Phi is not a number nor an angle unit.'); } else { throw new TypeError('Radius r is not a number.'); } + default: - throw new math.error.ArgumentsError('fromPolar', arguments.length, 1, 2); + throw new SyntaxError('Wrong number of arguments in function fromPolar'); } -} +}; /* * Return the value of the complex number in polar notation @@ -326,10 +333,10 @@ Complex.fromPolar = function fromPolar(args) { * @return {Object} Object with r and phi keys. */ Complex.prototype.toPolar = function() { - var polar = {}; - polar.r = math.sqrt(math.add(math.square(this.re), math.square(this.im))); - polar.phi = math.arg(this); - return polar; + return { + r: Math.sqrt(this.re * this.re + this.im * this.im), + phi: Math.atan2(this.im, this.re) + }; }; /** diff --git a/test/type/Complex.test.js b/test/type/Complex.test.js index 0167193b4..bc954aca0 100644 --- a/test/type/Complex.test.js +++ b/test/type/Complex.test.js @@ -1,8 +1,8 @@ // test data type Complex var assert = require('assert'), - Complex = require('../../lib/type/Complex'), - math = require('../../index')(); + Unit = require('../../lib/type/Unit'), + Complex = require('../../lib/type/Complex'); describe('Complex', function () { @@ -195,9 +195,9 @@ describe('Complex', function () { it('should save polar coordinates input correctly', function() { var complex1 = Complex.fromPolar({r: 0, phi: 4}); var complex2 = Complex.fromPolar({r: 5, phi: 0}); - var complex3 = Complex.fromPolar({r: 1, phi: math.pi}); - var complex4 = Complex.fromPolar({r: 3, phi: math.pi / 2}); - var complex5 = Complex.fromPolar({r: 3, phi: -math.pi / 2}); + var complex3 = Complex.fromPolar({r: 1, phi: Math.PI}); + var complex4 = Complex.fromPolar({r: 3, phi: Math.PI / 2}); + var complex5 = Complex.fromPolar({r: 3, phi: -Math.PI / 2}); assertComplex(complex1, 0, 0); assertComplex(complex2, 5, 0); assert.equal(complex3.re, -1); @@ -212,9 +212,9 @@ describe('Complex', function () { }); it('should accept angle units for phi properly', function() { - var fromDeg = Complex.fromPolar(1, math.unit('90deg')), - fromRad = Complex.fromPolar(1, math.unit('0rad')), - fromGrad = Complex.fromPolar(1, math.unit('100grad')); + var fromDeg = Complex.fromPolar(1, new Unit(90, 'deg')), + fromRad = Complex.fromPolar(1, new Unit(0, 'rad')), + fromGrad = Complex.fromPolar(1, new Unit(100, 'grad')); assert.equal(fromDeg.im, 1); assert.equal(fromGrad.im, 1); assert.equal(fromRad.im, 0); From fab41839bcc524840b568e6e83bf2d5b53d35daf Mon Sep 17 00:00:00 2001 From: josdejong Date: Sat, 5 Apr 2014 23:30:46 +0200 Subject: [PATCH 16/48] Implemented `BigNumber` support for function `det` --- HISTORY.md | 1 + lib/function/matrix/det.js | 7 +++---- test/function/matrix/det.test.js | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index b29d386fe..83ea2ded3 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -10,6 +10,7 @@ https://github.com/josdejong/mathjs Thanks Finn Pauls (@finnp). - Implemented conditional operator `a ? b : c` in expression parser. - Improved function `ifElse`, is now specified for special data types too. +- Implemented `BigNumber` support for function `det`. - Minor bug fixes. diff --git a/lib/function/matrix/det.js b/lib/function/matrix/det.js index 4e860f3c0..24789392f 100644 --- a/lib/function/matrix/det.js +++ b/lib/function/matrix/det.js @@ -90,7 +90,6 @@ module.exports = function (math) { } else { // this is an n x n matrix - // TODO: support for bignumbers, complex numbers, etc var a; var d = 1; var lead = 0; @@ -100,7 +99,7 @@ module.exports = function (math) { } var i = r; // Find the pivot element. - while (matrix[i][lead] == 0) { + while (math.equal(matrix[i][lead], 0)) { i++; if (i == rows) { i = r; @@ -127,7 +126,7 @@ module.exports = function (math) { // Scale row r and the determinant simultaneously. var div = matrix[r][lead]; for (a = 0; a < cols; a++) { - matrix[r][a] = matrix[r][a] / div; + matrix[r][a] = math.divide(matrix[r][a], div); } d *= div; // Back-substitute upwards. @@ -136,7 +135,7 @@ module.exports = function (math) { // Taking linear combinations does not change the det. var c = matrix[j][lead]; for (a = 0; a < cols; a++) { - matrix[j][a] = matrix[j][a] - matrix[r][a] * c; + matrix[j][a] = math.subtract(matrix[j][a], math.multiply(matrix[r][a], c)); } } } diff --git a/test/function/matrix/det.test.js b/test/function/matrix/det.test.js index cd6cc40d9..1c0f151dc 100644 --- a/test/function/matrix/det.test.js +++ b/test/function/matrix/det.test.js @@ -78,6 +78,23 @@ describe('det', function() { assert.equal(c2.re, 2); }); + it('should calculate correctly the determinant of a matrix with bignumbers', function() { + var bignumber = math.bignumber; + assert.deepEqual(math.det([bignumber(5)]), bignumber(5)); + assert.deepEqual(math.det([ + [bignumber(1), bignumber(2)], + [bignumber(3), bignumber(4)] + ]), bignumber(-2)); + }); + + it('should calculate the determinant of a matrix with mixed numbers and bignumbers', function() { + var bignumber = math.bignumber; + assert.deepEqual(math.det([ + [1, bignumber(2)], + [bignumber(3), 4] + ]), bignumber(-2)); + }); + it('should not change the value of the initial matrix', function() { var m_test = [[1,2,3],[4,5,6],[7,8,9]]; math.det(m_test); From d8ddbfddac73796e4b8453ee5d5a051876be072f Mon Sep 17 00:00:00 2001 From: josdejong Date: Sat, 5 Apr 2014 23:47:54 +0200 Subject: [PATCH 17/48] Fixed #156: Fixed support for element-wise comparisons between a string and a matrix --- HISTORY.md | 1 + lib/function/arithmetic/compare.js | 10 ++++++---- lib/function/arithmetic/equal.js | 10 ++++++---- lib/function/arithmetic/larger.js | 10 ++++++---- lib/function/arithmetic/largereq.js | 10 ++++++---- lib/function/arithmetic/smaller.js | 10 ++++++---- lib/function/arithmetic/smallereq.js | 10 ++++++---- lib/function/arithmetic/unequal.js | 10 ++++++---- test/function/arithmetic/compare.test.js | 5 +++++ test/function/arithmetic/equal.test.js | 5 +++++ test/function/arithmetic/larger.test.js | 5 +++++ test/function/arithmetic/largereq.test.js | 5 +++++ test/function/arithmetic/smaller.test.js | 5 +++++ test/function/arithmetic/smallereq.test.js | 5 +++++ test/function/arithmetic/unequal.test.js | 5 +++++ 15 files changed, 78 insertions(+), 28 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 83ea2ded3..c5e31a216 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -11,6 +11,7 @@ https://github.com/josdejong/mathjs - Implemented conditional operator `a ? b : c` in expression parser. - Improved function `ifElse`, is now specified for special data types too. - Implemented `BigNumber` support for function `det`. +- Fixed support for element-wise comparisons between a string and a matrix. - Minor bug fixes. diff --git a/lib/function/arithmetic/compare.js b/lib/function/arithmetic/compare.js index 13ab46007..31ee75748 100644 --- a/lib/function/arithmetic/compare.js +++ b/lib/function/arithmetic/compare.js @@ -72,14 +72,16 @@ module.exports = function (math) { return (x.value > y.value) ? 1 : ((x.value < y.value) ? -1 : 0); } - if (isString(x) || isString(y)) { - return (x > y) ? 1 : ((x < y) ? -1 : 0); - } - if (isCollection(x) || isCollection(y)) { return collection.deepMap2(x, y, compare); } + // Note: test strings after testing collections, + // else we can't compare a string with a matrix + if (isString(x) || isString(y)) { + return (x > y) ? 1 : ((x < y) ? -1 : 0); + } + if (isBoolean(x)) { return compare(+x, y); } diff --git a/lib/function/arithmetic/equal.js b/lib/function/arithmetic/equal.js index 6da60016d..04cd0fc07 100644 --- a/lib/function/arithmetic/equal.js +++ b/lib/function/arithmetic/equal.js @@ -89,14 +89,16 @@ module.exports = function (math) { return x.value == y.value; } - if (isString(x) || isString(y)) { - return x == y; - } - if (isCollection(x) || isCollection(y)) { return collection.deepMap2(x, y, equal); } + // Note: test strings after testing collections, + // else we can't compare a string with a matrix + if (isString(x) || isString(y)) { + return x == y; + } + if (isBoolean(x)) { return equal(+x, y); } diff --git a/lib/function/arithmetic/larger.js b/lib/function/arithmetic/larger.js index f3ace49f8..8902bc561 100644 --- a/lib/function/arithmetic/larger.js +++ b/lib/function/arithmetic/larger.js @@ -74,14 +74,16 @@ module.exports = function (math) { return x.value > y.value; } - if (isString(x) || isString(y)) { - return x > y; - } - if (isCollection(x) || isCollection(y)) { return collection.deepMap2(x, y, larger); } + // Note: test strings after testing collections, + // else we can't compare a string with a matrix + if (isString(x) || isString(y)) { + return x > y; + } + if (isBoolean(x)) { return larger(+x, y); } diff --git a/lib/function/arithmetic/largereq.js b/lib/function/arithmetic/largereq.js index 2910021aa..b6fae43ca 100644 --- a/lib/function/arithmetic/largereq.js +++ b/lib/function/arithmetic/largereq.js @@ -74,14 +74,16 @@ module.exports = function (math) { return x.value >= y.value; } - if (isString(x) || isString(y)) { - return x >= y; - } - if (isCollection(x) || isCollection(y)) { return collection.deepMap2(x, y, largereq); } + // Note: test strings after testing collections, + // else we can't compare a string with a matrix + if (isString(x) || isString(y)) { + return x >= y; + } + if (isBoolean(x)) { return largereq(+x, y); } diff --git a/lib/function/arithmetic/smaller.js b/lib/function/arithmetic/smaller.js index e6cad4550..7a0570cd9 100644 --- a/lib/function/arithmetic/smaller.js +++ b/lib/function/arithmetic/smaller.js @@ -74,14 +74,16 @@ module.exports = function (math) { return x.value < y.value; } - if (isString(x) || isString(y)) { - return x < y; - } - if (isCollection(x) || isCollection(y)) { return collection.deepMap2(x, y, smaller); } + // Note: test strings after testing collections, + // else we can't compare a string with a matrix + if (isString(x) || isString(y)) { + return x < y; + } + if (isBoolean(x)) { return smaller(+x, y); } diff --git a/lib/function/arithmetic/smallereq.js b/lib/function/arithmetic/smallereq.js index c627b664d..451d37a94 100644 --- a/lib/function/arithmetic/smallereq.js +++ b/lib/function/arithmetic/smallereq.js @@ -74,14 +74,16 @@ module.exports = function (math) { return x.value <= y.value; } - if (isString(x) || isString(y)) { - return x <= y; - } - if (isCollection(x) || isCollection(y)) { return collection.deepMap2(x, y, smallereq); } + // Note: test strings after testing collections, + // else we can't compare a string with a matrix + if (isString(x) || isString(y)) { + return x <= y; + } + if (isBoolean(x)) { return smallereq(+x, y); } diff --git a/lib/function/arithmetic/unequal.js b/lib/function/arithmetic/unequal.js index f46fb71ec..d29ccd71d 100644 --- a/lib/function/arithmetic/unequal.js +++ b/lib/function/arithmetic/unequal.js @@ -83,14 +83,16 @@ module.exports = function (math) { return x.value != y.value; } - if (isString(x) || isString(y)) { - return x != y; - } - if (isCollection(x) || isCollection(y)) { return collection.deepMap2(x, y, unequal); } + // Note: test strings after testing collections, + // else we can't compare a string with a matrix + if (isString(x) || isString(y)) { + return x != y; + } + if (isBoolean(x)) { return unequal(+x, y); } diff --git a/test/function/arithmetic/compare.test.js b/test/function/arithmetic/compare.test.js index e6ecabe6c..e79c6da0b 100644 --- a/test/function/arithmetic/compare.test.js +++ b/test/function/arithmetic/compare.test.js @@ -80,6 +80,11 @@ describe('compare', function() { assert.equal(compare('abc', 'abd'), -1); }); + it('should compare a string an matrix elementwise', function() { + assert.deepEqual(compare('B', ['A', 'B', 'C']), [1, 0, -1]); + assert.deepEqual(compare(['A', 'B', 'C'], 'B'), [-1, 0, 1]); + }); + it('should perform element-wise comparison for two matrices of same size', function() { assert.deepEqual(compare([1,4,6], [3,4,5]), [-1, 0, 1]); assert.deepEqual(compare([1,4,6], matrix([3,4,5])), matrix([-1, 0, 1])); diff --git a/test/function/arithmetic/equal.test.js b/test/function/arithmetic/equal.test.js index a1fb95835..3760cff40 100644 --- a/test/function/arithmetic/equal.test.js +++ b/test/function/arithmetic/equal.test.js @@ -101,6 +101,11 @@ describe('equal', function() { assert.equal(equal('hello', 'hello'), true); }); + it('should compare a string an matrix elementwise', function() { + assert.deepEqual(equal('B', ['A', 'B', 'C']), [false, true, false]); + assert.deepEqual(equal(['A', 'B', 'C'], 'B'), [false, true, false]); + }); + it('should compare two matrices correctly', function() { assert.deepEqual(equal([1,4,5], [3,4,5]), [false, true, true]); assert.deepEqual(equal([1,4,5], matrix([3,4,5])), matrix([false, true, true])); diff --git a/test/function/arithmetic/larger.test.js b/test/function/arithmetic/larger.test.js index 01a102825..1ac20f9ed 100644 --- a/test/function/arithmetic/larger.test.js +++ b/test/function/arithmetic/larger.test.js @@ -83,6 +83,11 @@ describe('larger', function() { assert.equal(larger('abc', 'abd'), false); }); + it('should compare a string an matrix elementwise', function() { + assert.deepEqual(larger('B', ['A', 'B', 'C']), [true, false, false]); + assert.deepEqual(larger(['A', 'B', 'C'], 'B'), [false, false, true]); + }); + it('should perform element-wise comparison for two matrices of same size', function() { assert.deepEqual(larger([1,4,6], [3,4,5]), [false, false, true]); assert.deepEqual(larger([1,4,6], matrix([3,4,5])), matrix([false, false, true])); diff --git a/test/function/arithmetic/largereq.test.js b/test/function/arithmetic/largereq.test.js index 2c814ae98..afce99730 100644 --- a/test/function/arithmetic/largereq.test.js +++ b/test/function/arithmetic/largereq.test.js @@ -85,6 +85,11 @@ describe('largereq', function() { assert.equal(largereq('abc', 'abd'), false); }); + it('should compare a string an matrix elementwise', function() { + assert.deepEqual(largereq('B', ['A', 'B', 'C']), [true, true, false]); + assert.deepEqual(largereq(['A', 'B', 'C'], 'B'), [false, true, true]); + }); + it('should perform element-wise comparison for two matrices of the same size', function() { assert.deepEqual(largereq([1,4,6], [3,4,5]), [false, true, true]); assert.deepEqual(largereq([1,4,6], matrix([3,4,5])), matrix([false, true, true])); diff --git a/test/function/arithmetic/smaller.test.js b/test/function/arithmetic/smaller.test.js index cfa94d03d..e821a8131 100644 --- a/test/function/arithmetic/smaller.test.js +++ b/test/function/arithmetic/smaller.test.js @@ -87,6 +87,11 @@ describe('smaller', function() { assert.equal(smaller('abc', 'abd'), true); }); + it('should compare a string an matrix elementwise', function() { + assert.deepEqual(smaller('B', ['A', 'B', 'C']), [false, false, true]); + assert.deepEqual(smaller(['A', 'B', 'C'], 'B'), [true, false, false]); + }); + it('should perform element-wise comparison on two matrices of same size', function() { assert.deepEqual(smaller([1,4,6], [3,4,5]), [true, false, false]); assert.deepEqual(smaller([1,4,6], matrix([3,4,5])), matrix([true, false, false])); diff --git a/test/function/arithmetic/smallereq.test.js b/test/function/arithmetic/smallereq.test.js index 866ff7455..6e6abd98d 100644 --- a/test/function/arithmetic/smallereq.test.js +++ b/test/function/arithmetic/smallereq.test.js @@ -90,6 +90,11 @@ describe('smallereq', function() { assert.equal(smallereq('abc', 'abd'), true); }); + it('should compare a string an matrix elementwise', function() { + assert.deepEqual(smallereq('B', ['A', 'B', 'C']), [false, true, true]); + assert.deepEqual(smallereq(['A', 'B', 'C'], 'B'), [true, true, false]); + }); + it('should perform element-wise comparison on two matrices', function() { assert.deepEqual(smallereq([1,4,6], [3,4,5]), [true, true, false]); assert.deepEqual(smallereq([1,4,6], matrix([3,4,5])), matrix([true, true, false])); diff --git a/test/function/arithmetic/unequal.test.js b/test/function/arithmetic/unequal.test.js index 0a66f76d7..e376d2dd1 100644 --- a/test/function/arithmetic/unequal.test.js +++ b/test/function/arithmetic/unequal.test.js @@ -105,6 +105,11 @@ describe('unequal', function() { assert.equal(unequal('hello', 'hello'), false); }); + it('should compare a string an matrix elementwise', function() { + assert.deepEqual(unequal('B', ['A', 'B', 'C']), [true, false, true]); + assert.deepEqual(unequal(['A', 'B', 'C'], 'B'), [true, false, true]); + }); + it('should perform element-wise comparison of two matrices of the same size', function() { assert.deepEqual(unequal([1,4,5], [3,4,5]), [true, false, false]); assert.deepEqual(unequal([1,4,5], matrix([3,4,5])), matrix([true, false, false])); From 45550e5ffbdb51d633bb7271af1a58e50a2475f0 Mon Sep 17 00:00:00 2001 From: josdejong Date: Sun, 6 Apr 2014 11:14:01 +0200 Subject: [PATCH 18/48] Changed configuration option `decimals` to `precision` --- HISTORY.md | 2 ++ docs/configuration.md | 7 ++-- docs/datatypes/bignumbers.md | 4 +-- examples/bignumbers.js | 2 +- lib/math.js | 37 ++++++++++---------- test/deprecated.test.js | 8 +++++ test/function/arithmetic/sqrt.test.js | 7 +++- test/function/construction/bignumber.test.js | 4 +-- test/function/matrix/det.test.js | 6 ++++ test/function/utils/format.test.js | 2 +- test/math.test.js | 10 +++--- test/util/bignumber.test.js | 4 +-- 12 files changed, 57 insertions(+), 36 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index c5e31a216..cb4b452dd 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -11,6 +11,8 @@ https://github.com/josdejong/mathjs - Implemented conditional operator `a ? b : c` in expression parser. - Improved function `ifElse`, is now specified for special data types too. - Implemented `BigNumber` support for function `det`. +- Changed configuration option `decimals` to `precision` (applies to BigNumbers + only). - Fixed support for element-wise comparisons between a string and a matrix. - Minor bug fixes. diff --git a/docs/configuration.md b/docs/configuration.md index bcecc4303..69effc470 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -20,9 +20,8 @@ Available configuration settings are: Available values are: `'number'` (default) or `'bignumber'`. BigNumbers have higher precision than the default numbers of JavaScript. -- `decimals`. The maximum number of decimal places behind the decimal - point (not the number of significant digits). Only applies to BigNumbers, - not to numbers. Default value is 20. +- `precision`. The maximum number of significant digits for bigNumbers. + This setting only applies to BigNumbers, not to numbers. Default value is 20. ## Examples @@ -76,7 +75,7 @@ var mathjs = require('mathjs'); // use BigNumbers by default var math3 = mathjs({ number: 'bignumber', - decimals: 32 + precision: 32 }); // parser will parse numbers as BigNumber now: diff --git a/docs/datatypes/bignumbers.md b/docs/datatypes/bignumbers.md index 7f8c015ef..9726e5c08 100644 --- a/docs/datatypes/bignumbers.md +++ b/docs/datatypes/bignumbers.md @@ -21,7 +21,7 @@ BigNumbers instead of [numbers](numbers.md) by default, configure math.js like: var mathjs = require('mathjs'), math = mathjs({ number: 'bignumber', // Default type of number: 'number' (default) or 'bignumber' - decimals: 20 // Number of decimal places behind the dot for BigNumbers + precision: 20 // Number of significant digits for BigNumbers }); // use math @@ -29,7 +29,7 @@ math.eval('0.1 + 0.2'); // BigNumber, 0.3 ``` The default precision for BigNumber is 20 digits, and can be configured with -the option `decimals`. +the option `precision`. *Important: BigNumber is not supported by the following functions: diff --git a/examples/bignumbers.js b/examples/bignumbers.js index a163657e0..3c8c78ef6 100644 --- a/examples/bignumbers.js +++ b/examples/bignumbers.js @@ -5,7 +5,7 @@ var mathjs = require('../index'), math = mathjs({ number: 'bignumber', // Default type of number: 'number' (default) or 'bignumber' - decimals: 20 // number of decimal places behind the dot for BigNumbers + precision: 20 // Number of significant digits for BigNumbers }); /** diff --git a/lib/math.js b/lib/math.js index 055ba4282..ac1cda105 100644 --- a/lib/math.js +++ b/lib/math.js @@ -13,9 +13,9 @@ var object = require('./util/object'); * A string 'matrix' (default) or 'array'. * {String} number * A string 'number' (default) or 'bignumber' - * {Number} decimals - * The number of decimals behind the decimal - * point for BigNumber. Not applicable for Numbers. + * {Number} precision + * The number of significant digits for BigNumbers. + * Not applicable for Numbers. */ function mathjs (settings) { // simple test for ES5 support @@ -35,8 +35,8 @@ function mathjs (settings) { // type of default number output. Choose 'number' (default) or 'bignumber' number: 'number', - // number of significant digits in bignumbers - decimals: 20 + // number of significant digits in BigNumbers + precision: 20 }; /** @@ -46,9 +46,9 @@ function mathjs (settings) { * A string 'matrix' (default) or 'array'. * {String} number * A string 'number' (default) or 'bignumber' - * {Number} decimals - * The number of decimals behind the decimal - * point for BigNumber. Not applicable for Numbers. + * {Number} precision + * The number of significant digits for BigNumbers. + * Not applicable for Numbers. * @return {Object} settings The currently applied settings */ math.config = function config (settings) { @@ -56,34 +56,35 @@ function mathjs (settings) { // merge settings object.deepExtend(_settings, settings); - if (settings.decimals) { + if (settings.precision) { math.type.BigNumber.config({ - precision: settings.decimals // TODO: rename decimals to precision + precision: settings.precision }); } // TODO: remove deprecated setting some day (deprecated since version 0.17.0) if (settings.number && settings.number.defaultType) { - throw new Error('setting `number.defaultType` is deprecated. ' + - 'Use `number` instead.') + throw new Error('setting `number.defaultType` is deprecated. Use `number` instead.') } // TODO: remove deprecated setting some day (deprecated since version 0.17.0) if (settings.number && settings.number.precision) { - throw new Error('setting `number.precision` is deprecated. ' + - 'Use `decimals` instead.') + throw new Error('setting `number.precision` is deprecated. Use `precision` instead.') } // TODO: remove deprecated setting some day (deprecated since version 0.17.0) if (settings.matrix && settings.matrix.defaultType) { - throw new Error('setting `matrix.defaultType` is deprecated. ' + - 'Use `matrix` instead.') + throw new Error('setting `matrix.defaultType` is deprecated. Use `matrix` instead.') } // TODO: remove deprecated setting some day (deprecated since version 0.15.0) if (settings.matrix && settings.matrix['default']) { - throw new Error('setting `matrix.default` is deprecated. ' + - 'Use `matrix` instead.') + throw new Error('setting `matrix.default` is deprecated. Use `matrix` instead.') + } + + // TODO: remove deprecated setting some day (deprecated since version 0.20.0) + if (settings.decimals) { + throw new Error('setting `decimals` is deprecated. Use `precision` instead.') } } diff --git a/test/deprecated.test.js b/test/deprecated.test.js index 12c12d463..91f9bbfd5 100644 --- a/test/deprecated.test.js +++ b/test/deprecated.test.js @@ -25,6 +25,14 @@ describe('deprecated stuff', function() { }, /is deprecated/); }); + it ('should throw an error when using deprecated setting decimals', function () { + assert.throws(function () { + mathjs({ + decimals: 100 + }) + }, /is deprecated/); + }); + it ('should throw an error when using deprecated setting matrix.defaultType', function () { assert.throws(function () { mathjs({ diff --git a/test/function/arithmetic/sqrt.test.js b/test/function/arithmetic/sqrt.test.js index 0b3af2623..f0f089360 100644 --- a/test/function/arithmetic/sqrt.test.js +++ b/test/function/arithmetic/sqrt.test.js @@ -1,7 +1,8 @@ // test sqrt var assert = require('assert'), approx = require('../../../tools/approx'), - math = require('../../../index')(), + mathjs = require('../../../index'), + math = mathjs(); sqrt = math.sqrt, bignumber = math.bignumber; @@ -29,6 +30,10 @@ describe('sqrt', function() { assert.deepEqual(sqrt(bignumber(9)), bignumber(3)); assert.deepEqual(sqrt(bignumber(16)), bignumber(4)); assert.deepEqual(sqrt(bignumber(25)), bignumber(5)); + + // validate whether we are really working at high precision + var bigmath = mathjs({precision: 100}); + assert.deepEqual(bigmath.sqrt(bigmath.bignumber(2)), bigmath.bignumber('1.414213562373095048801688724209698078569671875376948073176679737990732478462107038850387534327641573')); }); it('should return the square root of a complex number', function() { diff --git a/test/function/construction/bignumber.test.js b/test/function/construction/bignumber.test.js index e47e014e2..1a1d39152 100644 --- a/test/function/construction/bignumber.test.js +++ b/test/function/construction/bignumber.test.js @@ -54,7 +54,7 @@ describe('bignumber', function() { it('should apply precision setting to bignumbers', function() { var math = mathjs({ - decimals: 32 + precision: 32 }); var a = math.bignumber(1).dividedBy(3); @@ -62,7 +62,7 @@ describe('bignumber', function() { // restore default precision math.config({ - decimals: 20 + precision: 20 }); }); diff --git a/test/function/matrix/det.test.js b/test/function/matrix/det.test.js index 1c0f151dc..bffbd6ace 100644 --- a/test/function/matrix/det.test.js +++ b/test/function/matrix/det.test.js @@ -85,6 +85,12 @@ describe('det', function() { [bignumber(1), bignumber(2)], [bignumber(3), bignumber(4)] ]), bignumber(-2)); + + // the following would fail with regular Numbers due to a precision overflow + assert.deepEqual(math.det([ + [bignumber(1e10+1), bignumber(1e10)], + [bignumber(1e10), bignumber(1e10-1)] + ]), bignumber(-1)); }); it('should calculate the determinant of a matrix with mixed numbers and bignumbers', function() { diff --git a/test/function/utils/format.test.js b/test/function/utils/format.test.js index 4bdd559c2..9a8cff7ad 100644 --- a/test/function/utils/format.test.js +++ b/test/function/utils/format.test.js @@ -61,7 +61,7 @@ describe('format', function() { }); describe('bignumber', function () { - var math = mathjs({decimals: 20}); // ensure the precision is 20 digits, the default + var math = mathjs({precision: 20}); // ensure the precision is 20 digits, the default it('should format big numbers', function() { assert.equal(math.format(math.bignumber(2).dividedBy(7)), '0.28571428571428571429'); diff --git a/test/math.test.js b/test/math.test.js index 52e43fbe4..a69b142dd 100644 --- a/test/math.test.js +++ b/test/math.test.js @@ -11,7 +11,7 @@ describe('factory', function() { assert.deepEqual(math.config(), { matrix: 'matrix', number: 'number', - decimals: 20 + precision: 20 }); }); @@ -25,7 +25,7 @@ describe('factory', function() { assert.deepEqual(math.config(), { matrix: 'array', number: 'bignumber', - decimals: 20 + precision: 20 }); }); @@ -51,19 +51,19 @@ describe('factory', function() { assert.deepEqual(config, { matrix: 'matrix', number: 'number', - decimals: 20 + precision: 20 }); math.config({ matrix: 'array', number: 'bignumber', - decimals: 32 + precision: 32 }); assert.deepEqual(math.config(), { matrix: 'array', number: 'bignumber', - decimals: 32 + precision: 32 }); // restore the original config diff --git a/test/util/bignumber.test.js b/test/util/bignumber.test.js index fca41550a..e82372f7a 100644 --- a/test/util/bignumber.test.js +++ b/test/util/bignumber.test.js @@ -8,7 +8,7 @@ describe('bignumber', function() { it('should format a bignumber using toFixed', function() { var Big = BigNumber.constructor(); - Big.config({decimals: 100}); + Big.config({precision: 100}); assert.equal(bignumber.toFixed(new Big(2.34)), '2'); assert.equal(bignumber.toFixed(new Big(2.34), 1), '2.3'); @@ -20,7 +20,7 @@ describe('bignumber', function() { it('should format a bignumber using toExponential', function() { var Big = BigNumber.constructor(); - Big.config({decimals: 100}); + Big.config({precision: 100}); assert.equal(bignumber.toExponential(new Big(2.34)), '2.34e+0'); assert.equal(bignumber.toExponential(new Big(2.34e+3)), '2.34e+3'); From 8cea27406baf6bcc23ced5369e4704a4edc44036 Mon Sep 17 00:00:00 2001 From: josdejong Date: Sun, 6 Apr 2014 11:22:13 +0200 Subject: [PATCH 19/48] Some internal refactoring --- docs/configuration.md | 12 +- docs/functions.md | 2 +- docs/getting_started.md | 2 +- lib/expression/node/ArrayNode.js | 2 +- lib/expression/node/AssignmentNode.js | 2 +- lib/expression/node/BlockNode.js | 2 +- lib/expression/node/FunctionNode.js | 2 +- lib/expression/node/OperatorNode.js | 2 +- lib/expression/node/ParamsNode.js | 2 +- lib/expression/node/RangeNode.js | 2 +- lib/expression/node/UnitNode.js | 2 +- lib/expression/node/UpdateNode.js | 2 +- lib/function/expression/compile.js | 2 +- lib/function/expression/parse.js | 2 +- lib/function/matrix/eye.js | 4 +- lib/function/matrix/ones.js | 4 +- lib/function/matrix/range.js | 6 +- lib/function/matrix/resize.js | 4 +- lib/function/matrix/size.js | 4 +- lib/function/matrix/zeros.js | 4 +- lib/function/probability/random.js | 6 +- lib/math.js | 238 +++++++++++++------------- 22 files changed, 154 insertions(+), 154 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 69effc470..966ad20bf 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -1,8 +1,8 @@ # Configuration -Math.js contains a number of configuration settings. Configuration can be set +Math.js contains a number of configuration options. Configuration can be set when creating a math.js instance, or later on using the function `config`. -Available configuration settings are: +Available configuration options are: - `matrix`. The default type of matrix output for functions. Available values are: `'matrix'` (default) or `'array'`. @@ -29,7 +29,7 @@ Available configuration settings are: This section shows a number of configuration examples. -### Default settings +### Default configuration ```js // load the library @@ -48,11 +48,11 @@ math1.range(0, 4); // Matrix [0, 1, 2, 3] // load the library var mathjs = require('mathjs'); -// create an instance of math.js with configuration settings -var settings = { +// create an instance of math.js with configuration options +var config = { matrix: 'array' }; -var math2 = mathjs(settings); +var math2 = mathjs(config); // range will output an Array math2.range(0, 4); // Array [0, 1, 2, 3] diff --git a/docs/functions.md b/docs/functions.md index eb6f3830a..47e682351 100644 --- a/docs/functions.md +++ b/docs/functions.md @@ -139,7 +139,7 @@ math.add('hello ', 'world!'); // String 'hello world!' ## Utils -- math.config(settings) +- math.config(options) - math.clone(x) - math.forEach(x, callback) - math.format(value [, precision]) diff --git a/docs/getting_started.md b/docs/getting_started.md index 26493358e..ec78e7933 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -37,7 +37,7 @@ Or by downloading the latest version from Math.js can be used in node.js and in the browser. The library must be loaded and instantiated. When creating an instance, one can optionally provide -configuration settings as described in +configuration options as described in [Configuration](https://github.com/josdejong/mathjs/blob/master/docs/configuration.md). ### Node.js diff --git a/lib/expression/node/ArrayNode.js b/lib/expression/node/ArrayNode.js index 6fbc27ec4..95f364de6 100644 --- a/lib/expression/node/ArrayNode.js +++ b/lib/expression/node/ArrayNode.js @@ -49,7 +49,7 @@ ArrayNode.prototype._compile = function (defs) { /** * Find all nodes matching given filter - * @param {Object} filter See Node.find for a description of the filter settings + * @param {Object} filter See Node.find for a description of the filter options * @returns {Node[]} nodes */ ArrayNode.prototype.find = function (filter) { diff --git a/lib/expression/node/AssignmentNode.js b/lib/expression/node/AssignmentNode.js index b61a4ef9b..97db0d10a 100644 --- a/lib/expression/node/AssignmentNode.js +++ b/lib/expression/node/AssignmentNode.js @@ -37,7 +37,7 @@ AssignmentNode.prototype._compile = function (defs) { /** * Find all nodes matching given filter - * @param {Object} filter See Node.find for a description of the filter settings + * @param {Object} filter See Node.find for a description of the filter options * @returns {Node[]} nodes */ AssignmentNode.prototype.find = function (filter) { diff --git a/lib/expression/node/BlockNode.js b/lib/expression/node/BlockNode.js index 9bc53333a..d0b0dfab2 100644 --- a/lib/expression/node/BlockNode.js +++ b/lib/expression/node/BlockNode.js @@ -64,7 +64,7 @@ BlockNode.prototype._compile = function (defs) { /** * Find all nodes matching given filter - * @param {Object} filter See Node.find for a description of the filter settings + * @param {Object} filter See Node.find for a description of the filter options * @returns {Node[]} nodes */ BlockNode.prototype.find = function (filter) { diff --git a/lib/expression/node/FunctionNode.js b/lib/expression/node/FunctionNode.js index 146888f79..f5634d4a8 100644 --- a/lib/expression/node/FunctionNode.js +++ b/lib/expression/node/FunctionNode.js @@ -58,7 +58,7 @@ FunctionNode.prototype._compile = function (defs) { /** * Find all nodes matching given filter - * @param {Object} filter See Node.find for a description of the filter settings + * @param {Object} filter See Node.find for a description of the filter options * @returns {Node[]} nodes */ FunctionNode.prototype.find = function (filter) { diff --git a/lib/expression/node/OperatorNode.js b/lib/expression/node/OperatorNode.js index db6e34342..6a6ddc6ce 100644 --- a/lib/expression/node/OperatorNode.js +++ b/lib/expression/node/OperatorNode.js @@ -43,7 +43,7 @@ OperatorNode.prototype._compile = function (defs) { /** * Find all nodes matching given filter - * @param {Object} filter See Node.find for a description of the filter settings + * @param {Object} filter See Node.find for a description of the filter options * @returns {Node[]} nodes */ OperatorNode.prototype.find = function (filter) { diff --git a/lib/expression/node/ParamsNode.js b/lib/expression/node/ParamsNode.js index 86b2485e3..48d7eb521 100644 --- a/lib/expression/node/ParamsNode.js +++ b/lib/expression/node/ParamsNode.js @@ -45,7 +45,7 @@ ParamsNode.prototype._compile = function (defs) { /** * Find all nodes matching given filter - * @param {Object} filter See Node.find for a description of the filter settings + * @param {Object} filter See Node.find for a description of the filter options * @returns {Node[]} nodes */ ParamsNode.prototype.find = function (filter) { diff --git a/lib/expression/node/RangeNode.js b/lib/expression/node/RangeNode.js index c2dd5328c..f89a21176 100644 --- a/lib/expression/node/RangeNode.js +++ b/lib/expression/node/RangeNode.js @@ -45,7 +45,7 @@ RangeNode.prototype._compile = function (defs) { /** * Find all nodes matching given filter - * @param {Object} filter See Node.find for a description of the filter settings + * @param {Object} filter See Node.find for a description of the filter options * @returns {Node[]} nodes */ RangeNode.prototype.find = function (filter) { diff --git a/lib/expression/node/UnitNode.js b/lib/expression/node/UnitNode.js index 2aa2e371d..6464725ac 100644 --- a/lib/expression/node/UnitNode.js +++ b/lib/expression/node/UnitNode.js @@ -40,7 +40,7 @@ UnitNode.prototype._compile = function (defs) { /** * Find all nodes matching given filter - * @param {Object} filter See Node.find for a description of the filter settings + * @param {Object} filter See Node.find for a description of the filter options * @returns {Node[]} nodes */ UnitNode.prototype.find = function (filter) { diff --git a/lib/expression/node/UpdateNode.js b/lib/expression/node/UpdateNode.js index 3fb678275..4e569929b 100644 --- a/lib/expression/node/UpdateNode.js +++ b/lib/expression/node/UpdateNode.js @@ -42,7 +42,7 @@ UpdateNode.prototype._compile = function (defs) { /** * Find all nodes matching given filter - * @param {Object} filter See Node.find for a description of the filter settings + * @param {Object} filter See Node.find for a description of the filter options * @returns {Node[]} nodes */ UpdateNode.prototype.find = function (filter) { diff --git a/lib/function/expression/compile.js b/lib/function/expression/compile.js index 93de9229b..8e7804985 100644 --- a/lib/function/expression/compile.js +++ b/lib/function/expression/compile.js @@ -1,4 +1,4 @@ -module.exports = function (math, settings) { +module.exports = function (math, config) { var util = require('../../util/index'), _parse = require('../../expression/parse'), diff --git a/lib/function/expression/parse.js b/lib/function/expression/parse.js index d5811e944..d123a26ef 100644 --- a/lib/function/expression/parse.js +++ b/lib/function/expression/parse.js @@ -1,4 +1,4 @@ -module.exports = function (math, settings) { +module.exports = function (math, config) { var _parse = require('../../expression/parse'); /** diff --git a/lib/function/matrix/eye.js b/lib/function/matrix/eye.js index 359ebd8bc..58e53b4ac 100644 --- a/lib/function/matrix/eye.js +++ b/lib/function/matrix/eye.js @@ -1,4 +1,4 @@ -module.exports = function (math, settings) { +module.exports = function (math, config) { var util = require('../../util/index'), BigNumber = math.type.BigNumber, @@ -24,7 +24,7 @@ module.exports = function (math, settings) { math.eye = function eye (size) { var args = collection.argsToArray(arguments), asMatrix = (size instanceof Matrix) ? true : - (isArray(size) ? false : (settings.matrix === 'matrix')); + (isArray(size) ? false : (config.matrix === 'matrix')); if (args.length == 0) { diff --git a/lib/function/matrix/ones.js b/lib/function/matrix/ones.js index 37fda95df..0c603ffc7 100644 --- a/lib/function/matrix/ones.js +++ b/lib/function/matrix/ones.js @@ -1,4 +1,4 @@ -module.exports = function (math, settings) { +module.exports = function (math, config) { var util = require('../../util/index'), BigNumber = math.type.BigNumber, @@ -23,7 +23,7 @@ module.exports = function (math, settings) { math.ones = function ones (size) { var args = collection.argsToArray(arguments); var asMatrix = (size instanceof Matrix) ? true : - (isArray(size) ? false : (settings.matrix === 'matrix')); + (isArray(size) ? false : (config.matrix === 'matrix')); if (args.length == 0) { // output an empty matrix diff --git a/lib/function/matrix/range.js b/lib/function/matrix/range.js index a29a9cf21..0d18e5fd7 100644 --- a/lib/function/matrix/range.js +++ b/lib/function/matrix/range.js @@ -1,4 +1,4 @@ -module.exports = function (math, settings) { +module.exports = function (math, config) { var util = require('../../util/index'), BigNumber = math.type.BigNumber, @@ -134,7 +134,7 @@ module.exports = function (math, settings) { var array = fn(start, end, step); // return as array or matrix - return (settings.matrix === 'array') ? array : new Matrix(array); + return (config.matrix === 'array') ? array : new Matrix(array); }; /** @@ -260,7 +260,7 @@ module.exports = function (math, settings) { var args = str.split(':'), nums = null; - if (settings.number === 'bignumber') { + if (config.number === 'bignumber') { // bignumber try { nums = args.map(function (arg) { diff --git a/lib/function/matrix/resize.js b/lib/function/matrix/resize.js index 50da4b4e2..9706d8fce 100644 --- a/lib/function/matrix/resize.js +++ b/lib/function/matrix/resize.js @@ -1,4 +1,4 @@ -module.exports = function (math, settings) { +module.exports = function (math, config) { var util = require('../../util/index'), BigNumber = math.type.BigNumber, @@ -30,7 +30,7 @@ module.exports = function (math, settings) { throw new math.error.ArgumentsError('resize', arguments.length, 2, 3); } - var asMatrix = (x instanceof Matrix) ? true : isArray(x) ? false : (settings.matrix !== 'array'); + var asMatrix = (x instanceof Matrix) ? true : isArray(x) ? false : (config.matrix !== 'array'); if (x instanceof Matrix) { x = x.valueOf(); // get Array diff --git a/lib/function/matrix/size.js b/lib/function/matrix/size.js index 41161f936..9faeee85b 100644 --- a/lib/function/matrix/size.js +++ b/lib/function/matrix/size.js @@ -1,4 +1,4 @@ -module.exports = function (math, settings) { +module.exports = function (math, config) { var util = require('../../util/index'), BigNumber = math.type.BigNumber, @@ -26,7 +26,7 @@ module.exports = function (math, settings) { throw new math.error.ArgumentsError('size', arguments.length, 1); } - var asArray = (settings.matrix === 'array'); + var asArray = (config.matrix === 'array'); if (isNumber(x) || isComplex(x) || isUnit(x) || isBoolean(x) || x == null || x instanceof BigNumber) { diff --git a/lib/function/matrix/zeros.js b/lib/function/matrix/zeros.js index ffcfadcce..7c39582fd 100644 --- a/lib/function/matrix/zeros.js +++ b/lib/function/matrix/zeros.js @@ -1,4 +1,4 @@ -module.exports = function (math, settings) { +module.exports = function (math, config) { var util = require('../../util/index'), BigNumber = math.type.BigNumber, @@ -22,7 +22,7 @@ module.exports = function (math, settings) { math.zeros = function zeros (size) { var args = collection.argsToArray(arguments); var asMatrix = (size instanceof Matrix) ? true : - (isArray(size) ? false : (settings.matrix === 'matrix')); + (isArray(size) ? false : (config.matrix === 'matrix')); if (args.length == 0) { // output an empty matrix diff --git a/lib/function/probability/random.js b/lib/function/probability/random.js index 4066f5901..51ae62f85 100644 --- a/lib/function/probability/random.js +++ b/lib/function/probability/random.js @@ -1,4 +1,4 @@ -module.exports = function (math, settings) { +module.exports = function (math, config) { var Matrix = require('../../type/Matrix'), collection = require('../../type/collection'); @@ -91,7 +91,7 @@ module.exports = function (math, settings) { if (min === undefined) min = 0; if (size !== undefined) { var res = _randomDataForMatrix(size, min, max, _random); - return (settings.matrix === 'array') ? res : new Matrix(res); + return (config.matrix === 'array') ? res : new Matrix(res); } else return _random(min, max); }, @@ -121,7 +121,7 @@ module.exports = function (math, settings) { if (min === undefined) min = 0; if (size !== undefined) { var res = _randomDataForMatrix(size, min, max, _randomInt); - return (settings.matrix === 'array') ? res : new Matrix(res); + return (config.matrix === 'array') ? res : new Matrix(res); } else return _randomInt(min, max); }, diff --git a/lib/math.js b/lib/math.js index ac1cda105..7eeacf3e9 100644 --- a/lib/math.js +++ b/lib/math.js @@ -6,9 +6,9 @@ var object = require('./util/object'); * Usage: * * var math = mathjs(); - * var math = mathjs(settings); + * var math = mathjs(config); * - * @param {Object} [settings] Available settings: + * @param {Object} [config] Available configuration options: * {String} matrix * A string 'matrix' (default) or 'array'. * {String} number @@ -17,7 +17,7 @@ var object = require('./util/object'); * The number of significant digits for BigNumbers. * Not applicable for Numbers. */ -function mathjs (settings) { +function mathjs (config) { // simple test for ES5 support if (typeof Object.create !== 'function') { throw new Error('ES5 not supported by this JavaScript engine. ' + @@ -27,8 +27,8 @@ function mathjs (settings) { // create new namespace var math = {}; - // create configuration settings. These are private - var _settings = { + // create configuration options. These are private + var _config = { // type of default matrix output. Choose 'matrix' (default) or 'array' matrix: 'matrix', @@ -40,8 +40,8 @@ function mathjs (settings) { }; /** - * Set configuration settings for math.js, and get current settings - * @param {Object} [settings] Available settings: + * Set configuration options for math.js, and get current options + * @param {Object} [options] Available options: * {String} matrix * A string 'matrix' (default) or 'array'. * {String} number @@ -49,47 +49,47 @@ function mathjs (settings) { * {Number} precision * The number of significant digits for BigNumbers. * Not applicable for Numbers. - * @return {Object} settings The currently applied settings + * @return {Object} Returns the current configuration */ - math.config = function config (settings) { - if (settings) { - // merge settings - object.deepExtend(_settings, settings); + math.config = function config (options) { + if (options) { + // merge options + object.deepExtend(_config, options); - if (settings.precision) { + if (options.precision) { math.type.BigNumber.config({ - precision: settings.precision + precision: options.precision }); } // TODO: remove deprecated setting some day (deprecated since version 0.17.0) - if (settings.number && settings.number.defaultType) { + if (options.number && options.number.defaultType) { throw new Error('setting `number.defaultType` is deprecated. Use `number` instead.') } // TODO: remove deprecated setting some day (deprecated since version 0.17.0) - if (settings.number && settings.number.precision) { + if (options.number && options.number.precision) { throw new Error('setting `number.precision` is deprecated. Use `precision` instead.') } // TODO: remove deprecated setting some day (deprecated since version 0.17.0) - if (settings.matrix && settings.matrix.defaultType) { + if (options.matrix && options.matrix.defaultType) { throw new Error('setting `matrix.defaultType` is deprecated. Use `matrix` instead.') } // TODO: remove deprecated setting some day (deprecated since version 0.15.0) - if (settings.matrix && settings.matrix['default']) { + if (options.matrix && options.matrix['default']) { throw new Error('setting `matrix.default` is deprecated. Use `matrix` instead.') } // TODO: remove deprecated setting some day (deprecated since version 0.20.0) - if (settings.decimals) { + if (options.decimals) { throw new Error('setting `decimals` is deprecated. Use `precision` instead.') } } - // return a clone of the settings - return object.clone(_settings); + // return a clone of the configuration + return object.clone(_config); }; // create a new BigNumber factory for this instance of math.js @@ -154,128 +154,128 @@ function mathjs (settings) { require('./type/error')(math); // expression parser - require('./function/expression/compile.js')(math, _settings); - require('./function/expression/eval.js')(math, _settings); - require('./function/expression/help.js')(math, _settings); - require('./function/expression/parse.js')(math, _settings); + require('./function/expression/compile.js')(math, _config); + require('./function/expression/eval.js')(math, _config); + require('./function/expression/help.js')(math, _config); + require('./function/expression/parse.js')(math, _config); // functions - arithmetic - require('./function/arithmetic/abs.js')(math, _settings); - require('./function/arithmetic/add.js')(math, _settings); - require('./function/arithmetic/ceil.js')(math, _settings); - require('./function/arithmetic/compare.js')(math, _settings); - require('./function/arithmetic/cube.js')(math, _settings); - require('./function/arithmetic/divide.js')(math, _settings); - require('./function/arithmetic/edivide.js')(math, _settings); - require('./function/arithmetic/emultiply.js')(math, _settings); - require('./function/arithmetic/epow.js')(math, _settings); - require('./function/arithmetic/equal.js')(math, _settings); - require('./function/arithmetic/exp.js')(math, _settings); - require('./function/arithmetic/fix.js')(math, _settings); - require('./function/arithmetic/floor.js')(math, _settings); - require('./function/arithmetic/gcd.js')(math, _settings); - require('./function/arithmetic/larger.js')(math, _settings); - require('./function/arithmetic/largereq.js')(math, _settings); - require('./function/arithmetic/lcm.js')(math, _settings); - require('./function/arithmetic/log.js')(math, _settings); - require('./function/arithmetic/log10.js')(math, _settings); - require('./function/arithmetic/mod.js')(math, _settings); - require('./function/arithmetic/multiply.js')(math, _settings); - require('./function/arithmetic/pow.js')(math, _settings); - require('./function/arithmetic/round.js')(math, _settings); - require('./function/arithmetic/sign.js')(math, _settings); - require('./function/arithmetic/smaller.js')(math, _settings); - require('./function/arithmetic/smallereq.js')(math, _settings); - require('./function/arithmetic/sqrt.js')(math, _settings); - require('./function/arithmetic/square.js')(math, _settings); - require('./function/arithmetic/subtract.js')(math, _settings); - require('./function/arithmetic/unary.js')(math, _settings); - require('./function/arithmetic/unequal.js')(math, _settings); - require('./function/arithmetic/xgcd.js')(math, _settings); + require('./function/arithmetic/abs.js')(math, _config); + require('./function/arithmetic/add.js')(math, _config); + require('./function/arithmetic/ceil.js')(math, _config); + require('./function/arithmetic/compare.js')(math, _config); + require('./function/arithmetic/cube.js')(math, _config); + require('./function/arithmetic/divide.js')(math, _config); + require('./function/arithmetic/edivide.js')(math, _config); + require('./function/arithmetic/emultiply.js')(math, _config); + require('./function/arithmetic/epow.js')(math, _config); + require('./function/arithmetic/equal.js')(math, _config); + require('./function/arithmetic/exp.js')(math, _config); + require('./function/arithmetic/fix.js')(math, _config); + require('./function/arithmetic/floor.js')(math, _config); + require('./function/arithmetic/gcd.js')(math, _config); + require('./function/arithmetic/larger.js')(math, _config); + require('./function/arithmetic/largereq.js')(math, _config); + require('./function/arithmetic/lcm.js')(math, _config); + require('./function/arithmetic/log.js')(math, _config); + require('./function/arithmetic/log10.js')(math, _config); + require('./function/arithmetic/mod.js')(math, _config); + require('./function/arithmetic/multiply.js')(math, _config); + require('./function/arithmetic/pow.js')(math, _config); + require('./function/arithmetic/round.js')(math, _config); + require('./function/arithmetic/sign.js')(math, _config); + require('./function/arithmetic/smaller.js')(math, _config); + require('./function/arithmetic/smallereq.js')(math, _config); + require('./function/arithmetic/sqrt.js')(math, _config); + require('./function/arithmetic/square.js')(math, _config); + require('./function/arithmetic/subtract.js')(math, _config); + require('./function/arithmetic/unary.js')(math, _config); + require('./function/arithmetic/unequal.js')(math, _config); + require('./function/arithmetic/xgcd.js')(math, _config); // functions - complex - require('./function/complex/arg.js')(math, _settings); - require('./function/complex/conj.js')(math, _settings); - require('./function/complex/re.js')(math, _settings); - require('./function/complex/im.js')(math, _settings); + require('./function/complex/arg.js')(math, _config); + require('./function/complex/conj.js')(math, _config); + require('./function/complex/re.js')(math, _config); + require('./function/complex/im.js')(math, _config); // functions - construction - require('./function/construction/bignumber')(math, _settings); - require('./function/construction/boolean.js')(math, _settings); - require('./function/construction/complex.js')(math, _settings); - require('./function/construction/index.js')(math, _settings); - require('./function/construction/matrix.js')(math, _settings); - require('./function/construction/number.js')(math, _settings); - require('./function/construction/parser.js')(math, _settings); - require('./function/construction/select.js')(math, _settings); - require('./function/construction/string.js')(math, _settings); - require('./function/construction/unit.js')(math, _settings); + require('./function/construction/bignumber')(math, _config); + require('./function/construction/boolean.js')(math, _config); + require('./function/construction/complex.js')(math, _config); + require('./function/construction/index.js')(math, _config); + require('./function/construction/matrix.js')(math, _config); + require('./function/construction/number.js')(math, _config); + require('./function/construction/parser.js')(math, _config); + require('./function/construction/select.js')(math, _config); + require('./function/construction/string.js')(math, _config); + require('./function/construction/unit.js')(math, _config); // functions - matrix - require('./function/matrix/concat.js')(math, _settings); - require('./function/matrix/det.js')(math, _settings); - require('./function/matrix/diag.js')(math, _settings); - require('./function/matrix/eye.js')(math, _settings); - require('./function/matrix/inv.js')(math, _settings); - require('./function/matrix/ones.js')(math, _settings); - require('./function/matrix/range.js')(math, _settings); - require('./function/matrix/resize.js')(math, _settings); - require('./function/matrix/size.js')(math, _settings); - require('./function/matrix/squeeze.js')(math, _settings); - require('./function/matrix/subset.js')(math, _settings); - require('./function/matrix/transpose.js')(math, _settings); - require('./function/matrix/zeros.js')(math, _settings); + require('./function/matrix/concat.js')(math, _config); + require('./function/matrix/det.js')(math, _config); + require('./function/matrix/diag.js')(math, _config); + require('./function/matrix/eye.js')(math, _config); + require('./function/matrix/inv.js')(math, _config); + require('./function/matrix/ones.js')(math, _config); + require('./function/matrix/range.js')(math, _config); + require('./function/matrix/resize.js')(math, _config); + require('./function/matrix/size.js')(math, _config); + require('./function/matrix/squeeze.js')(math, _config); + require('./function/matrix/subset.js')(math, _config); + require('./function/matrix/transpose.js')(math, _config); + require('./function/matrix/zeros.js')(math, _config); // functions - probability - require('./function/probability/factorial.js')(math, _settings); - require('./function/probability/random.js')(math, _settings); - require('./function/probability/permutations.js')(math, _settings); - require('./function/probability/combinations.js')(math, _settings); + require('./function/probability/factorial.js')(math, _config); + require('./function/probability/random.js')(math, _config); + require('./function/probability/permutations.js')(math, _config); + require('./function/probability/combinations.js')(math, _config); // functions - statistics - require('./function/statistics/min.js')(math, _settings); - require('./function/statistics/max.js')(math, _settings); - require('./function/statistics/mean.js')(math, _settings); - require('./function/statistics/median.js')(math, _settings); - require('./function/statistics/prod.js')(math, _settings); - require('./function/statistics/std.js')(math, _settings); - require('./function/statistics/sum.js')(math, _settings); - require('./function/statistics/var.js')(math, _settings); + require('./function/statistics/min.js')(math, _config); + require('./function/statistics/max.js')(math, _config); + require('./function/statistics/mean.js')(math, _config); + require('./function/statistics/median.js')(math, _config); + require('./function/statistics/prod.js')(math, _config); + require('./function/statistics/std.js')(math, _config); + require('./function/statistics/sum.js')(math, _config); + require('./function/statistics/var.js')(math, _config); // functions - trigonometry - require('./function/trigonometry/acos.js')(math, _settings); - require('./function/trigonometry/asin.js')(math, _settings); - require('./function/trigonometry/atan.js')(math, _settings); - require('./function/trigonometry/atan2.js')(math, _settings); - require('./function/trigonometry/cos.js')(math, _settings); - require('./function/trigonometry/cot.js')(math, _settings); - require('./function/trigonometry/csc.js')(math, _settings); - require('./function/trigonometry/sec.js')(math, _settings); - require('./function/trigonometry/sin.js')(math, _settings); - require('./function/trigonometry/tan.js')(math, _settings); + require('./function/trigonometry/acos.js')(math, _config); + require('./function/trigonometry/asin.js')(math, _config); + require('./function/trigonometry/atan.js')(math, _config); + require('./function/trigonometry/atan2.js')(math, _config); + require('./function/trigonometry/cos.js')(math, _config); + require('./function/trigonometry/cot.js')(math, _config); + require('./function/trigonometry/csc.js')(math, _config); + require('./function/trigonometry/sec.js')(math, _config); + require('./function/trigonometry/sin.js')(math, _config); + require('./function/trigonometry/tan.js')(math, _config); // functions - units - require('./function/units/to.js')(math, _settings); + require('./function/units/to.js')(math, _config); // functions - utils - require('./function/utils/clone.js')(math, _settings); - require('./function/utils/format.js')(math, _settings); - require('./function/utils/ifElse.js')(math, _settings); - require('./function/utils/import.js')(math, _settings); - require('./function/utils/map.js')(math, _settings); - require('./function/utils/print.js')(math, _settings); - require('./function/utils/typeof.js')(math, _settings); - require('./function/utils/forEach.js')(math, _settings); + require('./function/utils/clone.js')(math, _config); + require('./function/utils/format.js')(math, _config); + require('./function/utils/ifElse.js')(math, _config); + require('./function/utils/import.js')(math, _config); + require('./function/utils/map.js')(math, _config); + require('./function/utils/print.js')(math, _config); + require('./function/utils/typeof.js')(math, _config); + require('./function/utils/forEach.js')(math, _config); // constants - require('./constants.js')(math, _settings); + require('./constants.js')(math, _config); // selector (we initialize after all functions are loaded) math.chaining = {}; - math.chaining.Selector = require('./chaining/Selector.js')(math, _settings); + math.chaining.Selector = require('./chaining/Selector.js')(math, _config); - // apply provided configuration settings - math.config(settings); + // apply provided configuration options + math.config(config); // return the new instance return math; From 83b41a16aba19c07812c7d3963781a40fd75f0a8 Mon Sep 17 00:00:00 2001 From: josdejong Date: Sun, 6 Apr 2014 12:01:10 +0200 Subject: [PATCH 20/48] Implemented BigNumber support for functions `exp`, `log`, and `log10`. --- HISTORY.md | 1 + docs/datatypes/bignumbers.md | 2 +- lib/function/arithmetic/exp.js | 8 +++----- lib/function/arithmetic/log.js | 10 ++++------ lib/function/arithmetic/log10.js | 8 +++----- lib/function/arithmetic/pow.js | 2 -- test/function/arithmetic/exp.test.js | 9 ++++++--- test/function/arithmetic/log.test.js | 12 +++++++++--- test/function/arithmetic/log10.test.js | 12 +++++++++--- 9 files changed, 36 insertions(+), 28 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index cb4b452dd..c108070ba 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -8,6 +8,7 @@ https://github.com/josdejong/mathjs `bignumber.js`. - Implemented support for polar coordinates to the `Complex` datatype. Thanks Finn Pauls (@finnp). +- Implemented BigNumber support for functions `exp`, `log`, and `log10`. - Implemented conditional operator `a ? b : c` in expression parser. - Improved function `ifElse`, is now specified for special data types too. - Implemented `BigNumber` support for function `det`. diff --git a/docs/datatypes/bignumbers.md b/docs/datatypes/bignumbers.md index 9726e5c08..931658047 100644 --- a/docs/datatypes/bignumbers.md +++ b/docs/datatypes/bignumbers.md @@ -33,7 +33,7 @@ the option `precision`. *Important: BigNumber is not supported by the following functions: -exp, gcd, lcm, log, log10, xgcd, +gcd, lcm, xgcd, arg, random, acos, asin, atan, atan2, cos, cot, csc, sec, sin, tan. diff --git a/lib/function/arithmetic/exp.js b/lib/function/arithmetic/exp.js index 95400fffd..1a492ec76 100644 --- a/lib/function/arithmetic/exp.js +++ b/lib/function/arithmetic/exp.js @@ -18,8 +18,8 @@ module.exports = function (math) { * * For matrices, the function is evaluated element wise. * - * @param {Number | Boolean | Complex | Array | Matrix} x - * @return {Number | Complex | Array | Matrix} res + * @param {Number | BigNumber | Boolean | Complex | Array | Matrix} x + * @return {Number | BigNumber | Complex | Array | Matrix} res */ math.exp = function exp (x) { if (arguments.length != 1) { @@ -39,9 +39,7 @@ module.exports = function (math) { } if (x instanceof BigNumber) { - // TODO: implement BigNumber support - // downgrade to Number - return exp(x.toNumber()); + return x.exp(); } if (isCollection(x)) { diff --git a/lib/function/arithmetic/log.js b/lib/function/arithmetic/log.js index 5c7dd39cb..c80447256 100644 --- a/lib/function/arithmetic/log.js +++ b/lib/function/arithmetic/log.js @@ -19,9 +19,9 @@ module.exports = function (math) { * base is optional. If not provided, the natural logarithm of x is calculated. * For matrices, the function is evaluated element wise. * - * @param {Number | Boolean | Complex | Array | Matrix} x - * @param {Number | Boolean | Complex} [base] - * @return {Number | Complex | Array | Matrix} res + * @param {Number | BigNumber | Boolean | Complex | Array | Matrix} x + * @param {Number | BigNumber | Boolean | Complex} [base] + * @return {Number | BigNumber | Complex | Array | Matrix} res */ math.log = function log(x, base) { if (arguments.length == 1) { @@ -44,9 +44,7 @@ module.exports = function (math) { } if (x instanceof BigNumber) { - // TODO: implement BigNumber support - // downgrade to Number - return log(x.toNumber()); + return x.ln(); } if (isCollection(x)) { diff --git a/lib/function/arithmetic/log10.js b/lib/function/arithmetic/log10.js index 637eedf9b..2672de816 100644 --- a/lib/function/arithmetic/log10.js +++ b/lib/function/arithmetic/log10.js @@ -17,8 +17,8 @@ module.exports = function (math) { * * For matrices, the function is evaluated element wise. * - * @param {Number | Boolean | Complex | Array | Matrix} x - * @return {Number | Complex | Array | Matrix} res + * @param {Number | BigNumber | Boolean | Complex | Array | Matrix} x + * @return {Number | BigNumber | Complex | Array | Matrix} res */ math.log10 = function log10(x) { if (arguments.length != 1) { @@ -36,9 +36,7 @@ module.exports = function (math) { } if (x instanceof BigNumber) { - // TODO: implement BigNumber support - // downgrade to Number - return log10(x.toNumber()); + return x.log(); } if (isComplex(x)) { diff --git a/lib/function/arithmetic/pow.js b/lib/function/arithmetic/pow.js index 6239725d8..63b4157e6 100644 --- a/lib/function/arithmetic/pow.js +++ b/lib/function/arithmetic/pow.js @@ -52,8 +52,6 @@ module.exports = function (math) { } } - // TODO: pow for complex numbers and bignumbers - if (x instanceof BigNumber) { // try to convert to big number if (isNumber(y)) { diff --git a/test/function/arithmetic/exp.test.js b/test/function/arithmetic/exp.test.js index 303eee36d..2d6646b92 100644 --- a/test/function/arithmetic/exp.test.js +++ b/test/function/arithmetic/exp.test.js @@ -1,7 +1,8 @@ // test exp var assert = require('assert'), approx = require('../../../tools/approx'), - math = require('../../../index')(), + mathjs = require('../../../index'), + math = mathjs(), complex = math.complex, matrix = math.matrix, unit = math.unit, @@ -25,8 +26,10 @@ describe('exp', function() { approx.equal(exp(math.log(100)), 100); }); - it('should exponentiate a bignumber (downgrades to number)', function() { - approx.equal(exp(math.bignumber(1)), 2.71828182845905); + it('should exponentiate a bignumber', function() { + var bigmath = mathjs({precision: 100}); + + assert.deepEqual(bigmath.exp(bigmath.bignumber(1)), bigmath.bignumber('2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427')); }); it('should throw an error if there\'s wrong number of arguments', function() { diff --git a/test/function/arithmetic/log.test.js b/test/function/arithmetic/log.test.js index 71b9bbb58..57767b590 100644 --- a/test/function/arithmetic/log.test.js +++ b/test/function/arithmetic/log.test.js @@ -1,7 +1,8 @@ // test exp var assert = require('assert'), approx = require('../../../tools/approx'), - math = require('../../../index')(), + mathjs = require('../../../index'), + math = mathjs(), complex = math.complex, matrix = math.matrix, unit = math.unit, @@ -38,9 +39,14 @@ describe('log', function() { }); it('should return the log of a bignumber', function() { - approx.deepEqual(log(math.bignumber(2)), 0.693147180559945); - approx.deepEqual(log(math.bignumber(3)), 1.098612288668110); + var bigmath = mathjs({precision: 100}); + assert.deepEqual(bigmath.log(bigmath.bignumber(1)), bigmath.bignumber('0')); + assert.deepEqual(bigmath.log(bigmath.bignumber(2)), bigmath.bignumber('0.6931471805599453094172321214581765680755001343602552541206800094933936219696947156058633269964186875')); + assert.deepEqual(bigmath.log(bigmath.bignumber(3)), bigmath.bignumber('1.098612288668109691395245236922525704647490557822749451734694333637494293218608966873615754813732089')); + + // note: the following gives a round-off error with regular numbers + assert.deepEqual(bigmath.log(bigmath.bignumber(1000), bigmath.bignumber(10)), bigmath.bignumber(3)); }); it('should return the log of a complex number', function() { diff --git a/test/function/arithmetic/log10.test.js b/test/function/arithmetic/log10.test.js index 42adffa60..586d4863d 100644 --- a/test/function/arithmetic/log10.test.js +++ b/test/function/arithmetic/log10.test.js @@ -1,7 +1,8 @@ // test exp var assert = require('assert'), approx = require('../../../tools/approx'), - math = require('../../../index')(), + mathjs = require('../../../index'), + math = mathjs(), complex = math.complex, matrix = math.matrix, unit = math.unit, @@ -32,9 +33,14 @@ describe('log10', function() { }); it('should return the log of a bignumber', function() { - approx.deepEqual(log10(math.bignumber(2)), 0.301029995663981); - approx.deepEqual(log10(math.bignumber(3)), 0.477121254719662); + var bigmath = mathjs({precision: 100}); + assert.deepEqual(bigmath.log10(bigmath.bignumber(1)), bigmath.bignumber(0)); + assert.deepEqual(bigmath.log10(bigmath.bignumber(10)), bigmath.bignumber(1)); + assert.deepEqual(bigmath.log10(bigmath.bignumber(100)), bigmath.bignumber(2)); + assert.deepEqual(bigmath.log10(bigmath.bignumber(1000)), bigmath.bignumber(3)); // note: this gives a round-off error with regular numbers + assert.deepEqual(bigmath.log10(bigmath.bignumber(10000)), bigmath.bignumber(4)); + assert.deepEqual(bigmath.log10(bigmath.bignumber('1e500')), bigmath.bignumber(500)); }); it('should throw an error if used with a wrong number of arguments', function() { From a7b24eca8c5d847f82f578dce8628dff0dc2e93b Mon Sep 17 00:00:00 2001 From: josdejong Date: Sun, 6 Apr 2014 12:57:55 +0200 Subject: [PATCH 21/48] Implemented `BigNumber` support for function `diag` --- HISTORY.md | 2 +- lib/function/matrix/diag.js | 10 +++-- test/function/matrix/diag.test.js | 63 ++++++++++++++++++++++++++++++- test/util/bignumber.test.js | 10 ++++- 4 files changed, 78 insertions(+), 7 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index c108070ba..8854142a1 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -11,7 +11,7 @@ https://github.com/josdejong/mathjs - Implemented BigNumber support for functions `exp`, `log`, and `log10`. - Implemented conditional operator `a ? b : c` in expression parser. - Improved function `ifElse`, is now specified for special data types too. -- Implemented `BigNumber` support for function `det`. +- Implemented `BigNumber` support for functions `det` and `diag`. - Changed configuration option `decimals` to `precision` (applies to BigNumbers only). - Fixed support for element-wise comparisons between a string and a matrix. diff --git a/lib/function/matrix/diag.js b/lib/function/matrix/diag.js index abe5c2b49..c0e07d252 100644 --- a/lib/function/matrix/diag.js +++ b/lib/function/matrix/diag.js @@ -1,6 +1,7 @@ module.exports = function (math) { var util = require('../../util/index'), + BigNumber = math.type.BigNumber, Matrix = require('../../type/Matrix'), object = util.object, @@ -19,7 +20,7 @@ module.exports = function (math) { * TODO: more documentation on diag * * @param {Matrix | Array} x - * @param {Number} [k] + * @param {Number | BigNumber} [k] * @return {Matrix | Array} matrix */ math.diag = function diag (x, k) { @@ -30,6 +31,9 @@ module.exports = function (math) { } if (k) { + // convert BigNumber to a number + if (k instanceof BigNumber) k = k.toNumber(); + if (!isNumber(k) || !isInteger(k)) { throw new TypeError ('Second parameter in function diag must be an integer'); } @@ -54,15 +58,13 @@ module.exports = function (math) { throw new TypeError ('First parameter in function diag must be a Matrix or Array'); } - // TODO: bignumber support for diag - var s = x.size(); switch (s.length) { case 1: // x is a vector. create diagonal matrix vector = x.valueOf(); var matrix = new Matrix(); - var defaultValue = 0; + var defaultValue = (vector[0] instanceof BigNumber) ? new BigNumber(0) : 0; matrix.resize([vector.length + kSub, vector.length + kSuper], defaultValue); data = matrix.valueOf(); iMax = vector.length; diff --git a/test/function/matrix/diag.test.js b/test/function/matrix/diag.test.js index 937193d49..643adaa07 100644 --- a/test/function/matrix/diag.test.js +++ b/test/function/matrix/diag.test.js @@ -1,5 +1,6 @@ var assert = require('assert'), - math = require('../../../index')(); + math = require('../../../index')(), + bignumber = math.bignumber; describe('diag', function() { @@ -33,6 +34,66 @@ describe('diag', function() { assert.throws(function () {math.diag([[1,2,3],[4,5,6]], 2.4)}, /Second parameter in function diag must be an integer/); }); + describe('bignumber', function () { + var array123 = [bignumber(1),bignumber(2),bignumber(3)]; + var array123456 = [ + [bignumber(1),bignumber(2),bignumber(3)], + [bignumber(4),bignumber(5),bignumber(6)] + ]; + + it('should return a diagonal matrix on the default diagonal', function() { + assert.deepEqual(math.diag(array123), + [ + [bignumber(1),bignumber(0),bignumber(0)], + [bignumber(0),bignumber(2),bignumber(0)], + [bignumber(0),bignumber(0),bignumber(3)] + ]); + + assert.deepEqual(math.diag(array123456), [bignumber(1),bignumber(5)]); + }); + + it('should return a array output on array input', function() { + assert.deepEqual(math.diag([bignumber(1),bignumber(2)]), + [ + [bignumber(1),bignumber(0)], + [bignumber(0),bignumber(2)] + ]); + }); + + it('should return a matrix output on matrix input', function() { + assert.deepEqual(math.diag(math.matrix([bignumber(1),bignumber(2)])), + math.matrix([ + [bignumber(1),bignumber(0)], + [bignumber(0),bignumber(2)] + ])); + assert.deepEqual(math.diag(math.matrix([ + [bignumber(1),bignumber(2)], + [bignumber(3),bignumber(4)] + ])), math.matrix([bignumber(1),bignumber(4)])); + }); + + it('should put vector on given diagonal k in returned matrix', function() { + assert.deepEqual(math.diag(array123, bignumber(1)), [ + [bignumber(0),bignumber(1),bignumber(0),bignumber(0)], + [bignumber(0),bignumber(0),bignumber(2),bignumber(0)], + [bignumber(0),bignumber(0),bignumber(0),bignumber(3)] + ]); + assert.deepEqual(math.diag(array123, bignumber(-1)), [ + [bignumber(0),bignumber(0),bignumber(0)], + [bignumber(1),bignumber(0),bignumber(0)], + [bignumber(0),bignumber(2),bignumber(0)], + [bignumber(0),bignumber(0),bignumber(3)] + ]); + }); + + it('should return diagonal k from a matrix', function() { + assert.deepEqual(math.diag(array123456, bignumber(1)), [bignumber(2),bignumber(6)]); + assert.deepEqual(math.diag(array123456, bignumber(-1)), [bignumber(4)]); + assert.deepEqual(math.diag(array123456, bignumber(-2)), []); + }); + + }); + it('should throw an error of the input matrix is not valid', function() { assert.throws(function () {math.diag([[[1],[2]],[[3],[4]]])}); // TODO: test diag for all types of input (also scalar) diff --git a/test/util/bignumber.test.js b/test/util/bignumber.test.js index e82372f7a..b52e124a0 100644 --- a/test/util/bignumber.test.js +++ b/test/util/bignumber.test.js @@ -1,11 +1,19 @@ // test bignumber utils var assert = require('assert'), approx = require('../../tools/approx'), - BigNumber = require('decimal.js'), // FIXME: don't use the global BigNumber + BigNumber = require('decimal.js'), bignumber = require('../../lib/util/bignumber'); describe('bignumber', function() { + it('should test whether an object is a BigNumber', function() { + assert.equal(bignumber.isBigNumber(new BigNumber(2.34)), true); + + assert.equal(bignumber.isBigNumber(new Date()), false); + assert.equal(bignumber.isBigNumber({}), false); + assert.equal(bignumber.isBigNumber(123), false); + }); + it('should format a bignumber using toFixed', function() { var Big = BigNumber.constructor(); Big.config({precision: 100}); From 2730edfd601cd42b81afe74272bb57bfec9082da Mon Sep 17 00:00:00 2001 From: josdejong Date: Sun, 6 Apr 2014 13:03:45 +0200 Subject: [PATCH 22/48] Removed errors for stuff deprecated since v0.16.0 --- lib/util/bignumber.js | 8 -------- lib/util/number.js | 8 -------- test/deprecated.test.js | 12 ------------ test/type/Complex.test.js | 10 ++++++++++ 4 files changed, 10 insertions(+), 28 deletions(-) diff --git a/lib/util/bignumber.js b/lib/util/bignumber.js index 786f296ce..04fbb4b11 100644 --- a/lib/util/bignumber.js +++ b/lib/util/bignumber.js @@ -110,10 +110,6 @@ exports.format = function format(value, options) { case 'fixed': return exports.toFixed(value, precision); - // TODO: notation 'scientific' is deprecated since version 0.16.0, remove this some day - case 'scientific': - throw new Error('Format notation "scientific" is deprecated. Use "exponential" instead.'); - case 'exponential': return exports.toExponential(value, precision); @@ -130,10 +126,6 @@ exports.format = function format(value, options) { upper = options.exponential.upper; } } - else if (options && options.scientific) { - // TODO: 'options.scientific' is deprecated since version 0.16.0, remove this some day - throw new Error('options.scientific is deprecated, use options.exponential instead.'); - } // adjust the configuration of the BigNumber constructor (yeah, this is quite tricky...) var oldConfig = value.constructor.config({}); diff --git a/lib/util/number.js b/lib/util/number.js index 789cb2293..4c68814dd 100644 --- a/lib/util/number.js +++ b/lib/util/number.js @@ -139,10 +139,6 @@ exports.format = function format(value, options) { case 'fixed': return exports.toFixed(value, precision); - // TODO: notation 'scientific' is deprecated since version 0.16.0, remove this some day - case 'scientific': - throw new Error('Format notation "scientific" is deprecated. Use "exponential" instead.'); - case 'exponential': return exports.toExponential(value, precision); @@ -159,10 +155,6 @@ exports.format = function format(value, options) { upper = options.exponential.upper; } } - else if (options && options.scientific) { - // TODO: 'options.scientific' is deprecated since version 0.16.0, remove this some day - throw new Error('options.scientific is deprecated, use options.exponential instead.'); - } // handle special case zero if (value === 0) return '0'; diff --git a/test/deprecated.test.js b/test/deprecated.test.js index 91f9bbfd5..382fcefe3 100644 --- a/test/deprecated.test.js +++ b/test/deprecated.test.js @@ -74,16 +74,4 @@ describe('deprecated stuff', function() { }, /Deprecated keyword "function"/); }); - it ('should throw an error when using deprecated notation "scientific in number.format"', function () { - assert.throws(function () { - new number.format(2.3, {notation: 'scientific'}); - }, /Format notation "scientific" is deprecated/); - }); - - it ('should throw an error when using deprecated option "scientific in number.format"', function () { - assert.throws(function () { - new number.format(2.3, {notation: 'auto', scientific: 5}); - }, /options.scientific is deprecated/); - }); - }); diff --git a/test/type/Complex.test.js b/test/type/Complex.test.js index bc954aca0..b66e54370 100644 --- a/test/type/Complex.test.js +++ b/test/type/Complex.test.js @@ -32,6 +32,11 @@ describe('Complex', function () { assert.throws(function () { new Complex(true, 2); }); }); + it('should throw an error if called with wrong type of arguments', function() { + assert.throws(function () { new Complex(1, true); }); + assert.throws(function () { new Complex({}); }, /Object with the re and im or r and phi properties expected/); + }); + it('should throw an error if called without new operator', function() { assert.throws(function () { Complex(3, -4); }); }); @@ -238,6 +243,11 @@ describe('Complex', function () { assert.throws(function() { Complex.fromPolar(1, true)}); assert.throws(function() { Complex.fromPolar(1, {})}); }); + + it('should throw an error in case of wrong number of arguments', function() { + assert.throws(function() { Complex.fromPolar(1,2,3)}, /Wrong number of arguments/); + assert.throws(function() { Complex.fromPolar()}, /Wrong number of arguments/); + }); }); describe('toPolar', function() { From 7baa9af67cc82039e43bca5ffd8ef842888fd72a Mon Sep 17 00:00:00 2001 From: josdejong Date: Sun, 6 Apr 2014 13:07:29 +0200 Subject: [PATCH 23/48] Added unit alias `lbs` (pound mass). --- HISTORY.md | 1 + lib/type/Unit.js | 1 + 2 files changed, 2 insertions(+) diff --git a/HISTORY.md b/HISTORY.md index 8854142a1..19c2a7db2 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -12,6 +12,7 @@ https://github.com/josdejong/mathjs - Implemented conditional operator `a ? b : c` in expression parser. - Improved function `ifElse`, is now specified for special data types too. - Implemented `BigNumber` support for functions `det` and `diag`. +- Added unit alias `lbs` (pound mass). - Changed configuration option `decimals` to `precision` (applies to BigNumbers only). - Fixed support for element-wise comparisons between a string and a matrix. diff --git a/lib/type/Unit.js b/lib/type/Unit.js index 479501a8c..686b6148f 100644 --- a/lib/type/Unit.js +++ b/lib/type/Unit.js @@ -845,6 +845,7 @@ UNITS.lt = UNITS.l; UNITS.liter = UNITS.litre; UNITS.liters = UNITS.litres; UNITS.lb = UNITS.lbm; +UNITS.lbs = UNITS.lbm; Unit.PREFIXES = PREFIXES; From d0fb727c431f578969b202954f7a62d40cdf24a2 Mon Sep 17 00:00:00 2001 From: josdejong Date: Sun, 6 Apr 2014 20:53:23 +0200 Subject: [PATCH 24/48] Implemented DimensionError and IndexError --- lib/expression/node/Node.js | 27 ++++++--- lib/function/arithmetic/multiply.js | 2 + lib/function/matrix/concat.js | 8 +-- lib/function/matrix/range.js | 3 +- lib/function/matrix/resize.js | 2 +- lib/function/matrix/subset.js | 7 +-- lib/function/utils/ifElse.js | 6 +- lib/function/utils/typeof.js | 4 +- lib/type/Matrix.js | 20 +++---- lib/type/collection.js | 3 +- lib/type/error.js | 4 +- lib/util/array.js | 26 ++++---- lib/util/error.js | 76 ++++++++++++++++++++++++ lib/util/index.js | 1 + test/function/matrix/concat.test.js | 2 +- test/type/Matrix.test.js | 2 +- test/util/error.test.js | 92 +++++++++++++++++++++++++++++ 17 files changed, 227 insertions(+), 58 deletions(-) create mode 100644 lib/util/error.js create mode 100644 test/util/error.test.js diff --git a/lib/expression/node/Node.js b/lib/expression/node/Node.js index dd0622ca4..a804b1514 100644 --- a/lib/expression/node/Node.js +++ b/lib/expression/node/Node.js @@ -1,4 +1,6 @@ -/** +var error = require('../../util/error'); + + /** * Node */ function Node() { @@ -32,7 +34,8 @@ Node.prototype.compile = function (math) { // definitions globally available inside the closure of the compiled expressions var defs = { - math: math + math: math, + error: error }; var code = this._compile(defs); @@ -43,12 +46,20 @@ Node.prototype.compile = function (math) { var factoryCode = defsCode.join(' ') + - 'return {' + - ' "eval": function (scope) {' + - ' scope = scope || {};' + - ' return ' + code + ';' + - ' }' + - '};'; + 'return {' + + ' "eval": function (scope) {' + + ' try {' + + ' scope = scope || {};' + + ' return ' + code + ';' + + ' } catch (err) {' + + // replace an index-out-of-range-error with a one-based message + ' if (err instanceof defs.error.IndexError) {' + + ' err = new defs.error.IndexError(err.index + 1, err.min + 1, err.max + 1);' + + ' }' + + ' throw err;' + + ' }' + + ' }' + + '};'; var factory = new Function ('defs', factoryCode); return factory(defs); diff --git a/lib/function/arithmetic/multiply.js b/lib/function/arithmetic/multiply.js index b64697951..363aa86ac 100644 --- a/lib/function/arithmetic/multiply.js +++ b/lib/function/arithmetic/multiply.js @@ -25,6 +25,8 @@ module.exports = function(math) { * @return {Number | BigNumber | Complex | Unit | Array | Matrix} res */ math.multiply = function multiply(x, y) { + var res; + if (arguments.length != 2) { throw new math.error.ArgumentsError('multiply', arguments.length, 2); } diff --git a/lib/function/matrix/concat.js b/lib/function/matrix/concat.js index 59242fa60..4b8b0898a 100644 --- a/lib/function/matrix/concat.js +++ b/lib/function/matrix/concat.js @@ -49,8 +49,7 @@ module.exports = function (math) { } if (i > 0 && dim > prevDim) { - throw new RangeError('Dimension out of range ' + - '(' + dim + ' > ' + prevDim + ')'); + throw new util.error.DimensionError(dim, prevDim, '>'); } } else if (isCollection(arg)) { @@ -63,8 +62,7 @@ module.exports = function (math) { // verify whether each of the matrices has the same number of dimensions if (i > 0 && dim != prevDim) { - throw new RangeError('Dimension mismatch ' + - '(' + prevDim + ' != ' + dim + ')'); + throw new util.error.DimensionError(dim, prevDim); } } else { @@ -98,7 +96,7 @@ module.exports = function (math) { if (dim < concatDim) { // recurse into next dimension if (a.length != b.length) { - throw new Error('Dimension mismatch (' + a.length + ' != ' + b.length + ')'); + throw new util.error.DimensionError(a.length, b.length); } var c = []; diff --git a/lib/function/matrix/range.js b/lib/function/matrix/range.js index 0d18e5fd7..35b7cfade 100644 --- a/lib/function/matrix/range.js +++ b/lib/function/matrix/range.js @@ -69,8 +69,7 @@ module.exports = function (math, config) { step = r.step; } else { - throw new TypeError( - 'Two or three numbers or a single string expected in function range'); + throw new TypeError('Two or three numbers or a single string expected in function range'); } break; diff --git a/lib/function/matrix/resize.js b/lib/function/matrix/resize.js index 9706d8fce..93bd18461 100644 --- a/lib/function/matrix/resize.js +++ b/lib/function/matrix/resize.js @@ -89,7 +89,7 @@ module.exports = function (math, config) { } if (size.length !== 1) { - throw new Error('Dimension mismatch: (' + size.length + ' != 1)'); + throw new util.error.DimensionError(size.length, 1); } var len = size[0]; if (!isNumber(len) || !isInteger(len)) { diff --git a/lib/function/matrix/subset.js b/lib/function/matrix/subset.js index d66781995..952560df2 100644 --- a/lib/function/matrix/subset.js +++ b/lib/function/matrix/subset.js @@ -84,7 +84,7 @@ module.exports = function (math) { throw new TypeError('Index expected'); } if (index.size().length != 1) { - throw new RangeError('Dimension mismatch (' + index.size().length + ' != 1)'); + throw new util.error.DimensionError(index.size().length, 1); } var range = index.range(0); @@ -146,7 +146,7 @@ module.exports = function (math) { throw new TypeError('Index expected'); } if (index.size().length != 1) { - throw new RangeError('Dimension mismatch (' + index.size().length + ' != 1)'); + throw new util.error.DimensionError(index.size().length, 1); } if (defaultValue !== undefined) { if (!isString(defaultValue) || defaultValue.length !== 1) { @@ -161,8 +161,7 @@ module.exports = function (math) { var len = range.size()[0]; if (len != replacement.length) { - throw new RangeError('Dimension mismatch ' + - '(' + range.size()[0] + ' != ' + replacement.length + ')'); + throw new util.error.DimensionError(range.size()[0], replacement.length); } // copy the string into an array with characters diff --git a/lib/function/utils/ifElse.js b/lib/function/utils/ifElse.js index 356d2eda7..3d768cf5f 100644 --- a/lib/function/utils/ifElse.js +++ b/lib/function/utils/ifElse.js @@ -90,6 +90,7 @@ module.exports = function (math) { condition.size().join(', ') + '] != [' + trueExpr.size().join(', ') + '])'); + throw new util.error.DimensionError(condition.size(), trueExpr.size()); } } @@ -99,10 +100,7 @@ module.exports = function (math) { if (!(falseExpr instanceof Matrix)) falseExpr = new Matrix(falseExpr); if (!deepEqual(condition.size(), falseExpr.size())) { - throw new RangeError('Dimension mismatch ([' + - condition.size().join(', ') + '] != [' + - falseExpr.size().join(', ') - + '])'); + throw new util.error.DimensionError(condition.size(), falseExpr.size()); } } diff --git a/lib/function/utils/typeof.js b/lib/function/utils/typeof.js index a602e4cd9..48c6b1fe6 100644 --- a/lib/function/utils/typeof.js +++ b/lib/function/utils/typeof.js @@ -1,7 +1,6 @@ module.exports = function (math) { var types = require('../../util/types'), - BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), Matrix = require('../../type/Matrix'), Unit = require('../../type/Unit'), @@ -30,13 +29,14 @@ module.exports = function (math) { // math.js types if (type === 'object') { if (x instanceof Complex) return 'complex'; - if (x instanceof BigNumber) return 'bignumber'; if (x instanceof Matrix) return 'matrix'; if (x instanceof Unit) return 'unit'; if (x instanceof Index) return 'index'; if (x instanceof Range) return 'range'; if (x instanceof Help) return 'help'; + // the following types are different instances per math.js instance + if (x instanceof math.type.BigNumber) return 'bignumber'; if (x instanceof math.chaining.Selector) return 'selector'; } diff --git a/lib/type/Matrix.js b/lib/type/Matrix.js index 271f055a5..3bc86ff78 100644 --- a/lib/type/Matrix.js +++ b/lib/type/Matrix.js @@ -101,11 +101,10 @@ Matrix.prototype.subset = function subset(index, replacement, defaultValue) { */ Matrix.prototype.get = function get(index) { if (!isArray(index)) { - throw new Error('Array expected'); + throw new TypeError('Array expected'); } if (index.length != this._size.length) { - throw new RangeError('Dimension mismatch ' + - '(' + index.length + ' != ' + this._size.length + ')'); + throw new util.error.DimensionError(index.length, this._size.length); } var data = this._data; @@ -135,8 +134,7 @@ Matrix.prototype.set = function set (index, value, defaultValue) { throw new Error('Array expected'); } if (index.length < this._size.length) { - throw new RangeError('Dimension mismatch ' + - '(' + index.length + ' < ' + this._size.length + ')'); + throw new util.error.DimensionError(index.length, this._size.length, '<'); } // enlarge matrix when needed @@ -181,8 +179,7 @@ function _get (matrix, index) { // validate dimensions var size = index.size(); if (size.length != matrix._size.length) { - throw new RangeError('Dimension mismatch ' + - '(' + size.length + ' != ' + matrix._size.length + ')'); + throw new util.error.DimensionError(size.length, matrix._size.length); } // retrieve submatrix @@ -264,8 +261,7 @@ function _set (matrix, index, submatrix, defaultValue) { // check whether submatrix is a scalar if (sSize.length != 0) { - throw new RangeError('Dimension mismatch ' + - '(scalar expected, got a matrix)'); + throw new TypeError('Scalar expected'); } matrix.set(index.min(), submatrix, defaultValue); @@ -275,8 +271,7 @@ function _set (matrix, index, submatrix, defaultValue) { // validate dimensions if (iSize.length < matrix._size.length) { - throw new RangeError('Dimension mismatch ' + - '(' + iSize.length + ' < ' + matrix._size.length + ')'); + throw new util.error.DimensionError(iSize.length, matrix._size.length, '<'); } // unsqueeze the submatrix when needed @@ -287,8 +282,7 @@ function _set (matrix, index, submatrix, defaultValue) { // check whether the size of the submatrix matches the index size if (!object.deepEqual(iSize, sSize)) { - throw new RangeError('Dimension mismatch ' + - '(' + string.format(iSize) + ' != '+ string.format(sSize) + ')'); + throw new util.error.DimensionError(iSize, sSize); } // enlarge matrix when needed diff --git a/lib/type/collection.js b/lib/type/collection.js index 4a2fd9385..21622769f 100644 --- a/lib/type/collection.js +++ b/lib/type/collection.js @@ -90,8 +90,7 @@ exports.deepMap2 = function deepMap2(array1, array2, callback) { if (isArray(array2)) { // callback(array, array) if (array1.length != array2.length) { - throw new RangeError('Dimension mismatch ' + - '(' + array1.length + ' != ' + array2.length + ')'); + throw new util.error.DimensionError(array1.length, array2.length); } res = []; diff --git a/lib/type/error.js b/lib/type/error.js index 6fc2fdd85..64fa70500 100644 --- a/lib/type/error.js +++ b/lib/type/error.js @@ -1,6 +1,8 @@ module.exports = function (math) { var types = require('./../util/types'); + // TODO: make error.js independent of the math namespace (currently uses math.typeof) + // export the error constructors to namespace math.error.* var error = {}; math.error = error; @@ -56,7 +58,7 @@ module.exports = function (math) { * @param {Number} count Actual argument count * @param {Number} min Minimum required argument count * @param {Number} [max] Maximum required argument count - * @extends SyntaxError + * @extends Error */ error.ArgumentsError = function ArgumentsError(name, count, min, max) { if (!(this instanceof ArgumentsError)) { diff --git a/lib/util/array.js b/lib/util/array.js index 0e0985659..f533f4205 100644 --- a/lib/util/array.js +++ b/lib/util/array.js @@ -1,7 +1,9 @@ var number = require('./number'), string = require('./string'), object = require('./object'), + error = require('./error'), types = require('./types'), + isArray = Array.isArray; /** @@ -46,7 +48,7 @@ exports.size = function size (x) { * @param {Array} array Array to be validated * @param {Number[]} size Array with the size of each dimension * @param {Number} dim Current dimension - * @throws RangeError + * @throws DimensionError * @private */ function _validate(array, size, dim) { @@ -54,7 +56,7 @@ function _validate(array, size, dim) { var len = array.length; if (len != size[dim]) { - throw new RangeError('Dimension mismatch (' + len + ' != ' + size[dim] + ')'); + throw new error.DimensionError(len, size[dim]); } if (dim < size.length - 1) { @@ -63,8 +65,7 @@ function _validate(array, size, dim) { for (i = 0; i < len; i++) { var child = array[i]; if (!isArray(child)) { - throw new RangeError('Dimension mismatch ' + - '(' + (size.length - 1) + ' < ' + size.length + ')'); + throw new error.DimensionError(size.length - 1, size.length, '<'); } _validate(array[i], size, dimNext); } @@ -73,8 +74,7 @@ function _validate(array, size, dim) { // last dimension. none of the childs may be an array for (i = 0; i < len; i++) { if (isArray(array[i])) { - throw new RangeError('Dimension mismatch ' + - '(' + (size.length + 1) + ' > ' + size.length + ')'); + throw new error.DimensionError(size.length + 1, size.length, '>'); } } } @@ -85,14 +85,14 @@ function _validate(array, size, dim) { * a size corresponding to the provided size array. * @param {Array} array Array to be validated * @param {Number[]} size Array with the size of each dimension - * @throws RangeError + * @throws DimensionError */ exports.validate = function validate(array, size) { var isScalar = (size.length == 0); if (isScalar) { // scalar if (isArray(array)) { - throw new RangeError('Dimension mismatch (' + array.length + ' != 0)'); + throw new error.DimensionError(array.length, 0); } } else { @@ -103,7 +103,7 @@ exports.validate = function validate(array, size) { /** * Test whether index is an integer number with index >= 0 and index < length - * @param {*} index Zero-based index + * @param {Number} index Zero-based index * @param {Number} [length] Length of the array */ exports.validateIndex = function validateIndex (index, length) { @@ -111,10 +111,10 @@ exports.validateIndex = function validateIndex (index, length) { throw new TypeError('Index must be an integer (value: ' + index + ')'); } if (index < 0) { - throw new RangeError('Index out of range (' + index + ' < 0)'); + throw new error.IndexError(index); } if (length !== undefined && index >= length) { - throw new RangeError('Index out of range (' + index + ' > ' + (length - 1) + ')'); + throw new error.IndexError(index, length); } }; @@ -179,9 +179,7 @@ exports.resize = function resize(array, size, defaultValue) { * @private */ function _resize (array, size, dim, defaultValue) { - if (!isArray(array)) { - throw Error('Array expected'); - } + if (!isArray(array)) throw Error('Array expected'); var i, elem, oldLen = array.length, diff --git a/lib/util/error.js b/lib/util/error.js new file mode 100644 index 000000000..96032b030 --- /dev/null +++ b/lib/util/error.js @@ -0,0 +1,76 @@ +/** + * Create a range error with the message: + * 'Dimension mismatch ( != )' + * @param {number | number[]} actual The actual size + * @param {number | number[]} expected The expected size + * @param {string} [relation='!='] Optional relation between actual + * and expected size: '!=', '<', etc. + * @extends RangeError + */ +function DimensionError(actual, expected, relation) { + if (!(this instanceof DimensionError)) { + throw new SyntaxError('Constructor must be called with the new operator'); + } + + this.actual = actual; + this.expected = expected; + this.relation = relation || '!='; + + this.message = 'Dimension mismatch (' + + (Array.isArray(actual) ? ('[' + actual.join(', ') + ']') : actual) + + ' ' + this.relation + ' ' + + (Array.isArray(expected) ? ('[' + expected.join(', ') + ']') : expected) + + ')'; + + this.stack = (new Error()).stack; +} + +DimensionError.prototype = new RangeError(); +DimensionError.prototype.constructor = RangeError; +DimensionError.prototype.name = 'DimensionError'; + +exports.DimensionError = DimensionError; + +/** + * Create a range error with the message: + * 'Index out of range (index < min)' + * 'Index out of range (index < max)' + * + * @param {number} index The actual index + * @param {number} [min=0] Minimum index (included) + * @param {number} [max] Maximum index (excluded) + * @extends RangeError + */ +function IndexError(index, min, max) { + if (!(this instanceof IndexError)) { + throw new SyntaxError('Constructor must be called with the new operator'); + } + + this.index = index; + if (arguments.length <= 2) { + this.min = 0; + this.max = min; + } + else { + this.min = min; + this.max = max; + } + + if (this.index < this.min) { + this.message = 'Index out of range (' + this.index + ' < ' + this.min + ')'; + } + else if (this.index >= this.max) { + this.message = 'Index out of range (' + this.index + ' > ' + (this.max - 1) + ')'; + } + else { + this.message = 'Index out of range (' + this.index + ')'; + } + + this.stack = (new Error()).stack; +} + +IndexError.prototype = new RangeError(); +IndexError.prototype.constructor = RangeError; +IndexError.prototype.name = 'IndexError'; + +exports.IndexError = IndexError; diff --git a/lib/util/index.js b/lib/util/index.js index 87193dfff..ac9962b66 100644 --- a/lib/util/index.js +++ b/lib/util/index.js @@ -5,3 +5,4 @@ exports.bignumber = require('./bignumber'); exports.object = require('./object'); exports.string = require('./string'); exports.types = require('./types'); +exports.error = require('./error'); diff --git a/test/function/matrix/concat.test.js b/test/function/matrix/concat.test.js index 369eaf382..bb76d55fb 100644 --- a/test/function/matrix/concat.test.js +++ b/test/function/matrix/concat.test.js @@ -79,7 +79,7 @@ describe('concat', function() { it('should throw an error in case of invalid requested dimension number', function() { assert.throws(function () {math.concat([1, 2], [3,4], 2.3)}, /Dimension number must be a positive integer/); - assert.throws(function () {math.concat([1, 2], [3,4], 1)}, /Dimension out of range/); + assert.throws(function () {math.concat([1, 2], [3,4], 1)}, /Dimension mismatch \(1 > 0\)/); }); it('should throw an error in case dimension mismatch', function() { diff --git a/test/type/Matrix.test.js b/test/type/Matrix.test.js index d9defa710..5c8e1bc18 100644 --- a/test/type/Matrix.test.js +++ b/test/type/Matrix.test.js @@ -308,7 +308,7 @@ describe('matrix', function() { }); it ('should throw an error in case of wrong size of submatrix', function () { - assert.throws(function () {new Matrix().subset(index(0), [2,3])}, /Dimension mismatch/) + assert.throws(function () {new Matrix().subset(index(0), [2,3])}, /Scalar expected/) }); it('should throw an error in case of dimension mismatch', function() { diff --git a/test/util/error.test.js b/test/util/error.test.js new file mode 100644 index 000000000..0104ef790 --- /dev/null +++ b/test/util/error.test.js @@ -0,0 +1,92 @@ +// test error types + +var assert = require('assert'), + error = require('../../lib/util/error'); + +describe('error', function () { + + describe('DimensionError', function () { + + it('should construct a DimensionError with numbers', function () { + var err = new error.DimensionError(3, 5); + assert(err instanceof Error); + assert(err instanceof RangeError); + assert(err instanceof error.DimensionError); + assert.equal(err.toString(), 'DimensionError: Dimension mismatch (3 != 5)'); + }); + + it('should construct a DimensionError with numbers and a custom relation', function () { + var err = new error.DimensionError(3, 5, '<'); + assert(err instanceof Error); + assert(err instanceof RangeError); + assert(err instanceof error.DimensionError); + assert.equal(err.toString(), 'DimensionError: Dimension mismatch (3 < 5)'); + }); + + it('should construct a DimensionError with arrays', function () { + var err = new error.DimensionError([2,3], [1,3]); + assert(err instanceof Error); + assert(err instanceof RangeError); + assert(err instanceof error.DimensionError); + assert.equal(err.toString(), 'DimensionError: Dimension mismatch ([2, 3] != [1, 3])'); + }); + + it('should construct a DimensionError with arrays and a custom relation', function () { + var err = new error.DimensionError([2,3], [1,3], '<'); + assert(err instanceof Error); + assert(err instanceof RangeError); + assert(err instanceof error.DimensionError); + assert.equal(err.toString(), 'DimensionError: Dimension mismatch ([2, 3] < [1, 3])'); + }); + + it('should throw an error when operator new is missing', function () { + assert.throws(function () {error.DimensionError(3, 5);}, SyntaxError); + }); + + }); + + describe('IndexError', function () { + + it('should construct an IndexError without min and max', function () { + var err = new error.IndexError(5); + assert(err instanceof Error); + assert(err instanceof RangeError); + assert(err instanceof error.IndexError); + assert.equal(err.toString(), 'IndexError: Index out of range (5)'); + }); + + it('should construct an IndexError without min and max (2)', function () { + var err = new error.IndexError(-5); + assert(err instanceof Error); + assert(err instanceof RangeError); + assert(err instanceof error.IndexError); + assert.equal(err.toString(), 'IndexError: Index out of range (-5 < 0)'); + }); + + it('should construct an IndexError with max', function () { + var err = new error.IndexError(5, 3); + assert(err instanceof Error); + assert(err instanceof RangeError); + assert(err instanceof error.IndexError); + assert.equal(err.toString(), 'IndexError: Index out of range (5 > 2)'); + }); + + it('should construct an IndexError with min and max', function () { + var err = new error.IndexError(0, 2, 5); + assert(err instanceof Error); + assert(err instanceof RangeError); + assert(err instanceof error.IndexError); + assert.equal(err.toString(), 'IndexError: Index out of range (0 < 2)'); + }); + + it('should construct an IndexError with min and max', function () { + var err = new error.IndexError(6, 1, 4); + assert(err instanceof Error); + assert(err instanceof RangeError); + assert(err instanceof error.IndexError); + assert.equal(err.toString(), 'IndexError: Index out of range (6 > 3)'); + }); + + }); + +}); From 492d7f4c4fffebabe8d34e1f076d5b9e2e184093 Mon Sep 17 00:00:00 2001 From: josdejong Date: Sun, 6 Apr 2014 21:25:46 +0200 Subject: [PATCH 25/48] Moved ArgumentsError from lib/type/ to lib/util/ --- lib/expression/node/FunctionNode.js | 2 +- lib/function/arithmetic/abs.js | 2 +- lib/function/arithmetic/add.js | 2 +- lib/function/arithmetic/ceil.js | 2 +- lib/function/arithmetic/compare.js | 2 +- lib/function/arithmetic/cube.js | 2 +- lib/function/arithmetic/divide.js | 2 +- lib/function/arithmetic/edivide.js | 2 +- lib/function/arithmetic/emultiply.js | 5 +-- lib/function/arithmetic/epow.js | 5 +-- lib/function/arithmetic/equal.js | 2 +- lib/function/arithmetic/exp.js | 2 +- lib/function/arithmetic/fix.js | 2 +- lib/function/arithmetic/floor.js | 2 +- lib/function/arithmetic/larger.js | 2 +- lib/function/arithmetic/largereq.js | 2 +- lib/function/arithmetic/log.js | 2 +- lib/function/arithmetic/log10.js | 2 +- lib/function/arithmetic/mod.js | 2 +- lib/function/arithmetic/multiply.js | 2 +- lib/function/arithmetic/pow.js | 2 +- lib/function/arithmetic/round.js | 2 +- lib/function/arithmetic/sign.js | 2 +- lib/function/arithmetic/smaller.js | 2 +- lib/function/arithmetic/smallereq.js | 2 +- lib/function/arithmetic/sqrt.js | 2 +- lib/function/arithmetic/square.js | 2 +- lib/function/arithmetic/subtract.js | 2 +- lib/function/arithmetic/unary.js | 2 +- lib/function/arithmetic/unequal.js | 2 +- lib/function/complex/arg.js | 2 +- lib/function/complex/conj.js | 2 +- lib/function/complex/im.js | 2 +- lib/function/complex/re.js | 2 +- lib/function/construction/bignumber.js | 2 +- lib/function/construction/boolean.js | 2 +- lib/function/construction/complex.js | 2 +- lib/function/construction/matrix.js | 5 +-- lib/function/construction/number.js | 2 +- lib/function/construction/string.js | 2 +- lib/function/construction/unit.js | 2 +- lib/function/expression/compile.js | 2 +- lib/function/expression/eval.js | 2 +- lib/function/matrix/det.js | 2 +- lib/function/matrix/diag.js | 2 +- lib/function/matrix/eye.js | 2 +- lib/function/matrix/inv.js | 5 +-- lib/function/matrix/range.js | 2 +- lib/function/matrix/resize.js | 2 +- lib/function/matrix/size.js | 2 +- lib/function/matrix/squeeze.js | 2 +- lib/function/matrix/subset.js | 2 +- lib/function/matrix/transpose.js | 2 +- lib/function/probability/combinations.js | 2 +- lib/function/probability/factorial.js | 2 +- lib/function/probability/permutations.js | 2 +- lib/function/probability/random.js | 6 ++-- lib/function/trigonometry/acos.js | 2 +- lib/function/trigonometry/asin.js | 2 +- lib/function/trigonometry/atan.js | 2 +- lib/function/trigonometry/atan2.js | 2 +- lib/function/trigonometry/cos.js | 2 +- lib/function/trigonometry/cot.js | 2 +- lib/function/trigonometry/csc.js | 2 +- lib/function/trigonometry/sec.js | 2 +- lib/function/trigonometry/sin.js | 2 +- lib/function/trigonometry/tan.js | 2 +- lib/function/units/to.js | 2 +- lib/function/utils/clone.js | 5 +-- lib/function/utils/forEach.js | 2 +- lib/function/utils/format.js | 5 +-- lib/function/utils/ifElse.js | 2 +- lib/function/utils/import.js | 2 +- lib/function/utils/map.js | 2 +- lib/function/utils/print.js | 6 ++-- lib/function/utils/typeof.js | 2 +- lib/type/error.js | 30 +----------------- lib/util/error.js | 31 +++++++++++++++++++ test/function/arithmetic/abs.test.js | 5 +-- test/function/arithmetic/add.test.js | 5 +-- test/function/arithmetic/ceil.test.js | 5 +-- test/function/arithmetic/compare.test.js | 5 +-- test/function/arithmetic/cube.test.js | 5 +-- test/function/arithmetic/divide.test.js | 1 + test/function/arithmetic/edivide.test.js | 5 +-- test/function/arithmetic/emultiply.test.js | 5 +-- test/function/arithmetic/epow.test.js | 5 +-- test/function/arithmetic/equal.test.js | 5 +-- test/function/arithmetic/exp.test.js | 5 +-- test/function/arithmetic/fix.test.js | 5 +-- test/function/arithmetic/floor.test.js | 5 +-- test/function/arithmetic/gcd.test.js | 1 + test/function/arithmetic/larger.test.js | 5 +-- test/function/arithmetic/largereq.test.js | 5 +-- test/function/arithmetic/lcm.test.js | 1 + test/function/arithmetic/log.test.js | 5 +-- test/function/arithmetic/log10.test.js | 5 +-- test/function/arithmetic/mod.test.js | 5 +-- test/function/arithmetic/multiply.test.js | 5 +-- test/function/arithmetic/pow.test.js | 5 +-- test/function/arithmetic/round.test.js | 5 +-- test/function/arithmetic/sign.test.js | 5 +-- test/function/arithmetic/smaller.test.js | 5 +-- test/function/arithmetic/smallereq.test.js | 5 +-- test/function/arithmetic/sqrt.test.js | 5 +-- test/function/arithmetic/square.test.js | 5 +-- test/function/arithmetic/subtract.test.js | 5 +-- test/function/arithmetic/unary.test.js | 5 +-- test/function/arithmetic/unequal.test.js | 5 +-- test/function/arithmetic/xgcd.test.js | 1 + test/function/complex/arg.test.js | 5 +-- test/function/complex/conj.test.js | 5 +-- test/function/complex/im.test.js | 5 +-- test/function/complex/re.test.js | 5 +-- test/function/construction/bignumber.test.js | 3 +- test/function/construction/boolean.test.js | 5 +-- test/function/construction/complex.test.js | 3 +- test/function/construction/index.test.js | 1 + test/function/construction/matrix.test.js | 3 +- test/function/construction/number.test.js | 5 +-- test/function/construction/parser.test.js | 1 + test/function/construction/string.test.js | 5 +-- test/function/construction/unit.test.js | 5 +-- test/function/expression/compile.test.js | 5 +-- test/function/expression/eval.test.js | 5 +-- test/function/expression/help.test.js | 1 + test/function/expression/parse.test.js | 1 + test/function/matrix/concat.test.js | 1 + test/function/matrix/det.test.js | 1 + test/function/matrix/diag.test.js | 5 +-- test/function/matrix/eye.test.js | 1 + test/function/matrix/inv.test.js | 5 +-- test/function/matrix/ones.test.js | 1 + test/function/matrix/range.test.js | 5 +-- test/function/matrix/resize.test.js | 1 + test/function/matrix/size.test.js | 5 +-- test/function/matrix/squeeze.test.js | 5 +-- test/function/matrix/subset.test.js | 7 +++-- test/function/matrix/transpose.test.js | 5 +-- test/function/matrix/zeros.test.js | 1 + .../function/probability/combinations.test.js | 1 + test/function/probability/factorial.test.js | 1 + .../function/probability/permutations.test.js | 1 + test/function/probability/random.test.js | 1 + test/function/trigonometry/acos.test.js | 5 +-- test/function/trigonometry/asin.test.js | 5 +-- test/function/trigonometry/atan.test.js | 5 +-- test/function/trigonometry/atan2.test.js | 5 +-- test/function/trigonometry/cos.test.js | 5 +-- test/function/trigonometry/cot.test.js | 5 +-- test/function/trigonometry/csc.test.js | 5 +-- test/function/trigonometry/sec.test.js | 5 +-- test/function/trigonometry/sin.test.js | 5 +-- test/function/trigonometry/tan.test.js | 5 +-- test/function/utils/clone.test.js | 5 +-- test/function/utils/forEach.test.js | 1 + test/function/utils/format.test.js | 5 +-- test/function/utils/ifElse.test.js | 1 + test/function/utils/import.test.js | 5 +-- test/function/utils/map.test.js | 1 + test/function/utils/print.test.js | 7 +++-- test/function/utils/typeof.test.js | 1 + test/type/error.test.js | 22 ------------- test/util/error.test.js | 22 +++++++++++++ 164 files changed, 353 insertions(+), 260 deletions(-) diff --git a/lib/expression/node/FunctionNode.js b/lib/expression/node/FunctionNode.js index f5634d4a8..6d0493137 100644 --- a/lib/expression/node/FunctionNode.js +++ b/lib/expression/node/FunctionNode.js @@ -42,7 +42,7 @@ FunctionNode.prototype._compile = function (defs) { ' scope = Object.create(scope); ' + ' var fn = function ' + this.name + '(' + this.args.join(',') + ') {' + ' if (arguments.length != ' + this.args.length + ') {' + - // TODO: use math.error.ArgumentsError here + // TODO: use util.error.ArgumentsError here // TODO: test arguments error ' throw new SyntaxError("Wrong number of arguments in function ' + this.name + ' (" + arguments.length + " provided, ' + this.args.length + ' expected)");' + ' }' + diff --git a/lib/function/arithmetic/abs.js b/lib/function/arithmetic/abs.js index fa1973401..3465db2d2 100644 --- a/lib/function/arithmetic/abs.js +++ b/lib/function/arithmetic/abs.js @@ -23,7 +23,7 @@ module.exports = function (math) { */ math.abs = function abs(x) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('abs', arguments.length, 1); + throw new util.error.ArgumentsError('abs', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/add.js b/lib/function/arithmetic/add.js index 9f543416a..b6fbabd32 100644 --- a/lib/function/arithmetic/add.js +++ b/lib/function/arithmetic/add.js @@ -28,7 +28,7 @@ module.exports = function (math) { */ math.add = function add(x, y) { if (arguments.length != 2) { - throw new math.error.ArgumentsError('add', arguments.length, 2); + throw new util.error.ArgumentsError('add', arguments.length, 2); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/ceil.js b/lib/function/arithmetic/ceil.js index 94a26936b..b37e1c574 100644 --- a/lib/function/arithmetic/ceil.js +++ b/lib/function/arithmetic/ceil.js @@ -22,7 +22,7 @@ module.exports = function (math) { */ math.ceil = function ceil(x) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('ceil', arguments.length, 1); + throw new util.error.ArgumentsError('ceil', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/compare.js b/lib/function/arithmetic/compare.js index 31ee75748..38de2e95e 100644 --- a/lib/function/arithmetic/compare.js +++ b/lib/function/arithmetic/compare.js @@ -25,7 +25,7 @@ module.exports = function (math) { */ math.compare = function compare(x, y) { if (arguments.length != 2) { - throw new math.error.ArgumentsError('compare', arguments.length, 2); + throw new util.error.ArgumentsError('compare', arguments.length, 2); } if (isNumber(x) && isNumber(y)) { diff --git a/lib/function/arithmetic/cube.js b/lib/function/arithmetic/cube.js index 7379cba3a..47ae041ba 100644 --- a/lib/function/arithmetic/cube.js +++ b/lib/function/arithmetic/cube.js @@ -23,7 +23,7 @@ module.exports = function (math) { */ math.cube = function cube(x) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('cube', arguments.length, 1); + throw new util.error.ArgumentsError('cube', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/divide.js b/lib/function/arithmetic/divide.js index 7c04f5e5c..77835a1ff 100644 --- a/lib/function/arithmetic/divide.js +++ b/lib/function/arithmetic/divide.js @@ -25,7 +25,7 @@ module.exports = function(math) { */ math.divide = function divide(x, y) { if (arguments.length != 2) { - throw new math.error.ArgumentsError('divide', arguments.length, 2); + throw new util.error.ArgumentsError('divide', arguments.length, 2); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/edivide.js b/lib/function/arithmetic/edivide.js index 8cebfa5a8..725b93dc4 100644 --- a/lib/function/arithmetic/edivide.js +++ b/lib/function/arithmetic/edivide.js @@ -13,7 +13,7 @@ module.exports = function (math) { */ math.edivide = function edivide(x, y) { if (arguments.length != 2) { - throw new math.error.ArgumentsError('edivide', arguments.length, 2); + throw new util.error.ArgumentsError('edivide', arguments.length, 2); } return collection.deepMap2(x, y, math.divide); diff --git a/lib/function/arithmetic/emultiply.js b/lib/function/arithmetic/emultiply.js index b0e50f522..fdb1f60de 100644 --- a/lib/function/arithmetic/emultiply.js +++ b/lib/function/arithmetic/emultiply.js @@ -1,5 +1,6 @@ module.exports = function (math) { - var collection = require('../../type/collection'); + var util = require('../../util/index'), + collection = require('../../type/collection'); /** * Multiply two values element wise. @@ -13,7 +14,7 @@ module.exports = function (math) { */ math.emultiply = function emultiply(x, y) { if (arguments.length != 2) { - throw new math.error.ArgumentsError('emultiply', arguments.length, 2); + throw new util.error.ArgumentsError('emultiply', arguments.length, 2); } return collection.deepMap2(x, y, math.multiply); diff --git a/lib/function/arithmetic/epow.js b/lib/function/arithmetic/epow.js index 8919dca94..f4cb30083 100644 --- a/lib/function/arithmetic/epow.js +++ b/lib/function/arithmetic/epow.js @@ -1,5 +1,6 @@ module.exports = function (math) { - var collection = require('../../type/collection'); + var util = require('../../util/index'), + collection = require('../../type/collection'); /** * Calculates the power of x to y element wise @@ -13,7 +14,7 @@ module.exports = function (math) { */ math.epow = function epow(x, y) { if (arguments.length != 2) { - throw new math.error.ArgumentsError('epow', arguments.length, 2); + throw new util.error.ArgumentsError('epow', arguments.length, 2); } return collection.deepMap2(x, y, math.pow); diff --git a/lib/function/arithmetic/equal.js b/lib/function/arithmetic/equal.js index 04cd0fc07..6cd6601b6 100644 --- a/lib/function/arithmetic/equal.js +++ b/lib/function/arithmetic/equal.js @@ -28,7 +28,7 @@ module.exports = function (math) { */ math.equal = function equal(x, y) { if (arguments.length != 2) { - throw new math.error.ArgumentsError('equal', arguments.length, 2); + throw new util.error.ArgumentsError('equal', arguments.length, 2); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/exp.js b/lib/function/arithmetic/exp.js index 1a492ec76..49872c56b 100644 --- a/lib/function/arithmetic/exp.js +++ b/lib/function/arithmetic/exp.js @@ -23,7 +23,7 @@ module.exports = function (math) { */ math.exp = function exp (x) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('exp', arguments.length, 1); + throw new util.error.ArgumentsError('exp', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/fix.js b/lib/function/arithmetic/fix.js index 97f630d2a..b72b5e929 100644 --- a/lib/function/arithmetic/fix.js +++ b/lib/function/arithmetic/fix.js @@ -22,7 +22,7 @@ module.exports = function (math) { */ math.fix = function fix(x) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('fix', arguments.length, 1); + throw new util.error.ArgumentsError('fix', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/floor.js b/lib/function/arithmetic/floor.js index 668bcbcd4..8ad823869 100644 --- a/lib/function/arithmetic/floor.js +++ b/lib/function/arithmetic/floor.js @@ -22,7 +22,7 @@ module.exports = function (math) { */ math.floor = function floor(x) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('floor', arguments.length, 1); + throw new util.error.ArgumentsError('floor', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/larger.js b/lib/function/arithmetic/larger.js index 8902bc561..d86750928 100644 --- a/lib/function/arithmetic/larger.js +++ b/lib/function/arithmetic/larger.js @@ -27,7 +27,7 @@ module.exports = function (math) { */ math.larger = function larger(x, y) { if (arguments.length != 2) { - throw new math.error.ArgumentsError('larger', arguments.length, 2); + throw new util.error.ArgumentsError('larger', arguments.length, 2); } if (isNumber(x) && isNumber(y)) { diff --git a/lib/function/arithmetic/largereq.js b/lib/function/arithmetic/largereq.js index b6fae43ca..0abf44be1 100644 --- a/lib/function/arithmetic/largereq.js +++ b/lib/function/arithmetic/largereq.js @@ -27,7 +27,7 @@ module.exports = function (math) { */ math.largereq = function largereq(x, y) { if (arguments.length != 2) { - throw new math.error.ArgumentsError('largereq', arguments.length, 2); + throw new util.error.ArgumentsError('largereq', arguments.length, 2); } if (isNumber(x) && isNumber(y)) { diff --git a/lib/function/arithmetic/log.js b/lib/function/arithmetic/log.js index c80447256..0c8a27215 100644 --- a/lib/function/arithmetic/log.js +++ b/lib/function/arithmetic/log.js @@ -62,7 +62,7 @@ module.exports = function (math) { return math.divide(log(x), log(base)); } else { - throw new math.error.ArgumentsError('log', arguments.length, 1, 2); + throw new util.error.ArgumentsError('log', arguments.length, 1, 2); } }; }; diff --git a/lib/function/arithmetic/log10.js b/lib/function/arithmetic/log10.js index 2672de816..0e56ea189 100644 --- a/lib/function/arithmetic/log10.js +++ b/lib/function/arithmetic/log10.js @@ -22,7 +22,7 @@ module.exports = function (math) { */ math.log10 = function log10(x) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('log10', arguments.length, 1); + throw new util.error.ArgumentsError('log10', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/mod.js b/lib/function/arithmetic/mod.js index 636a13a08..8943ca326 100644 --- a/lib/function/arithmetic/mod.js +++ b/lib/function/arithmetic/mod.js @@ -22,7 +22,7 @@ module.exports = function (math) { */ math.mod = function mod(x, y) { if (arguments.length != 2) { - throw new math.error.ArgumentsError('mod', arguments.length, 2); + throw new util.error.ArgumentsError('mod', arguments.length, 2); } // see http://functions.wolfram.com/IntegerFunctions/Mod/ diff --git a/lib/function/arithmetic/multiply.js b/lib/function/arithmetic/multiply.js index 363aa86ac..a256c2877 100644 --- a/lib/function/arithmetic/multiply.js +++ b/lib/function/arithmetic/multiply.js @@ -28,7 +28,7 @@ module.exports = function(math) { var res; if (arguments.length != 2) { - throw new math.error.ArgumentsError('multiply', arguments.length, 2); + throw new util.error.ArgumentsError('multiply', arguments.length, 2); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/pow.js b/lib/function/arithmetic/pow.js index 63b4157e6..17d7b17d5 100644 --- a/lib/function/arithmetic/pow.js +++ b/lib/function/arithmetic/pow.js @@ -25,7 +25,7 @@ module.exports = function (math) { */ math.pow = function pow(x, y) { if (arguments.length != 2) { - throw new math.error.ArgumentsError('pow', arguments.length, 2); + throw new util.error.ArgumentsError('pow', arguments.length, 2); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/round.js b/lib/function/arithmetic/round.js index 19953c655..ff88f4e2a 100644 --- a/lib/function/arithmetic/round.js +++ b/lib/function/arithmetic/round.js @@ -26,7 +26,7 @@ module.exports = function (math) { */ math.round = function round(x, n) { if (arguments.length != 1 && arguments.length != 2) { - throw new math.error.ArgumentsError('round', arguments.length, 1, 2); + throw new util.error.ArgumentsError('round', arguments.length, 1, 2); } if (n == undefined) { diff --git a/lib/function/arithmetic/sign.js b/lib/function/arithmetic/sign.js index 919009353..b9ac54961 100644 --- a/lib/function/arithmetic/sign.js +++ b/lib/function/arithmetic/sign.js @@ -24,7 +24,7 @@ module.exports = function (math) { */ math.sign = function sign(x) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('sign', arguments.length, 1); + throw new util.error.ArgumentsError('sign', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/smaller.js b/lib/function/arithmetic/smaller.js index 7a0570cd9..a2bac4a94 100644 --- a/lib/function/arithmetic/smaller.js +++ b/lib/function/arithmetic/smaller.js @@ -27,7 +27,7 @@ module.exports = function (math) { */ math.smaller = function smaller(x, y) { if (arguments.length != 2) { - throw new math.error.ArgumentsError('smaller', arguments.length, 2); + throw new util.error.ArgumentsError('smaller', arguments.length, 2); } if (isNumber(x) && isNumber(y)) { diff --git a/lib/function/arithmetic/smallereq.js b/lib/function/arithmetic/smallereq.js index 451d37a94..7aad7277f 100644 --- a/lib/function/arithmetic/smallereq.js +++ b/lib/function/arithmetic/smallereq.js @@ -27,7 +27,7 @@ module.exports = function (math) { */ math.smallereq = function smallereq(x, y) { if (arguments.length != 2) { - throw new math.error.ArgumentsError('smallereq', arguments.length, 2); + throw new util.error.ArgumentsError('smallereq', arguments.length, 2); } if (isNumber(x) && isNumber(y)) { diff --git a/lib/function/arithmetic/sqrt.js b/lib/function/arithmetic/sqrt.js index 06d20af4c..8c0a51d45 100644 --- a/lib/function/arithmetic/sqrt.js +++ b/lib/function/arithmetic/sqrt.js @@ -22,7 +22,7 @@ module.exports = function (math) { */ math.sqrt = function sqrt (x) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('sqrt', arguments.length, 1); + throw new util.error.ArgumentsError('sqrt', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/square.js b/lib/function/arithmetic/square.js index 487101034..c6d844098 100644 --- a/lib/function/arithmetic/square.js +++ b/lib/function/arithmetic/square.js @@ -23,7 +23,7 @@ module.exports = function (math) { */ math.square = function square(x) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('square', arguments.length, 1); + throw new util.error.ArgumentsError('square', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/subtract.js b/lib/function/arithmetic/subtract.js index 90c9094c3..cb8a170e2 100644 --- a/lib/function/arithmetic/subtract.js +++ b/lib/function/arithmetic/subtract.js @@ -27,7 +27,7 @@ module.exports = function (math) { */ math.subtract = function subtract(x, y) { if (arguments.length != 2) { - throw new math.error.ArgumentsError('subtract', arguments.length, 2); + throw new util.error.ArgumentsError('subtract', arguments.length, 2); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/unary.js b/lib/function/arithmetic/unary.js index fc5144755..42786e321 100644 --- a/lib/function/arithmetic/unary.js +++ b/lib/function/arithmetic/unary.js @@ -25,7 +25,7 @@ module.exports = function (math) { */ math.unary = function unary(x) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('unary', arguments.length, 1); + throw new util.error.ArgumentsError('unary', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/unequal.js b/lib/function/arithmetic/unequal.js index d29ccd71d..32012f5bf 100644 --- a/lib/function/arithmetic/unequal.js +++ b/lib/function/arithmetic/unequal.js @@ -22,7 +22,7 @@ module.exports = function (math) { */ math.unequal = function unequal(x, y) { if (arguments.length != 2) { - throw new math.error.ArgumentsError('unequal', arguments.length, 2); + throw new util.error.ArgumentsError('unequal', arguments.length, 2); } if (isNumber(x)) { diff --git a/lib/function/complex/arg.js b/lib/function/complex/arg.js index 53518acd6..96a73b6f8 100644 --- a/lib/function/complex/arg.js +++ b/lib/function/complex/arg.js @@ -23,7 +23,7 @@ module.exports = function (math) { */ math.arg = function arg(x) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('arg', arguments.length, 1); + throw new util.error.ArgumentsError('arg', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/complex/conj.js b/lib/function/complex/conj.js index fd6125ede..f9b5a1e3f 100644 --- a/lib/function/complex/conj.js +++ b/lib/function/complex/conj.js @@ -24,7 +24,7 @@ module.exports = function (math) { */ math.conj = function conj(x) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('conj', arguments.length, 1); + throw new util.error.ArgumentsError('conj', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/complex/im.js b/lib/function/complex/im.js index 39c83f9ab..6cc420119 100644 --- a/lib/function/complex/im.js +++ b/lib/function/complex/im.js @@ -22,7 +22,7 @@ module.exports = function (math) { */ math.im = function im(x) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('im', arguments.length, 1); + throw new util.error.ArgumentsError('im', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/complex/re.js b/lib/function/complex/re.js index 461da7d07..0ddca53d4 100644 --- a/lib/function/complex/re.js +++ b/lib/function/complex/re.js @@ -23,7 +23,7 @@ module.exports = function (math) { */ math.re = function re(x) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('re', arguments.length, 1); + throw new util.error.ArgumentsError('re', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/construction/bignumber.js b/lib/function/construction/bignumber.js index c413f2c37..359376024 100644 --- a/lib/function/construction/bignumber.js +++ b/lib/function/construction/bignumber.js @@ -20,7 +20,7 @@ module.exports = function (math) { */ math.bignumber = function bignumber(value) { if (arguments.length > 1) { - throw new math.error.ArgumentsError('bignumber', arguments.length, 0, 1); + throw new util.error.ArgumentsError('bignumber', arguments.length, 0, 1); } if ((value instanceof BigNumber) || isNumber(value) || isString(value)) { diff --git a/lib/function/construction/boolean.js b/lib/function/construction/boolean.js index 3bdab0f52..fdb35ba01 100644 --- a/lib/function/construction/boolean.js +++ b/lib/function/construction/boolean.js @@ -19,7 +19,7 @@ module.exports = function (math) { */ math['boolean'] = function bool (value) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('boolean', arguments.length, 0, 1); + throw new util.error.ArgumentsError('boolean', arguments.length, 0, 1); } if (value === 'true' || value === true) { diff --git a/lib/function/construction/complex.js b/lib/function/construction/complex.js index d1542be13..9bccc9990 100644 --- a/lib/function/construction/complex.js +++ b/lib/function/construction/complex.js @@ -112,7 +112,7 @@ module.exports = function (math) { } default: - throw new math.error.ArgumentsError('complex', arguments.length, 0, 2); + throw new util.error.ArgumentsError('complex', arguments.length, 0, 2); } }; }; diff --git a/lib/function/construction/matrix.js b/lib/function/construction/matrix.js index b4c4591cc..98783b862 100644 --- a/lib/function/construction/matrix.js +++ b/lib/function/construction/matrix.js @@ -1,5 +1,6 @@ module.exports = function (math) { - var Matrix = require('../../type/Matrix'); + var util = require('../../util/index'), + Matrix = require('../../type/Matrix'); /** * Create a matrix. The function creates a new math.type.Matrix object. @@ -20,7 +21,7 @@ module.exports = function (math) { */ math.matrix = function matrix(data) { if (arguments.length > 1) { - throw new math.error.ArgumentsError('matrix', arguments.length, 0, 1); + throw new util.error.ArgumentsError('matrix', arguments.length, 0, 1); } return new Matrix(data); diff --git a/lib/function/construction/number.js b/lib/function/construction/number.js index 8935f2862..d9cfb3aaf 100644 --- a/lib/function/construction/number.js +++ b/lib/function/construction/number.js @@ -51,7 +51,7 @@ module.exports = function (math) { throw new math.error.UnsupportedTypeError('number', value); default: - throw new math.error.ArgumentsError('number', arguments.length, 0, 1); + throw new util.error.ArgumentsError('number', arguments.length, 0, 1); } }; }; diff --git a/lib/function/construction/string.js b/lib/function/construction/string.js index b3a96ffb2..d0bfb133b 100644 --- a/lib/function/construction/string.js +++ b/lib/function/construction/string.js @@ -34,7 +34,7 @@ module.exports = function (math) { return value.toString(); default: - throw new math.error.ArgumentsError('string', arguments.length, 0, 1); + throw new util.error.ArgumentsError('string', arguments.length, 0, 1); } }; }; diff --git a/lib/function/construction/unit.js b/lib/function/construction/unit.js index a4e2e3cb6..448c1c83c 100644 --- a/lib/function/construction/unit.js +++ b/lib/function/construction/unit.js @@ -67,7 +67,7 @@ module.exports = function (math) { } default: - throw new math.error.ArgumentsError('unit', arguments.length, 1, 2); + throw new util.error.ArgumentsError('unit', arguments.length, 1, 2); } }; }; diff --git a/lib/function/expression/compile.js b/lib/function/expression/compile.js index 8e7804985..fd1525edb 100644 --- a/lib/function/expression/compile.js +++ b/lib/function/expression/compile.js @@ -37,7 +37,7 @@ module.exports = function (math, config) { */ math.compile = function compile (expr) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('compile', arguments.length, 1); + throw new util.error.ArgumentsError('compile', arguments.length, 1); } if (isString(expr)) { diff --git a/lib/function/expression/eval.js b/lib/function/expression/eval.js index 3c3b363a6..ca39a7955 100644 --- a/lib/function/expression/eval.js +++ b/lib/function/expression/eval.js @@ -34,7 +34,7 @@ module.exports = function (math) { */ math.eval = function _eval (expr, scope) { if (arguments.length != 1 && arguments.length != 2) { - throw new math.error.ArgumentsError('eval', arguments.length, 1, 2); + throw new util.error.ArgumentsError('eval', arguments.length, 1, 2); } // instantiate a scope diff --git a/lib/function/matrix/det.js b/lib/function/matrix/det.js index 24789392f..6438c88b0 100644 --- a/lib/function/matrix/det.js +++ b/lib/function/matrix/det.js @@ -17,7 +17,7 @@ module.exports = function (math) { */ math.det = function det (x) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('det', arguments.length, 1); + throw new util.error.ArgumentsError('det', arguments.length, 1); } var size; diff --git a/lib/function/matrix/diag.js b/lib/function/matrix/diag.js index c0e07d252..18ea2bcca 100644 --- a/lib/function/matrix/diag.js +++ b/lib/function/matrix/diag.js @@ -27,7 +27,7 @@ module.exports = function (math) { var data, vector, i, iMax; if (arguments.length != 1 && arguments.length != 2) { - throw new math.error.ArgumentsError('diag', arguments.length, 1, 2); + throw new util.error.ArgumentsError('diag', arguments.length, 1, 2); } if (k) { diff --git a/lib/function/matrix/eye.js b/lib/function/matrix/eye.js index 58e53b4ac..6f7aa736b 100644 --- a/lib/function/matrix/eye.js +++ b/lib/function/matrix/eye.js @@ -37,7 +37,7 @@ module.exports = function (math, config) { } else if (args.length > 2) { // error in case of an n-dimensional size - throw new math.error.ArgumentsError('eye', args.length, 0, 2); + throw new util.error.ArgumentsError('eye', args.length, 0, 2); } var rows = args[0], diff --git a/lib/function/matrix/inv.js b/lib/function/matrix/inv.js index a1f097e9e..1dfa87289 100644 --- a/lib/function/matrix/inv.js +++ b/lib/function/matrix/inv.js @@ -1,5 +1,6 @@ module.exports = function (math) { - var string = require('../../util/string'), + var util = require('../../util/index'), + string = util.string, Matrix = require('../../type/Matrix'), collection = require('../../type/collection'); @@ -16,7 +17,7 @@ module.exports = function (math) { */ math.inv = function inv (x) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('inv', arguments.length, 1); + throw new util.error.ArgumentsError('inv', arguments.length, 1); } var size = math.size(x).valueOf(); switch (size.length) { diff --git a/lib/function/matrix/range.js b/lib/function/matrix/range.js index 35b7cfade..9d3cc727b 100644 --- a/lib/function/matrix/range.js +++ b/lib/function/matrix/range.js @@ -92,7 +92,7 @@ module.exports = function (math, config) { throw new TypeError('Parameter includeEnd must be a boolean'); default: - throw new math.error.ArgumentsError('range', arguments.length, 2, 4); + throw new util.error.ArgumentsError('range', arguments.length, 2, 4); } // verify type of parameters diff --git a/lib/function/matrix/resize.js b/lib/function/matrix/resize.js index 93bd18461..c4a55ce9a 100644 --- a/lib/function/matrix/resize.js +++ b/lib/function/matrix/resize.js @@ -27,7 +27,7 @@ module.exports = function (math, config) { */ math.resize = function resize (x, size, defaultValue) { if (arguments.length != 2 && arguments.length != 3) { - throw new math.error.ArgumentsError('resize', arguments.length, 2, 3); + throw new util.error.ArgumentsError('resize', arguments.length, 2, 3); } var asMatrix = (x instanceof Matrix) ? true : isArray(x) ? false : (config.matrix !== 'array'); diff --git a/lib/function/matrix/size.js b/lib/function/matrix/size.js index 9faeee85b..908d87e2e 100644 --- a/lib/function/matrix/size.js +++ b/lib/function/matrix/size.js @@ -23,7 +23,7 @@ module.exports = function (math, config) { */ math.size = function size (x) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('size', arguments.length, 1); + throw new util.error.ArgumentsError('size', arguments.length, 1); } var asArray = (config.matrix === 'array'); diff --git a/lib/function/matrix/squeeze.js b/lib/function/matrix/squeeze.js index 6b092f447..a7c54ce69 100644 --- a/lib/function/matrix/squeeze.js +++ b/lib/function/matrix/squeeze.js @@ -17,7 +17,7 @@ module.exports = function (math) { */ math.squeeze = function squeeze (x) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('squeeze', arguments.length, 1); + throw new util.error.ArgumentsError('squeeze', arguments.length, 1); } if (isArray(x)) { diff --git a/lib/function/matrix/subset.js b/lib/function/matrix/subset.js index 952560df2..38599a32d 100644 --- a/lib/function/matrix/subset.js +++ b/lib/function/matrix/subset.js @@ -40,7 +40,7 @@ module.exports = function (math) { return _setSubset(arguments[0], arguments[1], arguments[2], arguments[3]); default: // wrong number of arguments - throw new math.error.ArgumentsError('subset', arguments.length, 2, 4); + throw new util.error.ArgumentsError('subset', arguments.length, 2, 4); } }; diff --git a/lib/function/matrix/transpose.js b/lib/function/matrix/transpose.js index 4183201bd..fda40d4e9 100644 --- a/lib/function/matrix/transpose.js +++ b/lib/function/matrix/transpose.js @@ -17,7 +17,7 @@ module.exports = function (math) { */ math.transpose = function transpose (x) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('transpose', arguments.length, 1); + throw new util.error.ArgumentsError('transpose', arguments.length, 1); } var size = math.size(x).valueOf(); diff --git a/lib/function/probability/combinations.js b/lib/function/probability/combinations.js index 237e9caec..9a24c4f9c 100644 --- a/lib/function/probability/combinations.js +++ b/lib/function/probability/combinations.js @@ -24,7 +24,7 @@ module.exports = function (math) { var arity = arguments.length; if (arity != 2) { - throw new math.error.ArgumentsError('combinations', arguments.length, 2); + throw new util.error.ArgumentsError('combinations', arguments.length, 2); } if (isNumber(n)) { diff --git a/lib/function/probability/factorial.js b/lib/function/probability/factorial.js index 221ac272d..5759c9f02 100644 --- a/lib/function/probability/factorial.js +++ b/lib/function/probability/factorial.js @@ -25,7 +25,7 @@ module.exports = function (math) { var value, res; if (arguments.length != 1) { - throw new math.error.ArgumentsError('factorial', arguments.length, 1); + throw new util.error.ArgumentsError('factorial', arguments.length, 1); } if (isNumber(n)) { diff --git a/lib/function/probability/permutations.js b/lib/function/probability/permutations.js index c19ab92e5..89d7ab4dd 100644 --- a/lib/function/probability/permutations.js +++ b/lib/function/probability/permutations.js @@ -24,7 +24,7 @@ module.exports = function (math) { var arity = arguments.length; if (arity > 2) { - throw new math.error.ArgumentsError('permutations', arguments.length, 2); + throw new util.error.ArgumentsError('permutations', arguments.length, 2); } if (isNumber(n)) { diff --git a/lib/function/probability/random.js b/lib/function/probability/random.js index 51ae62f85..48c40a1e6 100644 --- a/lib/function/probability/random.js +++ b/lib/function/probability/random.js @@ -64,7 +64,7 @@ module.exports = function (math, config) { random: function(arg1, arg2, arg3) { var size, min, max; if (arguments.length > 3) { - throw new math.error.ArgumentsError('random', arguments.length, 0, 3); + throw new util.error.ArgumentsError('random', arguments.length, 0, 3); // `random(max)` or `random(size)` } else if (arguments.length === 1) { @@ -99,7 +99,7 @@ module.exports = function (math, config) { randomInt: function(arg1, arg2, arg3) { var size, min, max; if (arguments.length > 3 || arguments.length < 1) - throw new math.error.ArgumentsError('randomInt', arguments.length, 1, 3); + throw new util.error.ArgumentsError('randomInt', arguments.length, 1, 3); // `randomInt(max)` else if (arguments.length === 1) max = arg1; @@ -128,7 +128,7 @@ module.exports = function (math, config) { pickRandom: function(possibles) { if (arguments.length !== 1) { - throw new math.error.ArgumentsError('pickRandom', arguments.length, 1); + throw new util.error.ArgumentsError('pickRandom', arguments.length, 1); } if (!Array.isArray(possibles)) { throw new math.error.UnsupportedTypeError('pickRandom', possibles); diff --git a/lib/function/trigonometry/acos.js b/lib/function/trigonometry/acos.js index 3d94211a1..bcb7a8b40 100644 --- a/lib/function/trigonometry/acos.js +++ b/lib/function/trigonometry/acos.js @@ -24,7 +24,7 @@ module.exports = function (math) { */ math.acos = function acos(x) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('acos', arguments.length, 1); + throw new util.error.ArgumentsError('acos', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/trigonometry/asin.js b/lib/function/trigonometry/asin.js index 419e4bfc4..00ea94459 100644 --- a/lib/function/trigonometry/asin.js +++ b/lib/function/trigonometry/asin.js @@ -24,7 +24,7 @@ module.exports = function (math) { */ math.asin = function asin(x) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('asin', arguments.length, 1); + throw new util.error.ArgumentsError('asin', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/trigonometry/atan.js b/lib/function/trigonometry/atan.js index 12602304a..2787de909 100644 --- a/lib/function/trigonometry/atan.js +++ b/lib/function/trigonometry/atan.js @@ -24,7 +24,7 @@ module.exports = function (math) { */ math.atan = function atan(x) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('atan', arguments.length, 1); + throw new util.error.ArgumentsError('atan', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/trigonometry/atan2.js b/lib/function/trigonometry/atan2.js index e1daf18c8..f9770153f 100644 --- a/lib/function/trigonometry/atan2.js +++ b/lib/function/trigonometry/atan2.js @@ -25,7 +25,7 @@ module.exports = function (math) { */ math.atan2 = function atan2(y, x) { if (arguments.length != 2) { - throw new math.error.ArgumentsError('atan2', arguments.length, 2); + throw new util.error.ArgumentsError('atan2', arguments.length, 2); } if (isNumber(y)) { diff --git a/lib/function/trigonometry/cos.js b/lib/function/trigonometry/cos.js index 21b941731..9d90861b8 100644 --- a/lib/function/trigonometry/cos.js +++ b/lib/function/trigonometry/cos.js @@ -26,7 +26,7 @@ module.exports = function (math) { */ math.cos = function cos(x) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('cos', arguments.length, 1); + throw new util.error.ArgumentsError('cos', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/trigonometry/cot.js b/lib/function/trigonometry/cot.js index 53fd01ec4..fe879aa8c 100644 --- a/lib/function/trigonometry/cot.js +++ b/lib/function/trigonometry/cot.js @@ -24,7 +24,7 @@ module.exports = function (math) { */ math.cot = function cot(x) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('cot', arguments.length, 1); + throw new util.error.ArgumentsError('cot', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/trigonometry/csc.js b/lib/function/trigonometry/csc.js index b8c2c787c..0175eeeda 100644 --- a/lib/function/trigonometry/csc.js +++ b/lib/function/trigonometry/csc.js @@ -24,7 +24,7 @@ module.exports = function (math) { */ math.csc = function csc(x) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('csc', arguments.length, 1); + throw new util.error.ArgumentsError('csc', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/trigonometry/sec.js b/lib/function/trigonometry/sec.js index 2aa362b20..df5e66548 100644 --- a/lib/function/trigonometry/sec.js +++ b/lib/function/trigonometry/sec.js @@ -24,7 +24,7 @@ module.exports = function (math) { */ math.sec = function sec(x) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('sec', arguments.length, 1); + throw new util.error.ArgumentsError('sec', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/trigonometry/sin.js b/lib/function/trigonometry/sin.js index 12856cdb1..0ba4cfce3 100644 --- a/lib/function/trigonometry/sin.js +++ b/lib/function/trigonometry/sin.js @@ -26,7 +26,7 @@ module.exports = function (math) { */ math.sin = function sin(x) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('sin', arguments.length, 1); + throw new util.error.ArgumentsError('sin', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/trigonometry/tan.js b/lib/function/trigonometry/tan.js index 54f6dfc38..aee5c1e2b 100644 --- a/lib/function/trigonometry/tan.js +++ b/lib/function/trigonometry/tan.js @@ -26,7 +26,7 @@ module.exports = function (math) { */ math.tan = function tan(x) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('tan', arguments.length, 1); + throw new util.error.ArgumentsError('tan', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/units/to.js b/lib/function/units/to.js index 2260ec826..153ebcd02 100644 --- a/lib/function/units/to.js +++ b/lib/function/units/to.js @@ -22,7 +22,7 @@ module.exports = function (math) { */ math.to = function to(x, unit) { if (arguments.length != 2) { - throw new math.error.ArgumentsError('to', arguments.length, 2); + throw new util.error.ArgumentsError('to', arguments.length, 2); } if (isUnit(x)) { diff --git a/lib/function/utils/clone.js b/lib/function/utils/clone.js index 95c60753f..3616b457c 100644 --- a/lib/function/utils/clone.js +++ b/lib/function/utils/clone.js @@ -1,5 +1,6 @@ module.exports = function (math) { - var object = require('../../util/object'); + var util = require('../../util/index'), + object = util.object; /** * Clone an object @@ -11,7 +12,7 @@ module.exports = function (math) { */ math.clone = function clone (x) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('clone', arguments.length, 1); + throw new util.error.ArgumentsError('clone', arguments.length, 1); } return object.clone(x); diff --git a/lib/function/utils/forEach.js b/lib/function/utils/forEach.js index 9e9f0162e..e298f4f76 100644 --- a/lib/function/utils/forEach.js +++ b/lib/function/utils/forEach.js @@ -10,7 +10,7 @@ module.exports = function (math) { */ math.forEach = function (x, callback) { if (arguments.length != 2) { - throw new math.error.ArgumentsError('forEach', arguments.length, 2); + throw new util.error.ArgumentsError('forEach', arguments.length, 2); } if (Array.isArray(x)) { diff --git a/lib/function/utils/format.js b/lib/function/utils/format.js index 53a4c29f1..51c8a8c15 100644 --- a/lib/function/utils/format.js +++ b/lib/function/utils/format.js @@ -1,5 +1,6 @@ module.exports = function (math) { - var string = require('../../util/string'); + var util = require('../../util/index'), + string = util.string; /** * Format a value of any type into a string. @@ -68,7 +69,7 @@ module.exports = function (math) { math.format = function format (value, options) { var num = arguments.length; if (num !== 1 && num !== 2) { - throw new math.error.ArgumentsError('format', num, 1, 2); + throw new util.error.ArgumentsError('format', num, 1, 2); } return string.format(value, options); diff --git a/lib/function/utils/ifElse.js b/lib/function/utils/ifElse.js index 3d768cf5f..55fd14166 100644 --- a/lib/function/utils/ifElse.js +++ b/lib/function/utils/ifElse.js @@ -30,7 +30,7 @@ module.exports = function (math) { */ math.ifElse = function ifElse(condition, trueExpr, falseExpr) { if (arguments.length != 3) { - throw new math.error.ArgumentsError('ifElse', arguments.length, 3); + throw new util.error.ArgumentsError('ifElse', arguments.length, 3); } if (isNumber(condition) || isBoolean(condition)) { diff --git a/lib/function/utils/import.js b/lib/function/utils/import.js index 82c72fb88..2e1b6faf8 100644 --- a/lib/function/utils/import.js +++ b/lib/function/utils/import.js @@ -29,7 +29,7 @@ module.exports = function (math) { math['import'] = function math_import(object, options) { var num = arguments.length; if (num != 1 && num != 2) { - throw new math.error.ArgumentsError('import', num, 1, 2); + throw new util.error.ArgumentsError('import', num, 1, 2); } var name; diff --git a/lib/function/utils/map.js b/lib/function/utils/map.js index 9c5a19cb6..3f1bcb0f6 100644 --- a/lib/function/utils/map.js +++ b/lib/function/utils/map.js @@ -12,7 +12,7 @@ module.exports = function (math) { */ math.map = function (x, callback) { if (arguments.length != 2) { - throw new math.error.ArgumentsError('map', arguments.length, 2); + throw new util.error.ArgumentsError('map', arguments.length, 2); } if (Array.isArray(x)) { diff --git a/lib/function/utils/print.js b/lib/function/utils/print.js index 565c4672a..464f05e1c 100644 --- a/lib/function/utils/print.js +++ b/lib/function/utils/print.js @@ -1,7 +1,7 @@ module.exports = function (math) { - var string = require('../../util/string'), + var util = require('../../util/index'), - isString = string.isString; + isString = util.string.isString; /** * Interpolate values into a string template. @@ -33,7 +33,7 @@ module.exports = function (math) { math.print = function print (template, values, precision) { var num = arguments.length; if (num != 2 && num != 3) { - throw new math.error.ArgumentsError('print', num, 2, 3); + throw new util.error.ArgumentsError('print', num, 2, 3); } if (!isString(template)) { diff --git a/lib/function/utils/typeof.js b/lib/function/utils/typeof.js index 48c6b1fe6..1d9948652 100644 --- a/lib/function/utils/typeof.js +++ b/lib/function/utils/typeof.js @@ -20,7 +20,7 @@ module.exports = function (math) { */ math['typeof'] = function _typeof (x) { if (arguments.length != 1) { - throw new math.error.ArgumentsError('typeof', arguments.length, 1); + throw new util.error.ArgumentsError('typeof', arguments.length, 1); } // JavaScript types diff --git a/lib/type/error.js b/lib/type/error.js index 64fa70500..94d0ef0ed 100644 --- a/lib/type/error.js +++ b/lib/type/error.js @@ -1,8 +1,6 @@ module.exports = function (math) { var types = require('./../util/types'); - // TODO: make error.js independent of the math namespace (currently uses math.typeof) - // export the error constructors to namespace math.error.* var error = {}; math.error = error; @@ -16,6 +14,7 @@ module.exports = function (math) { * @extends TypeError */ // TODO: rename UnsupportedTypeError to TypeError? + // TODO: move UnsupportedTypeError to lib/util/ error.UnsupportedTypeError = function UnsupportedTypeError(name, value1, value_n) { if (!(this instanceof UnsupportedTypeError)) { throw new SyntaxError('Constructor must be called with the new operator'); @@ -51,31 +50,4 @@ module.exports = function (math) { error.UnsupportedTypeError.prototype.constructor = TypeError; error.UnsupportedTypeError.prototype.name = 'UnsupportedTypeError'; - /** - * Create a syntax error with the message: - * 'Wrong number of arguments in function ( provided, - expected)' - * @param {String} name Function name - * @param {Number} count Actual argument count - * @param {Number} min Minimum required argument count - * @param {Number} [max] Maximum required argument count - * @extends Error - */ - error.ArgumentsError = function ArgumentsError(name, count, min, max) { - if (!(this instanceof ArgumentsError)) { - throw new SyntaxError('Constructor must be called with the new operator'); - } - - this.message = 'Wrong number of arguments in function ' + name + - ' (' + count + ' provided, ' + - min + ((max != undefined) ? ('-' + max) : '') + ' expected)'; - - this.stack = (new Error()).stack; - }; - - error.ArgumentsError.prototype = new Error(); - error.ArgumentsError.prototype.constructor = Error; - error.ArgumentsError.prototype.name = 'ArgumentsError'; - - // TODO: implement a InvalidValueError? - }; \ No newline at end of file diff --git a/lib/util/error.js b/lib/util/error.js index 96032b030..ab3a5d186 100644 --- a/lib/util/error.js +++ b/lib/util/error.js @@ -1,3 +1,31 @@ + +/** + * Create a syntax error with the message: + * 'Wrong number of arguments in function ( provided, - expected)' + * @param {String} name Function name + * @param {Number} count Actual argument count + * @param {Number} min Minimum required argument count + * @param {Number} [max] Maximum required argument count + * @extends Error + */ +function ArgumentsError(name, count, min, max) { + if (!(this instanceof ArgumentsError)) { + throw new SyntaxError('Constructor must be called with the new operator'); + } + + this.message = 'Wrong number of arguments in function ' + name + + ' (' + count + ' provided, ' + + min + ((max != undefined) ? ('-' + max) : '') + ' expected)'; + + this.stack = (new Error()).stack; +} + +ArgumentsError.prototype = new Error(); +ArgumentsError.prototype.constructor = Error; +ArgumentsError.prototype.name = 'ArgumentsError'; + +exports.ArgumentsError = ArgumentsError; + /** * Create a range error with the message: * 'Dimension mismatch ( != )' @@ -74,3 +102,6 @@ IndexError.prototype.constructor = RangeError; IndexError.prototype.name = 'IndexError'; exports.IndexError = IndexError; + + +// TODO: implement a InvalidValueError? diff --git a/test/function/arithmetic/abs.test.js b/test/function/arithmetic/abs.test.js index b22c01010..a63f82baa 100644 --- a/test/function/arithmetic/abs.test.js +++ b/test/function/arithmetic/abs.test.js @@ -1,5 +1,6 @@ // test abs var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(); describe('abs', function () { @@ -43,8 +44,8 @@ describe('abs', function () { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {math.abs()}, math.error.ArgumentsError); - assert.throws(function () {math.abs(1, 2)}, math.error.ArgumentsError); + assert.throws(function () {math.abs()}, error.ArgumentsError); + assert.throws(function () {math.abs(1, 2)}, error.ArgumentsError); }); it('should throw an error with a string', function () { diff --git a/test/function/arithmetic/add.test.js b/test/function/arithmetic/add.test.js index a68fb3ae2..63c45d6e0 100644 --- a/test/function/arithmetic/add.test.js +++ b/test/function/arithmetic/add.test.js @@ -1,6 +1,7 @@ // test add var assert = require('assert'), approx = require('../../../tools/approx'), + error = require('../../../lib/util/error'), math = require('../../../index')(), bignumber = math.bignumber, add = math.add; @@ -124,8 +125,8 @@ describe('add', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {add(1)}, math.error.ArgumentsError); - assert.throws(function () {add(1, 2, 3)}, math.error.ArgumentsError); + assert.throws(function () {add(1)}, error.ArgumentsError); + assert.throws(function () {add(1, 2, 3)}, error.ArgumentsError); }); }); diff --git a/test/function/arithmetic/ceil.test.js b/test/function/arithmetic/ceil.test.js index a62eef0ee..50d9f1ebf 100644 --- a/test/function/arithmetic/ceil.test.js +++ b/test/function/arithmetic/ceil.test.js @@ -1,6 +1,7 @@ // test ceil var assert = require('assert'), approx = require('../../../tools/approx'), + error = require('../../../lib/util/error'), math = require('../../../index')(), bignumber = math.bignumber, complex = math.complex, @@ -65,8 +66,8 @@ describe('ceil', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {ceil()}, math.error.ArgumentsError); - assert.throws(function () {ceil(1, 2)}, math.error.ArgumentsError); + assert.throws(function () {ceil()}, error.ArgumentsError); + assert.throws(function () {ceil(1, 2)}, error.ArgumentsError); }); }); diff --git a/test/function/arithmetic/compare.test.js b/test/function/arithmetic/compare.test.js index e79c6da0b..7ecea3c07 100644 --- a/test/function/arithmetic/compare.test.js +++ b/test/function/arithmetic/compare.test.js @@ -1,6 +1,7 @@ // test compare var assert = require('assert'), math = require('../../../index')(), + error = require('../../../lib/util/error'), bignumber = math.bignumber, complex = math.complex, matrix = math.matrix, @@ -103,8 +104,8 @@ describe('compare', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {compare(1)}, math.error.ArgumentsError); - assert.throws(function () {compare(1, 2, 3)}, math.error.ArgumentsError); + assert.throws(function () {compare(1)}, error.ArgumentsError); + assert.throws(function () {compare(1, 2, 3)}, error.ArgumentsError); }); }); diff --git a/test/function/arithmetic/cube.test.js b/test/function/arithmetic/cube.test.js index 51e3868df..49daad52e 100644 --- a/test/function/arithmetic/cube.test.js +++ b/test/function/arithmetic/cube.test.js @@ -1,6 +1,7 @@ // test cube var assert = require('assert'), math = require('../../../index')(), + error = require('../../../lib/util/error'), unit = math.unit, bignumber = math.bignumber, matrix = math.matrix, @@ -40,8 +41,8 @@ describe('cube', function() { }); it('should throw an error if there\'s wrong number of args', function() { - assert.throws(function () {cube()}, math.error.ArgumentsError); - assert.throws(function () {cube(1, 2)}, math.error.ArgumentsError); + assert.throws(function () {cube()}, error.ArgumentsError); + assert.throws(function () {cube(1, 2)}, error.ArgumentsError); }); it('should cube each element in a matrix, array or range', function() { diff --git a/test/function/arithmetic/divide.test.js b/test/function/arithmetic/divide.test.js index 156d6050f..94c97aaba 100644 --- a/test/function/arithmetic/divide.test.js +++ b/test/function/arithmetic/divide.test.js @@ -1,6 +1,7 @@ // test divide var assert = require('assert'), math = require('../../../index')(), + error = require('../../../lib/util/error'), approx = require('../../../tools/approx'), divide = math.divide, bignumber = math.bignumber, diff --git a/test/function/arithmetic/edivide.test.js b/test/function/arithmetic/edivide.test.js index af7153a1a..f2fb4e5a6 100644 --- a/test/function/arithmetic/edivide.test.js +++ b/test/function/arithmetic/edivide.test.js @@ -1,6 +1,7 @@ // test edivide (element-wise divide) -var assert = require('assert'); -math = require('../../../index')(), +var assert = require('assert'), + math = require('../../../index')(), + error = require('../../../lib/util/error'), approx = require('../../../tools/approx'), edivide = math.edivide, complex = math.complex; diff --git a/test/function/arithmetic/emultiply.test.js b/test/function/arithmetic/emultiply.test.js index 02bcca148..f2a2e1a53 100644 --- a/test/function/arithmetic/emultiply.test.js +++ b/test/function/arithmetic/emultiply.test.js @@ -2,6 +2,7 @@ var assert = require('assert'), math = require('../../../index')(), approx = require('../../../tools/approx'), + error = require('../../../lib/util/error'), emultiply = math.emultiply, divide = math.divide, matrix = math.matrix, @@ -85,8 +86,8 @@ describe('emultiply', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {emultiply(1)}, math.error.ArgumentsError); - assert.throws(function () {emultiply(1, 2, 3)}, math.error.ArgumentsError); + assert.throws(function () {emultiply(1)}, error.ArgumentsError); + assert.throws(function () {emultiply(1, 2, 3)}, error.ArgumentsError); }); }); diff --git a/test/function/arithmetic/epow.test.js b/test/function/arithmetic/epow.test.js index 2aee4be70..5d640f722 100644 --- a/test/function/arithmetic/epow.test.js +++ b/test/function/arithmetic/epow.test.js @@ -1,6 +1,7 @@ // test exp var assert = require('assert'), approx = require('../../../tools/approx'), + error = require('../../../lib/util/error'), math = require('../../../index')(), complex = math.complex, matrix = math.matrix, @@ -38,8 +39,8 @@ describe('epow', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {epow(1)}, math.error.ArgumentsError); - assert.throws(function () {epow(1, 2, 3)}, math.error.ArgumentsError); + assert.throws(function () {epow(1)}, error.ArgumentsError); + assert.throws(function () {epow(1, 2, 3)}, error.ArgumentsError); }); it('should elevate a complex number to the given power', function() { diff --git a/test/function/arithmetic/equal.test.js b/test/function/arithmetic/equal.test.js index 3760cff40..d2ce0ce3a 100644 --- a/test/function/arithmetic/equal.test.js +++ b/test/function/arithmetic/equal.test.js @@ -1,6 +1,7 @@ // test equal var assert = require('assert'), math = require('../../../index')(), + error = require('../../../lib/util/error'), bignumber = math.bignumber, complex = math.complex, matrix = math.matrix, @@ -116,8 +117,8 @@ describe('equal', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {equal(1)}, math.error.ArgumentsError); - assert.throws(function () {equal(1, 2, 3)}, math.error.ArgumentsError); + assert.throws(function () {equal(1)}, error.ArgumentsError); + assert.throws(function () {equal(1, 2, 3)}, error.ArgumentsError); }); }); diff --git a/test/function/arithmetic/exp.test.js b/test/function/arithmetic/exp.test.js index 2d6646b92..fd2257f2a 100644 --- a/test/function/arithmetic/exp.test.js +++ b/test/function/arithmetic/exp.test.js @@ -1,6 +1,7 @@ // test exp var assert = require('assert'), approx = require('../../../tools/approx'), + error = require('../../../lib/util/error'), mathjs = require('../../../index'), math = mathjs(), complex = math.complex, @@ -33,8 +34,8 @@ describe('exp', function() { }); it('should throw an error if there\'s wrong number of arguments', function() { - assert.throws(function () {exp()}, math.error.ArgumentsError); - assert.throws(function () {exp(1, 2)}, math.error.ArgumentsError); + assert.throws(function () {exp()}, error.ArgumentsError); + assert.throws(function () {exp(1, 2)}, error.ArgumentsError); }); it('should exponentiate a complex number correctly', function() { diff --git a/test/function/arithmetic/fix.test.js b/test/function/arithmetic/fix.test.js index d4b083c52..4c99f1a31 100644 --- a/test/function/arithmetic/fix.test.js +++ b/test/function/arithmetic/fix.test.js @@ -1,5 +1,6 @@ // test fix var assert = require('assert'), + error = require('../../../lib/util/error'), approx = require('../../../tools/approx'), math = require('../../../index')(), bignumber = math.bignumber, @@ -67,8 +68,8 @@ describe('fix', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {fix()}, math.error.ArgumentsError); - assert.throws(function () {fix(1, 2)}, math.error.ArgumentsError); + assert.throws(function () {fix()}, error.ArgumentsError); + assert.throws(function () {fix(1, 2)}, error.ArgumentsError); }); }); \ No newline at end of file diff --git a/test/function/arithmetic/floor.test.js b/test/function/arithmetic/floor.test.js index 5bbab81d9..552c31088 100644 --- a/test/function/arithmetic/floor.test.js +++ b/test/function/arithmetic/floor.test.js @@ -1,6 +1,7 @@ // test floor var assert = require('assert'), approx = require('../../../tools/approx'), + error = require('../../../lib/util/error'), math = require('../../../index')(), bignumber = math.bignumber, complex = math.complex, @@ -63,8 +64,8 @@ describe('floor', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {floor()}, math.error.ArgumentsError); - assert.throws(function () {floor(1, 2)}, math.error.ArgumentsError); + assert.throws(function () {floor()}, error.ArgumentsError); + assert.throws(function () {floor(1, 2)}, error.ArgumentsError); }); }); \ No newline at end of file diff --git a/test/function/arithmetic/gcd.test.js b/test/function/arithmetic/gcd.test.js index 98a65e9a0..0e6e22e0a 100644 --- a/test/function/arithmetic/gcd.test.js +++ b/test/function/arithmetic/gcd.test.js @@ -1,5 +1,6 @@ // test gcd var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), gcd = math.gcd; diff --git a/test/function/arithmetic/larger.test.js b/test/function/arithmetic/larger.test.js index 1ac20f9ed..64832be4a 100644 --- a/test/function/arithmetic/larger.test.js +++ b/test/function/arithmetic/larger.test.js @@ -1,6 +1,7 @@ // test larger var assert = require('assert'), math = require('../../../index')(), + error = require('../../../lib/util/error'), bignumber = math.bignumber, complex = math.complex, matrix = math.matrix, @@ -106,8 +107,8 @@ describe('larger', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {larger(1)}, math.error.ArgumentsError); - assert.throws(function () {larger(1, 2, 3)}, math.error.ArgumentsError); + assert.throws(function () {larger(1)}, error.ArgumentsError); + assert.throws(function () {larger(1, 2, 3)}, error.ArgumentsError); }); }); diff --git a/test/function/arithmetic/largereq.test.js b/test/function/arithmetic/largereq.test.js index afce99730..e1bcac8e7 100644 --- a/test/function/arithmetic/largereq.test.js +++ b/test/function/arithmetic/largereq.test.js @@ -1,6 +1,7 @@ // test largereq var assert = require('assert'), math = require('../../../index')(), + error = require('../../../lib/util/error'), bignumber = math.bignumber, complex = math.complex, matrix = math.matrix, @@ -108,8 +109,8 @@ describe('largereq', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {largereq(1)}, math.error.ArgumentsError); - assert.throws(function () {largereq(1, 2, 3)}, math.error.ArgumentsError); + assert.throws(function () {largereq(1)}, error.ArgumentsError); + assert.throws(function () {largereq(1, 2, 3)}, error.ArgumentsError); }); }); \ No newline at end of file diff --git a/test/function/arithmetic/lcm.test.js b/test/function/arithmetic/lcm.test.js index 6276cefa7..33b499e12 100644 --- a/test/function/arithmetic/lcm.test.js +++ b/test/function/arithmetic/lcm.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), lcm = math.lcm; diff --git a/test/function/arithmetic/log.test.js b/test/function/arithmetic/log.test.js index 57767b590..a18791fab 100644 --- a/test/function/arithmetic/log.test.js +++ b/test/function/arithmetic/log.test.js @@ -1,6 +1,7 @@ // test exp var assert = require('assert'), approx = require('../../../tools/approx'), + error = require('../../../lib/util/error'), mathjs = require('../../../index'), math = mathjs(), complex = math.complex, @@ -34,8 +35,8 @@ describe('log', function() { }); it('should throw an error if invalid number of arguments', function() { - assert.throws(function () {log()}, math.error.ArgumentsError); - assert.throws(function () {log(1, 2, 3)}, math.error.ArgumentsError); + assert.throws(function () {log()}, error.ArgumentsError); + assert.throws(function () {log(1, 2, 3)}, error.ArgumentsError); }); it('should return the log of a bignumber', function() { diff --git a/test/function/arithmetic/log10.test.js b/test/function/arithmetic/log10.test.js index 586d4863d..e3095ade9 100644 --- a/test/function/arithmetic/log10.test.js +++ b/test/function/arithmetic/log10.test.js @@ -1,6 +1,7 @@ // test exp var assert = require('assert'), approx = require('../../../tools/approx'), + error = require('../../../lib/util/error'), mathjs = require('../../../index'), math = mathjs(), complex = math.complex, @@ -44,8 +45,8 @@ describe('log10', function() { }); it('should throw an error if used with a wrong number of arguments', function() { - assert.throws(function () {log10()}, math.error.ArgumentsError); - assert.throws(function () {log10(1, 2)}, math.error.ArgumentsError); + assert.throws(function () {log10()}, error.ArgumentsError); + assert.throws(function () {log10(1, 2)}, error.ArgumentsError); }); it('should return the log base 10 of a complex number', function() { diff --git a/test/function/arithmetic/mod.test.js b/test/function/arithmetic/mod.test.js index 20ec49a07..4f568a324 100644 --- a/test/function/arithmetic/mod.test.js +++ b/test/function/arithmetic/mod.test.js @@ -1,6 +1,7 @@ // test mod var assert = require('assert'), approx = require('../../../tools/approx'), + error = require('../../../lib/util/error'), math = require('../../../index')(), bignumber = math.bignumber, matrix = math.matrix, @@ -36,8 +37,8 @@ describe('mod', function() { }); it('should throw an error if used with wrong number of arguments', function() { - assert.throws(function () {mod(1)}, math.error.ArgumentsError); - assert.throws(function () {mod(1,2,3)}, math.error.ArgumentsError); + assert.throws(function () {mod(1)}, error.ArgumentsError); + assert.throws(function () {mod(1,2,3)}, error.ArgumentsError); }); it('should throw an error if used with wrong type of arguments', function() { diff --git a/test/function/arithmetic/multiply.test.js b/test/function/arithmetic/multiply.test.js index 374758bb6..bf78db285 100644 --- a/test/function/arithmetic/multiply.test.js +++ b/test/function/arithmetic/multiply.test.js @@ -1,6 +1,7 @@ // test multiply var assert = require('assert'), math = require('../../../index')(), + error = require('../../../lib/util/error'), approx = require('../../../tools/approx'), multiply = math.multiply, divide = math.divide, @@ -216,8 +217,8 @@ describe('multiply', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {multiply(1)}, math.error.ArgumentsError); - assert.throws(function () {multiply(1, 2, 3)}, math.error.ArgumentsError); + assert.throws(function () {multiply(1)}, error.ArgumentsError); + assert.throws(function () {multiply(1, 2, 3)}, error.ArgumentsError); }); }); diff --git a/test/function/arithmetic/pow.test.js b/test/function/arithmetic/pow.test.js index 241dfa1a4..640155bbe 100644 --- a/test/function/arithmetic/pow.test.js +++ b/test/function/arithmetic/pow.test.js @@ -1,6 +1,7 @@ // test exp var assert = require('assert'), approx = require('../../../tools/approx'), + error = require('../../../lib/util/error'), math = require('../../../index')(), bignumber = math.bignumber, complex = math.complex, @@ -59,8 +60,8 @@ describe('pow', function() { }); it('should throw an error if used with wrong number of arguments', function() { - assert.throws(function () {pow(1)}, math.error.ArgumentsError); - assert.throws(function () {pow(1, 2, 3)}, math.error.ArgumentsError); + assert.throws(function () {pow(1)}, error.ArgumentsError); + assert.throws(function () {pow(1, 2, 3)}, error.ArgumentsError); }); it('should exponentiate a complex number to the given power', function() { diff --git a/test/function/arithmetic/round.test.js b/test/function/arithmetic/round.test.js index e0f69f84f..caea38870 100644 --- a/test/function/arithmetic/round.test.js +++ b/test/function/arithmetic/round.test.js @@ -1,6 +1,7 @@ // test round var assert = require('assert'), approx = require('../../../tools/approx'), + error = require('../../../lib/util/error'), math = require('../../../index')(), bignumber = math.bignumber, round = math.round; @@ -38,8 +39,8 @@ describe('round', function() { }); it('should throw an error if used with wrong number of arguments', function() { - assert.throws(function () {round();}, math.error.ArgumentsError); - assert.throws(function () {round(1,2,3);}, math.error.ArgumentsError); + assert.throws(function () {round();}, error.ArgumentsError); + assert.throws(function () {round(1,2,3);}, error.ArgumentsError); }); it('should round bignumbers', function() { diff --git a/test/function/arithmetic/sign.test.js b/test/function/arithmetic/sign.test.js index be2d70219..0f3e7ffec 100644 --- a/test/function/arithmetic/sign.test.js +++ b/test/function/arithmetic/sign.test.js @@ -1,6 +1,7 @@ // test sign var assert = require('assert'), approx = require('../../../tools/approx'), + error = require('../../../lib/util/error'), math = require('../../../index')(), bignumber = math.bignumber; @@ -43,8 +44,8 @@ describe('sign', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {math.sign()}, math.error.ArgumentsError); - assert.throws(function () {math.sign(1, 2)}, math.error.ArgumentsError); + assert.throws(function () {math.sign()}, error.ArgumentsError); + assert.throws(function () {math.sign(1, 2)}, error.ArgumentsError); }); }); \ No newline at end of file diff --git a/test/function/arithmetic/smaller.test.js b/test/function/arithmetic/smaller.test.js index e821a8131..7f9ff9806 100644 --- a/test/function/arithmetic/smaller.test.js +++ b/test/function/arithmetic/smaller.test.js @@ -1,6 +1,7 @@ // test smaller var assert = require('assert'), math = require('../../../index')(), + error = require('../../../lib/util/error'), bignumber = math.bignumber, complex = math.complex, matrix = math.matrix, @@ -110,8 +111,8 @@ describe('smaller', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {smaller(1)}, math.error.ArgumentsError); - assert.throws(function () {smaller(1, 2, 3)}, math.error.ArgumentsError); + assert.throws(function () {smaller(1)}, error.ArgumentsError); + assert.throws(function () {smaller(1, 2, 3)}, error.ArgumentsError); }); }); diff --git a/test/function/arithmetic/smallereq.test.js b/test/function/arithmetic/smallereq.test.js index 6e6abd98d..6083807c7 100644 --- a/test/function/arithmetic/smallereq.test.js +++ b/test/function/arithmetic/smallereq.test.js @@ -1,6 +1,7 @@ // test smaller var assert = require('assert'), math = require('../../../index')(), + error = require('../../../lib/util/error'), bignumber = math.bignumber, complex = math.complex, matrix = math.matrix, @@ -113,8 +114,8 @@ describe('smallereq', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {smallereq(1)}, math.error.ArgumentsError); - assert.throws(function () {smallereq(1, 2, 3)}, math.error.ArgumentsError); + assert.throws(function () {smallereq(1)}, error.ArgumentsError); + assert.throws(function () {smallereq(1, 2, 3)}, error.ArgumentsError); }); }); \ No newline at end of file diff --git a/test/function/arithmetic/sqrt.test.js b/test/function/arithmetic/sqrt.test.js index f0f089360..211a8c0ed 100644 --- a/test/function/arithmetic/sqrt.test.js +++ b/test/function/arithmetic/sqrt.test.js @@ -1,6 +1,7 @@ // test sqrt var assert = require('assert'), approx = require('../../../tools/approx'), + error = require('../../../lib/util/error'), mathjs = require('../../../index'), math = mathjs(); sqrt = math.sqrt, @@ -59,8 +60,8 @@ describe('sqrt', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {sqrt()}, math.error.ArgumentsError); - assert.throws(function () {sqrt(1, 2)}, math.error.ArgumentsError); + assert.throws(function () {sqrt()}, error.ArgumentsError); + assert.throws(function () {sqrt(1, 2)}, error.ArgumentsError); }); }); \ No newline at end of file diff --git a/test/function/arithmetic/square.test.js b/test/function/arithmetic/square.test.js index 2b174f289..98f861d17 100644 --- a/test/function/arithmetic/square.test.js +++ b/test/function/arithmetic/square.test.js @@ -1,6 +1,7 @@ // test square var assert = require('assert'), math = require('../../../index')(), + error = require('../../../lib/util/error'), unit = math.unit, bignumber = math.bignumber, matrix = math.matrix, @@ -26,8 +27,8 @@ describe('square', function() { }); it('should throw an error if used with wrong number of arguments', function() { - assert.throws(function () {square()}, math.error.ArgumentsError); - assert.throws(function () {square(1, 2)}, math.error.ArgumentsError); + assert.throws(function () {square()}, error.ArgumentsError); + assert.throws(function () {square(1, 2)}, error.ArgumentsError); }); it('should return the square of a complex number', function() { diff --git a/test/function/arithmetic/subtract.test.js b/test/function/arithmetic/subtract.test.js index f3fe9dcb1..18943f3cc 100644 --- a/test/function/arithmetic/subtract.test.js +++ b/test/function/arithmetic/subtract.test.js @@ -1,6 +1,7 @@ // test subtract var assert = require('assert'), approx = require('../../../tools/approx'), + error = require('../../../lib/util/error'), math = require('../../../index')(), bignumber = math.bignumber, subtract = math.subtract; @@ -116,8 +117,8 @@ describe('subtract', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {subtract(1)}, math.error.ArgumentsError); - assert.throws(function () {subtract(1, 2, 3)}, math.error.ArgumentsError); + assert.throws(function () {subtract(1)}, error.ArgumentsError); + assert.throws(function () {subtract(1, 2, 3)}, error.ArgumentsError); }); }); diff --git a/test/function/arithmetic/unary.test.js b/test/function/arithmetic/unary.test.js index 05184e83b..fbb5612c6 100644 --- a/test/function/arithmetic/unary.test.js +++ b/test/function/arithmetic/unary.test.js @@ -1,6 +1,7 @@ // test unary minus var assert = require('assert'), math = require('../../../index')(), + error = require('../../../lib/util/error'), bignumber = math.bignumber; describe('unaryminus', function() { @@ -46,8 +47,8 @@ describe('unaryminus', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {math.unary()}, math.error.ArgumentsError); - assert.throws(function () {math.unary(1, 2)}, math.error.ArgumentsError); + assert.throws(function () {math.unary()}, error.ArgumentsError); + assert.throws(function () {math.unary(1, 2)}, error.ArgumentsError); }); }); \ No newline at end of file diff --git a/test/function/arithmetic/unequal.test.js b/test/function/arithmetic/unequal.test.js index e376d2dd1..ab949ca12 100644 --- a/test/function/arithmetic/unequal.test.js +++ b/test/function/arithmetic/unequal.test.js @@ -1,5 +1,6 @@ // test equal var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), bignumber = math.bignumber, complex = math.complex, @@ -120,8 +121,8 @@ describe('unequal', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {unequal(1)}, math.error.ArgumentsError); - assert.throws(function () {unequal(1, 2, 3)}, math.error.ArgumentsError); + assert.throws(function () {unequal(1)}, error.ArgumentsError); + assert.throws(function () {unequal(1, 2, 3)}, error.ArgumentsError); }); }); diff --git a/test/function/arithmetic/xgcd.test.js b/test/function/arithmetic/xgcd.test.js index 0e85648be..c862cf1f0 100644 --- a/test/function/arithmetic/xgcd.test.js +++ b/test/function/arithmetic/xgcd.test.js @@ -1,5 +1,6 @@ // test xgcd var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), gcd = math.gcd, xgcd = math.xgcd; diff --git a/test/function/complex/arg.test.js b/test/function/complex/arg.test.js index 589fc26b5..c003e527b 100644 --- a/test/function/complex/arg.test.js +++ b/test/function/complex/arg.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), approx = require('../../../tools/approx'), math = require('../../../index')(), arg = math.arg; @@ -60,8 +61,8 @@ describe('arg', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {arg()}, math.error.ArgumentsError); - assert.throws(function () {arg(1, 2)}, math.error.ArgumentsError); + assert.throws(function () {arg()}, error.ArgumentsError); + assert.throws(function () {arg(1, 2)}, error.ArgumentsError); }); }); \ No newline at end of file diff --git a/test/function/complex/conj.test.js b/test/function/complex/conj.test.js index cec2b7751..238406da4 100644 --- a/test/function/complex/conj.test.js +++ b/test/function/complex/conj.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), conj = math.conj; @@ -43,8 +44,8 @@ describe('conj', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {conj()}, math.error.ArgumentsError); - assert.throws(function () {conj(1, 2)}, math.error.ArgumentsError); + assert.throws(function () {conj()}, error.ArgumentsError); + assert.throws(function () {conj(1, 2)}, error.ArgumentsError); }); }); \ No newline at end of file diff --git a/test/function/complex/im.test.js b/test/function/complex/im.test.js index 179757d1a..841de1487 100644 --- a/test/function/complex/im.test.js +++ b/test/function/complex/im.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(); describe('im', function() { @@ -37,8 +38,8 @@ describe('im', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {math.im()}, math.error.ArgumentsError); - assert.throws(function () {math.im(1, 2)}, math.error.ArgumentsError); + assert.throws(function () {math.im()}, error.ArgumentsError); + assert.throws(function () {math.im(1, 2)}, error.ArgumentsError); }); }); \ No newline at end of file diff --git a/test/function/complex/re.test.js b/test/function/complex/re.test.js index d290c5ad1..ea05d361f 100644 --- a/test/function/complex/re.test.js +++ b/test/function/complex/re.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(); describe('re', function() { @@ -32,8 +33,8 @@ describe('re', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {math.re()}, math.error.ArgumentsError); - assert.throws(function () {math.re(1, 2)}, math.error.ArgumentsError); + assert.throws(function () {math.re()}, error.ArgumentsError); + assert.throws(function () {math.re(1, 2)}, error.ArgumentsError); }); }); \ No newline at end of file diff --git a/test/function/construction/bignumber.test.js b/test/function/construction/bignumber.test.js index 1a1d39152..17c080336 100644 --- a/test/function/construction/bignumber.test.js +++ b/test/function/construction/bignumber.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), mathjs = require('../../../index'), math = mathjs(), bignumber = math.bignumber, @@ -71,7 +72,7 @@ describe('bignumber', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {math.bignumber(1, 2)}, math.error.ArgumentsError); + assert.throws(function () {math.bignumber(1, 2)}, error.ArgumentsError); }); }); \ No newline at end of file diff --git a/test/function/construction/boolean.test.js b/test/function/construction/boolean.test.js index 54ad70d92..95ed6466f 100644 --- a/test/function/construction/boolean.test.js +++ b/test/function/construction/boolean.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), bool = math['boolean']; @@ -57,8 +58,8 @@ describe('boolean', function() { }); it('should throw an error if there\'s a wrong number of arguments', function() { - assert.throws(function () {bool(1,2)}, math.error.ArgumentsError); - assert.throws(function () {bool(1,2,3)}, math.error.ArgumentsError); + assert.throws(function () {bool(1,2)}, error.ArgumentsError); + assert.throws(function () {bool(1,2,3)}, error.ArgumentsError); }); it('should throw an error if used with a complex', function() { diff --git a/test/function/construction/complex.test.js b/test/function/construction/complex.test.js index ceeeae8e9..a1955c728 100644 --- a/test/function/construction/complex.test.js +++ b/test/function/construction/complex.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), complex = math.complex; @@ -75,6 +76,6 @@ describe('complex', function() { }); it('should throw an error if called with more than 2 arguments', function() { - assert.throws(function () {complex(2,3,4)}, math.error.ArgumentsError); + assert.throws(function () {complex(2,3,4)}, error.ArgumentsError); }); }); \ No newline at end of file diff --git a/test/function/construction/index.test.js b/test/function/construction/index.test.js index c283ed5e4..402164091 100644 --- a/test/function/construction/index.test.js +++ b/test/function/construction/index.test.js @@ -1,5 +1,6 @@ // test index construction var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(); describe('index', function() { diff --git a/test/function/construction/matrix.test.js b/test/function/construction/matrix.test.js index 634ac8b69..1a36fa9a2 100644 --- a/test/function/construction/matrix.test.js +++ b/test/function/construction/matrix.test.js @@ -1,5 +1,6 @@ // test matrix construction var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), matrix = math.matrix; @@ -42,7 +43,7 @@ describe('matrix', function() { }); it('should throw an error if called with 2 numbers', function() { - assert.throws(function () {matrix(2, 3)}, math.error.ArgumentsError); + assert.throws(function () {matrix(2, 3)}, error.ArgumentsError); }); }); \ No newline at end of file diff --git a/test/function/construction/number.test.js b/test/function/construction/number.test.js index 336335a9a..9bf275230 100644 --- a/test/function/construction/number.test.js +++ b/test/function/construction/number.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), approx = require('../../../tools/approx'), number = math.number; @@ -45,8 +46,8 @@ describe('number', function() { }); it('should throw an error if called with a wrong number of arguments', function() { - assert.throws(function () {number(1,2)}, math.error.ArgumentsError); - assert.throws(function () {number(1,2,3)}, math.error.ArgumentsError); + assert.throws(function () {number(1,2)}, error.ArgumentsError); + assert.throws(function () {number(1,2,3)}, error.ArgumentsError); }); it('should throw an error if called with a complex number', function() { diff --git a/test/function/construction/parser.test.js b/test/function/construction/parser.test.js index 8a7b04f49..bb56450e5 100644 --- a/test/function/construction/parser.test.js +++ b/test/function/construction/parser.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), Parser = require('../../../lib/expression/Parser'), math = require('../../../index')(); diff --git a/test/function/construction/string.test.js b/test/function/construction/string.test.js index 6f54484b3..ff4b75c54 100644 --- a/test/function/construction/string.test.js +++ b/test/function/construction/string.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), string = math.string; @@ -48,7 +49,7 @@ describe('string', function() { }); it('should throw an error if called with wrong number of arguments', function() { - assert.throws(function () {string(1,2)}, math.error.ArgumentsError); - assert.throws(function () {string(1,2,3)}, math.error.ArgumentsError); + assert.throws(function () {string(1,2)}, error.ArgumentsError); + assert.throws(function () {string(1,2,3)}, error.ArgumentsError); }); }); diff --git a/test/function/construction/unit.test.js b/test/function/construction/unit.test.js index be838f7e4..8e9d737f5 100644 --- a/test/function/construction/unit.test.js +++ b/test/function/construction/unit.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), unit = math.unit; Unit = require('../../../lib/type/Unit'); @@ -61,10 +62,10 @@ describe('unit', function() { }); it('should throw an error if called with no argument', function() { - assert.throws(function () {unit()}, math.error.ArgumentsError); + assert.throws(function () {unit()}, error.ArgumentsError); }); it('should throw an error if called with an invalid number of arguments', function() { - assert.throws(function () {unit(1,2,3)}, math.error.ArgumentsError); + assert.throws(function () {unit(1,2,3)}, error.ArgumentsError); }); }); \ No newline at end of file diff --git a/test/function/expression/compile.test.js b/test/function/expression/compile.test.js index 7d954b409..1520eed2d 100644 --- a/test/function/expression/compile.test.js +++ b/test/function/expression/compile.test.js @@ -1,5 +1,6 @@ // test parse var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), Node = require('../../../lib/expression/node/Node'); @@ -22,8 +23,8 @@ describe('parse', function() { }); it('should throw an error on wrong number of arguments', function() { - assert.throws(function () {math.compile()}, math.error.ArgumentsError); - assert.throws(function () {math.compile('2+3', '3+4')}, math.error.ArgumentsError); + assert.throws(function () {math.compile()}, error.ArgumentsError); + assert.throws(function () {math.compile('2+3', '3+4')}, error.ArgumentsError); }); it('should throw an error on wrong type of argument', function() { diff --git a/test/function/expression/eval.test.js b/test/function/expression/eval.test.js index 5814ffcc6..c198517b1 100644 --- a/test/function/expression/eval.test.js +++ b/test/function/expression/eval.test.js @@ -1,6 +1,7 @@ // test eval var assert = require('assert'), approx = require('../../../tools/approx'), + error = require('../../../lib/util/error'), math = require('../../../index')(), Complex = math.type.Complex, Matrix = math.type.Matrix, @@ -27,8 +28,8 @@ describe('eval', function() { }); it('should throw an error if wrong number of arguments', function() { - assert.throws(function () {math.eval()}, math.error.ArgumentsError); - assert.throws(function () {math.eval(1,2,3)}, math.error.ArgumentsError); + assert.throws(function () {math.eval()}, error.ArgumentsError); + assert.throws(function () {math.eval(1,2,3)}, error.ArgumentsError); }); it('should throw an error with a number', function() { diff --git a/test/function/expression/help.test.js b/test/function/expression/help.test.js index 23f7ec833..5767a083a 100644 --- a/test/function/expression/help.test.js +++ b/test/function/expression/help.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(); describe('help', function() { diff --git a/test/function/expression/parse.test.js b/test/function/expression/parse.test.js index 75fce7212..e6914f05e 100644 --- a/test/function/expression/parse.test.js +++ b/test/function/expression/parse.test.js @@ -1,5 +1,6 @@ // test parse var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), Node = require('../../../lib/expression/node/Node'); diff --git a/test/function/matrix/concat.test.js b/test/function/matrix/concat.test.js index bb76d55fb..609539353 100644 --- a/test/function/matrix/concat.test.js +++ b/test/function/matrix/concat.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), bignumber = math.bignumber; diff --git a/test/function/matrix/det.test.js b/test/function/matrix/det.test.js index bffbd6ace..c72d97fe4 100644 --- a/test/function/matrix/det.test.js +++ b/test/function/matrix/det.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), approx = require('../../../tools/approx'), math = require('../../../index')(); diff --git a/test/function/matrix/diag.test.js b/test/function/matrix/diag.test.js index 643adaa07..0953835fb 100644 --- a/test/function/matrix/diag.test.js +++ b/test/function/matrix/diag.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), bignumber = math.bignumber; @@ -100,8 +101,8 @@ describe('diag', function() { }); it('should throw an error in case of wrong number of arguments', function() { - assert.throws(function () {math.diag()}, math.error.ArgumentsError); - assert.throws(function () {math.diag([], 2, 3)}, math.error.ArgumentsError); + assert.throws(function () {math.diag()}, error.ArgumentsError); + assert.throws(function () {math.diag([], 2, 3)}, error.ArgumentsError); }); it('should throw an error in case of invalid type of arguments', function() { diff --git a/test/function/matrix/eye.test.js b/test/function/matrix/eye.test.js index e08e164b8..cf1700ca5 100644 --- a/test/function/matrix/eye.test.js +++ b/test/function/matrix/eye.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), mathjs = require('../../../index'), math = mathjs(), matrix = math.matrix, diff --git a/test/function/matrix/inv.test.js b/test/function/matrix/inv.test.js index 551764744..7908ae9f3 100644 --- a/test/function/matrix/inv.test.js +++ b/test/function/matrix/inv.test.js @@ -1,6 +1,7 @@ // test inv var assert = require('assert'), approx = require('../../../tools/approx'), + error = require('../../../lib/util/error'), math = require('../../../index')(), inv = math.inv; @@ -74,8 +75,8 @@ describe('inv', function() { }); it('should throw an error in case of wrong number of arguments', function() { - assert.throws(function () {inv()}, math.error.ArgumentsError); - assert.throws(function () {inv([], [])}, math.error.ArgumentsError); + assert.throws(function () {inv()}, error.ArgumentsError); + assert.throws(function () {inv([], [])}, error.ArgumentsError); }); it('should throw an error in case of invalid type of arguments', function() { diff --git a/test/function/matrix/ones.test.js b/test/function/matrix/ones.test.js index ac99280a8..15decc1a1 100644 --- a/test/function/matrix/ones.test.js +++ b/test/function/matrix/ones.test.js @@ -1,5 +1,6 @@ // test ones var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), ones = math.ones, matrix = math.matrix; diff --git a/test/function/matrix/range.test.js b/test/function/matrix/range.test.js index d80c6821b..9ed437315 100644 --- a/test/function/matrix/range.test.js +++ b/test/function/matrix/range.test.js @@ -1,5 +1,6 @@ var assert = require('assert'), approx = require('../../../tools/approx'), + error = require('../../../lib/util/error'), mathjs = require('../../../index'), math = mathjs(), range = math.range, @@ -144,7 +145,7 @@ describe('range', function() { }); it('should throw an error if called with an invalid number of arguments', function() { - assert.throws(function () {range()}, math.error.ArgumentsError); - assert.throws(function () {range(1,2,3,4,5)}, math.error.ArgumentsError); + assert.throws(function () {range()}, error.ArgumentsError); + assert.throws(function () {range(1,2,3,4,5)}, error.ArgumentsError); }); }); \ No newline at end of file diff --git a/test/function/matrix/resize.test.js b/test/function/matrix/resize.test.js index e7df92e13..0ddf7e400 100644 --- a/test/function/matrix/resize.test.js +++ b/test/function/matrix/resize.test.js @@ -1,5 +1,6 @@ // test resize var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), Matrix = math.type.Matrix; diff --git a/test/function/matrix/size.test.js b/test/function/matrix/size.test.js index 752b6ce89..8ba0b27ac 100644 --- a/test/function/matrix/size.test.js +++ b/test/function/matrix/size.test.js @@ -1,5 +1,6 @@ // test size var assert = require('assert'), + error = require('../../../lib/util/error'), mathjs = require('../../../index'), math = mathjs(), size = math.size, @@ -53,8 +54,8 @@ describe('size', function() { }); it('should throw an error if called with an invalid number of arguments', function() { - assert.throws(function () {size()}, math.error.ArgumentsError); - assert.throws(function () {size(1,2)}, math.error.ArgumentsError); + assert.throws(function () {size()}, error.ArgumentsError); + assert.throws(function () {size(1,2)}, error.ArgumentsError); }); it('should throw an error if called with invalid type of arguments', function() { diff --git a/test/function/matrix/squeeze.test.js b/test/function/matrix/squeeze.test.js index 6af320f2e..62cf1b696 100644 --- a/test/function/matrix/squeeze.test.js +++ b/test/function/matrix/squeeze.test.js @@ -1,5 +1,6 @@ // test squeeze var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), squeeze = math.squeeze, size = math.size, @@ -27,7 +28,7 @@ describe('squeeze', function() { }); it('should throw an error if called with an invalid number of arguments', function() { - assert.throws(function () {squeeze()}, math.error.ArgumentsError); - assert.throws(function () {squeeze(1,2)}, math.error.ArgumentsError); + assert.throws(function () {squeeze()}, error.ArgumentsError); + assert.throws(function () {squeeze(1,2)}, error.ArgumentsError); }); }); \ No newline at end of file diff --git a/test/function/matrix/subset.test.js b/test/function/matrix/subset.test.js index 39c730b63..c944db5db 100644 --- a/test/function/matrix/subset.test.js +++ b/test/function/matrix/subset.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), subset = math.subset, matrix = math.matrix, @@ -122,9 +123,9 @@ describe('subset', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {subset()}, math.error.ArgumentsError); - assert.throws(function () {subset(d)}, math.error.ArgumentsError); - assert.throws(function () {subset(d, index(0,0), 1, 0, 5)}, math.error.ArgumentsError); + assert.throws(function () {subset()}, error.ArgumentsError); + assert.throws(function () {subset(d)}, error.ArgumentsError); + assert.throws(function () {subset(d, index(0,0), 1, 0, 5)}, error.ArgumentsError); }); it('should throw an error in case of invalid type of arguments', function() { diff --git a/test/function/matrix/transpose.test.js b/test/function/matrix/transpose.test.js index 2df9fd2e5..082179e6d 100644 --- a/test/function/matrix/transpose.test.js +++ b/test/function/matrix/transpose.test.js @@ -1,5 +1,6 @@ // test transpose var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), transpose = math.transpose; @@ -31,8 +32,8 @@ describe('transpose', function() { }); it('should throw an error if called with an invalid number of arguments', function() { - assert.throws(function () {transpose()}, math.error.ArgumentsError); - assert.throws(function () {transpose([1,2],2)}, math.error.ArgumentsError); + assert.throws(function () {transpose()}, error.ArgumentsError); + assert.throws(function () {transpose([1,2],2)}, error.ArgumentsError); }); }); diff --git a/test/function/matrix/zeros.test.js b/test/function/matrix/zeros.test.js index d0d9fd87b..d222506a5 100644 --- a/test/function/matrix/zeros.test.js +++ b/test/function/matrix/zeros.test.js @@ -1,5 +1,6 @@ // test zeros var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), zeros = math.zeros, matrix = math.matrix; diff --git a/test/function/probability/combinations.test.js b/test/function/probability/combinations.test.js index e859cd860..e268125e9 100644 --- a/test/function/probability/combinations.test.js +++ b/test/function/probability/combinations.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), combinations = math.combinations; diff --git a/test/function/probability/factorial.test.js b/test/function/probability/factorial.test.js index c4fbbe511..fe816ffb8 100644 --- a/test/function/probability/factorial.test.js +++ b/test/function/probability/factorial.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), factorial = math.factorial; diff --git a/test/function/probability/permutations.test.js b/test/function/probability/permutations.test.js index 726f5f3ed..a696551d0 100644 --- a/test/function/probability/permutations.test.js +++ b/test/function/probability/permutations.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), permutations = math.permutations; diff --git a/test/function/probability/random.test.js b/test/function/probability/random.test.js index 4d6fee6b6..0edc8a070 100644 --- a/test/function/probability/random.test.js +++ b/test/function/probability/random.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), seed = require('seed-random'), _ = require('underscore'), math = require('../../../index')(); diff --git a/test/function/trigonometry/acos.test.js b/test/function/trigonometry/acos.test.js index 2820653fa..d78428ea7 100644 --- a/test/function/trigonometry/acos.test.js +++ b/test/function/trigonometry/acos.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), approx = require('../../../tools/approx'), pi = math.pi, @@ -62,8 +63,8 @@ describe('acos', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {acos()}, math.error.ArgumentsError); - assert.throws(function () {acos(1, 2)}, math.error.ArgumentsError); + assert.throws(function () {acos()}, error.ArgumentsError); + assert.throws(function () {acos(1, 2)}, error.ArgumentsError); }); }); \ No newline at end of file diff --git a/test/function/trigonometry/asin.test.js b/test/function/trigonometry/asin.test.js index d75daa45b..d155f9d0c 100644 --- a/test/function/trigonometry/asin.test.js +++ b/test/function/trigonometry/asin.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), approx = require('../../../tools/approx'), pi = math.pi, @@ -67,8 +68,8 @@ describe('asin', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {asin()}, math.error.ArgumentsError); - assert.throws(function () {asin(1, 2)}, math.error.ArgumentsError); + assert.throws(function () {asin()}, error.ArgumentsError); + assert.throws(function () {asin(1, 2)}, error.ArgumentsError); }); }); \ No newline at end of file diff --git a/test/function/trigonometry/atan.test.js b/test/function/trigonometry/atan.test.js index 6e6d25773..f6d7b1c1d 100644 --- a/test/function/trigonometry/atan.test.js +++ b/test/function/trigonometry/atan.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), approx = require('../../../tools/approx'), pi = math.pi, @@ -63,8 +64,8 @@ describe('atan', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {atan()}, math.error.ArgumentsError); - assert.throws(function () {atan(1, 2)}, math.error.ArgumentsError); + assert.throws(function () {atan()}, error.ArgumentsError); + assert.throws(function () {atan(1, 2)}, error.ArgumentsError); }); }); \ No newline at end of file diff --git a/test/function/trigonometry/atan2.test.js b/test/function/trigonometry/atan2.test.js index 863432e5a..56c7c55de 100644 --- a/test/function/trigonometry/atan2.test.js +++ b/test/function/trigonometry/atan2.test.js @@ -1,5 +1,6 @@ // test atan2 var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), approx = require('../../../tools/approx'), pi = math.pi, @@ -80,8 +81,8 @@ describe('atan2', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {atan2(1)}, math.error.ArgumentsError); - assert.throws(function () {atan2(1, 2, 3)}, math.error.ArgumentsError); + assert.throws(function () {atan2(1)}, error.ArgumentsError); + assert.throws(function () {atan2(1, 2, 3)}, error.ArgumentsError); }); }); \ No newline at end of file diff --git a/test/function/trigonometry/cos.test.js b/test/function/trigonometry/cos.test.js index d4c0acc87..74cd2fc62 100644 --- a/test/function/trigonometry/cos.test.js +++ b/test/function/trigonometry/cos.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), approx = require('../../../tools/approx'), pi = math.pi, @@ -67,8 +68,8 @@ describe('cos', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {cos()}, math.error.ArgumentsError); - assert.throws(function () {cos(1, 2)}, math.error.ArgumentsError); + assert.throws(function () {cos()}, error.ArgumentsError); + assert.throws(function () {cos(1, 2)}, error.ArgumentsError); }); }); \ No newline at end of file diff --git a/test/function/trigonometry/cot.test.js b/test/function/trigonometry/cot.test.js index 8f1e76f9e..5ff4ad203 100644 --- a/test/function/trigonometry/cot.test.js +++ b/test/function/trigonometry/cot.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), approx = require('../../../tools/approx'), pi = math.pi, @@ -66,8 +67,8 @@ describe('cot', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {cot()}, math.error.ArgumentsError); - assert.throws(function () {cot(1, 2)}, math.error.ArgumentsError); + assert.throws(function () {cot()}, error.ArgumentsError); + assert.throws(function () {cot(1, 2)}, error.ArgumentsError); }); }); \ No newline at end of file diff --git a/test/function/trigonometry/csc.test.js b/test/function/trigonometry/csc.test.js index ab172efca..2e05d69a2 100644 --- a/test/function/trigonometry/csc.test.js +++ b/test/function/trigonometry/csc.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), approx = require('../../../tools/approx'), pi = math.pi, @@ -67,8 +68,8 @@ describe('csc', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {csc()}, math.error.ArgumentsError); - assert.throws(function () {csc(1, 2)}, math.error.ArgumentsError); + assert.throws(function () {csc()}, error.ArgumentsError); + assert.throws(function () {csc(1, 2)}, error.ArgumentsError); }); }); \ No newline at end of file diff --git a/test/function/trigonometry/sec.test.js b/test/function/trigonometry/sec.test.js index b71924ec2..cccc801aa 100644 --- a/test/function/trigonometry/sec.test.js +++ b/test/function/trigonometry/sec.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), approx = require('../../../tools/approx'), pi = math.pi, @@ -75,8 +76,8 @@ describe('sec', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {sec()}, math.error.ArgumentsError); - assert.throws(function () {sec(1, 2)}, math.error.ArgumentsError); + assert.throws(function () {sec()}, error.ArgumentsError); + assert.throws(function () {sec(1, 2)}, error.ArgumentsError); }); }); \ No newline at end of file diff --git a/test/function/trigonometry/sin.test.js b/test/function/trigonometry/sin.test.js index 8e81c4854..cf3e47bdc 100644 --- a/test/function/trigonometry/sin.test.js +++ b/test/function/trigonometry/sin.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), approx = require('../../../tools/approx'), pi = math.pi, @@ -67,8 +68,8 @@ describe('sin', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {sin()}, math.error.ArgumentsError); - assert.throws(function () {sin(1, 2)}, math.error.ArgumentsError); + assert.throws(function () {sin()}, error.ArgumentsError); + assert.throws(function () {sin(1, 2)}, error.ArgumentsError); }); }); diff --git a/test/function/trigonometry/tan.test.js b/test/function/trigonometry/tan.test.js index 7971e0b82..e41c00e36 100644 --- a/test/function/trigonometry/tan.test.js +++ b/test/function/trigonometry/tan.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), approx = require('../../../tools/approx'), pi = math.pi, @@ -68,8 +69,8 @@ describe('tan', function() { }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {tan()}, math.error.ArgumentsError); - assert.throws(function () {tan(1, 2)}, math.error.ArgumentsError); + assert.throws(function () {tan()}, error.ArgumentsError); + assert.throws(function () {tan(1, 2)}, error.ArgumentsError); }); }); \ No newline at end of file diff --git a/test/function/utils/clone.test.js b/test/function/utils/clone.test.js index 8368c6947..0a79c6156 100644 --- a/test/function/utils/clone.test.js +++ b/test/function/utils/clone.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(); describe('clone', function() { @@ -11,8 +12,8 @@ describe('clone', function() { }); it('should throw an error on wrong number of arguments', function() { - assert.throws (function () {math.clone()}, math.error.ArgumentsError); - assert.throws (function () {math.clone(2, 4)}, math.error.ArgumentsError); + assert.throws (function () {math.clone()}, error.ArgumentsError); + assert.throws (function () {math.clone(2, 4)}, error.ArgumentsError); }); it('should clone a bignumber', function() { diff --git a/test/function/utils/forEach.test.js b/test/function/utils/forEach.test.js index d346e3dc4..d4d94629d 100644 --- a/test/function/utils/forEach.test.js +++ b/test/function/utils/forEach.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(); describe('forEach', function() { diff --git a/test/function/utils/format.test.js b/test/function/utils/format.test.js index 9a8cff7ad..e334eb7bb 100644 --- a/test/function/utils/format.test.js +++ b/test/function/utils/format.test.js @@ -1,5 +1,6 @@ // test format var assert = require('assert'), + error = require('../../../lib/util/error'), mathjs = require('../../../index'); math = mathjs(); @@ -81,8 +82,8 @@ describe('format', function() { }); it('should throw an error on wrong number of arguments', function() { - assert.throws (function () {math.format()}, math.error.ArgumentsError); - assert.throws (function () {math.format(1, 2, 3)}, math.error.ArgumentsError); + assert.throws (function () {math.format()}, error.ArgumentsError); + assert.throws (function () {math.format(1, 2, 3)}, error.ArgumentsError); }); }); \ No newline at end of file diff --git a/test/function/utils/ifElse.test.js b/test/function/utils/ifElse.test.js index 2aa3954e4..a1f0523c2 100644 --- a/test/function/utils/ifElse.test.js +++ b/test/function/utils/ifElse.test.js @@ -1,5 +1,6 @@ // test format var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(), ifElse = math.ifElse; diff --git a/test/function/utils/import.test.js b/test/function/utils/import.test.js index 8d5194e1f..374938fda 100644 --- a/test/function/utils/import.test.js +++ b/test/function/utils/import.test.js @@ -1,5 +1,6 @@ // test import var assert = require('assert'), + error = require('../../../lib/util/error'), mathjs = require('../../../index'), approx = require('../../../tools/approx'); @@ -111,8 +112,8 @@ describe('import', function() { }); it('should throw an error in case of wrong number of arguments', function () { - assert.throws (function () {math.import()}, math.error.ArgumentsError); - assert.throws (function () {math.import('', {}, 3)}, math.error.ArgumentsError); + assert.throws (function () {math.import()}, error.ArgumentsError); + assert.throws (function () {math.import('', {}, 3)}, error.ArgumentsError); }); diff --git a/test/function/utils/map.test.js b/test/function/utils/map.test.js index b7eeb86d9..54d59c93b 100644 --- a/test/function/utils/map.test.js +++ b/test/function/utils/map.test.js @@ -1,4 +1,5 @@ var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(); describe('map', function() { diff --git a/test/function/utils/print.test.js b/test/function/utils/print.test.js index bfc711502..5f53e3c6e 100644 --- a/test/function/utils/print.test.js +++ b/test/function/utils/print.test.js @@ -1,5 +1,6 @@ // test print var assert = require('assert'), + error = require('../../../lib/util/error'), math = require('../../../index')(); describe('print', function() { @@ -33,9 +34,9 @@ describe('print', function() { }); it('should throw an error on wrong number of arguments', function() { - assert.throws (function () {math.print()}, math.error.ArgumentsError); - assert.throws (function () {math.print('')}, math.error.ArgumentsError); - assert.throws (function () {math.print('', {}, 6, 2)}, math.error.ArgumentsError); + assert.throws (function () {math.print()}, error.ArgumentsError); + assert.throws (function () {math.print('')}, error.ArgumentsError); + assert.throws (function () {math.print('', {}, 6, 2)}, error.ArgumentsError); }); it('should throw an error on wrong type of arguments', function() { diff --git a/test/function/utils/typeof.test.js b/test/function/utils/typeof.test.js index 519b5dc6b..fcebf0639 100644 --- a/test/function/utils/typeof.test.js +++ b/test/function/utils/typeof.test.js @@ -1,5 +1,6 @@ // test typeof var assert = require('assert'), + error = require('../../../lib/util/error'), Index = require('../../../lib/type/Index'), Range = require('../../../lib/type/Range'), Matrix = require('../../../lib/type/Matrix'), diff --git a/test/type/error.test.js b/test/type/error.test.js index d15d92619..73a983da9 100644 --- a/test/type/error.test.js +++ b/test/type/error.test.js @@ -48,26 +48,4 @@ describe('error', function () { }); - describe('ArgumentsError', function () { - - it('should construct an ArgumentsError without max', function () { - var err = new math.error.ArgumentsError('myfunction', 1, 2); - assert(err instanceof Error); - assert(err instanceof math.error.ArgumentsError); - assert.equal(err.toString(), 'ArgumentsError: Wrong number of arguments in function myfunction (1 provided, 2 expected)'); - }); - - it('should construct an ArgumentsError with max', function () { - var err = new math.error.ArgumentsError('myfunction', 1, 2, 3); - assert(err instanceof Error); - assert(err instanceof math.error.ArgumentsError); - assert.equal(err.toString(), 'ArgumentsError: Wrong number of arguments in function myfunction (1 provided, 2-3 expected)'); - }); - - it('should throw an error when operator new is missing', function () { - assert.throws(function () {math.error.ArgumentsError();}, SyntaxError); - }); - - }); - }); diff --git a/test/util/error.test.js b/test/util/error.test.js index 0104ef790..0bd447c25 100644 --- a/test/util/error.test.js +++ b/test/util/error.test.js @@ -5,6 +5,28 @@ var assert = require('assert'), describe('error', function () { + describe('ArgumentsError', function () { + + it('should construct an ArgumentsError without max', function () { + var err = new error.ArgumentsError('myfunction', 1, 2); + assert(err instanceof Error); + assert(err instanceof error.ArgumentsError); + assert.equal(err.toString(), 'ArgumentsError: Wrong number of arguments in function myfunction (1 provided, 2 expected)'); + }); + + it('should construct an ArgumentsError with max', function () { + var err = new error.ArgumentsError('myfunction', 1, 2, 3); + assert(err instanceof Error); + assert(err instanceof error.ArgumentsError); + assert.equal(err.toString(), 'ArgumentsError: Wrong number of arguments in function myfunction (1 provided, 2-3 expected)'); + }); + + it('should throw an error when operator new is missing', function () { + assert.throws(function () {error.ArgumentsError();}, SyntaxError); + }); + + }); + describe('DimensionError', function () { it('should construct a DimensionError with numbers', function () { From 8692d7ffa10cc87816a05a9692463bae4847a2ab Mon Sep 17 00:00:00 2001 From: Bryan Cuccioli Date: Mon, 7 Apr 2014 07:09:52 +0000 Subject: [PATCH 26/48] Implement poly-time determinant without divisions. This is based on the paper 'A Simple Division-Free Algorithm for Computing Determinants' (Bird 2011). --- lib/function/matrix/det.js | 79 +++++++++++++------------------------- 1 file changed, 27 insertions(+), 52 deletions(-) diff --git a/lib/function/matrix/det.js b/lib/function/matrix/det.js index 686c2c0d4..8a6e4e1f4 100644 --- a/lib/function/matrix/det.js +++ b/lib/function/matrix/det.js @@ -91,63 +91,38 @@ module.exports = function (math) { else { // this is an n x n matrix // TODO: support for bignumbers, complex numbers, etc - var a; - var d = 1; - var lead = 0; - for (var r = 0; r < rows; r++) { - if (lead >= cols) { - break; + function compute_mu(matrix) { + // Compute the matrix with zero lower triangle, same upper triangle, + // and diagonals given by the negated sum of the below diagonal + // elements. + var mu = new Array(matrix.length); + var sum = 0; + for (var i = 1; i < matrix.length; i++) { + sum += matrix[i][i]; } - var i = r; - // Find the pivot element. - while (matrix[i][lead] == 0) { - i++; - if (i == rows) { - i = r; - lead++; - if (lead == cols) { - // We found the last pivot. - if (object.deepEqual(matrix, math.eye(rows).valueOf())) { - return math.round(d, 6); // FIXME: should d be rounded to 6 here? - } else { - return 0; - } - } + for (var i = 0; i < matrix.length; i++) { + mu[i] = new Array(matrix.length); + mu[i][i] = -sum; + for (var j = 0; j < i; j++) { + mu[i][j] = 0; + } + for (var j = i+1; j < matrix.length; j++) { + mu[i][j] = matrix[i][j]; + } + if (i+1 < matrix.length) { + sum -= matrix[i+1][i+1]; } } - if (i != r) { - // Swap rows i and r, which negates the determinant. - for (a = 0; a < cols; a++) { - var temp = matrix[i][a]; - matrix[i][a] = matrix[r][a]; - matrix[r][a] = temp; - } - d *= -1; - } - // Scale row r and the determinant simultaneously. - var div = matrix[r][lead]; - for (a = 0; a < cols; a++) { - matrix[r][a] = matrix[r][a] / div; - } - d *= div; - // Back-substitute upwards. - for (var j = 0; j < rows; j++) { - if (j != r) { - // Taking linear combinations does not change the det. - var c = matrix[j][lead]; - for (a = 0; a < cols; a++) { - matrix[j][a] = matrix[j][a] - matrix[r][a] * c; - } - } - } - lead++; // Now looking for a pivot further right. + return mu; } - - // If reduction did not result in the identity, the matrix is singular. - if (object.deepEqual(matrix, math.eye(rows).valueOf())) { - return math.round(d, 6); // FIXME: should d be rounded to 6 here? + var fa = matrix; + for (var i = 0; i < rows-1; i++) { + fa = math.multiply(compute_mu(fa), matrix); + } + if (rows % 2 == 0) { + return -fa[0][0]; } else { - return 0; + return fa[0][0]; } } } From b7d016b6266b3c0105447cc9c9621639bcd2378d Mon Sep 17 00:00:00 2001 From: josdejong Date: Wed, 9 Apr 2014 08:28:37 +0200 Subject: [PATCH 27/48] Added bignumber support for improved function `det`. --- HISTORY.md | 1 + lib/function/matrix/det.js | 20 +++++++++++++------- test/function/matrix/det.test.js | 11 +++++++++++ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 19c2a7db2..c60e7eceb 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -11,6 +11,7 @@ https://github.com/josdejong/mathjs - Implemented BigNumber support for functions `exp`, `log`, and `log10`. - Implemented conditional operator `a ? b : c` in expression parser. - Improved function `ifElse`, is now specified for special data types too. +- Improved function `det`. Thanks Bryan Cuccioli (@bcuccioli). - Implemented `BigNumber` support for functions `det` and `diag`. - Added unit alias `lbs` (pound mass). - Changed configuration option `decimals` to `precision` (applies to BigNumbers diff --git a/lib/function/matrix/det.js b/lib/function/matrix/det.js index 881d0ae6b..8a460eb1f 100644 --- a/lib/function/matrix/det.js +++ b/lib/function/matrix/det.js @@ -90,7 +90,6 @@ module.exports = function (math) { } else { // this is an n x n matrix - // TODO: support for bignumbers, complex numbers, etc function compute_mu(matrix) { var i, j; @@ -100,29 +99,36 @@ module.exports = function (math) { var mu = new Array(matrix.length); var sum = 0; for (i = 1; i < matrix.length; i++) { - sum += matrix[i][i]; + sum = math.add(sum, matrix[i][i]); } + for (i = 0; i < matrix.length; i++) { mu[i] = new Array(matrix.length); - mu[i][i] = -sum; + mu[i][i] = math.unary(sum); + for (j = 0; j < i; j++) { mu[i][j] = 0; } - for (j = i+1; j < matrix.length; j++) { + + for (j = i + 1; j < matrix.length; j++) { mu[i][j] = matrix[i][j]; } + if (i+1 < matrix.length) { - sum -= matrix[i+1][i+1]; + sum = math.subtract(sum, matrix[i + 1][i + 1]); } } + return mu; } + var fa = matrix; - for (var i = 0; i < rows-1; i++) { + for (var i = 0; i < rows - 1; i++) { fa = math.multiply(compute_mu(fa), matrix); } + if (rows % 2 == 0) { - return -fa[0][0]; + return math.unary(fa[0][0]); } else { return fa[0][0]; } diff --git a/test/function/matrix/det.test.js b/test/function/matrix/det.test.js index c72d97fe4..4c8be218b 100644 --- a/test/function/matrix/det.test.js +++ b/test/function/matrix/det.test.js @@ -81,12 +81,23 @@ describe('det', function() { it('should calculate correctly the determinant of a matrix with bignumbers', function() { var bignumber = math.bignumber; + + // 1x1 assert.deepEqual(math.det([bignumber(5)]), bignumber(5)); + + // 2x2 assert.deepEqual(math.det([ [bignumber(1), bignumber(2)], [bignumber(3), bignumber(4)] ]), bignumber(-2)); + // 3x3 + assert.deepEqual(math.det([ + [bignumber(-2), bignumber(2), bignumber( 3)], + [bignumber(-1), bignumber(1), bignumber( 3)], + [bignumber( 2), bignumber(0), bignumber(-1)] + ]), bignumber(6)); + // the following would fail with regular Numbers due to a precision overflow assert.deepEqual(math.det([ [bignumber(1e10+1), bignumber(1e10)], From 922ce679e64b864f718bc5dbdbce22fc3a6dbc17 Mon Sep 17 00:00:00 2001 From: josdejong Date: Fri, 11 Apr 2014 17:44:55 +0200 Subject: [PATCH 28/48] Moved UnsupportedTypeError to the others, and made it independent of the math namespace --- lib/function/arithmetic/abs.js | 2 +- lib/function/arithmetic/add.js | 2 +- lib/function/arithmetic/ceil.js | 2 +- lib/function/arithmetic/compare.js | 2 +- lib/function/arithmetic/cube.js | 2 +- lib/function/arithmetic/divide.js | 2 +- lib/function/arithmetic/equal.js | 2 +- lib/function/arithmetic/exp.js | 2 +- lib/function/arithmetic/fix.js | 2 +- lib/function/arithmetic/floor.js | 2 +- lib/function/arithmetic/gcd.js | 2 +- lib/function/arithmetic/larger.js | 2 +- lib/function/arithmetic/largereq.js | 2 +- lib/function/arithmetic/lcm.js | 2 +- lib/function/arithmetic/log.js | 2 +- lib/function/arithmetic/log10.js | 2 +- lib/function/arithmetic/mod.js | 2 +- lib/function/arithmetic/multiply.js | 2 +- lib/function/arithmetic/pow.js | 2 +- lib/function/arithmetic/round.js | 4 +- lib/function/arithmetic/sign.js | 2 +- lib/function/arithmetic/smaller.js | 2 +- lib/function/arithmetic/smallereq.js | 2 +- lib/function/arithmetic/sqrt.js | 2 +- lib/function/arithmetic/square.js | 2 +- lib/function/arithmetic/subtract.js | 2 +- lib/function/arithmetic/unary.js | 2 +- lib/function/arithmetic/unequal.js | 2 +- lib/function/arithmetic/xgcd.js | 2 +- lib/function/complex/arg.js | 2 +- lib/function/construction/bignumber.js | 2 +- lib/function/construction/number.js | 2 +- lib/function/matrix/concat.js | 2 +- lib/function/matrix/size.js | 2 +- lib/function/matrix/subset.js | 4 +- lib/function/probability/combinations.js | 2 +- lib/function/probability/factorial.js | 2 +- lib/function/probability/permutations.js | 2 +- lib/function/probability/random.js | 2 +- lib/function/statistics/median.js | 6 +-- lib/function/trigonometry/acos.js | 2 +- lib/function/trigonometry/asin.js | 2 +- lib/function/trigonometry/atan.js | 2 +- lib/function/trigonometry/atan2.js | 2 +- lib/function/trigonometry/cos.js | 2 +- lib/function/trigonometry/cot.js | 2 +- lib/function/trigonometry/csc.js | 2 +- lib/function/trigonometry/sec.js | 2 +- lib/function/trigonometry/sin.js | 2 +- lib/function/trigonometry/tan.js | 2 +- lib/function/units/to.js | 2 +- lib/function/utils/forEach.js | 2 +- lib/function/utils/ifElse.js | 2 +- lib/function/utils/map.js | 2 +- lib/math.js | 6 +-- lib/type/error.js | 53 ------------------------ lib/util/error.js | 45 +++++++++++++++++++- test/math.test.js | 8 ++++ test/type/error.test.js | 51 ----------------------- test/util/error.test.js | 43 +++++++++++++++++++ 60 files changed, 156 insertions(+), 166 deletions(-) delete mode 100644 lib/type/error.js delete mode 100644 test/type/error.test.js diff --git a/lib/function/arithmetic/abs.js b/lib/function/arithmetic/abs.js index 3465db2d2..37d06ff1a 100644 --- a/lib/function/arithmetic/abs.js +++ b/lib/function/arithmetic/abs.js @@ -46,6 +46,6 @@ module.exports = function (math) { return Math.abs(x); } - throw new math.error.UnsupportedTypeError('abs', x); + throw new math.error.UnsupportedTypeError('abs', math['typeof'](x)); }; }; diff --git a/lib/function/arithmetic/add.js b/lib/function/arithmetic/add.js index b6fbabd32..6743f9f2f 100644 --- a/lib/function/arithmetic/add.js +++ b/lib/function/arithmetic/add.js @@ -131,6 +131,6 @@ module.exports = function (math) { return add(x, +y); } - throw new math.error.UnsupportedTypeError('add', x, y); + throw new math.error.UnsupportedTypeError('add', math['typeof'](x), math['typeof'](y)); }; }; diff --git a/lib/function/arithmetic/ceil.js b/lib/function/arithmetic/ceil.js index b37e1c574..291ec4b26 100644 --- a/lib/function/arithmetic/ceil.js +++ b/lib/function/arithmetic/ceil.js @@ -48,6 +48,6 @@ module.exports = function (math) { return Math.ceil(x); } - throw new math.error.UnsupportedTypeError('ceil', x); + throw new math.error.UnsupportedTypeError('ceil', math['typeof'](x)); }; }; diff --git a/lib/function/arithmetic/compare.js b/lib/function/arithmetic/compare.js index 38de2e95e..9e610d34b 100644 --- a/lib/function/arithmetic/compare.js +++ b/lib/function/arithmetic/compare.js @@ -93,6 +93,6 @@ module.exports = function (math) { throw new TypeError('No ordering relation is defined for complex numbers'); } - throw new math.error.UnsupportedTypeError('compare', x, y); + throw new math.error.UnsupportedTypeError('compare', math['typeof'](x), math['typeof'](y)); }; }; diff --git a/lib/function/arithmetic/cube.js b/lib/function/arithmetic/cube.js index 47ae041ba..f54e91902 100644 --- a/lib/function/arithmetic/cube.js +++ b/lib/function/arithmetic/cube.js @@ -46,6 +46,6 @@ module.exports = function (math) { return cube(+x); } - throw new math.error.UnsupportedTypeError('cube', x); + throw new math.error.UnsupportedTypeError('cube', math['typeof'](x)); }; }; diff --git a/lib/function/arithmetic/divide.js b/lib/function/arithmetic/divide.js index 77835a1ff..e8978a1fb 100644 --- a/lib/function/arithmetic/divide.js +++ b/lib/function/arithmetic/divide.js @@ -117,7 +117,7 @@ module.exports = function(math) { return divide(x, +y); } - throw new math.error.UnsupportedTypeError('divide', x, y); + throw new math.error.UnsupportedTypeError('divide', math['typeof'](x), math['typeof'](y)); }; /** diff --git a/lib/function/arithmetic/equal.js b/lib/function/arithmetic/equal.js index 6cd6601b6..00af93473 100644 --- a/lib/function/arithmetic/equal.js +++ b/lib/function/arithmetic/equal.js @@ -106,6 +106,6 @@ module.exports = function (math) { return equal(x, +y); } - throw new math.error.UnsupportedTypeError('equal', x, y); + throw new math.error.UnsupportedTypeError('equal', math['typeof'](x), math['typeof'](y)); }; }; diff --git a/lib/function/arithmetic/exp.js b/lib/function/arithmetic/exp.js index 49872c56b..b5f63838e 100644 --- a/lib/function/arithmetic/exp.js +++ b/lib/function/arithmetic/exp.js @@ -50,6 +50,6 @@ module.exports = function (math) { return Math.exp(x); } - throw new math.error.UnsupportedTypeError('exp', x); + throw new math.error.UnsupportedTypeError('exp', math['typeof'](x)); }; }; diff --git a/lib/function/arithmetic/fix.js b/lib/function/arithmetic/fix.js index b72b5e929..9737150f0 100644 --- a/lib/function/arithmetic/fix.js +++ b/lib/function/arithmetic/fix.js @@ -48,6 +48,6 @@ module.exports = function (math) { return fix(+x); } - throw new math.error.UnsupportedTypeError('fix', x); + throw new math.error.UnsupportedTypeError('fix', math['typeof'](x)); }; }; diff --git a/lib/function/arithmetic/floor.js b/lib/function/arithmetic/floor.js index 8ad823869..6c6a99260 100644 --- a/lib/function/arithmetic/floor.js +++ b/lib/function/arithmetic/floor.js @@ -48,6 +48,6 @@ module.exports = function (math) { return floor(+x); } - throw new math.error.UnsupportedTypeError('floor', x); + throw new math.error.UnsupportedTypeError('floor', math['typeof'](x)); }; }; diff --git a/lib/function/arithmetic/gcd.js b/lib/function/arithmetic/gcd.js index 470b8562d..e077c03fe 100644 --- a/lib/function/arithmetic/gcd.js +++ b/lib/function/arithmetic/gcd.js @@ -63,7 +63,7 @@ module.exports = function (math) { return gcd(a, +b); } - throw new math.error.UnsupportedTypeError('gcd', a, b); + throw new math.error.UnsupportedTypeError('gcd', math['typeof'](a), math['typeof'](b)); } if (arguments.length > 2) { diff --git a/lib/function/arithmetic/larger.js b/lib/function/arithmetic/larger.js index d86750928..3f5212b78 100644 --- a/lib/function/arithmetic/larger.js +++ b/lib/function/arithmetic/larger.js @@ -95,6 +95,6 @@ module.exports = function (math) { throw new TypeError('No ordering relation is defined for complex numbers'); } - throw new math.error.UnsupportedTypeError('larger', x, y); + throw new math.error.UnsupportedTypeError('larger', math['typeof'](x), math['typeof'](y)); }; }; diff --git a/lib/function/arithmetic/largereq.js b/lib/function/arithmetic/largereq.js index 0abf44be1..b3bc0dc9f 100644 --- a/lib/function/arithmetic/largereq.js +++ b/lib/function/arithmetic/largereq.js @@ -95,6 +95,6 @@ module.exports = function (math) { throw new TypeError('No ordering relation is defined for complex numbers'); } - throw new math.error.UnsupportedTypeError('largereq', x, y); + throw new math.error.UnsupportedTypeError('largereq', math['typeof'](x), math['typeof'](y)); }; }; diff --git a/lib/function/arithmetic/lcm.js b/lib/function/arithmetic/lcm.js index f74e2ff60..591773e32 100644 --- a/lib/function/arithmetic/lcm.js +++ b/lib/function/arithmetic/lcm.js @@ -72,7 +72,7 @@ module.exports = function (math) { return lcm(a, b.toNumber()); } - throw new math.error.UnsupportedTypeError('lcm', a, b); + throw new math.error.UnsupportedTypeError('lcm', math['typeof'](a), math['typeof'](b)); } if (arguments.length > 2) { diff --git a/lib/function/arithmetic/log.js b/lib/function/arithmetic/log.js index 0c8a27215..f2ebd1c2d 100644 --- a/lib/function/arithmetic/log.js +++ b/lib/function/arithmetic/log.js @@ -55,7 +55,7 @@ module.exports = function (math) { return log(+x); } - throw new math.error.UnsupportedTypeError('log', x); + throw new math.error.UnsupportedTypeError('log', math['typeof'](x)); } else if (arguments.length == 2) { // calculate logarithm for a specified base, log(x, base) diff --git a/lib/function/arithmetic/log10.js b/lib/function/arithmetic/log10.js index 0e56ea189..5cfc9e8e1 100644 --- a/lib/function/arithmetic/log10.js +++ b/lib/function/arithmetic/log10.js @@ -54,6 +54,6 @@ module.exports = function (math) { return log10(+x); } - throw new math.error.UnsupportedTypeError('log10', x); + throw new math.error.UnsupportedTypeError('log10', math['typeof'](x)); }; }; diff --git a/lib/function/arithmetic/mod.js b/lib/function/arithmetic/mod.js index 8943ca326..057ecec05 100644 --- a/lib/function/arithmetic/mod.js +++ b/lib/function/arithmetic/mod.js @@ -80,7 +80,7 @@ module.exports = function (math) { return mod(x, +y); } - throw new math.error.UnsupportedTypeError('mod', x, y); + throw new math.error.UnsupportedTypeError('mod', math['typeof'](x), math['typeof'](y)); }; /** diff --git a/lib/function/arithmetic/multiply.js b/lib/function/arithmetic/multiply.js index a256c2877..4655049b6 100644 --- a/lib/function/arithmetic/multiply.js +++ b/lib/function/arithmetic/multiply.js @@ -208,7 +208,7 @@ module.exports = function(math) { return multiply(x, +y); } - throw new math.error.UnsupportedTypeError('multiply', x, y); + throw new math.error.UnsupportedTypeError('multiply', math['typeof'](x), math['typeof'](y)); }; /** diff --git a/lib/function/arithmetic/pow.js b/lib/function/arithmetic/pow.js index 17d7b17d5..41f293b6a 100644 --- a/lib/function/arithmetic/pow.js +++ b/lib/function/arithmetic/pow.js @@ -125,7 +125,7 @@ module.exports = function (math) { return pow(x, +y); } - throw new math.error.UnsupportedTypeError('pow', x, y); + throw new math.error.UnsupportedTypeError('pow', math['typeof'](x), math['typeof'](y)); }; /** diff --git a/lib/function/arithmetic/round.js b/lib/function/arithmetic/round.js index ff88f4e2a..af7f5fbbe 100644 --- a/lib/function/arithmetic/round.js +++ b/lib/function/arithmetic/round.js @@ -54,7 +54,7 @@ module.exports = function (math) { return Math.round(x); } - throw new math.error.UnsupportedTypeError('round', x); + throw new math.error.UnsupportedTypeError('round', math['typeof'](x)); } else { // round (x, n) @@ -96,7 +96,7 @@ module.exports = function (math) { return round(+x, n); } - throw new math.error.UnsupportedTypeError('round', x, n); + throw new math.error.UnsupportedTypeError('round', math['typeof'](x), math['typeof'](n)); } }; diff --git a/lib/function/arithmetic/sign.js b/lib/function/arithmetic/sign.js index b9ac54961..eb35e1ece 100644 --- a/lib/function/arithmetic/sign.js +++ b/lib/function/arithmetic/sign.js @@ -48,6 +48,6 @@ module.exports = function (math) { return number.sign(x); } - throw new math.error.UnsupportedTypeError('sign', x); + throw new math.error.UnsupportedTypeError('sign', math['typeof'](x)); }; }; diff --git a/lib/function/arithmetic/smaller.js b/lib/function/arithmetic/smaller.js index a2bac4a94..d19b187b0 100644 --- a/lib/function/arithmetic/smaller.js +++ b/lib/function/arithmetic/smaller.js @@ -95,6 +95,6 @@ module.exports = function (math) { throw new TypeError('No ordering relation is defined for complex numbers'); } - throw new math.error.UnsupportedTypeError('smaller', x, y); + throw new math.error.UnsupportedTypeError('smaller', math['typeof'](x), math['typeof'](y)); }; }; diff --git a/lib/function/arithmetic/smallereq.js b/lib/function/arithmetic/smallereq.js index 7aad7277f..a0173a59c 100644 --- a/lib/function/arithmetic/smallereq.js +++ b/lib/function/arithmetic/smallereq.js @@ -95,6 +95,6 @@ module.exports = function (math) { throw new TypeError('No ordering relation is defined for complex numbers'); } - throw new math.error.UnsupportedTypeError('smallereq', x, y); + throw new math.error.UnsupportedTypeError('smallereq', math['typeof'](x), math['typeof'](y)); }; }; diff --git a/lib/function/arithmetic/sqrt.js b/lib/function/arithmetic/sqrt.js index 8c0a51d45..bedd8f77b 100644 --- a/lib/function/arithmetic/sqrt.js +++ b/lib/function/arithmetic/sqrt.js @@ -62,6 +62,6 @@ module.exports = function (math) { return sqrt(+x); } - throw new math.error.UnsupportedTypeError('sqrt', x); + throw new math.error.UnsupportedTypeError('sqrt', math['typeof'](x)); }; }; diff --git a/lib/function/arithmetic/square.js b/lib/function/arithmetic/square.js index c6d844098..1e8f97a8e 100644 --- a/lib/function/arithmetic/square.js +++ b/lib/function/arithmetic/square.js @@ -46,6 +46,6 @@ module.exports = function (math) { return x * x; } - throw new math.error.UnsupportedTypeError('square', x); + throw new math.error.UnsupportedTypeError('square', math['typeof'](x)); }; }; diff --git a/lib/function/arithmetic/subtract.js b/lib/function/arithmetic/subtract.js index cb8a170e2..c4fe0af8a 100644 --- a/lib/function/arithmetic/subtract.js +++ b/lib/function/arithmetic/subtract.js @@ -126,6 +126,6 @@ module.exports = function (math) { return subtract(x, +y); } - throw new math.error.UnsupportedTypeError('subtract', x, y); + throw new math.error.UnsupportedTypeError('subtract', math['typeof'](x), math['typeof'](y)); }; }; diff --git a/lib/function/arithmetic/unary.js b/lib/function/arithmetic/unary.js index 42786e321..5cf7a0667 100644 --- a/lib/function/arithmetic/unary.js +++ b/lib/function/arithmetic/unary.js @@ -57,6 +57,6 @@ module.exports = function (math) { return -x; } - throw new math.error.UnsupportedTypeError('unary', x); + throw new math.error.UnsupportedTypeError('unary', math['typeof'](x)); }; }; diff --git a/lib/function/arithmetic/unequal.js b/lib/function/arithmetic/unequal.js index 32012f5bf..b98c40c31 100644 --- a/lib/function/arithmetic/unequal.js +++ b/lib/function/arithmetic/unequal.js @@ -100,6 +100,6 @@ module.exports = function (math) { return unequal(x, +y); } - throw new math.error.UnsupportedTypeError('unequal', x, y); + throw new math.error.UnsupportedTypeError('unequal', math['typeof'](x), math['typeof'](y)); }; }; diff --git a/lib/function/arithmetic/xgcd.js b/lib/function/arithmetic/xgcd.js index 86200c1c7..f68f7df9d 100644 --- a/lib/function/arithmetic/xgcd.js +++ b/lib/function/arithmetic/xgcd.js @@ -47,7 +47,7 @@ module.exports = function (math) { return xgcd(a, +b); } - throw new math.error.UnsupportedTypeError('xgcd', a, b); + throw new math.error.UnsupportedTypeError('xgcd', math['typeof'](a), math['typeof'](b)); } // zero or one argument diff --git a/lib/function/complex/arg.js b/lib/function/complex/arg.js index 96a73b6f8..cb95aa50b 100644 --- a/lib/function/complex/arg.js +++ b/lib/function/complex/arg.js @@ -48,6 +48,6 @@ module.exports = function (math) { return arg(x.toNumber()); } - throw new math.error.UnsupportedTypeError('arg', x); + throw new math.error.UnsupportedTypeError('arg', math['typeof'](x)); }; }; diff --git a/lib/function/construction/bignumber.js b/lib/function/construction/bignumber.js index 359376024..b22b2253d 100644 --- a/lib/function/construction/bignumber.js +++ b/lib/function/construction/bignumber.js @@ -39,6 +39,6 @@ module.exports = function (math) { return new BigNumber(0); } - throw new math.error.UnsupportedTypeError('bignumber', value); + throw new math.error.UnsupportedTypeError('bignumber', math['typeof'](value)); }; }; diff --git a/lib/function/construction/number.js b/lib/function/construction/number.js index d9cfb3aaf..b92f326fc 100644 --- a/lib/function/construction/number.js +++ b/lib/function/construction/number.js @@ -48,7 +48,7 @@ module.exports = function (math) { return value; } - throw new math.error.UnsupportedTypeError('number', value); + throw new math.error.UnsupportedTypeError('number', math['typeof'](value)); default: throw new util.error.ArgumentsError('number', arguments.length, 0, 1); diff --git a/lib/function/matrix/concat.js b/lib/function/matrix/concat.js index 4b8b0898a..eac6e5b0f 100644 --- a/lib/function/matrix/concat.js +++ b/lib/function/matrix/concat.js @@ -66,7 +66,7 @@ module.exports = function (math) { } } else { - throw new math.error.UnsupportedTypeError('concat', arg); + throw new math.error.UnsupportedTypeError('concat', math['typeof'](arg)); } } diff --git a/lib/function/matrix/size.js b/lib/function/matrix/size.js index 908d87e2e..d2938a30f 100644 --- a/lib/function/matrix/size.js +++ b/lib/function/matrix/size.js @@ -45,6 +45,6 @@ module.exports = function (math, config) { return new Matrix(x.size()); } - throw new math.error.UnsupportedTypeError('size', x); + throw new math.error.UnsupportedTypeError('size', math['typeof'](x)); }; }; diff --git a/lib/function/matrix/subset.js b/lib/function/matrix/subset.js index 38599a32d..e7d75ced6 100644 --- a/lib/function/matrix/subset.js +++ b/lib/function/matrix/subset.js @@ -67,7 +67,7 @@ module.exports = function (math) { return _getSubstring(value, index); } else { - throw new math.error.UnsupportedTypeError('subset', value); + throw new math.error.UnsupportedTypeError('subset', math['typeof'](value)); } } @@ -126,7 +126,7 @@ module.exports = function (math) { return _setSubstring(value, index, replacement, defaultValue); } else { - throw new math.error.UnsupportedTypeError('subset', value); + throw new math.error.UnsupportedTypeError('subset', math['typeof'](value)); } } diff --git a/lib/function/probability/combinations.js b/lib/function/probability/combinations.js index 9a24c4f9c..59532511d 100644 --- a/lib/function/probability/combinations.js +++ b/lib/function/probability/combinations.js @@ -64,7 +64,7 @@ module.exports = function (math) { return result; } - throw new math.error.UnsupportedTypeError('combinations', n); + throw new math.error.UnsupportedTypeError('combinations', math['typeof'](n)); }; /** diff --git a/lib/function/probability/factorial.js b/lib/function/probability/factorial.js index 5759c9f02..7142008e0 100644 --- a/lib/function/probability/factorial.js +++ b/lib/function/probability/factorial.js @@ -76,7 +76,7 @@ module.exports = function (math) { return collection.deepMap(n, factorial); } - throw new math.error.UnsupportedTypeError('factorial', n); + throw new math.error.UnsupportedTypeError('factorial', math['typeof'](n)); }; /** diff --git a/lib/function/probability/permutations.js b/lib/function/probability/permutations.js index 89d7ab4dd..02509582f 100644 --- a/lib/function/probability/permutations.js +++ b/lib/function/probability/permutations.js @@ -79,7 +79,7 @@ module.exports = function (math) { return result; } - throw new math.error.UnsupportedTypeError('permutations', n); + throw new math.error.UnsupportedTypeError('permutations', math['typeof'](n)); }; /** diff --git a/lib/function/probability/random.js b/lib/function/probability/random.js index 48c40a1e6..ec78d98a6 100644 --- a/lib/function/probability/random.js +++ b/lib/function/probability/random.js @@ -131,7 +131,7 @@ module.exports = function (math, config) { throw new util.error.ArgumentsError('pickRandom', arguments.length, 1); } if (!Array.isArray(possibles)) { - throw new math.error.UnsupportedTypeError('pickRandom', possibles); + throw new math.error.UnsupportedTypeError('pickRandom', math['typeof'](possibles)); } // TODO: add support for matrices diff --git a/lib/function/statistics/median.js b/lib/function/statistics/median.js index cf1e4dff6..6e7ce8af3 100644 --- a/lib/function/statistics/median.js +++ b/lib/function/statistics/median.js @@ -73,10 +73,10 @@ module.exports = function (math) { var right = flat[num / 2]; if (!isNumber(left) && !(left instanceof BigNumber) && !(left instanceof Unit)) { - throw new math.error.UnsupportedTypeError('median', left); + throw new math.error.UnsupportedTypeError('median', math['typeof'](left)); } if (!isNumber(right) && !(right instanceof BigNumber) && !(right instanceof Unit)) { - throw new math.error.UnsupportedTypeError('median', right); + throw new math.error.UnsupportedTypeError('median', math['typeof'](right)); } return math.divide(math.add(left, right), 2); @@ -86,7 +86,7 @@ module.exports = function (math) { var middle = flat[(num - 1) / 2]; if (!isNumber(middle) && !(middle instanceof BigNumber) && !(middle instanceof Unit)) { - throw new math.error.UnsupportedTypeError('median', middle); + throw new math.error.UnsupportedTypeError('median', math['typeof'](middle)); } return middle; diff --git a/lib/function/trigonometry/acos.js b/lib/function/trigonometry/acos.js index bcb7a8b40..997db5c67 100644 --- a/lib/function/trigonometry/acos.js +++ b/lib/function/trigonometry/acos.js @@ -70,6 +70,6 @@ module.exports = function (math) { return acos(x.toNumber()); } - throw new math.error.UnsupportedTypeError('acos', x); + throw new math.error.UnsupportedTypeError('acos', math['typeof'](x)); }; }; diff --git a/lib/function/trigonometry/asin.js b/lib/function/trigonometry/asin.js index 00ea94459..2ab08f488 100644 --- a/lib/function/trigonometry/asin.js +++ b/lib/function/trigonometry/asin.js @@ -68,6 +68,6 @@ module.exports = function (math) { return asin(x.toNumber()); } - throw new math.error.UnsupportedTypeError('asin', x); + throw new math.error.UnsupportedTypeError('asin', math['typeof'](x)); }; }; diff --git a/lib/function/trigonometry/atan.js b/lib/function/trigonometry/atan.js index 2787de909..c21e12f84 100644 --- a/lib/function/trigonometry/atan.js +++ b/lib/function/trigonometry/atan.js @@ -63,6 +63,6 @@ module.exports = function (math) { return atan(x.toNumber()); } - throw new math.error.UnsupportedTypeError('atan', x); + throw new math.error.UnsupportedTypeError('atan', math['typeof'](x)); }; }; diff --git a/lib/function/trigonometry/atan2.js b/lib/function/trigonometry/atan2.js index f9770153f..29df91739 100644 --- a/lib/function/trigonometry/atan2.js +++ b/lib/function/trigonometry/atan2.js @@ -55,6 +55,6 @@ module.exports = function (math) { return atan2(y, x.toNumber()); } - throw new math.error.UnsupportedTypeError('atan2', y, x); + throw new math.error.UnsupportedTypeError('atan2', math['typeof'](y), math['typeof'](x)); }; }; diff --git a/lib/function/trigonometry/cos.js b/lib/function/trigonometry/cos.js index 9d90861b8..ea420748f 100644 --- a/lib/function/trigonometry/cos.js +++ b/lib/function/trigonometry/cos.js @@ -62,6 +62,6 @@ module.exports = function (math) { return cos(x.toNumber()); } - throw new math.error.UnsupportedTypeError('cos', x); + throw new math.error.UnsupportedTypeError('cos', math['typeof'](x)); }; }; diff --git a/lib/function/trigonometry/cot.js b/lib/function/trigonometry/cot.js index fe879aa8c..ed37866db 100644 --- a/lib/function/trigonometry/cot.js +++ b/lib/function/trigonometry/cot.js @@ -62,6 +62,6 @@ module.exports = function (math) { return cot(x.toNumber()); } - throw new math.error.UnsupportedTypeError('cot', x); + throw new math.error.UnsupportedTypeError('cot', math['typeof'](x)); }; }; diff --git a/lib/function/trigonometry/csc.js b/lib/function/trigonometry/csc.js index 0175eeeda..4a9d9150c 100644 --- a/lib/function/trigonometry/csc.js +++ b/lib/function/trigonometry/csc.js @@ -63,6 +63,6 @@ module.exports = function (math) { return csc(x.toNumber()); } - throw new math.error.UnsupportedTypeError('csc', x); + throw new math.error.UnsupportedTypeError('csc', math['typeof'](x)); }; }; diff --git a/lib/function/trigonometry/sec.js b/lib/function/trigonometry/sec.js index df5e66548..94b3ee515 100644 --- a/lib/function/trigonometry/sec.js +++ b/lib/function/trigonometry/sec.js @@ -63,6 +63,6 @@ module.exports = function (math) { return sec(x.toNumber()); } - throw new math.error.UnsupportedTypeError('sec', x); + throw new math.error.UnsupportedTypeError('sec', math['typeof'](x)); }; }; diff --git a/lib/function/trigonometry/sin.js b/lib/function/trigonometry/sin.js index 0ba4cfce3..f9390cc9c 100644 --- a/lib/function/trigonometry/sin.js +++ b/lib/function/trigonometry/sin.js @@ -61,6 +61,6 @@ module.exports = function (math) { return sin(x.toNumber()); } - throw new math.error.UnsupportedTypeError('sin', x); + throw new math.error.UnsupportedTypeError('sin', math['typeof'](x)); }; }; diff --git a/lib/function/trigonometry/tan.js b/lib/function/trigonometry/tan.js index aee5c1e2b..1f298e063 100644 --- a/lib/function/trigonometry/tan.js +++ b/lib/function/trigonometry/tan.js @@ -65,6 +65,6 @@ module.exports = function (math) { return tan(x.toNumber()); } - throw new math.error.UnsupportedTypeError('tan', x); + throw new math.error.UnsupportedTypeError('tan', math['typeof'](x)); }; }; diff --git a/lib/function/units/to.js b/lib/function/units/to.js index 153ebcd02..3aa5431a9 100644 --- a/lib/function/units/to.js +++ b/lib/function/units/to.js @@ -37,6 +37,6 @@ module.exports = function (math) { return collection.deepMap2(x, unit, to); } - throw new math.error.UnsupportedTypeError('to', x, unit); + throw new math.error.UnsupportedTypeError('to', math['typeof'](x), math['typeof'](unit)); }; }; diff --git a/lib/function/utils/forEach.js b/lib/function/utils/forEach.js index e298f4f76..233532f8b 100644 --- a/lib/function/utils/forEach.js +++ b/lib/function/utils/forEach.js @@ -18,7 +18,7 @@ module.exports = function (math) { } else if (isMatrix(x)) { return x.forEach(callback); } else { - throw new math.error.UnsupportedTypeError('forEach', x); + throw new math.error.UnsupportedTypeError('forEach', math['typeof'](x)); } }; diff --git a/lib/function/utils/ifElse.js b/lib/function/utils/ifElse.js index 55fd14166..7b9529f30 100644 --- a/lib/function/utils/ifElse.js +++ b/lib/function/utils/ifElse.js @@ -61,7 +61,7 @@ module.exports = function (math) { return _ifElseCollection(condition, trueExpr, falseExpr); } - throw new math.error.UnsupportedTypeError('ifElse', condition); + throw new math.error.UnsupportedTypeError('ifElse', math['typeof'](condition)); }; /** diff --git a/lib/function/utils/map.js b/lib/function/utils/map.js index 3f1bcb0f6..e000b3911 100644 --- a/lib/function/utils/map.js +++ b/lib/function/utils/map.js @@ -20,7 +20,7 @@ module.exports = function (math) { } else if (isMatrix(x)) { return x.map(callback); } else { - throw new math.error.UnsupportedTypeError('map', x); + throw new math.error.UnsupportedTypeError('map', math['typeof'](x)); } }; diff --git a/lib/math.js b/lib/math.js index 7eeacf3e9..f7fc426fe 100644 --- a/lib/math.js +++ b/lib/math.js @@ -128,6 +128,9 @@ function mathjs (config) { throw new Error('Cannot add function convert to BigNumber: function already exists'); } + // errors + math.error = require('./util/error'); + // types (Matrix, Complex, Unit, ...) math.type = {}; math.type.Complex = require('./type/Complex'); @@ -150,9 +153,6 @@ function mathjs (config) { math.expression.Parser = require('./expression/Parser.js'); math.expression.docs = require('./expression/docs/index.js'); - // error utility functions - require('./type/error')(math); - // expression parser require('./function/expression/compile.js')(math, _config); require('./function/expression/eval.js')(math, _config); diff --git a/lib/type/error.js b/lib/type/error.js deleted file mode 100644 index 94d0ef0ed..000000000 --- a/lib/type/error.js +++ /dev/null @@ -1,53 +0,0 @@ -module.exports = function (math) { - var types = require('./../util/types'); - - // export the error constructors to namespace math.error.* - var error = {}; - math.error = error; - - /** - * Create a TypeError with message: - * 'Function does not support a parameter of type '; - * @param {String} name Function name - * @param {*} [value1] - * @param {*...} [value_n] - * @extends TypeError - */ - // TODO: rename UnsupportedTypeError to TypeError? - // TODO: move UnsupportedTypeError to lib/util/ - error.UnsupportedTypeError = function UnsupportedTypeError(name, value1, value_n) { - if (!(this instanceof UnsupportedTypeError)) { - throw new SyntaxError('Constructor must be called with the new operator'); - } - - switch (arguments.length) { - case 0: - this.message = 'Unsupported type of argument'; - break; - - case 1: - this.message = 'Unsupported type of argument in function ' + name; - break; - - case 2: - var type1 = math['typeof'](value1); - this.message = 'Function ' + name + '(' + type1 + ') not supported'; - break; - - default: // more than two arguments - var values = Array.prototype.splice.call(arguments, 1); - var types = values.map(function (value) { - return math['typeof'](value); - }); - this.message = 'Function ' + name + '(' + types.join(', ') + ') not supported'; - break; - } - - this.stack = (new Error()).stack; - }; - - error.UnsupportedTypeError.prototype = new TypeError(); - error.UnsupportedTypeError.prototype.constructor = TypeError; - error.UnsupportedTypeError.prototype.name = 'UnsupportedTypeError'; - -}; \ No newline at end of file diff --git a/lib/util/error.js b/lib/util/error.js index ab3a5d186..c76c1cd1d 100644 --- a/lib/util/error.js +++ b/lib/util/error.js @@ -1,3 +1,4 @@ +// TODO: put each of the errors in a separate files /** * Create a syntax error with the message: @@ -103,5 +104,47 @@ IndexError.prototype.name = 'IndexError'; exports.IndexError = IndexError; +/** + * Create a TypeError with message: + * 'Function does not support a parameter of type '; + * @param {String} name Function name + * @param {*} [type1] + * @param {*...} [type_n] + * @extends TypeError + */ +function UnsupportedTypeError(name, type1, type_n) { + if (!(this instanceof UnsupportedTypeError)) { + throw new SyntaxError('Constructor must be called with the new operator'); + } -// TODO: implement a InvalidValueError? + switch (arguments.length) { + case 0: + this.message = 'Unsupported type of argument'; + break; + + case 1: + this.message = 'Unsupported type of argument in function ' + name; + break; + + case 2: + this.message = 'Function ' + name + '(' + type1 + ') not supported'; + break; + + default: // more than two arguments + var types = Array.prototype.splice.call(arguments, 1); + this.message = 'Function ' + name + '(' + types.join(', ') + ') not supported'; + break; + } + + this.stack = (new Error()).stack; +} + +UnsupportedTypeError.prototype = new TypeError(); +UnsupportedTypeError.prototype.constructor = TypeError; +UnsupportedTypeError.prototype.name = 'UnsupportedTypeError'; + +exports.UnsupportedTypeError = UnsupportedTypeError; + + + +// TODO: implement an InvalidValueError? diff --git a/test/math.test.js b/test/math.test.js index a69b142dd..970c4a7e2 100644 --- a/test/math.test.js +++ b/test/math.test.js @@ -71,6 +71,14 @@ describe('factory', function() { }); + it('should contain error namespace', function() { + assert.equal (typeof math.error, 'object'); + assert('ArgumentsError' in math.error); + assert('DimensionError' in math.error); + assert('IndexError' in math.error); + assert('UnsupportedTypeError' in math.error); + }); + it('should convert a number into a bignumber (when possible)', function() { var BigNumber = math.type.BigNumber; diff --git a/test/type/error.test.js b/test/type/error.test.js deleted file mode 100644 index 73a983da9..000000000 --- a/test/type/error.test.js +++ /dev/null @@ -1,51 +0,0 @@ -// test error types - -var assert = require('assert'), - math = require('../../index')(); - -describe('error', function () { - - describe('UnsupportedTypeError', function () { - - it('should construct an UnsupportedTypeError with no argument', function () { - var err = new math.error.UnsupportedTypeError(); - assert(err instanceof Error); - assert(err instanceof math.error.UnsupportedTypeError); - assert.equal(err.toString(), 'UnsupportedTypeError: Unsupported type of argument'); - }); - - it('should construct an UnsupportedTypeError with one argument', function () { - var err = new math.error.UnsupportedTypeError('myfunction'); - assert(err instanceof Error); - assert(err instanceof math.error.UnsupportedTypeError); - assert.equal(err.toString(), 'UnsupportedTypeError: Unsupported type of argument in function myfunction'); - }); - - it('should construct an UnsupportedTypeError with two arguments', function () { - var err = new math.error.UnsupportedTypeError('myfunction', 2); - assert(err instanceof Error); - assert(err instanceof math.error.UnsupportedTypeError); - assert.equal(err.toString(), 'UnsupportedTypeError: Function myfunction(number) not supported'); - }); - - it('should construct an UnsupportedTypeError with three arguments', function () { - var err = new math.error.UnsupportedTypeError('myfunction', 2, 'hi'); - assert(err instanceof Error); - assert(err instanceof math.error.UnsupportedTypeError); - assert.equal(err.toString(), 'UnsupportedTypeError: Function myfunction(number, string) not supported'); - }); - - it('should construct an UnsupportedTypeError with more than three arguments', function () { - var err = new math.error.UnsupportedTypeError('myfunction', 2, 'hi', new Date()); - assert(err instanceof Error); - assert(err instanceof math.error.UnsupportedTypeError); - assert.equal(err.toString(), 'UnsupportedTypeError: Function myfunction(number, string, date) not supported'); - }); - - it('should throw an error when operator new is missing', function () { - assert.throws(function () {math.error.UnsupportedTypeError();}, SyntaxError); - }); - - }); - -}); diff --git a/test/util/error.test.js b/test/util/error.test.js index 0bd447c25..0ffbec91d 100644 --- a/test/util/error.test.js +++ b/test/util/error.test.js @@ -111,4 +111,47 @@ describe('error', function () { }); + describe('UnsupportedTypeError', function () { + + it('should construct an UnsupportedTypeError with no argument', function () { + var err = new error.UnsupportedTypeError(); + assert(err instanceof Error); + assert(err instanceof error.UnsupportedTypeError); + assert.equal(err.toString(), 'UnsupportedTypeError: Unsupported type of argument'); + }); + + it('should construct an UnsupportedTypeError with one argument', function () { + var err = new error.UnsupportedTypeError('myfunction'); + assert(err instanceof Error); + assert(err instanceof error.UnsupportedTypeError); + assert.equal(err.toString(), 'UnsupportedTypeError: Unsupported type of argument in function myfunction'); + }); + + it('should construct an UnsupportedTypeError with two arguments', function () { + var err = new error.UnsupportedTypeError('myfunction', 'number'); + assert(err instanceof Error); + assert(err instanceof error.UnsupportedTypeError); + assert.equal(err.toString(), 'UnsupportedTypeError: Function myfunction(number) not supported'); + }); + + it('should construct an UnsupportedTypeError with three arguments', function () { + var err = new error.UnsupportedTypeError('myfunction', 'number', 'string'); + assert(err instanceof Error); + assert(err instanceof error.UnsupportedTypeError); + assert.equal(err.toString(), 'UnsupportedTypeError: Function myfunction(number, string) not supported'); + }); + + it('should construct an UnsupportedTypeError with more than three arguments', function () { + var err = new error.UnsupportedTypeError('myfunction', 'number', 'string', 'date'); + assert(err instanceof Error); + assert(err instanceof error.UnsupportedTypeError); + assert.equal(err.toString(), 'UnsupportedTypeError: Function myfunction(number, string, date) not supported'); + }); + + it('should throw an error when operator new is missing', function () { + assert.throws(function () {error.UnsupportedTypeError();}, SyntaxError); + }); + + }); + }); From 97cbb0093feb33781d7f4b3d2ab9e0b998508b54 Mon Sep 17 00:00:00 2001 From: josdejong Date: Fri, 11 Apr 2014 18:02:29 +0200 Subject: [PATCH 29/48] Moved errors to their own namespace and folder --- lib/error/ArgumentsError.js | 26 +++ lib/error/DimensionError.js | 32 ++++ lib/error/IndexError.js | 43 +++++ lib/error/UnsupportedTypeError.js | 40 +++++ lib/error/index.js | 6 + lib/expression/node/Node.js | 2 +- lib/function/arithmetic/abs.js | 2 +- lib/function/arithmetic/add.js | 2 +- lib/function/arithmetic/ceil.js | 2 +- lib/function/arithmetic/compare.js | 2 +- lib/function/arithmetic/cube.js | 2 +- lib/function/arithmetic/divide.js | 2 +- lib/function/arithmetic/edivide.js | 2 +- lib/function/arithmetic/emultiply.js | 2 +- lib/function/arithmetic/epow.js | 2 +- lib/function/arithmetic/equal.js | 2 +- lib/function/arithmetic/exp.js | 2 +- lib/function/arithmetic/fix.js | 2 +- lib/function/arithmetic/floor.js | 2 +- lib/function/arithmetic/larger.js | 2 +- lib/function/arithmetic/largereq.js | 2 +- lib/function/arithmetic/log.js | 2 +- lib/function/arithmetic/log10.js | 2 +- lib/function/arithmetic/mod.js | 2 +- lib/function/arithmetic/multiply.js | 2 +- lib/function/arithmetic/pow.js | 2 +- lib/function/arithmetic/round.js | 2 +- lib/function/arithmetic/sign.js | 2 +- lib/function/arithmetic/smaller.js | 2 +- lib/function/arithmetic/smallereq.js | 2 +- lib/function/arithmetic/sqrt.js | 2 +- lib/function/arithmetic/square.js | 2 +- lib/function/arithmetic/subtract.js | 2 +- lib/function/arithmetic/unary.js | 2 +- lib/function/arithmetic/unequal.js | 2 +- lib/function/complex/arg.js | 2 +- lib/function/complex/conj.js | 2 +- lib/function/complex/im.js | 2 +- lib/function/complex/re.js | 2 +- lib/function/construction/bignumber.js | 2 +- lib/function/construction/boolean.js | 2 +- lib/function/construction/complex.js | 2 +- lib/function/construction/matrix.js | 2 +- lib/function/construction/number.js | 2 +- lib/function/construction/string.js | 2 +- lib/function/construction/unit.js | 2 +- lib/function/expression/compile.js | 2 +- lib/function/expression/eval.js | 2 +- lib/function/matrix/concat.js | 6 +- lib/function/matrix/det.js | 2 +- lib/function/matrix/diag.js | 2 +- lib/function/matrix/eye.js | 2 +- lib/function/matrix/inv.js | 2 +- lib/function/matrix/range.js | 2 +- lib/function/matrix/resize.js | 4 +- lib/function/matrix/size.js | 2 +- lib/function/matrix/squeeze.js | 2 +- lib/function/matrix/subset.js | 8 +- lib/function/matrix/transpose.js | 2 +- lib/function/probability/combinations.js | 2 +- lib/function/probability/factorial.js | 2 +- lib/function/probability/permutations.js | 2 +- lib/function/probability/random.js | 6 +- lib/function/trigonometry/acos.js | 2 +- lib/function/trigonometry/asin.js | 2 +- lib/function/trigonometry/atan.js | 2 +- lib/function/trigonometry/atan2.js | 2 +- lib/function/trigonometry/cos.js | 2 +- lib/function/trigonometry/cot.js | 2 +- lib/function/trigonometry/csc.js | 2 +- lib/function/trigonometry/sec.js | 2 +- lib/function/trigonometry/sin.js | 2 +- lib/function/trigonometry/tan.js | 2 +- lib/function/units/to.js | 2 +- lib/function/utils/clone.js | 2 +- lib/function/utils/forEach.js | 2 +- lib/function/utils/format.js | 2 +- lib/function/utils/ifElse.js | 6 +- lib/function/utils/import.js | 2 +- lib/function/utils/map.js | 2 +- lib/function/utils/print.js | 2 +- lib/function/utils/typeof.js | 2 +- lib/math.js | 2 +- lib/type/Matrix.js | 12 +- lib/type/collection.js | 4 +- lib/util/array.js | 16 +- lib/util/error.js | 150 ----------------- lib/util/index.js | 1 - test/error/ArgumentsError.test.js | 26 +++ test/error/DimensionError.test.js | 42 +++++ test/error/IndexError.test.js | 46 +++++ test/error/UnsupportedTypeError.test.js | 45 +++++ test/error/index.test.js | 14 ++ test/function/arithmetic/abs.test.js | 2 +- test/function/arithmetic/add.test.js | 2 +- test/function/arithmetic/ceil.test.js | 2 +- test/function/arithmetic/compare.test.js | 2 +- test/function/arithmetic/cube.test.js | 2 +- test/function/arithmetic/divide.test.js | 2 +- test/function/arithmetic/edivide.test.js | 2 +- test/function/arithmetic/emultiply.test.js | 2 +- test/function/arithmetic/epow.test.js | 2 +- test/function/arithmetic/equal.test.js | 2 +- test/function/arithmetic/exp.test.js | 2 +- test/function/arithmetic/fix.test.js | 2 +- test/function/arithmetic/floor.test.js | 2 +- test/function/arithmetic/gcd.test.js | 2 +- test/function/arithmetic/larger.test.js | 2 +- test/function/arithmetic/largereq.test.js | 2 +- test/function/arithmetic/lcm.test.js | 2 +- test/function/arithmetic/log.test.js | 2 +- test/function/arithmetic/log10.test.js | 2 +- test/function/arithmetic/mod.test.js | 2 +- test/function/arithmetic/multiply.test.js | 2 +- test/function/arithmetic/pow.test.js | 2 +- test/function/arithmetic/round.test.js | 2 +- test/function/arithmetic/sign.test.js | 2 +- test/function/arithmetic/smaller.test.js | 2 +- test/function/arithmetic/smallereq.test.js | 2 +- test/function/arithmetic/sqrt.test.js | 2 +- test/function/arithmetic/square.test.js | 2 +- test/function/arithmetic/subtract.test.js | 2 +- test/function/arithmetic/unary.test.js | 2 +- test/function/arithmetic/unequal.test.js | 2 +- test/function/arithmetic/xgcd.test.js | 2 +- test/function/complex/arg.test.js | 2 +- test/function/complex/conj.test.js | 2 +- test/function/complex/im.test.js | 2 +- test/function/complex/re.test.js | 2 +- test/function/construction/bignumber.test.js | 2 +- test/function/construction/boolean.test.js | 2 +- test/function/construction/complex.test.js | 2 +- test/function/construction/index.test.js | 2 +- test/function/construction/matrix.test.js | 2 +- test/function/construction/number.test.js | 2 +- test/function/construction/parser.test.js | 2 +- test/function/construction/string.test.js | 2 +- test/function/construction/unit.test.js | 2 +- test/function/expression/compile.test.js | 2 +- test/function/expression/eval.test.js | 2 +- test/function/expression/help.test.js | 2 +- test/function/expression/parse.test.js | 2 +- test/function/matrix/concat.test.js | 2 +- test/function/matrix/det.test.js | 2 +- test/function/matrix/diag.test.js | 2 +- test/function/matrix/eye.test.js | 2 +- test/function/matrix/inv.test.js | 2 +- test/function/matrix/ones.test.js | 2 +- test/function/matrix/range.test.js | 2 +- test/function/matrix/resize.test.js | 2 +- test/function/matrix/size.test.js | 2 +- test/function/matrix/squeeze.test.js | 2 +- test/function/matrix/subset.test.js | 2 +- test/function/matrix/transpose.test.js | 2 +- test/function/matrix/zeros.test.js | 2 +- .../function/probability/combinations.test.js | 2 +- test/function/probability/factorial.test.js | 2 +- .../function/probability/permutations.test.js | 2 +- test/function/probability/random.test.js | 2 +- test/function/trigonometry/acos.test.js | 2 +- test/function/trigonometry/asin.test.js | 2 +- test/function/trigonometry/atan.test.js | 2 +- test/function/trigonometry/atan2.test.js | 2 +- test/function/trigonometry/cos.test.js | 2 +- test/function/trigonometry/cot.test.js | 2 +- test/function/trigonometry/csc.test.js | 2 +- test/function/trigonometry/sec.test.js | 2 +- test/function/trigonometry/sin.test.js | 2 +- test/function/trigonometry/tan.test.js | 2 +- test/function/utils/clone.test.js | 2 +- test/function/utils/forEach.test.js | 2 +- test/function/utils/format.test.js | 2 +- test/function/utils/ifElse.test.js | 2 +- test/function/utils/import.test.js | 2 +- test/function/utils/map.test.js | 2 +- test/function/utils/print.test.js | 2 +- test/function/utils/typeof.test.js | 2 +- test/math.test.js | 9 +- test/util/error.test.js | 157 ------------------ 179 files changed, 512 insertions(+), 501 deletions(-) create mode 100644 lib/error/ArgumentsError.js create mode 100644 lib/error/DimensionError.js create mode 100644 lib/error/IndexError.js create mode 100644 lib/error/UnsupportedTypeError.js create mode 100644 lib/error/index.js delete mode 100644 lib/util/error.js create mode 100644 test/error/ArgumentsError.test.js create mode 100644 test/error/DimensionError.test.js create mode 100644 test/error/IndexError.test.js create mode 100644 test/error/UnsupportedTypeError.test.js create mode 100644 test/error/index.test.js delete mode 100644 test/util/error.test.js diff --git a/lib/error/ArgumentsError.js b/lib/error/ArgumentsError.js new file mode 100644 index 000000000..7aa8341fd --- /dev/null +++ b/lib/error/ArgumentsError.js @@ -0,0 +1,26 @@ +/** + * Create a syntax error with the message: + * 'Wrong number of arguments in function ( provided, - expected)' + * @param {String} name Function name + * @param {Number} count Actual argument count + * @param {Number} min Minimum required argument count + * @param {Number} [max] Maximum required argument count + * @extends Error + */ +function ArgumentsError(name, count, min, max) { + if (!(this instanceof ArgumentsError)) { + throw new SyntaxError('Constructor must be called with the new operator'); + } + + this.message = 'Wrong number of arguments in function ' + name + + ' (' + count + ' provided, ' + + min + ((max != undefined) ? ('-' + max) : '') + ' expected)'; + + this.stack = (new Error()).stack; +} + +ArgumentsError.prototype = new Error(); +ArgumentsError.prototype.constructor = Error; +ArgumentsError.prototype.name = 'ArgumentsError'; + +module.exports = ArgumentsError; diff --git a/lib/error/DimensionError.js b/lib/error/DimensionError.js new file mode 100644 index 000000000..06353f21a --- /dev/null +++ b/lib/error/DimensionError.js @@ -0,0 +1,32 @@ +/** + * Create a range error with the message: + * 'Dimension mismatch ( != )' + * @param {number | number[]} actual The actual size + * @param {number | number[]} expected The expected size + * @param {string} [relation='!='] Optional relation between actual + * and expected size: '!=', '<', etc. + * @extends RangeError + */ +function DimensionError(actual, expected, relation) { + if (!(this instanceof DimensionError)) { + throw new SyntaxError('Constructor must be called with the new operator'); + } + + this.actual = actual; + this.expected = expected; + this.relation = relation || '!='; + + this.message = 'Dimension mismatch (' + + (Array.isArray(actual) ? ('[' + actual.join(', ') + ']') : actual) + + ' ' + this.relation + ' ' + + (Array.isArray(expected) ? ('[' + expected.join(', ') + ']') : expected) + + ')'; + + this.stack = (new Error()).stack; +} + +DimensionError.prototype = new RangeError(); +DimensionError.prototype.constructor = RangeError; +DimensionError.prototype.name = 'DimensionError'; + +module.exports = DimensionError; diff --git a/lib/error/IndexError.js b/lib/error/IndexError.js new file mode 100644 index 000000000..3b1c2e982 --- /dev/null +++ b/lib/error/IndexError.js @@ -0,0 +1,43 @@ +/** + * Create a range error with the message: + * 'Index out of range (index < min)' + * 'Index out of range (index < max)' + * + * @param {number} index The actual index + * @param {number} [min=0] Minimum index (included) + * @param {number} [max] Maximum index (excluded) + * @extends RangeError + */ +function IndexError(index, min, max) { + if (!(this instanceof IndexError)) { + throw new SyntaxError('Constructor must be called with the new operator'); + } + + this.index = index; + if (arguments.length <= 2) { + this.min = 0; + this.max = min; + } + else { + this.min = min; + this.max = max; + } + + if (this.index < this.min) { + this.message = 'Index out of range (' + this.index + ' < ' + this.min + ')'; + } + else if (this.index >= this.max) { + this.message = 'Index out of range (' + this.index + ' > ' + (this.max - 1) + ')'; + } + else { + this.message = 'Index out of range (' + this.index + ')'; + } + + this.stack = (new Error()).stack; +} + +IndexError.prototype = new RangeError(); +IndexError.prototype.constructor = RangeError; +IndexError.prototype.name = 'IndexError'; + +module.exports = IndexError; diff --git a/lib/error/UnsupportedTypeError.js b/lib/error/UnsupportedTypeError.js new file mode 100644 index 000000000..d3528ec4e --- /dev/null +++ b/lib/error/UnsupportedTypeError.js @@ -0,0 +1,40 @@ +/** + * Create a TypeError with message: + * 'Function does not support a parameter of type '; + * @param {String} name Function name + * @param {*} [type1] + * @param {*...} [type_n] + * @extends TypeError + */ +function UnsupportedTypeError(name, type1, type_n) { + if (!(this instanceof UnsupportedTypeError)) { + throw new SyntaxError('Constructor must be called with the new operator'); + } + + switch (arguments.length) { + case 0: + this.message = 'Unsupported type of argument'; + break; + + case 1: + this.message = 'Unsupported type of argument in function ' + name; + break; + + case 2: + this.message = 'Function ' + name + '(' + type1 + ') not supported'; + break; + + default: // more than two arguments + var types = Array.prototype.splice.call(arguments, 1); + this.message = 'Function ' + name + '(' + types.join(', ') + ') not supported'; + break; + } + + this.stack = (new Error()).stack; +} + +UnsupportedTypeError.prototype = new TypeError(); +UnsupportedTypeError.prototype.constructor = TypeError; +UnsupportedTypeError.prototype.name = 'UnsupportedTypeError'; + +module.exports = UnsupportedTypeError; diff --git a/lib/error/index.js b/lib/error/index.js new file mode 100644 index 000000000..6ac1b5282 --- /dev/null +++ b/lib/error/index.js @@ -0,0 +1,6 @@ +exports.ArgumentsError = require('./ArgumentsError'); +exports.DimensionError = require('./DimensionError'); +exports.IndexError = require('./IndexError'); +exports.UnsupportedTypeError = require('./UnsupportedTypeError'); + +// TODO: implement an InvalidValueError? diff --git a/lib/expression/node/Node.js b/lib/expression/node/Node.js index a804b1514..f9566abd7 100644 --- a/lib/expression/node/Node.js +++ b/lib/expression/node/Node.js @@ -1,4 +1,4 @@ -var error = require('../../util/error'); +var error = require('../../error'); /** * Node diff --git a/lib/function/arithmetic/abs.js b/lib/function/arithmetic/abs.js index 37d06ff1a..28109b919 100644 --- a/lib/function/arithmetic/abs.js +++ b/lib/function/arithmetic/abs.js @@ -23,7 +23,7 @@ module.exports = function (math) { */ math.abs = function abs(x) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('abs', arguments.length, 1); + throw new math.error.ArgumentsError('abs', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/add.js b/lib/function/arithmetic/add.js index 6743f9f2f..0485875c9 100644 --- a/lib/function/arithmetic/add.js +++ b/lib/function/arithmetic/add.js @@ -28,7 +28,7 @@ module.exports = function (math) { */ math.add = function add(x, y) { if (arguments.length != 2) { - throw new util.error.ArgumentsError('add', arguments.length, 2); + throw new math.error.ArgumentsError('add', arguments.length, 2); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/ceil.js b/lib/function/arithmetic/ceil.js index 291ec4b26..ba9473328 100644 --- a/lib/function/arithmetic/ceil.js +++ b/lib/function/arithmetic/ceil.js @@ -22,7 +22,7 @@ module.exports = function (math) { */ math.ceil = function ceil(x) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('ceil', arguments.length, 1); + throw new math.error.ArgumentsError('ceil', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/compare.js b/lib/function/arithmetic/compare.js index 9e610d34b..8157c14c0 100644 --- a/lib/function/arithmetic/compare.js +++ b/lib/function/arithmetic/compare.js @@ -25,7 +25,7 @@ module.exports = function (math) { */ math.compare = function compare(x, y) { if (arguments.length != 2) { - throw new util.error.ArgumentsError('compare', arguments.length, 2); + throw new math.error.ArgumentsError('compare', arguments.length, 2); } if (isNumber(x) && isNumber(y)) { diff --git a/lib/function/arithmetic/cube.js b/lib/function/arithmetic/cube.js index f54e91902..b951559cf 100644 --- a/lib/function/arithmetic/cube.js +++ b/lib/function/arithmetic/cube.js @@ -23,7 +23,7 @@ module.exports = function (math) { */ math.cube = function cube(x) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('cube', arguments.length, 1); + throw new math.error.ArgumentsError('cube', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/divide.js b/lib/function/arithmetic/divide.js index e8978a1fb..84fa1a08e 100644 --- a/lib/function/arithmetic/divide.js +++ b/lib/function/arithmetic/divide.js @@ -25,7 +25,7 @@ module.exports = function(math) { */ math.divide = function divide(x, y) { if (arguments.length != 2) { - throw new util.error.ArgumentsError('divide', arguments.length, 2); + throw new math.error.ArgumentsError('divide', arguments.length, 2); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/edivide.js b/lib/function/arithmetic/edivide.js index 725b93dc4..8cebfa5a8 100644 --- a/lib/function/arithmetic/edivide.js +++ b/lib/function/arithmetic/edivide.js @@ -13,7 +13,7 @@ module.exports = function (math) { */ math.edivide = function edivide(x, y) { if (arguments.length != 2) { - throw new util.error.ArgumentsError('edivide', arguments.length, 2); + throw new math.error.ArgumentsError('edivide', arguments.length, 2); } return collection.deepMap2(x, y, math.divide); diff --git a/lib/function/arithmetic/emultiply.js b/lib/function/arithmetic/emultiply.js index fdb1f60de..8db5f1141 100644 --- a/lib/function/arithmetic/emultiply.js +++ b/lib/function/arithmetic/emultiply.js @@ -14,7 +14,7 @@ module.exports = function (math) { */ math.emultiply = function emultiply(x, y) { if (arguments.length != 2) { - throw new util.error.ArgumentsError('emultiply', arguments.length, 2); + throw new math.error.ArgumentsError('emultiply', arguments.length, 2); } return collection.deepMap2(x, y, math.multiply); diff --git a/lib/function/arithmetic/epow.js b/lib/function/arithmetic/epow.js index f4cb30083..34be56fed 100644 --- a/lib/function/arithmetic/epow.js +++ b/lib/function/arithmetic/epow.js @@ -14,7 +14,7 @@ module.exports = function (math) { */ math.epow = function epow(x, y) { if (arguments.length != 2) { - throw new util.error.ArgumentsError('epow', arguments.length, 2); + throw new math.error.ArgumentsError('epow', arguments.length, 2); } return collection.deepMap2(x, y, math.pow); diff --git a/lib/function/arithmetic/equal.js b/lib/function/arithmetic/equal.js index 00af93473..949237951 100644 --- a/lib/function/arithmetic/equal.js +++ b/lib/function/arithmetic/equal.js @@ -28,7 +28,7 @@ module.exports = function (math) { */ math.equal = function equal(x, y) { if (arguments.length != 2) { - throw new util.error.ArgumentsError('equal', arguments.length, 2); + throw new math.error.ArgumentsError('equal', arguments.length, 2); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/exp.js b/lib/function/arithmetic/exp.js index b5f63838e..7cd66380f 100644 --- a/lib/function/arithmetic/exp.js +++ b/lib/function/arithmetic/exp.js @@ -23,7 +23,7 @@ module.exports = function (math) { */ math.exp = function exp (x) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('exp', arguments.length, 1); + throw new math.error.ArgumentsError('exp', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/fix.js b/lib/function/arithmetic/fix.js index 9737150f0..2a35d9e48 100644 --- a/lib/function/arithmetic/fix.js +++ b/lib/function/arithmetic/fix.js @@ -22,7 +22,7 @@ module.exports = function (math) { */ math.fix = function fix(x) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('fix', arguments.length, 1); + throw new math.error.ArgumentsError('fix', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/floor.js b/lib/function/arithmetic/floor.js index 6c6a99260..de75c14a4 100644 --- a/lib/function/arithmetic/floor.js +++ b/lib/function/arithmetic/floor.js @@ -22,7 +22,7 @@ module.exports = function (math) { */ math.floor = function floor(x) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('floor', arguments.length, 1); + throw new math.error.ArgumentsError('floor', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/larger.js b/lib/function/arithmetic/larger.js index 3f5212b78..fbc5d85c3 100644 --- a/lib/function/arithmetic/larger.js +++ b/lib/function/arithmetic/larger.js @@ -27,7 +27,7 @@ module.exports = function (math) { */ math.larger = function larger(x, y) { if (arguments.length != 2) { - throw new util.error.ArgumentsError('larger', arguments.length, 2); + throw new math.error.ArgumentsError('larger', arguments.length, 2); } if (isNumber(x) && isNumber(y)) { diff --git a/lib/function/arithmetic/largereq.js b/lib/function/arithmetic/largereq.js index b3bc0dc9f..424c0087c 100644 --- a/lib/function/arithmetic/largereq.js +++ b/lib/function/arithmetic/largereq.js @@ -27,7 +27,7 @@ module.exports = function (math) { */ math.largereq = function largereq(x, y) { if (arguments.length != 2) { - throw new util.error.ArgumentsError('largereq', arguments.length, 2); + throw new math.error.ArgumentsError('largereq', arguments.length, 2); } if (isNumber(x) && isNumber(y)) { diff --git a/lib/function/arithmetic/log.js b/lib/function/arithmetic/log.js index f2ebd1c2d..b6e28d246 100644 --- a/lib/function/arithmetic/log.js +++ b/lib/function/arithmetic/log.js @@ -62,7 +62,7 @@ module.exports = function (math) { return math.divide(log(x), log(base)); } else { - throw new util.error.ArgumentsError('log', arguments.length, 1, 2); + throw new math.error.ArgumentsError('log', arguments.length, 1, 2); } }; }; diff --git a/lib/function/arithmetic/log10.js b/lib/function/arithmetic/log10.js index 5cfc9e8e1..b13ac97b1 100644 --- a/lib/function/arithmetic/log10.js +++ b/lib/function/arithmetic/log10.js @@ -22,7 +22,7 @@ module.exports = function (math) { */ math.log10 = function log10(x) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('log10', arguments.length, 1); + throw new math.error.ArgumentsError('log10', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/mod.js b/lib/function/arithmetic/mod.js index 057ecec05..2f962853b 100644 --- a/lib/function/arithmetic/mod.js +++ b/lib/function/arithmetic/mod.js @@ -22,7 +22,7 @@ module.exports = function (math) { */ math.mod = function mod(x, y) { if (arguments.length != 2) { - throw new util.error.ArgumentsError('mod', arguments.length, 2); + throw new math.error.ArgumentsError('mod', arguments.length, 2); } // see http://functions.wolfram.com/IntegerFunctions/Mod/ diff --git a/lib/function/arithmetic/multiply.js b/lib/function/arithmetic/multiply.js index 4655049b6..e8c4fe966 100644 --- a/lib/function/arithmetic/multiply.js +++ b/lib/function/arithmetic/multiply.js @@ -28,7 +28,7 @@ module.exports = function(math) { var res; if (arguments.length != 2) { - throw new util.error.ArgumentsError('multiply', arguments.length, 2); + throw new math.error.ArgumentsError('multiply', arguments.length, 2); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/pow.js b/lib/function/arithmetic/pow.js index 41f293b6a..124ccef1f 100644 --- a/lib/function/arithmetic/pow.js +++ b/lib/function/arithmetic/pow.js @@ -25,7 +25,7 @@ module.exports = function (math) { */ math.pow = function pow(x, y) { if (arguments.length != 2) { - throw new util.error.ArgumentsError('pow', arguments.length, 2); + throw new math.error.ArgumentsError('pow', arguments.length, 2); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/round.js b/lib/function/arithmetic/round.js index af7f5fbbe..771580acd 100644 --- a/lib/function/arithmetic/round.js +++ b/lib/function/arithmetic/round.js @@ -26,7 +26,7 @@ module.exports = function (math) { */ math.round = function round(x, n) { if (arguments.length != 1 && arguments.length != 2) { - throw new util.error.ArgumentsError('round', arguments.length, 1, 2); + throw new math.error.ArgumentsError('round', arguments.length, 1, 2); } if (n == undefined) { diff --git a/lib/function/arithmetic/sign.js b/lib/function/arithmetic/sign.js index eb35e1ece..4a8c114b0 100644 --- a/lib/function/arithmetic/sign.js +++ b/lib/function/arithmetic/sign.js @@ -24,7 +24,7 @@ module.exports = function (math) { */ math.sign = function sign(x) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('sign', arguments.length, 1); + throw new math.error.ArgumentsError('sign', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/smaller.js b/lib/function/arithmetic/smaller.js index d19b187b0..97340352f 100644 --- a/lib/function/arithmetic/smaller.js +++ b/lib/function/arithmetic/smaller.js @@ -27,7 +27,7 @@ module.exports = function (math) { */ math.smaller = function smaller(x, y) { if (arguments.length != 2) { - throw new util.error.ArgumentsError('smaller', arguments.length, 2); + throw new math.error.ArgumentsError('smaller', arguments.length, 2); } if (isNumber(x) && isNumber(y)) { diff --git a/lib/function/arithmetic/smallereq.js b/lib/function/arithmetic/smallereq.js index a0173a59c..e5c3178c8 100644 --- a/lib/function/arithmetic/smallereq.js +++ b/lib/function/arithmetic/smallereq.js @@ -27,7 +27,7 @@ module.exports = function (math) { */ math.smallereq = function smallereq(x, y) { if (arguments.length != 2) { - throw new util.error.ArgumentsError('smallereq', arguments.length, 2); + throw new math.error.ArgumentsError('smallereq', arguments.length, 2); } if (isNumber(x) && isNumber(y)) { diff --git a/lib/function/arithmetic/sqrt.js b/lib/function/arithmetic/sqrt.js index bedd8f77b..93be598d2 100644 --- a/lib/function/arithmetic/sqrt.js +++ b/lib/function/arithmetic/sqrt.js @@ -22,7 +22,7 @@ module.exports = function (math) { */ math.sqrt = function sqrt (x) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('sqrt', arguments.length, 1); + throw new math.error.ArgumentsError('sqrt', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/square.js b/lib/function/arithmetic/square.js index 1e8f97a8e..8edca7e05 100644 --- a/lib/function/arithmetic/square.js +++ b/lib/function/arithmetic/square.js @@ -23,7 +23,7 @@ module.exports = function (math) { */ math.square = function square(x) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('square', arguments.length, 1); + throw new math.error.ArgumentsError('square', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/subtract.js b/lib/function/arithmetic/subtract.js index c4fe0af8a..053e3f6f0 100644 --- a/lib/function/arithmetic/subtract.js +++ b/lib/function/arithmetic/subtract.js @@ -27,7 +27,7 @@ module.exports = function (math) { */ math.subtract = function subtract(x, y) { if (arguments.length != 2) { - throw new util.error.ArgumentsError('subtract', arguments.length, 2); + throw new math.error.ArgumentsError('subtract', arguments.length, 2); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/unary.js b/lib/function/arithmetic/unary.js index 5cf7a0667..26e4ff763 100644 --- a/lib/function/arithmetic/unary.js +++ b/lib/function/arithmetic/unary.js @@ -25,7 +25,7 @@ module.exports = function (math) { */ math.unary = function unary(x) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('unary', arguments.length, 1); + throw new math.error.ArgumentsError('unary', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/arithmetic/unequal.js b/lib/function/arithmetic/unequal.js index b98c40c31..8604a0bf5 100644 --- a/lib/function/arithmetic/unequal.js +++ b/lib/function/arithmetic/unequal.js @@ -22,7 +22,7 @@ module.exports = function (math) { */ math.unequal = function unequal(x, y) { if (arguments.length != 2) { - throw new util.error.ArgumentsError('unequal', arguments.length, 2); + throw new math.error.ArgumentsError('unequal', arguments.length, 2); } if (isNumber(x)) { diff --git a/lib/function/complex/arg.js b/lib/function/complex/arg.js index cb95aa50b..3a90d252b 100644 --- a/lib/function/complex/arg.js +++ b/lib/function/complex/arg.js @@ -23,7 +23,7 @@ module.exports = function (math) { */ math.arg = function arg(x) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('arg', arguments.length, 1); + throw new math.error.ArgumentsError('arg', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/complex/conj.js b/lib/function/complex/conj.js index f9b5a1e3f..fd6125ede 100644 --- a/lib/function/complex/conj.js +++ b/lib/function/complex/conj.js @@ -24,7 +24,7 @@ module.exports = function (math) { */ math.conj = function conj(x) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('conj', arguments.length, 1); + throw new math.error.ArgumentsError('conj', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/complex/im.js b/lib/function/complex/im.js index 6cc420119..39c83f9ab 100644 --- a/lib/function/complex/im.js +++ b/lib/function/complex/im.js @@ -22,7 +22,7 @@ module.exports = function (math) { */ math.im = function im(x) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('im', arguments.length, 1); + throw new math.error.ArgumentsError('im', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/complex/re.js b/lib/function/complex/re.js index 0ddca53d4..461da7d07 100644 --- a/lib/function/complex/re.js +++ b/lib/function/complex/re.js @@ -23,7 +23,7 @@ module.exports = function (math) { */ math.re = function re(x) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('re', arguments.length, 1); + throw new math.error.ArgumentsError('re', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/construction/bignumber.js b/lib/function/construction/bignumber.js index b22b2253d..d3770e8ca 100644 --- a/lib/function/construction/bignumber.js +++ b/lib/function/construction/bignumber.js @@ -20,7 +20,7 @@ module.exports = function (math) { */ math.bignumber = function bignumber(value) { if (arguments.length > 1) { - throw new util.error.ArgumentsError('bignumber', arguments.length, 0, 1); + throw new math.error.ArgumentsError('bignumber', arguments.length, 0, 1); } if ((value instanceof BigNumber) || isNumber(value) || isString(value)) { diff --git a/lib/function/construction/boolean.js b/lib/function/construction/boolean.js index fdb35ba01..3bdab0f52 100644 --- a/lib/function/construction/boolean.js +++ b/lib/function/construction/boolean.js @@ -19,7 +19,7 @@ module.exports = function (math) { */ math['boolean'] = function bool (value) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('boolean', arguments.length, 0, 1); + throw new math.error.ArgumentsError('boolean', arguments.length, 0, 1); } if (value === 'true' || value === true) { diff --git a/lib/function/construction/complex.js b/lib/function/construction/complex.js index 9bccc9990..d1542be13 100644 --- a/lib/function/construction/complex.js +++ b/lib/function/construction/complex.js @@ -112,7 +112,7 @@ module.exports = function (math) { } default: - throw new util.error.ArgumentsError('complex', arguments.length, 0, 2); + throw new math.error.ArgumentsError('complex', arguments.length, 0, 2); } }; }; diff --git a/lib/function/construction/matrix.js b/lib/function/construction/matrix.js index 98783b862..f8c11c28d 100644 --- a/lib/function/construction/matrix.js +++ b/lib/function/construction/matrix.js @@ -21,7 +21,7 @@ module.exports = function (math) { */ math.matrix = function matrix(data) { if (arguments.length > 1) { - throw new util.error.ArgumentsError('matrix', arguments.length, 0, 1); + throw new math.error.ArgumentsError('matrix', arguments.length, 0, 1); } return new Matrix(data); diff --git a/lib/function/construction/number.js b/lib/function/construction/number.js index b92f326fc..44b2e0d87 100644 --- a/lib/function/construction/number.js +++ b/lib/function/construction/number.js @@ -51,7 +51,7 @@ module.exports = function (math) { throw new math.error.UnsupportedTypeError('number', math['typeof'](value)); default: - throw new util.error.ArgumentsError('number', arguments.length, 0, 1); + throw new math.error.ArgumentsError('number', arguments.length, 0, 1); } }; }; diff --git a/lib/function/construction/string.js b/lib/function/construction/string.js index d0bfb133b..b3a96ffb2 100644 --- a/lib/function/construction/string.js +++ b/lib/function/construction/string.js @@ -34,7 +34,7 @@ module.exports = function (math) { return value.toString(); default: - throw new util.error.ArgumentsError('string', arguments.length, 0, 1); + throw new math.error.ArgumentsError('string', arguments.length, 0, 1); } }; }; diff --git a/lib/function/construction/unit.js b/lib/function/construction/unit.js index 448c1c83c..a4e2e3cb6 100644 --- a/lib/function/construction/unit.js +++ b/lib/function/construction/unit.js @@ -67,7 +67,7 @@ module.exports = function (math) { } default: - throw new util.error.ArgumentsError('unit', arguments.length, 1, 2); + throw new math.error.ArgumentsError('unit', arguments.length, 1, 2); } }; }; diff --git a/lib/function/expression/compile.js b/lib/function/expression/compile.js index fd1525edb..8e7804985 100644 --- a/lib/function/expression/compile.js +++ b/lib/function/expression/compile.js @@ -37,7 +37,7 @@ module.exports = function (math, config) { */ math.compile = function compile (expr) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('compile', arguments.length, 1); + throw new math.error.ArgumentsError('compile', arguments.length, 1); } if (isString(expr)) { diff --git a/lib/function/expression/eval.js b/lib/function/expression/eval.js index ca39a7955..3c3b363a6 100644 --- a/lib/function/expression/eval.js +++ b/lib/function/expression/eval.js @@ -34,7 +34,7 @@ module.exports = function (math) { */ math.eval = function _eval (expr, scope) { if (arguments.length != 1 && arguments.length != 2) { - throw new util.error.ArgumentsError('eval', arguments.length, 1, 2); + throw new math.error.ArgumentsError('eval', arguments.length, 1, 2); } // instantiate a scope diff --git a/lib/function/matrix/concat.js b/lib/function/matrix/concat.js index eac6e5b0f..0a468a336 100644 --- a/lib/function/matrix/concat.js +++ b/lib/function/matrix/concat.js @@ -49,7 +49,7 @@ module.exports = function (math) { } if (i > 0 && dim > prevDim) { - throw new util.error.DimensionError(dim, prevDim, '>'); + throw new math.error.DimensionError(dim, prevDim, '>'); } } else if (isCollection(arg)) { @@ -62,7 +62,7 @@ module.exports = function (math) { // verify whether each of the matrices has the same number of dimensions if (i > 0 && dim != prevDim) { - throw new util.error.DimensionError(dim, prevDim); + throw new math.error.DimensionError(dim, prevDim); } } else { @@ -96,7 +96,7 @@ module.exports = function (math) { if (dim < concatDim) { // recurse into next dimension if (a.length != b.length) { - throw new util.error.DimensionError(a.length, b.length); + throw new math.error.DimensionError(a.length, b.length); } var c = []; diff --git a/lib/function/matrix/det.js b/lib/function/matrix/det.js index 8a460eb1f..ac37695d8 100644 --- a/lib/function/matrix/det.js +++ b/lib/function/matrix/det.js @@ -17,7 +17,7 @@ module.exports = function (math) { */ math.det = function det (x) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('det', arguments.length, 1); + throw new math.error.ArgumentsError('det', arguments.length, 1); } var size; diff --git a/lib/function/matrix/diag.js b/lib/function/matrix/diag.js index 18ea2bcca..c0e07d252 100644 --- a/lib/function/matrix/diag.js +++ b/lib/function/matrix/diag.js @@ -27,7 +27,7 @@ module.exports = function (math) { var data, vector, i, iMax; if (arguments.length != 1 && arguments.length != 2) { - throw new util.error.ArgumentsError('diag', arguments.length, 1, 2); + throw new math.error.ArgumentsError('diag', arguments.length, 1, 2); } if (k) { diff --git a/lib/function/matrix/eye.js b/lib/function/matrix/eye.js index 6f7aa736b..58e53b4ac 100644 --- a/lib/function/matrix/eye.js +++ b/lib/function/matrix/eye.js @@ -37,7 +37,7 @@ module.exports = function (math, config) { } else if (args.length > 2) { // error in case of an n-dimensional size - throw new util.error.ArgumentsError('eye', args.length, 0, 2); + throw new math.error.ArgumentsError('eye', args.length, 0, 2); } var rows = args[0], diff --git a/lib/function/matrix/inv.js b/lib/function/matrix/inv.js index 1dfa87289..af417e7b4 100644 --- a/lib/function/matrix/inv.js +++ b/lib/function/matrix/inv.js @@ -17,7 +17,7 @@ module.exports = function (math) { */ math.inv = function inv (x) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('inv', arguments.length, 1); + throw new math.error.ArgumentsError('inv', arguments.length, 1); } var size = math.size(x).valueOf(); switch (size.length) { diff --git a/lib/function/matrix/range.js b/lib/function/matrix/range.js index 9d3cc727b..35b7cfade 100644 --- a/lib/function/matrix/range.js +++ b/lib/function/matrix/range.js @@ -92,7 +92,7 @@ module.exports = function (math, config) { throw new TypeError('Parameter includeEnd must be a boolean'); default: - throw new util.error.ArgumentsError('range', arguments.length, 2, 4); + throw new math.error.ArgumentsError('range', arguments.length, 2, 4); } // verify type of parameters diff --git a/lib/function/matrix/resize.js b/lib/function/matrix/resize.js index c4a55ce9a..4521199a3 100644 --- a/lib/function/matrix/resize.js +++ b/lib/function/matrix/resize.js @@ -27,7 +27,7 @@ module.exports = function (math, config) { */ math.resize = function resize (x, size, defaultValue) { if (arguments.length != 2 && arguments.length != 3) { - throw new util.error.ArgumentsError('resize', arguments.length, 2, 3); + throw new math.error.ArgumentsError('resize', arguments.length, 2, 3); } var asMatrix = (x instanceof Matrix) ? true : isArray(x) ? false : (config.matrix !== 'array'); @@ -89,7 +89,7 @@ module.exports = function (math, config) { } if (size.length !== 1) { - throw new util.error.DimensionError(size.length, 1); + throw new math.error.DimensionError(size.length, 1); } var len = size[0]; if (!isNumber(len) || !isInteger(len)) { diff --git a/lib/function/matrix/size.js b/lib/function/matrix/size.js index d2938a30f..01ff54f6f 100644 --- a/lib/function/matrix/size.js +++ b/lib/function/matrix/size.js @@ -23,7 +23,7 @@ module.exports = function (math, config) { */ math.size = function size (x) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('size', arguments.length, 1); + throw new math.error.ArgumentsError('size', arguments.length, 1); } var asArray = (config.matrix === 'array'); diff --git a/lib/function/matrix/squeeze.js b/lib/function/matrix/squeeze.js index a7c54ce69..6b092f447 100644 --- a/lib/function/matrix/squeeze.js +++ b/lib/function/matrix/squeeze.js @@ -17,7 +17,7 @@ module.exports = function (math) { */ math.squeeze = function squeeze (x) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('squeeze', arguments.length, 1); + throw new math.error.ArgumentsError('squeeze', arguments.length, 1); } if (isArray(x)) { diff --git a/lib/function/matrix/subset.js b/lib/function/matrix/subset.js index e7d75ced6..49bc4bf71 100644 --- a/lib/function/matrix/subset.js +++ b/lib/function/matrix/subset.js @@ -40,7 +40,7 @@ module.exports = function (math) { return _setSubset(arguments[0], arguments[1], arguments[2], arguments[3]); default: // wrong number of arguments - throw new util.error.ArgumentsError('subset', arguments.length, 2, 4); + throw new math.error.ArgumentsError('subset', arguments.length, 2, 4); } }; @@ -84,7 +84,7 @@ module.exports = function (math) { throw new TypeError('Index expected'); } if (index.size().length != 1) { - throw new util.error.DimensionError(index.size().length, 1); + throw new math.error.DimensionError(index.size().length, 1); } var range = index.range(0); @@ -146,7 +146,7 @@ module.exports = function (math) { throw new TypeError('Index expected'); } if (index.size().length != 1) { - throw new util.error.DimensionError(index.size().length, 1); + throw new math.error.DimensionError(index.size().length, 1); } if (defaultValue !== undefined) { if (!isString(defaultValue) || defaultValue.length !== 1) { @@ -161,7 +161,7 @@ module.exports = function (math) { var len = range.size()[0]; if (len != replacement.length) { - throw new util.error.DimensionError(range.size()[0], replacement.length); + throw new math.error.DimensionError(range.size()[0], replacement.length); } // copy the string into an array with characters diff --git a/lib/function/matrix/transpose.js b/lib/function/matrix/transpose.js index fda40d4e9..4183201bd 100644 --- a/lib/function/matrix/transpose.js +++ b/lib/function/matrix/transpose.js @@ -17,7 +17,7 @@ module.exports = function (math) { */ math.transpose = function transpose (x) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('transpose', arguments.length, 1); + throw new math.error.ArgumentsError('transpose', arguments.length, 1); } var size = math.size(x).valueOf(); diff --git a/lib/function/probability/combinations.js b/lib/function/probability/combinations.js index 59532511d..465d4dd11 100644 --- a/lib/function/probability/combinations.js +++ b/lib/function/probability/combinations.js @@ -24,7 +24,7 @@ module.exports = function (math) { var arity = arguments.length; if (arity != 2) { - throw new util.error.ArgumentsError('combinations', arguments.length, 2); + throw new math.error.ArgumentsError('combinations', arguments.length, 2); } if (isNumber(n)) { diff --git a/lib/function/probability/factorial.js b/lib/function/probability/factorial.js index 7142008e0..4e455f549 100644 --- a/lib/function/probability/factorial.js +++ b/lib/function/probability/factorial.js @@ -25,7 +25,7 @@ module.exports = function (math) { var value, res; if (arguments.length != 1) { - throw new util.error.ArgumentsError('factorial', arguments.length, 1); + throw new math.error.ArgumentsError('factorial', arguments.length, 1); } if (isNumber(n)) { diff --git a/lib/function/probability/permutations.js b/lib/function/probability/permutations.js index 02509582f..d6b84f81f 100644 --- a/lib/function/probability/permutations.js +++ b/lib/function/probability/permutations.js @@ -24,7 +24,7 @@ module.exports = function (math) { var arity = arguments.length; if (arity > 2) { - throw new util.error.ArgumentsError('permutations', arguments.length, 2); + throw new math.error.ArgumentsError('permutations', arguments.length, 2); } if (isNumber(n)) { diff --git a/lib/function/probability/random.js b/lib/function/probability/random.js index ec78d98a6..d43f3f3ed 100644 --- a/lib/function/probability/random.js +++ b/lib/function/probability/random.js @@ -64,7 +64,7 @@ module.exports = function (math, config) { random: function(arg1, arg2, arg3) { var size, min, max; if (arguments.length > 3) { - throw new util.error.ArgumentsError('random', arguments.length, 0, 3); + throw new math.error.ArgumentsError('random', arguments.length, 0, 3); // `random(max)` or `random(size)` } else if (arguments.length === 1) { @@ -99,7 +99,7 @@ module.exports = function (math, config) { randomInt: function(arg1, arg2, arg3) { var size, min, max; if (arguments.length > 3 || arguments.length < 1) - throw new util.error.ArgumentsError('randomInt', arguments.length, 1, 3); + throw new math.error.ArgumentsError('randomInt', arguments.length, 1, 3); // `randomInt(max)` else if (arguments.length === 1) max = arg1; @@ -128,7 +128,7 @@ module.exports = function (math, config) { pickRandom: function(possibles) { if (arguments.length !== 1) { - throw new util.error.ArgumentsError('pickRandom', arguments.length, 1); + throw new math.error.ArgumentsError('pickRandom', arguments.length, 1); } if (!Array.isArray(possibles)) { throw new math.error.UnsupportedTypeError('pickRandom', math['typeof'](possibles)); diff --git a/lib/function/trigonometry/acos.js b/lib/function/trigonometry/acos.js index 997db5c67..972a37d09 100644 --- a/lib/function/trigonometry/acos.js +++ b/lib/function/trigonometry/acos.js @@ -24,7 +24,7 @@ module.exports = function (math) { */ math.acos = function acos(x) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('acos', arguments.length, 1); + throw new math.error.ArgumentsError('acos', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/trigonometry/asin.js b/lib/function/trigonometry/asin.js index 2ab08f488..ebd272e5b 100644 --- a/lib/function/trigonometry/asin.js +++ b/lib/function/trigonometry/asin.js @@ -24,7 +24,7 @@ module.exports = function (math) { */ math.asin = function asin(x) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('asin', arguments.length, 1); + throw new math.error.ArgumentsError('asin', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/trigonometry/atan.js b/lib/function/trigonometry/atan.js index c21e12f84..e6a7e988f 100644 --- a/lib/function/trigonometry/atan.js +++ b/lib/function/trigonometry/atan.js @@ -24,7 +24,7 @@ module.exports = function (math) { */ math.atan = function atan(x) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('atan', arguments.length, 1); + throw new math.error.ArgumentsError('atan', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/trigonometry/atan2.js b/lib/function/trigonometry/atan2.js index 29df91739..dfc3f1ea1 100644 --- a/lib/function/trigonometry/atan2.js +++ b/lib/function/trigonometry/atan2.js @@ -25,7 +25,7 @@ module.exports = function (math) { */ math.atan2 = function atan2(y, x) { if (arguments.length != 2) { - throw new util.error.ArgumentsError('atan2', arguments.length, 2); + throw new math.error.ArgumentsError('atan2', arguments.length, 2); } if (isNumber(y)) { diff --git a/lib/function/trigonometry/cos.js b/lib/function/trigonometry/cos.js index ea420748f..667a9dcd3 100644 --- a/lib/function/trigonometry/cos.js +++ b/lib/function/trigonometry/cos.js @@ -26,7 +26,7 @@ module.exports = function (math) { */ math.cos = function cos(x) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('cos', arguments.length, 1); + throw new math.error.ArgumentsError('cos', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/trigonometry/cot.js b/lib/function/trigonometry/cot.js index ed37866db..56ee9ae9c 100644 --- a/lib/function/trigonometry/cot.js +++ b/lib/function/trigonometry/cot.js @@ -24,7 +24,7 @@ module.exports = function (math) { */ math.cot = function cot(x) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('cot', arguments.length, 1); + throw new math.error.ArgumentsError('cot', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/trigonometry/csc.js b/lib/function/trigonometry/csc.js index 4a9d9150c..faaaeb6fd 100644 --- a/lib/function/trigonometry/csc.js +++ b/lib/function/trigonometry/csc.js @@ -24,7 +24,7 @@ module.exports = function (math) { */ math.csc = function csc(x) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('csc', arguments.length, 1); + throw new math.error.ArgumentsError('csc', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/trigonometry/sec.js b/lib/function/trigonometry/sec.js index 94b3ee515..3d59dee60 100644 --- a/lib/function/trigonometry/sec.js +++ b/lib/function/trigonometry/sec.js @@ -24,7 +24,7 @@ module.exports = function (math) { */ math.sec = function sec(x) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('sec', arguments.length, 1); + throw new math.error.ArgumentsError('sec', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/trigonometry/sin.js b/lib/function/trigonometry/sin.js index f9390cc9c..276ac7dca 100644 --- a/lib/function/trigonometry/sin.js +++ b/lib/function/trigonometry/sin.js @@ -26,7 +26,7 @@ module.exports = function (math) { */ math.sin = function sin(x) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('sin', arguments.length, 1); + throw new math.error.ArgumentsError('sin', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/trigonometry/tan.js b/lib/function/trigonometry/tan.js index 1f298e063..7219b7570 100644 --- a/lib/function/trigonometry/tan.js +++ b/lib/function/trigonometry/tan.js @@ -26,7 +26,7 @@ module.exports = function (math) { */ math.tan = function tan(x) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('tan', arguments.length, 1); + throw new math.error.ArgumentsError('tan', arguments.length, 1); } if (isNumber(x)) { diff --git a/lib/function/units/to.js b/lib/function/units/to.js index 3aa5431a9..d3952371e 100644 --- a/lib/function/units/to.js +++ b/lib/function/units/to.js @@ -22,7 +22,7 @@ module.exports = function (math) { */ math.to = function to(x, unit) { if (arguments.length != 2) { - throw new util.error.ArgumentsError('to', arguments.length, 2); + throw new math.error.ArgumentsError('to', arguments.length, 2); } if (isUnit(x)) { diff --git a/lib/function/utils/clone.js b/lib/function/utils/clone.js index 3616b457c..2fb63d176 100644 --- a/lib/function/utils/clone.js +++ b/lib/function/utils/clone.js @@ -12,7 +12,7 @@ module.exports = function (math) { */ math.clone = function clone (x) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('clone', arguments.length, 1); + throw new math.error.ArgumentsError('clone', arguments.length, 1); } return object.clone(x); diff --git a/lib/function/utils/forEach.js b/lib/function/utils/forEach.js index 233532f8b..b979d73f0 100644 --- a/lib/function/utils/forEach.js +++ b/lib/function/utils/forEach.js @@ -10,7 +10,7 @@ module.exports = function (math) { */ math.forEach = function (x, callback) { if (arguments.length != 2) { - throw new util.error.ArgumentsError('forEach', arguments.length, 2); + throw new math.error.ArgumentsError('forEach', arguments.length, 2); } if (Array.isArray(x)) { diff --git a/lib/function/utils/format.js b/lib/function/utils/format.js index 51c8a8c15..4397367f2 100644 --- a/lib/function/utils/format.js +++ b/lib/function/utils/format.js @@ -69,7 +69,7 @@ module.exports = function (math) { math.format = function format (value, options) { var num = arguments.length; if (num !== 1 && num !== 2) { - throw new util.error.ArgumentsError('format', num, 1, 2); + throw new math.error.ArgumentsError('format', num, 1, 2); } return string.format(value, options); diff --git a/lib/function/utils/ifElse.js b/lib/function/utils/ifElse.js index 7b9529f30..cfa22f57d 100644 --- a/lib/function/utils/ifElse.js +++ b/lib/function/utils/ifElse.js @@ -30,7 +30,7 @@ module.exports = function (math) { */ math.ifElse = function ifElse(condition, trueExpr, falseExpr) { if (arguments.length != 3) { - throw new util.error.ArgumentsError('ifElse', arguments.length, 3); + throw new math.error.ArgumentsError('ifElse', arguments.length, 3); } if (isNumber(condition) || isBoolean(condition)) { @@ -90,7 +90,7 @@ module.exports = function (math) { condition.size().join(', ') + '] != [' + trueExpr.size().join(', ') + '])'); - throw new util.error.DimensionError(condition.size(), trueExpr.size()); + throw new math.error.DimensionError(condition.size(), trueExpr.size()); } } @@ -100,7 +100,7 @@ module.exports = function (math) { if (!(falseExpr instanceof Matrix)) falseExpr = new Matrix(falseExpr); if (!deepEqual(condition.size(), falseExpr.size())) { - throw new util.error.DimensionError(condition.size(), falseExpr.size()); + throw new math.error.DimensionError(condition.size(), falseExpr.size()); } } diff --git a/lib/function/utils/import.js b/lib/function/utils/import.js index 2e1b6faf8..82c72fb88 100644 --- a/lib/function/utils/import.js +++ b/lib/function/utils/import.js @@ -29,7 +29,7 @@ module.exports = function (math) { math['import'] = function math_import(object, options) { var num = arguments.length; if (num != 1 && num != 2) { - throw new util.error.ArgumentsError('import', num, 1, 2); + throw new math.error.ArgumentsError('import', num, 1, 2); } var name; diff --git a/lib/function/utils/map.js b/lib/function/utils/map.js index e000b3911..8a12a6a29 100644 --- a/lib/function/utils/map.js +++ b/lib/function/utils/map.js @@ -12,7 +12,7 @@ module.exports = function (math) { */ math.map = function (x, callback) { if (arguments.length != 2) { - throw new util.error.ArgumentsError('map', arguments.length, 2); + throw new math.error.ArgumentsError('map', arguments.length, 2); } if (Array.isArray(x)) { diff --git a/lib/function/utils/print.js b/lib/function/utils/print.js index 464f05e1c..ef37f8fb9 100644 --- a/lib/function/utils/print.js +++ b/lib/function/utils/print.js @@ -33,7 +33,7 @@ module.exports = function (math) { math.print = function print (template, values, precision) { var num = arguments.length; if (num != 2 && num != 3) { - throw new util.error.ArgumentsError('print', num, 2, 3); + throw new math.error.ArgumentsError('print', num, 2, 3); } if (!isString(template)) { diff --git a/lib/function/utils/typeof.js b/lib/function/utils/typeof.js index 1d9948652..48c6b1fe6 100644 --- a/lib/function/utils/typeof.js +++ b/lib/function/utils/typeof.js @@ -20,7 +20,7 @@ module.exports = function (math) { */ math['typeof'] = function _typeof (x) { if (arguments.length != 1) { - throw new util.error.ArgumentsError('typeof', arguments.length, 1); + throw new math.error.ArgumentsError('typeof', arguments.length, 1); } // JavaScript types diff --git a/lib/math.js b/lib/math.js index f7fc426fe..316a459d4 100644 --- a/lib/math.js +++ b/lib/math.js @@ -129,7 +129,7 @@ function mathjs (config) { } // errors - math.error = require('./util/error'); + math.error = require('./error/index'); // types (Matrix, Complex, Unit, ...) math.type = {}; diff --git a/lib/type/Matrix.js b/lib/type/Matrix.js index 3bc86ff78..42ae833ad 100644 --- a/lib/type/Matrix.js +++ b/lib/type/Matrix.js @@ -1,4 +1,6 @@ var util = require('../util/index'), + DimensionError = require('../error/DimensionError'), + Index = require('./Index'), number = util.number, @@ -104,7 +106,7 @@ Matrix.prototype.get = function get(index) { throw new TypeError('Array expected'); } if (index.length != this._size.length) { - throw new util.error.DimensionError(index.length, this._size.length); + throw new DimensionError(index.length, this._size.length); } var data = this._data; @@ -134,7 +136,7 @@ Matrix.prototype.set = function set (index, value, defaultValue) { throw new Error('Array expected'); } if (index.length < this._size.length) { - throw new util.error.DimensionError(index.length, this._size.length, '<'); + throw new DimensionError(index.length, this._size.length, '<'); } // enlarge matrix when needed @@ -179,7 +181,7 @@ function _get (matrix, index) { // validate dimensions var size = index.size(); if (size.length != matrix._size.length) { - throw new util.error.DimensionError(size.length, matrix._size.length); + throw new DimensionError(size.length, matrix._size.length); } // retrieve submatrix @@ -271,7 +273,7 @@ function _set (matrix, index, submatrix, defaultValue) { // validate dimensions if (iSize.length < matrix._size.length) { - throw new util.error.DimensionError(iSize.length, matrix._size.length, '<'); + throw new DimensionError(iSize.length, matrix._size.length, '<'); } // unsqueeze the submatrix when needed @@ -282,7 +284,7 @@ function _set (matrix, index, submatrix, defaultValue) { // check whether the size of the submatrix matches the index size if (!object.deepEqual(iSize, sSize)) { - throw new util.error.DimensionError(iSize, sSize); + throw new DimensionError(iSize, sSize); } // enlarge matrix when needed diff --git a/lib/type/collection.js b/lib/type/collection.js index 21622769f..6748d8833 100644 --- a/lib/type/collection.js +++ b/lib/type/collection.js @@ -2,6 +2,8 @@ var util = require('../util/index'), + DimensionError = require('../error/DimensionError'), + Matrix = require('./Matrix'), isArray = util.array.isArray, @@ -90,7 +92,7 @@ exports.deepMap2 = function deepMap2(array1, array2, callback) { if (isArray(array2)) { // callback(array, array) if (array1.length != array2.length) { - throw new util.error.DimensionError(array1.length, array2.length); + throw new DimensionError(array1.length, array2.length); } res = []; diff --git a/lib/util/array.js b/lib/util/array.js index f533f4205..13e3e4b6e 100644 --- a/lib/util/array.js +++ b/lib/util/array.js @@ -1,9 +1,11 @@ var number = require('./number'), string = require('./string'), object = require('./object'), - error = require('./error'), types = require('./types'), + DimensionError = require('../error/DimensionError'), + IndexError = require('../error/IndexError'), + isArray = Array.isArray; /** @@ -56,7 +58,7 @@ function _validate(array, size, dim) { var len = array.length; if (len != size[dim]) { - throw new error.DimensionError(len, size[dim]); + throw new DimensionError(len, size[dim]); } if (dim < size.length - 1) { @@ -65,7 +67,7 @@ function _validate(array, size, dim) { for (i = 0; i < len; i++) { var child = array[i]; if (!isArray(child)) { - throw new error.DimensionError(size.length - 1, size.length, '<'); + throw new DimensionError(size.length - 1, size.length, '<'); } _validate(array[i], size, dimNext); } @@ -74,7 +76,7 @@ function _validate(array, size, dim) { // last dimension. none of the childs may be an array for (i = 0; i < len; i++) { if (isArray(array[i])) { - throw new error.DimensionError(size.length + 1, size.length, '>'); + throw new DimensionError(size.length + 1, size.length, '>'); } } } @@ -92,7 +94,7 @@ exports.validate = function validate(array, size) { if (isScalar) { // scalar if (isArray(array)) { - throw new error.DimensionError(array.length, 0); + throw new DimensionError(array.length, 0); } } else { @@ -111,10 +113,10 @@ exports.validateIndex = function validateIndex (index, length) { throw new TypeError('Index must be an integer (value: ' + index + ')'); } if (index < 0) { - throw new error.IndexError(index); + throw new IndexError(index); } if (length !== undefined && index >= length) { - throw new error.IndexError(index, length); + throw new IndexError(index, length); } }; diff --git a/lib/util/error.js b/lib/util/error.js deleted file mode 100644 index c76c1cd1d..000000000 --- a/lib/util/error.js +++ /dev/null @@ -1,150 +0,0 @@ -// TODO: put each of the errors in a separate files - -/** - * Create a syntax error with the message: - * 'Wrong number of arguments in function ( provided, - expected)' - * @param {String} name Function name - * @param {Number} count Actual argument count - * @param {Number} min Minimum required argument count - * @param {Number} [max] Maximum required argument count - * @extends Error - */ -function ArgumentsError(name, count, min, max) { - if (!(this instanceof ArgumentsError)) { - throw new SyntaxError('Constructor must be called with the new operator'); - } - - this.message = 'Wrong number of arguments in function ' + name + - ' (' + count + ' provided, ' + - min + ((max != undefined) ? ('-' + max) : '') + ' expected)'; - - this.stack = (new Error()).stack; -} - -ArgumentsError.prototype = new Error(); -ArgumentsError.prototype.constructor = Error; -ArgumentsError.prototype.name = 'ArgumentsError'; - -exports.ArgumentsError = ArgumentsError; - -/** - * Create a range error with the message: - * 'Dimension mismatch ( != )' - * @param {number | number[]} actual The actual size - * @param {number | number[]} expected The expected size - * @param {string} [relation='!='] Optional relation between actual - * and expected size: '!=', '<', etc. - * @extends RangeError - */ -function DimensionError(actual, expected, relation) { - if (!(this instanceof DimensionError)) { - throw new SyntaxError('Constructor must be called with the new operator'); - } - - this.actual = actual; - this.expected = expected; - this.relation = relation || '!='; - - this.message = 'Dimension mismatch (' + - (Array.isArray(actual) ? ('[' + actual.join(', ') + ']') : actual) + - ' ' + this.relation + ' ' + - (Array.isArray(expected) ? ('[' + expected.join(', ') + ']') : expected) + - ')'; - - this.stack = (new Error()).stack; -} - -DimensionError.prototype = new RangeError(); -DimensionError.prototype.constructor = RangeError; -DimensionError.prototype.name = 'DimensionError'; - -exports.DimensionError = DimensionError; - -/** - * Create a range error with the message: - * 'Index out of range (index < min)' - * 'Index out of range (index < max)' - * - * @param {number} index The actual index - * @param {number} [min=0] Minimum index (included) - * @param {number} [max] Maximum index (excluded) - * @extends RangeError - */ -function IndexError(index, min, max) { - if (!(this instanceof IndexError)) { - throw new SyntaxError('Constructor must be called with the new operator'); - } - - this.index = index; - if (arguments.length <= 2) { - this.min = 0; - this.max = min; - } - else { - this.min = min; - this.max = max; - } - - if (this.index < this.min) { - this.message = 'Index out of range (' + this.index + ' < ' + this.min + ')'; - } - else if (this.index >= this.max) { - this.message = 'Index out of range (' + this.index + ' > ' + (this.max - 1) + ')'; - } - else { - this.message = 'Index out of range (' + this.index + ')'; - } - - this.stack = (new Error()).stack; -} - -IndexError.prototype = new RangeError(); -IndexError.prototype.constructor = RangeError; -IndexError.prototype.name = 'IndexError'; - -exports.IndexError = IndexError; - -/** - * Create a TypeError with message: - * 'Function does not support a parameter of type '; - * @param {String} name Function name - * @param {*} [type1] - * @param {*...} [type_n] - * @extends TypeError - */ -function UnsupportedTypeError(name, type1, type_n) { - if (!(this instanceof UnsupportedTypeError)) { - throw new SyntaxError('Constructor must be called with the new operator'); - } - - switch (arguments.length) { - case 0: - this.message = 'Unsupported type of argument'; - break; - - case 1: - this.message = 'Unsupported type of argument in function ' + name; - break; - - case 2: - this.message = 'Function ' + name + '(' + type1 + ') not supported'; - break; - - default: // more than two arguments - var types = Array.prototype.splice.call(arguments, 1); - this.message = 'Function ' + name + '(' + types.join(', ') + ') not supported'; - break; - } - - this.stack = (new Error()).stack; -} - -UnsupportedTypeError.prototype = new TypeError(); -UnsupportedTypeError.prototype.constructor = TypeError; -UnsupportedTypeError.prototype.name = 'UnsupportedTypeError'; - -exports.UnsupportedTypeError = UnsupportedTypeError; - - - -// TODO: implement an InvalidValueError? diff --git a/lib/util/index.js b/lib/util/index.js index ac9962b66..87193dfff 100644 --- a/lib/util/index.js +++ b/lib/util/index.js @@ -5,4 +5,3 @@ exports.bignumber = require('./bignumber'); exports.object = require('./object'); exports.string = require('./string'); exports.types = require('./types'); -exports.error = require('./error'); diff --git a/test/error/ArgumentsError.test.js b/test/error/ArgumentsError.test.js new file mode 100644 index 000000000..b5a0913fe --- /dev/null +++ b/test/error/ArgumentsError.test.js @@ -0,0 +1,26 @@ +var assert = require('assert'), + ArgumentsError = require('../../lib/error/ArgumentsError'); + +describe('ArgumentsError', function () { + + it('should construct an ArgumentsError without max', function () { + var err = new ArgumentsError('myfunction', 1, 2); + assert(err instanceof Error); + assert(err instanceof ArgumentsError); + assert.equal(err.toString(), 'ArgumentsError: Wrong number of arguments in function myfunction (1 provided, 2 expected)'); + }); + + it('should construct an ArgumentsError with max', function () { + var err = new ArgumentsError('myfunction', 1, 2, 3); + assert(err instanceof Error); + assert(err instanceof ArgumentsError); + assert.equal(err.toString(), 'ArgumentsError: Wrong number of arguments in function myfunction (1 provided, 2-3 expected)'); + }); + + it('should throw an error when operator new is missing', function () { + assert.throws(function () { + ArgumentsError(); + }, SyntaxError); + }); + +}); diff --git a/test/error/DimensionError.test.js b/test/error/DimensionError.test.js new file mode 100644 index 000000000..8581eab42 --- /dev/null +++ b/test/error/DimensionError.test.js @@ -0,0 +1,42 @@ +var assert = require('assert'), + DimensionError = require('../../lib/error/DimensionError'); + +describe('DimensionError', function () { + + it('should construct a DimensionError with numbers', function () { + var err = new DimensionError(3, 5); + assert(err instanceof Error); + assert(err instanceof RangeError); + assert(err instanceof DimensionError); + assert.equal(err.toString(), 'DimensionError: Dimension mismatch (3 != 5)'); + }); + + it('should construct a DimensionError with numbers and a custom relation', function () { + var err = new DimensionError(3, 5, '<'); + assert(err instanceof Error); + assert(err instanceof RangeError); + assert(err instanceof DimensionError); + assert.equal(err.toString(), 'DimensionError: Dimension mismatch (3 < 5)'); + }); + + it('should construct a DimensionError with arrays', function () { + var err = new DimensionError([2,3], [1,3]); + assert(err instanceof Error); + assert(err instanceof RangeError); + assert(err instanceof DimensionError); + assert.equal(err.toString(), 'DimensionError: Dimension mismatch ([2, 3] != [1, 3])'); + }); + + it('should construct a DimensionError with arrays and a custom relation', function () { + var err = new DimensionError([2,3], [1,3], '<'); + assert(err instanceof Error); + assert(err instanceof RangeError); + assert(err instanceof DimensionError); + assert.equal(err.toString(), 'DimensionError: Dimension mismatch ([2, 3] < [1, 3])'); + }); + + it('should throw an error when operator new is missing', function () { + assert.throws(function () {DimensionError(3, 5);}, SyntaxError); + }); + +}); diff --git a/test/error/IndexError.test.js b/test/error/IndexError.test.js new file mode 100644 index 000000000..af0600eee --- /dev/null +++ b/test/error/IndexError.test.js @@ -0,0 +1,46 @@ +var assert = require('assert'), + IndexError = require('../../lib/error/IndexError'); + +describe('IndexError', function () { + + it('should construct an IndexError without min and max', function () { + var err = new IndexError(5); + assert(err instanceof Error); + assert(err instanceof RangeError); + assert(err instanceof IndexError); + assert.equal(err.toString(), 'IndexError: Index out of range (5)'); + }); + + it('should construct an IndexError without min and max (2)', function () { + var err = new IndexError(-5); + assert(err instanceof Error); + assert(err instanceof RangeError); + assert(err instanceof IndexError); + assert.equal(err.toString(), 'IndexError: Index out of range (-5 < 0)'); + }); + + it('should construct an IndexError with max', function () { + var err = new IndexError(5, 3); + assert(err instanceof Error); + assert(err instanceof RangeError); + assert(err instanceof IndexError); + assert.equal(err.toString(), 'IndexError: Index out of range (5 > 2)'); + }); + + it('should construct an IndexError with min and max', function () { + var err = new IndexError(0, 2, 5); + assert(err instanceof Error); + assert(err instanceof RangeError); + assert(err instanceof IndexError); + assert.equal(err.toString(), 'IndexError: Index out of range (0 < 2)'); + }); + + it('should construct an IndexError with min and max', function () { + var err = new IndexError(6, 1, 4); + assert(err instanceof Error); + assert(err instanceof RangeError); + assert(err instanceof IndexError); + assert.equal(err.toString(), 'IndexError: Index out of range (6 > 3)'); + }); + +}); diff --git a/test/error/UnsupportedTypeError.test.js b/test/error/UnsupportedTypeError.test.js new file mode 100644 index 000000000..ae15b3a32 --- /dev/null +++ b/test/error/UnsupportedTypeError.test.js @@ -0,0 +1,45 @@ +var assert = require('assert'), + UnsupportedTypeError = require('../../lib/error/UnsupportedTypeError'); + +describe('UnsupportedTypeError', function () { + + it('should construct an UnsupportedTypeError with no argument', function () { + var err = new UnsupportedTypeError(); + assert(err instanceof Error); + assert(err instanceof UnsupportedTypeError); + assert.equal(err.toString(), 'UnsupportedTypeError: Unsupported type of argument'); + }); + + it('should construct an UnsupportedTypeError with one argument', function () { + var err = new UnsupportedTypeError('myfunction'); + assert(err instanceof Error); + assert(err instanceof UnsupportedTypeError); + assert.equal(err.toString(), 'UnsupportedTypeError: Unsupported type of argument in function myfunction'); + }); + + it('should construct an UnsupportedTypeError with two arguments', function () { + var err = new UnsupportedTypeError('myfunction', 'number'); + assert(err instanceof Error); + assert(err instanceof UnsupportedTypeError); + assert.equal(err.toString(), 'UnsupportedTypeError: Function myfunction(number) not supported'); + }); + + it('should construct an UnsupportedTypeError with three arguments', function () { + var err = new UnsupportedTypeError('myfunction', 'number', 'string'); + assert(err instanceof Error); + assert(err instanceof UnsupportedTypeError); + assert.equal(err.toString(), 'UnsupportedTypeError: Function myfunction(number, string) not supported'); + }); + + it('should construct an UnsupportedTypeError with more than three arguments', function () { + var err = new UnsupportedTypeError('myfunction', 'number', 'string', 'date'); + assert(err instanceof Error); + assert(err instanceof UnsupportedTypeError); + assert.equal(err.toString(), 'UnsupportedTypeError: Function myfunction(number, string, date) not supported'); + }); + + it('should throw an error when operator new is missing', function () { + assert.throws(function () {UnsupportedTypeError();}, SyntaxError); + }); + +}); diff --git a/test/error/index.test.js b/test/error/index.test.js new file mode 100644 index 000000000..d0ac9d8fe --- /dev/null +++ b/test/error/index.test.js @@ -0,0 +1,14 @@ +var assert = require('assert'), + error = require('../../lib/error/index'); + +describe('index.js', function () { + + it('should contain error namespace', function () { + assert.equal(typeof error, 'object'); + assert('ArgumentsError' in error); + assert('DimensionError' in error); + assert('IndexError' in error); + assert('UnsupportedTypeError' in error); + }); + +}); \ No newline at end of file diff --git a/test/function/arithmetic/abs.test.js b/test/function/arithmetic/abs.test.js index a63f82baa..865d0edf4 100644 --- a/test/function/arithmetic/abs.test.js +++ b/test/function/arithmetic/abs.test.js @@ -1,6 +1,6 @@ // test abs var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error'), math = require('../../../index')(); describe('abs', function () { diff --git a/test/function/arithmetic/add.test.js b/test/function/arithmetic/add.test.js index 63c45d6e0..0f624b994 100644 --- a/test/function/arithmetic/add.test.js +++ b/test/function/arithmetic/add.test.js @@ -1,7 +1,7 @@ // test add var assert = require('assert'), approx = require('../../../tools/approx'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), bignumber = math.bignumber, add = math.add; diff --git a/test/function/arithmetic/ceil.test.js b/test/function/arithmetic/ceil.test.js index 50d9f1ebf..5c527fa8b 100644 --- a/test/function/arithmetic/ceil.test.js +++ b/test/function/arithmetic/ceil.test.js @@ -1,7 +1,7 @@ // test ceil var assert = require('assert'), approx = require('../../../tools/approx'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), bignumber = math.bignumber, complex = math.complex, diff --git a/test/function/arithmetic/compare.test.js b/test/function/arithmetic/compare.test.js index 7ecea3c07..4e3fe3bd5 100644 --- a/test/function/arithmetic/compare.test.js +++ b/test/function/arithmetic/compare.test.js @@ -1,7 +1,7 @@ // test compare var assert = require('assert'), math = require('../../../index')(), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), bignumber = math.bignumber, complex = math.complex, matrix = math.matrix, diff --git a/test/function/arithmetic/cube.test.js b/test/function/arithmetic/cube.test.js index 49daad52e..b045840df 100644 --- a/test/function/arithmetic/cube.test.js +++ b/test/function/arithmetic/cube.test.js @@ -1,7 +1,7 @@ // test cube var assert = require('assert'), math = require('../../../index')(), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), unit = math.unit, bignumber = math.bignumber, matrix = math.matrix, diff --git a/test/function/arithmetic/divide.test.js b/test/function/arithmetic/divide.test.js index 94c97aaba..e9333c367 100644 --- a/test/function/arithmetic/divide.test.js +++ b/test/function/arithmetic/divide.test.js @@ -1,7 +1,7 @@ // test divide var assert = require('assert'), math = require('../../../index')(), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), approx = require('../../../tools/approx'), divide = math.divide, bignumber = math.bignumber, diff --git a/test/function/arithmetic/edivide.test.js b/test/function/arithmetic/edivide.test.js index f2fb4e5a6..ca5ab916a 100644 --- a/test/function/arithmetic/edivide.test.js +++ b/test/function/arithmetic/edivide.test.js @@ -1,7 +1,7 @@ // test edivide (element-wise divide) var assert = require('assert'), math = require('../../../index')(), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), approx = require('../../../tools/approx'), edivide = math.edivide, complex = math.complex; diff --git a/test/function/arithmetic/emultiply.test.js b/test/function/arithmetic/emultiply.test.js index f2a2e1a53..609eecb56 100644 --- a/test/function/arithmetic/emultiply.test.js +++ b/test/function/arithmetic/emultiply.test.js @@ -2,7 +2,7 @@ var assert = require('assert'), math = require('../../../index')(), approx = require('../../../tools/approx'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), emultiply = math.emultiply, divide = math.divide, matrix = math.matrix, diff --git a/test/function/arithmetic/epow.test.js b/test/function/arithmetic/epow.test.js index 5d640f722..f1910db35 100644 --- a/test/function/arithmetic/epow.test.js +++ b/test/function/arithmetic/epow.test.js @@ -1,7 +1,7 @@ // test exp var assert = require('assert'), approx = require('../../../tools/approx'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), complex = math.complex, matrix = math.matrix, diff --git a/test/function/arithmetic/equal.test.js b/test/function/arithmetic/equal.test.js index d2ce0ce3a..b07f80396 100644 --- a/test/function/arithmetic/equal.test.js +++ b/test/function/arithmetic/equal.test.js @@ -1,7 +1,7 @@ // test equal var assert = require('assert'), math = require('../../../index')(), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), bignumber = math.bignumber, complex = math.complex, matrix = math.matrix, diff --git a/test/function/arithmetic/exp.test.js b/test/function/arithmetic/exp.test.js index fd2257f2a..2815e6606 100644 --- a/test/function/arithmetic/exp.test.js +++ b/test/function/arithmetic/exp.test.js @@ -1,7 +1,7 @@ // test exp var assert = require('assert'), approx = require('../../../tools/approx'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), mathjs = require('../../../index'), math = mathjs(), complex = math.complex, diff --git a/test/function/arithmetic/fix.test.js b/test/function/arithmetic/fix.test.js index 4c99f1a31..e2b1879cf 100644 --- a/test/function/arithmetic/fix.test.js +++ b/test/function/arithmetic/fix.test.js @@ -1,6 +1,6 @@ // test fix var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), approx = require('../../../tools/approx'), math = require('../../../index')(), bignumber = math.bignumber, diff --git a/test/function/arithmetic/floor.test.js b/test/function/arithmetic/floor.test.js index 552c31088..975ee06cb 100644 --- a/test/function/arithmetic/floor.test.js +++ b/test/function/arithmetic/floor.test.js @@ -1,7 +1,7 @@ // test floor var assert = require('assert'), approx = require('../../../tools/approx'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), bignumber = math.bignumber, complex = math.complex, diff --git a/test/function/arithmetic/gcd.test.js b/test/function/arithmetic/gcd.test.js index 0e6e22e0a..6e3a68daa 100644 --- a/test/function/arithmetic/gcd.test.js +++ b/test/function/arithmetic/gcd.test.js @@ -1,6 +1,6 @@ // test gcd var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), gcd = math.gcd; diff --git a/test/function/arithmetic/larger.test.js b/test/function/arithmetic/larger.test.js index 64832be4a..86d991f1e 100644 --- a/test/function/arithmetic/larger.test.js +++ b/test/function/arithmetic/larger.test.js @@ -1,7 +1,7 @@ // test larger var assert = require('assert'), math = require('../../../index')(), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), bignumber = math.bignumber, complex = math.complex, matrix = math.matrix, diff --git a/test/function/arithmetic/largereq.test.js b/test/function/arithmetic/largereq.test.js index e1bcac8e7..0c2658749 100644 --- a/test/function/arithmetic/largereq.test.js +++ b/test/function/arithmetic/largereq.test.js @@ -1,7 +1,7 @@ // test largereq var assert = require('assert'), math = require('../../../index')(), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), bignumber = math.bignumber, complex = math.complex, matrix = math.matrix, diff --git a/test/function/arithmetic/lcm.test.js b/test/function/arithmetic/lcm.test.js index 33b499e12..6eeef5463 100644 --- a/test/function/arithmetic/lcm.test.js +++ b/test/function/arithmetic/lcm.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), lcm = math.lcm; diff --git a/test/function/arithmetic/log.test.js b/test/function/arithmetic/log.test.js index a18791fab..abb3b6fae 100644 --- a/test/function/arithmetic/log.test.js +++ b/test/function/arithmetic/log.test.js @@ -1,7 +1,7 @@ // test exp var assert = require('assert'), approx = require('../../../tools/approx'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), mathjs = require('../../../index'), math = mathjs(), complex = math.complex, diff --git a/test/function/arithmetic/log10.test.js b/test/function/arithmetic/log10.test.js index e3095ade9..c02b9a66b 100644 --- a/test/function/arithmetic/log10.test.js +++ b/test/function/arithmetic/log10.test.js @@ -1,7 +1,7 @@ // test exp var assert = require('assert'), approx = require('../../../tools/approx'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), mathjs = require('../../../index'), math = mathjs(), complex = math.complex, diff --git a/test/function/arithmetic/mod.test.js b/test/function/arithmetic/mod.test.js index 4f568a324..4f6483ebe 100644 --- a/test/function/arithmetic/mod.test.js +++ b/test/function/arithmetic/mod.test.js @@ -1,7 +1,7 @@ // test mod var assert = require('assert'), approx = require('../../../tools/approx'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), bignumber = math.bignumber, matrix = math.matrix, diff --git a/test/function/arithmetic/multiply.test.js b/test/function/arithmetic/multiply.test.js index bf78db285..3e5fff2a8 100644 --- a/test/function/arithmetic/multiply.test.js +++ b/test/function/arithmetic/multiply.test.js @@ -1,7 +1,7 @@ // test multiply var assert = require('assert'), math = require('../../../index')(), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), approx = require('../../../tools/approx'), multiply = math.multiply, divide = math.divide, diff --git a/test/function/arithmetic/pow.test.js b/test/function/arithmetic/pow.test.js index 640155bbe..8b1588a6b 100644 --- a/test/function/arithmetic/pow.test.js +++ b/test/function/arithmetic/pow.test.js @@ -1,7 +1,7 @@ // test exp var assert = require('assert'), approx = require('../../../tools/approx'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), bignumber = math.bignumber, complex = math.complex, diff --git a/test/function/arithmetic/round.test.js b/test/function/arithmetic/round.test.js index caea38870..97f5b7168 100644 --- a/test/function/arithmetic/round.test.js +++ b/test/function/arithmetic/round.test.js @@ -1,7 +1,7 @@ // test round var assert = require('assert'), approx = require('../../../tools/approx'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), bignumber = math.bignumber, round = math.round; diff --git a/test/function/arithmetic/sign.test.js b/test/function/arithmetic/sign.test.js index 0f3e7ffec..1d43c1fcb 100644 --- a/test/function/arithmetic/sign.test.js +++ b/test/function/arithmetic/sign.test.js @@ -1,7 +1,7 @@ // test sign var assert = require('assert'), approx = require('../../../tools/approx'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), bignumber = math.bignumber; diff --git a/test/function/arithmetic/smaller.test.js b/test/function/arithmetic/smaller.test.js index 7f9ff9806..db0b6c2be 100644 --- a/test/function/arithmetic/smaller.test.js +++ b/test/function/arithmetic/smaller.test.js @@ -1,7 +1,7 @@ // test smaller var assert = require('assert'), math = require('../../../index')(), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), bignumber = math.bignumber, complex = math.complex, matrix = math.matrix, diff --git a/test/function/arithmetic/smallereq.test.js b/test/function/arithmetic/smallereq.test.js index 6083807c7..be251254d 100644 --- a/test/function/arithmetic/smallereq.test.js +++ b/test/function/arithmetic/smallereq.test.js @@ -1,7 +1,7 @@ // test smaller var assert = require('assert'), math = require('../../../index')(), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), bignumber = math.bignumber, complex = math.complex, matrix = math.matrix, diff --git a/test/function/arithmetic/sqrt.test.js b/test/function/arithmetic/sqrt.test.js index 211a8c0ed..617517b30 100644 --- a/test/function/arithmetic/sqrt.test.js +++ b/test/function/arithmetic/sqrt.test.js @@ -1,7 +1,7 @@ // test sqrt var assert = require('assert'), approx = require('../../../tools/approx'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), mathjs = require('../../../index'), math = mathjs(); sqrt = math.sqrt, diff --git a/test/function/arithmetic/square.test.js b/test/function/arithmetic/square.test.js index 98f861d17..7d0f2243d 100644 --- a/test/function/arithmetic/square.test.js +++ b/test/function/arithmetic/square.test.js @@ -1,7 +1,7 @@ // test square var assert = require('assert'), math = require('../../../index')(), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), unit = math.unit, bignumber = math.bignumber, matrix = math.matrix, diff --git a/test/function/arithmetic/subtract.test.js b/test/function/arithmetic/subtract.test.js index 18943f3cc..8828a6bd3 100644 --- a/test/function/arithmetic/subtract.test.js +++ b/test/function/arithmetic/subtract.test.js @@ -1,7 +1,7 @@ // test subtract var assert = require('assert'), approx = require('../../../tools/approx'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), bignumber = math.bignumber, subtract = math.subtract; diff --git a/test/function/arithmetic/unary.test.js b/test/function/arithmetic/unary.test.js index fbb5612c6..7b9402894 100644 --- a/test/function/arithmetic/unary.test.js +++ b/test/function/arithmetic/unary.test.js @@ -1,7 +1,7 @@ // test unary minus var assert = require('assert'), math = require('../../../index')(), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), bignumber = math.bignumber; describe('unaryminus', function() { diff --git a/test/function/arithmetic/unequal.test.js b/test/function/arithmetic/unequal.test.js index ab949ca12..40654deb0 100644 --- a/test/function/arithmetic/unequal.test.js +++ b/test/function/arithmetic/unequal.test.js @@ -1,6 +1,6 @@ // test equal var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), bignumber = math.bignumber, complex = math.complex, diff --git a/test/function/arithmetic/xgcd.test.js b/test/function/arithmetic/xgcd.test.js index c862cf1f0..4d46a3bac 100644 --- a/test/function/arithmetic/xgcd.test.js +++ b/test/function/arithmetic/xgcd.test.js @@ -1,6 +1,6 @@ // test xgcd var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), gcd = math.gcd, xgcd = math.xgcd; diff --git a/test/function/complex/arg.test.js b/test/function/complex/arg.test.js index c003e527b..b164975ab 100644 --- a/test/function/complex/arg.test.js +++ b/test/function/complex/arg.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), approx = require('../../../tools/approx'), math = require('../../../index')(), arg = math.arg; diff --git a/test/function/complex/conj.test.js b/test/function/complex/conj.test.js index 238406da4..31d4ca01c 100644 --- a/test/function/complex/conj.test.js +++ b/test/function/complex/conj.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), conj = math.conj; diff --git a/test/function/complex/im.test.js b/test/function/complex/im.test.js index 841de1487..a11b09f6b 100644 --- a/test/function/complex/im.test.js +++ b/test/function/complex/im.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(); describe('im', function() { diff --git a/test/function/complex/re.test.js b/test/function/complex/re.test.js index ea05d361f..7d69be21b 100644 --- a/test/function/complex/re.test.js +++ b/test/function/complex/re.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(); describe('re', function() { diff --git a/test/function/construction/bignumber.test.js b/test/function/construction/bignumber.test.js index 17c080336..b2bfdc12c 100644 --- a/test/function/construction/bignumber.test.js +++ b/test/function/construction/bignumber.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), mathjs = require('../../../index'), math = mathjs(), bignumber = math.bignumber, diff --git a/test/function/construction/boolean.test.js b/test/function/construction/boolean.test.js index 95ed6466f..2810bf8e4 100644 --- a/test/function/construction/boolean.test.js +++ b/test/function/construction/boolean.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), bool = math['boolean']; diff --git a/test/function/construction/complex.test.js b/test/function/construction/complex.test.js index a1955c728..33f014ea4 100644 --- a/test/function/construction/complex.test.js +++ b/test/function/construction/complex.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), complex = math.complex; diff --git a/test/function/construction/index.test.js b/test/function/construction/index.test.js index 402164091..6bb153487 100644 --- a/test/function/construction/index.test.js +++ b/test/function/construction/index.test.js @@ -1,6 +1,6 @@ // test index construction var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(); describe('index', function() { diff --git a/test/function/construction/matrix.test.js b/test/function/construction/matrix.test.js index 1a36fa9a2..3e41dda5b 100644 --- a/test/function/construction/matrix.test.js +++ b/test/function/construction/matrix.test.js @@ -1,6 +1,6 @@ // test matrix construction var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), matrix = math.matrix; diff --git a/test/function/construction/number.test.js b/test/function/construction/number.test.js index 9bf275230..e6b3d9dab 100644 --- a/test/function/construction/number.test.js +++ b/test/function/construction/number.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), approx = require('../../../tools/approx'), number = math.number; diff --git a/test/function/construction/parser.test.js b/test/function/construction/parser.test.js index bb56450e5..421ad5567 100644 --- a/test/function/construction/parser.test.js +++ b/test/function/construction/parser.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), Parser = require('../../../lib/expression/Parser'), math = require('../../../index')(); diff --git a/test/function/construction/string.test.js b/test/function/construction/string.test.js index ff4b75c54..2d0f00841 100644 --- a/test/function/construction/string.test.js +++ b/test/function/construction/string.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), string = math.string; diff --git a/test/function/construction/unit.test.js b/test/function/construction/unit.test.js index 8e9d737f5..37133ae0c 100644 --- a/test/function/construction/unit.test.js +++ b/test/function/construction/unit.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), unit = math.unit; Unit = require('../../../lib/type/Unit'); diff --git a/test/function/expression/compile.test.js b/test/function/expression/compile.test.js index 1520eed2d..d13e04df9 100644 --- a/test/function/expression/compile.test.js +++ b/test/function/expression/compile.test.js @@ -1,6 +1,6 @@ // test parse var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), Node = require('../../../lib/expression/node/Node'); diff --git a/test/function/expression/eval.test.js b/test/function/expression/eval.test.js index c198517b1..b97422787 100644 --- a/test/function/expression/eval.test.js +++ b/test/function/expression/eval.test.js @@ -1,7 +1,7 @@ // test eval var assert = require('assert'), approx = require('../../../tools/approx'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), Complex = math.type.Complex, Matrix = math.type.Matrix, diff --git a/test/function/expression/help.test.js b/test/function/expression/help.test.js index 5767a083a..8325d7294 100644 --- a/test/function/expression/help.test.js +++ b/test/function/expression/help.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(); describe('help', function() { diff --git a/test/function/expression/parse.test.js b/test/function/expression/parse.test.js index e6914f05e..b8de30993 100644 --- a/test/function/expression/parse.test.js +++ b/test/function/expression/parse.test.js @@ -1,6 +1,6 @@ // test parse var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), Node = require('../../../lib/expression/node/Node'); diff --git a/test/function/matrix/concat.test.js b/test/function/matrix/concat.test.js index 609539353..062ff251a 100644 --- a/test/function/matrix/concat.test.js +++ b/test/function/matrix/concat.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), bignumber = math.bignumber; diff --git a/test/function/matrix/det.test.js b/test/function/matrix/det.test.js index 4c8be218b..5bda46fda 100644 --- a/test/function/matrix/det.test.js +++ b/test/function/matrix/det.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), approx = require('../../../tools/approx'), math = require('../../../index')(); diff --git a/test/function/matrix/diag.test.js b/test/function/matrix/diag.test.js index 0953835fb..6a1285c25 100644 --- a/test/function/matrix/diag.test.js +++ b/test/function/matrix/diag.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), bignumber = math.bignumber; diff --git a/test/function/matrix/eye.test.js b/test/function/matrix/eye.test.js index cf1700ca5..546fa6cf2 100644 --- a/test/function/matrix/eye.test.js +++ b/test/function/matrix/eye.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), mathjs = require('../../../index'), math = mathjs(), matrix = math.matrix, diff --git a/test/function/matrix/inv.test.js b/test/function/matrix/inv.test.js index 7908ae9f3..915978f70 100644 --- a/test/function/matrix/inv.test.js +++ b/test/function/matrix/inv.test.js @@ -1,7 +1,7 @@ // test inv var assert = require('assert'), approx = require('../../../tools/approx'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), inv = math.inv; diff --git a/test/function/matrix/ones.test.js b/test/function/matrix/ones.test.js index 15decc1a1..e8f365be5 100644 --- a/test/function/matrix/ones.test.js +++ b/test/function/matrix/ones.test.js @@ -1,6 +1,6 @@ // test ones var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), ones = math.ones, matrix = math.matrix; diff --git a/test/function/matrix/range.test.js b/test/function/matrix/range.test.js index 9ed437315..38125c837 100644 --- a/test/function/matrix/range.test.js +++ b/test/function/matrix/range.test.js @@ -1,6 +1,6 @@ var assert = require('assert'), approx = require('../../../tools/approx'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), mathjs = require('../../../index'), math = mathjs(), range = math.range, diff --git a/test/function/matrix/resize.test.js b/test/function/matrix/resize.test.js index 0ddf7e400..428de12bd 100644 --- a/test/function/matrix/resize.test.js +++ b/test/function/matrix/resize.test.js @@ -1,6 +1,6 @@ // test resize var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), Matrix = math.type.Matrix; diff --git a/test/function/matrix/size.test.js b/test/function/matrix/size.test.js index 8ba0b27ac..ac4bfe6f8 100644 --- a/test/function/matrix/size.test.js +++ b/test/function/matrix/size.test.js @@ -1,6 +1,6 @@ // test size var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), mathjs = require('../../../index'), math = mathjs(), size = math.size, diff --git a/test/function/matrix/squeeze.test.js b/test/function/matrix/squeeze.test.js index 62cf1b696..70cdb9509 100644 --- a/test/function/matrix/squeeze.test.js +++ b/test/function/matrix/squeeze.test.js @@ -1,6 +1,6 @@ // test squeeze var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), squeeze = math.squeeze, size = math.size, diff --git a/test/function/matrix/subset.test.js b/test/function/matrix/subset.test.js index c944db5db..7cc34a850 100644 --- a/test/function/matrix/subset.test.js +++ b/test/function/matrix/subset.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), subset = math.subset, matrix = math.matrix, diff --git a/test/function/matrix/transpose.test.js b/test/function/matrix/transpose.test.js index 082179e6d..4b8612248 100644 --- a/test/function/matrix/transpose.test.js +++ b/test/function/matrix/transpose.test.js @@ -1,6 +1,6 @@ // test transpose var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), transpose = math.transpose; diff --git a/test/function/matrix/zeros.test.js b/test/function/matrix/zeros.test.js index d222506a5..cc135d98c 100644 --- a/test/function/matrix/zeros.test.js +++ b/test/function/matrix/zeros.test.js @@ -1,6 +1,6 @@ // test zeros var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), zeros = math.zeros, matrix = math.matrix; diff --git a/test/function/probability/combinations.test.js b/test/function/probability/combinations.test.js index e268125e9..898cc2ab1 100644 --- a/test/function/probability/combinations.test.js +++ b/test/function/probability/combinations.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), combinations = math.combinations; diff --git a/test/function/probability/factorial.test.js b/test/function/probability/factorial.test.js index fe816ffb8..71fb42fbc 100644 --- a/test/function/probability/factorial.test.js +++ b/test/function/probability/factorial.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), factorial = math.factorial; diff --git a/test/function/probability/permutations.test.js b/test/function/probability/permutations.test.js index a696551d0..2de6a8c7a 100644 --- a/test/function/probability/permutations.test.js +++ b/test/function/probability/permutations.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), permutations = math.permutations; diff --git a/test/function/probability/random.test.js b/test/function/probability/random.test.js index 0edc8a070..428f596a9 100644 --- a/test/function/probability/random.test.js +++ b/test/function/probability/random.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), seed = require('seed-random'), _ = require('underscore'), math = require('../../../index')(); diff --git a/test/function/trigonometry/acos.test.js b/test/function/trigonometry/acos.test.js index d78428ea7..c9bfe1eac 100644 --- a/test/function/trigonometry/acos.test.js +++ b/test/function/trigonometry/acos.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), approx = require('../../../tools/approx'), pi = math.pi, diff --git a/test/function/trigonometry/asin.test.js b/test/function/trigonometry/asin.test.js index d155f9d0c..134934241 100644 --- a/test/function/trigonometry/asin.test.js +++ b/test/function/trigonometry/asin.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), approx = require('../../../tools/approx'), pi = math.pi, diff --git a/test/function/trigonometry/atan.test.js b/test/function/trigonometry/atan.test.js index f6d7b1c1d..61b21e742 100644 --- a/test/function/trigonometry/atan.test.js +++ b/test/function/trigonometry/atan.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), approx = require('../../../tools/approx'), pi = math.pi, diff --git a/test/function/trigonometry/atan2.test.js b/test/function/trigonometry/atan2.test.js index 56c7c55de..8614535ad 100644 --- a/test/function/trigonometry/atan2.test.js +++ b/test/function/trigonometry/atan2.test.js @@ -1,6 +1,6 @@ // test atan2 var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), approx = require('../../../tools/approx'), pi = math.pi, diff --git a/test/function/trigonometry/cos.test.js b/test/function/trigonometry/cos.test.js index 74cd2fc62..35a3b6c85 100644 --- a/test/function/trigonometry/cos.test.js +++ b/test/function/trigonometry/cos.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), approx = require('../../../tools/approx'), pi = math.pi, diff --git a/test/function/trigonometry/cot.test.js b/test/function/trigonometry/cot.test.js index 5ff4ad203..5bfbbf255 100644 --- a/test/function/trigonometry/cot.test.js +++ b/test/function/trigonometry/cot.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), approx = require('../../../tools/approx'), pi = math.pi, diff --git a/test/function/trigonometry/csc.test.js b/test/function/trigonometry/csc.test.js index 2e05d69a2..ea57ac987 100644 --- a/test/function/trigonometry/csc.test.js +++ b/test/function/trigonometry/csc.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), approx = require('../../../tools/approx'), pi = math.pi, diff --git a/test/function/trigonometry/sec.test.js b/test/function/trigonometry/sec.test.js index cccc801aa..ac36aa4e0 100644 --- a/test/function/trigonometry/sec.test.js +++ b/test/function/trigonometry/sec.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), approx = require('../../../tools/approx'), pi = math.pi, diff --git a/test/function/trigonometry/sin.test.js b/test/function/trigonometry/sin.test.js index cf3e47bdc..59cf74b18 100644 --- a/test/function/trigonometry/sin.test.js +++ b/test/function/trigonometry/sin.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), approx = require('../../../tools/approx'), pi = math.pi, diff --git a/test/function/trigonometry/tan.test.js b/test/function/trigonometry/tan.test.js index e41c00e36..d440c98e0 100644 --- a/test/function/trigonometry/tan.test.js +++ b/test/function/trigonometry/tan.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), approx = require('../../../tools/approx'), pi = math.pi, diff --git a/test/function/utils/clone.test.js b/test/function/utils/clone.test.js index 0a79c6156..b9eba1037 100644 --- a/test/function/utils/clone.test.js +++ b/test/function/utils/clone.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(); describe('clone', function() { diff --git a/test/function/utils/forEach.test.js b/test/function/utils/forEach.test.js index d4d94629d..045992ef4 100644 --- a/test/function/utils/forEach.test.js +++ b/test/function/utils/forEach.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(); describe('forEach', function() { diff --git a/test/function/utils/format.test.js b/test/function/utils/format.test.js index e334eb7bb..5b4b91beb 100644 --- a/test/function/utils/format.test.js +++ b/test/function/utils/format.test.js @@ -1,6 +1,6 @@ // test format var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), mathjs = require('../../../index'); math = mathjs(); diff --git a/test/function/utils/ifElse.test.js b/test/function/utils/ifElse.test.js index a1f0523c2..9df91bd13 100644 --- a/test/function/utils/ifElse.test.js +++ b/test/function/utils/ifElse.test.js @@ -1,6 +1,6 @@ // test format var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(), ifElse = math.ifElse; diff --git a/test/function/utils/import.test.js b/test/function/utils/import.test.js index 374938fda..caf934c2e 100644 --- a/test/function/utils/import.test.js +++ b/test/function/utils/import.test.js @@ -1,6 +1,6 @@ // test import var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), mathjs = require('../../../index'), approx = require('../../../tools/approx'); diff --git a/test/function/utils/map.test.js b/test/function/utils/map.test.js index 54d59c93b..f0bb319f2 100644 --- a/test/function/utils/map.test.js +++ b/test/function/utils/map.test.js @@ -1,5 +1,5 @@ var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(); describe('map', function() { diff --git a/test/function/utils/print.test.js b/test/function/utils/print.test.js index 5f53e3c6e..8a5640c70 100644 --- a/test/function/utils/print.test.js +++ b/test/function/utils/print.test.js @@ -1,6 +1,6 @@ // test print var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(); describe('print', function() { diff --git a/test/function/utils/typeof.test.js b/test/function/utils/typeof.test.js index fcebf0639..fe5f5a32b 100644 --- a/test/function/utils/typeof.test.js +++ b/test/function/utils/typeof.test.js @@ -1,6 +1,6 @@ // test typeof var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error/index'), Index = require('../../../lib/type/Index'), Range = require('../../../lib/type/Range'), Matrix = require('../../../lib/type/Matrix'), diff --git a/test/math.test.js b/test/math.test.js index 970c4a7e2..7c31fa0f1 100644 --- a/test/math.test.js +++ b/test/math.test.js @@ -70,14 +70,7 @@ describe('factory', function() { math.config(config); }); - - it('should contain error namespace', function() { - assert.equal (typeof math.error, 'object'); - assert('ArgumentsError' in math.error); - assert('DimensionError' in math.error); - assert('IndexError' in math.error); - assert('UnsupportedTypeError' in math.error); - }); + // TODO: test whether the namespace is correct: has functions like sin, constants like pi, objects like type and error. it('should convert a number into a bignumber (when possible)', function() { var BigNumber = math.type.BigNumber; diff --git a/test/util/error.test.js b/test/util/error.test.js deleted file mode 100644 index 0ffbec91d..000000000 --- a/test/util/error.test.js +++ /dev/null @@ -1,157 +0,0 @@ -// test error types - -var assert = require('assert'), - error = require('../../lib/util/error'); - -describe('error', function () { - - describe('ArgumentsError', function () { - - it('should construct an ArgumentsError without max', function () { - var err = new error.ArgumentsError('myfunction', 1, 2); - assert(err instanceof Error); - assert(err instanceof error.ArgumentsError); - assert.equal(err.toString(), 'ArgumentsError: Wrong number of arguments in function myfunction (1 provided, 2 expected)'); - }); - - it('should construct an ArgumentsError with max', function () { - var err = new error.ArgumentsError('myfunction', 1, 2, 3); - assert(err instanceof Error); - assert(err instanceof error.ArgumentsError); - assert.equal(err.toString(), 'ArgumentsError: Wrong number of arguments in function myfunction (1 provided, 2-3 expected)'); - }); - - it('should throw an error when operator new is missing', function () { - assert.throws(function () {error.ArgumentsError();}, SyntaxError); - }); - - }); - - describe('DimensionError', function () { - - it('should construct a DimensionError with numbers', function () { - var err = new error.DimensionError(3, 5); - assert(err instanceof Error); - assert(err instanceof RangeError); - assert(err instanceof error.DimensionError); - assert.equal(err.toString(), 'DimensionError: Dimension mismatch (3 != 5)'); - }); - - it('should construct a DimensionError with numbers and a custom relation', function () { - var err = new error.DimensionError(3, 5, '<'); - assert(err instanceof Error); - assert(err instanceof RangeError); - assert(err instanceof error.DimensionError); - assert.equal(err.toString(), 'DimensionError: Dimension mismatch (3 < 5)'); - }); - - it('should construct a DimensionError with arrays', function () { - var err = new error.DimensionError([2,3], [1,3]); - assert(err instanceof Error); - assert(err instanceof RangeError); - assert(err instanceof error.DimensionError); - assert.equal(err.toString(), 'DimensionError: Dimension mismatch ([2, 3] != [1, 3])'); - }); - - it('should construct a DimensionError with arrays and a custom relation', function () { - var err = new error.DimensionError([2,3], [1,3], '<'); - assert(err instanceof Error); - assert(err instanceof RangeError); - assert(err instanceof error.DimensionError); - assert.equal(err.toString(), 'DimensionError: Dimension mismatch ([2, 3] < [1, 3])'); - }); - - it('should throw an error when operator new is missing', function () { - assert.throws(function () {error.DimensionError(3, 5);}, SyntaxError); - }); - - }); - - describe('IndexError', function () { - - it('should construct an IndexError without min and max', function () { - var err = new error.IndexError(5); - assert(err instanceof Error); - assert(err instanceof RangeError); - assert(err instanceof error.IndexError); - assert.equal(err.toString(), 'IndexError: Index out of range (5)'); - }); - - it('should construct an IndexError without min and max (2)', function () { - var err = new error.IndexError(-5); - assert(err instanceof Error); - assert(err instanceof RangeError); - assert(err instanceof error.IndexError); - assert.equal(err.toString(), 'IndexError: Index out of range (-5 < 0)'); - }); - - it('should construct an IndexError with max', function () { - var err = new error.IndexError(5, 3); - assert(err instanceof Error); - assert(err instanceof RangeError); - assert(err instanceof error.IndexError); - assert.equal(err.toString(), 'IndexError: Index out of range (5 > 2)'); - }); - - it('should construct an IndexError with min and max', function () { - var err = new error.IndexError(0, 2, 5); - assert(err instanceof Error); - assert(err instanceof RangeError); - assert(err instanceof error.IndexError); - assert.equal(err.toString(), 'IndexError: Index out of range (0 < 2)'); - }); - - it('should construct an IndexError with min and max', function () { - var err = new error.IndexError(6, 1, 4); - assert(err instanceof Error); - assert(err instanceof RangeError); - assert(err instanceof error.IndexError); - assert.equal(err.toString(), 'IndexError: Index out of range (6 > 3)'); - }); - - }); - - describe('UnsupportedTypeError', function () { - - it('should construct an UnsupportedTypeError with no argument', function () { - var err = new error.UnsupportedTypeError(); - assert(err instanceof Error); - assert(err instanceof error.UnsupportedTypeError); - assert.equal(err.toString(), 'UnsupportedTypeError: Unsupported type of argument'); - }); - - it('should construct an UnsupportedTypeError with one argument', function () { - var err = new error.UnsupportedTypeError('myfunction'); - assert(err instanceof Error); - assert(err instanceof error.UnsupportedTypeError); - assert.equal(err.toString(), 'UnsupportedTypeError: Unsupported type of argument in function myfunction'); - }); - - it('should construct an UnsupportedTypeError with two arguments', function () { - var err = new error.UnsupportedTypeError('myfunction', 'number'); - assert(err instanceof Error); - assert(err instanceof error.UnsupportedTypeError); - assert.equal(err.toString(), 'UnsupportedTypeError: Function myfunction(number) not supported'); - }); - - it('should construct an UnsupportedTypeError with three arguments', function () { - var err = new error.UnsupportedTypeError('myfunction', 'number', 'string'); - assert(err instanceof Error); - assert(err instanceof error.UnsupportedTypeError); - assert.equal(err.toString(), 'UnsupportedTypeError: Function myfunction(number, string) not supported'); - }); - - it('should construct an UnsupportedTypeError with more than three arguments', function () { - var err = new error.UnsupportedTypeError('myfunction', 'number', 'string', 'date'); - assert(err instanceof Error); - assert(err instanceof error.UnsupportedTypeError); - assert.equal(err.toString(), 'UnsupportedTypeError: Function myfunction(number, string, date) not supported'); - }); - - it('should throw an error when operator new is missing', function () { - assert.throws(function () {error.UnsupportedTypeError();}, SyntaxError); - }); - - }); - -}); From b0f19da5c3f6bc0484b4754cb514e430630fba4a Mon Sep 17 00:00:00 2001 From: josdejong Date: Fri, 11 Apr 2014 21:30:08 +0200 Subject: [PATCH 30/48] Storing all arguments in the errors --- lib/error/ArgumentsError.js | 11 +++++--- lib/error/DimensionError.js | 4 +-- lib/error/IndexError.js | 6 ++--- lib/error/UnsupportedTypeError.js | 35 +++++++++++-------------- test/error/ArgumentsError.test.js | 8 ++++++ test/error/DimensionError.test.js | 12 +++++++++ test/error/IndexError.test.js | 15 +++++++++++ test/error/UnsupportedTypeError.test.js | 10 +++++++ 8 files changed, 73 insertions(+), 28 deletions(-) diff --git a/lib/error/ArgumentsError.js b/lib/error/ArgumentsError.js index 7aa8341fd..ad22f4665 100644 --- a/lib/error/ArgumentsError.js +++ b/lib/error/ArgumentsError.js @@ -1,18 +1,23 @@ /** * Create a syntax error with the message: * 'Wrong number of arguments in function ( provided, - expected)' - * @param {String} name Function name + * @param {String} fn Function name * @param {Number} count Actual argument count * @param {Number} min Minimum required argument count * @param {Number} [max] Maximum required argument count * @extends Error */ -function ArgumentsError(name, count, min, max) { +function ArgumentsError(fn, count, min, max) { if (!(this instanceof ArgumentsError)) { throw new SyntaxError('Constructor must be called with the new operator'); } - this.message = 'Wrong number of arguments in function ' + name + + this.fn = fn; + this.count = count; + this.min = min; + this.max = max; + + this.message = 'Wrong number of arguments in function ' + fn + ' (' + count + ' provided, ' + min + ((max != undefined) ? ('-' + max) : '') + ' expected)'; diff --git a/lib/error/DimensionError.js b/lib/error/DimensionError.js index 06353f21a..d5d8d6db4 100644 --- a/lib/error/DimensionError.js +++ b/lib/error/DimensionError.js @@ -14,11 +14,11 @@ function DimensionError(actual, expected, relation) { this.actual = actual; this.expected = expected; - this.relation = relation || '!='; + this.relation = relation; this.message = 'Dimension mismatch (' + (Array.isArray(actual) ? ('[' + actual.join(', ') + ']') : actual) + - ' ' + this.relation + ' ' + + ' ' + (this.relation || '!=') + ' ' + (Array.isArray(expected) ? ('[' + expected.join(', ') + ']') : expected) + ')'; diff --git a/lib/error/IndexError.js b/lib/error/IndexError.js index 3b1c2e982..7239760ea 100644 --- a/lib/error/IndexError.js +++ b/lib/error/IndexError.js @@ -14,7 +14,7 @@ function IndexError(index, min, max) { } this.index = index; - if (arguments.length <= 2) { + if (arguments.length < 3) { this.min = 0; this.max = min; } @@ -23,10 +23,10 @@ function IndexError(index, min, max) { this.max = max; } - if (this.index < this.min) { + if (this.min !== undefined && this.index < this.min) { this.message = 'Index out of range (' + this.index + ' < ' + this.min + ')'; } - else if (this.index >= this.max) { + else if (this.max !== undefined && this.index >= this.max) { this.message = 'Index out of range (' + this.index + ' > ' + (this.max - 1) + ')'; } else { diff --git a/lib/error/UnsupportedTypeError.js b/lib/error/UnsupportedTypeError.js index d3528ec4e..7d0e51327 100644 --- a/lib/error/UnsupportedTypeError.js +++ b/lib/error/UnsupportedTypeError.js @@ -1,33 +1,28 @@ /** * Create a TypeError with message: * 'Function does not support a parameter of type '; - * @param {String} name Function name - * @param {*} [type1] - * @param {*...} [type_n] + * @param {String} fn Function name + * @param {*...} [types] The types of the function arguments * @extends TypeError */ -function UnsupportedTypeError(name, type1, type_n) { +function UnsupportedTypeError(fn, types) { if (!(this instanceof UnsupportedTypeError)) { throw new SyntaxError('Constructor must be called with the new operator'); } - switch (arguments.length) { - case 0: - this.message = 'Unsupported type of argument'; - break; + this.fn = fn; + this.types = Array.prototype.splice.call(arguments, 1); - case 1: - this.message = 'Unsupported type of argument in function ' + name; - break; - - case 2: - this.message = 'Function ' + name + '(' + type1 + ') not supported'; - break; - - default: // more than two arguments - var types = Array.prototype.splice.call(arguments, 1); - this.message = 'Function ' + name + '(' + types.join(', ') + ') not supported'; - break; + if (!fn) { + this.message = 'Unsupported type of argument'; + } + else { + if (this.types.length == 0) { + this.message = 'Unsupported type of argument in function ' + fn; + } + else { + this.message = 'Function ' + fn + '(' + this.types.join(', ') + ') not supported'; + } } this.stack = (new Error()).stack; diff --git a/test/error/ArgumentsError.test.js b/test/error/ArgumentsError.test.js index b5a0913fe..0e0746fde 100644 --- a/test/error/ArgumentsError.test.js +++ b/test/error/ArgumentsError.test.js @@ -7,6 +7,10 @@ describe('ArgumentsError', function () { var err = new ArgumentsError('myfunction', 1, 2); assert(err instanceof Error); assert(err instanceof ArgumentsError); + assert.equal(err.fn, 'myfunction'); + assert.equal(err.count, 1); + assert.equal(err.min, 2); + assert.equal(err.max, undefined); assert.equal(err.toString(), 'ArgumentsError: Wrong number of arguments in function myfunction (1 provided, 2 expected)'); }); @@ -14,6 +18,10 @@ describe('ArgumentsError', function () { var err = new ArgumentsError('myfunction', 1, 2, 3); assert(err instanceof Error); assert(err instanceof ArgumentsError); + assert.equal(err.fn, 'myfunction'); + assert.equal(err.count, 1); + assert.equal(err.min, 2); + assert.equal(err.max, 3); assert.equal(err.toString(), 'ArgumentsError: Wrong number of arguments in function myfunction (1 provided, 2-3 expected)'); }); diff --git a/test/error/DimensionError.test.js b/test/error/DimensionError.test.js index 8581eab42..efeb85df7 100644 --- a/test/error/DimensionError.test.js +++ b/test/error/DimensionError.test.js @@ -8,6 +8,9 @@ describe('DimensionError', function () { assert(err instanceof Error); assert(err instanceof RangeError); assert(err instanceof DimensionError); + assert.equal(err.actual, 3); + assert.equal(err.expected, 5); + assert.equal(err.relation, undefined); assert.equal(err.toString(), 'DimensionError: Dimension mismatch (3 != 5)'); }); @@ -16,6 +19,9 @@ describe('DimensionError', function () { assert(err instanceof Error); assert(err instanceof RangeError); assert(err instanceof DimensionError); + assert.equal(err.actual, 3); + assert.equal(err.expected, 5); + assert.equal(err.relation, '<'); assert.equal(err.toString(), 'DimensionError: Dimension mismatch (3 < 5)'); }); @@ -24,6 +30,9 @@ describe('DimensionError', function () { assert(err instanceof Error); assert(err instanceof RangeError); assert(err instanceof DimensionError); + assert.deepEqual(err.actual, [2,3]); + assert.deepEqual(err.expected, [1,3]); + assert.equal(err.relation, undefined); assert.equal(err.toString(), 'DimensionError: Dimension mismatch ([2, 3] != [1, 3])'); }); @@ -32,6 +41,9 @@ describe('DimensionError', function () { assert(err instanceof Error); assert(err instanceof RangeError); assert(err instanceof DimensionError); + assert.deepEqual(err.actual, [2,3]); + assert.deepEqual(err.expected, [1,3]); + assert.equal(err.relation, '<'); assert.equal(err.toString(), 'DimensionError: Dimension mismatch ([2, 3] < [1, 3])'); }); diff --git a/test/error/IndexError.test.js b/test/error/IndexError.test.js index af0600eee..192517a4d 100644 --- a/test/error/IndexError.test.js +++ b/test/error/IndexError.test.js @@ -8,6 +8,9 @@ describe('IndexError', function () { assert(err instanceof Error); assert(err instanceof RangeError); assert(err instanceof IndexError); + assert.equal(err.index, 5); + assert.equal(err.min, 0); + assert.equal(err.max, undefined); assert.equal(err.toString(), 'IndexError: Index out of range (5)'); }); @@ -16,6 +19,9 @@ describe('IndexError', function () { assert(err instanceof Error); assert(err instanceof RangeError); assert(err instanceof IndexError); + assert.equal(err.index, -5); + assert.equal(err.min, 0); + assert.equal(err.max, undefined); assert.equal(err.toString(), 'IndexError: Index out of range (-5 < 0)'); }); @@ -24,6 +30,9 @@ describe('IndexError', function () { assert(err instanceof Error); assert(err instanceof RangeError); assert(err instanceof IndexError); + assert.equal(err.index, 5); + assert.equal(err.min, 0); + assert.equal(err.max, 3); assert.equal(err.toString(), 'IndexError: Index out of range (5 > 2)'); }); @@ -32,6 +41,9 @@ describe('IndexError', function () { assert(err instanceof Error); assert(err instanceof RangeError); assert(err instanceof IndexError); + assert.equal(err.index, 0); + assert.equal(err.min, 2); + assert.equal(err.max, 5); assert.equal(err.toString(), 'IndexError: Index out of range (0 < 2)'); }); @@ -40,6 +52,9 @@ describe('IndexError', function () { assert(err instanceof Error); assert(err instanceof RangeError); assert(err instanceof IndexError); + assert.equal(err.index, 6); + assert.equal(err.min, 1); + assert.equal(err.max, 4); assert.equal(err.toString(), 'IndexError: Index out of range (6 > 3)'); }); diff --git a/test/error/UnsupportedTypeError.test.js b/test/error/UnsupportedTypeError.test.js index ae15b3a32..e1e123bcc 100644 --- a/test/error/UnsupportedTypeError.test.js +++ b/test/error/UnsupportedTypeError.test.js @@ -7,6 +7,8 @@ describe('UnsupportedTypeError', function () { var err = new UnsupportedTypeError(); assert(err instanceof Error); assert(err instanceof UnsupportedTypeError); + assert.equal(err.fn, undefined); + assert.deepEqual(err.types, []); assert.equal(err.toString(), 'UnsupportedTypeError: Unsupported type of argument'); }); @@ -14,6 +16,8 @@ describe('UnsupportedTypeError', function () { var err = new UnsupportedTypeError('myfunction'); assert(err instanceof Error); assert(err instanceof UnsupportedTypeError); + assert.equal(err.fn, 'myfunction'); + assert.deepEqual(err.types, []); assert.equal(err.toString(), 'UnsupportedTypeError: Unsupported type of argument in function myfunction'); }); @@ -21,6 +25,8 @@ describe('UnsupportedTypeError', function () { var err = new UnsupportedTypeError('myfunction', 'number'); assert(err instanceof Error); assert(err instanceof UnsupportedTypeError); + assert.equal(err.fn, 'myfunction'); + assert.deepEqual(err.types, ['number']); assert.equal(err.toString(), 'UnsupportedTypeError: Function myfunction(number) not supported'); }); @@ -28,6 +34,8 @@ describe('UnsupportedTypeError', function () { var err = new UnsupportedTypeError('myfunction', 'number', 'string'); assert(err instanceof Error); assert(err instanceof UnsupportedTypeError); + assert.equal(err.fn, 'myfunction'); + assert.deepEqual(err.types, ['number', 'string']); assert.equal(err.toString(), 'UnsupportedTypeError: Function myfunction(number, string) not supported'); }); @@ -35,6 +43,8 @@ describe('UnsupportedTypeError', function () { var err = new UnsupportedTypeError('myfunction', 'number', 'string', 'date'); assert(err instanceof Error); assert(err instanceof UnsupportedTypeError); + assert.equal(err.fn, 'myfunction'); + assert.deepEqual(err.types, ['number', 'string', 'date']); assert.equal(err.toString(), 'UnsupportedTypeError: Function myfunction(number, string, date) not supported'); }); From fdc7c8db039a4f641578a826d20a2417ce500f05 Mon Sep 17 00:00:00 2001 From: josdejong Date: Fri, 11 Apr 2014 22:18:40 +0200 Subject: [PATCH 31/48] Fixed some errors after solving merge conflicts --- lib/function/arithmetic/smallereq.js | 2 +- lib/math.js | 6 ++---- lib/util/number.js | 2 -- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/function/arithmetic/smallereq.js b/lib/function/arithmetic/smallereq.js index e3836ade4..0e2cbcb98 100644 --- a/lib/function/arithmetic/smallereq.js +++ b/lib/function/arithmetic/smallereq.js @@ -13,7 +13,7 @@ module.exports = function (math, config) { isComplex = Complex.isComplex, isUnit = Unit.isUnit, isCollection = collection.isCollection, - config = settings.epsilon; + epsilon = config.epsilon; /** * Check if value a is smaller or equal to b diff --git a/lib/math.js b/lib/math.js index 8fb71286e..f166ee400 100644 --- a/lib/math.js +++ b/lib/math.js @@ -38,7 +38,7 @@ function mathjs (config) { // number of significant digits in BigNumbers precision: 20, - // relative difference between values to consider them equal + // relative difference between values to test equality for numbers epsilon: 1e-6 }; @@ -92,9 +92,7 @@ function mathjs (config) { } // return a clone of the settings - var current = object.clone(_settings); - current.decimals = BigNumber.config().DECIMAL_PLACES; - return current; + return object.clone(_config); }; // create a new BigNumber factory for this instance of math.js diff --git a/lib/util/number.js b/lib/util/number.js index 59c0fe053..19e0892e5 100644 --- a/lib/util/number.js +++ b/lib/util/number.js @@ -1,5 +1,3 @@ -var BigNumber = require('bignumber.js'); - /** * Test whether value is a Number * @param {*} value From ac365c7a9c896454eb414feff8b0356d7a4a652c Mon Sep 17 00:00:00 2001 From: "Rogelio J. Baucells" Date: Fri, 11 Apr 2014 17:45:21 -0400 Subject: [PATCH 32/48] Initial norm() implementation --- lib/function/arithmetic/norm.js | 94 +++++++++++++++++++++++++++ lib/math.js | 1 + test/function/arithmetic/norm.test.js | 54 +++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 lib/function/arithmetic/norm.js create mode 100644 test/function/arithmetic/norm.test.js diff --git a/lib/function/arithmetic/norm.js b/lib/function/arithmetic/norm.js new file mode 100644 index 000000000..3220a5004 --- /dev/null +++ b/lib/function/arithmetic/norm.js @@ -0,0 +1,94 @@ +module.exports = function (math) { + var util = require('../../util/index'), + + array = require('../../../lib/util/array'), + + BigNumber = require('bignumber.js'), + Complex = require('../../type/Complex'), + Matrix = require('../../type/Matrix'), + collection = require('../../type/collection'), + + isNumber = util.number.isNumber, + isBoolean = util['boolean'].isBoolean, + isComplex = Complex.isComplex, + isCollection = collection.isCollection; + + /** + * Calculate the norm of a number, vector or matrix. + * + * norm(x, [p]) + * + * @param {Number | BigNumber | Complex | Boolean | Array | Matrix} x + * @param {Number | Infinity} p, optional defaults to 2 + * @return {Number} the p-norm + */ + math.norm = function norm(x, p) { + if (arguments.length < 1 || arguments.length > 2) { + throw new math.error.ArgumentsError('norm', arguments.length, 1, 2); + } + + if (isNumber(x)) { + // norm(x) = abs(x) + return Math.abs(x); + } + + if (isComplex(x)) { + // ignore p, complex numbers + return Math.sqrt(x.re * x.re + x.im * x.im); + } + + if (x instanceof BigNumber) { + // norm(x) = abs(x) + return x.abs(); + } + + if (isBoolean(x)) { + // norm(x) = abs(x) + return Math.abs(x); + } + + if (isArray(x)) { + // size + var sizeX = array.size(x); + // p + p = p || 2; + // check it is a Vector + if (sizeX.length == 1) { + // check p + if (p == Number.POSITIVE_INFINITY) { + // norm(x, Infinity) = max(abs(x)) + var n = 0; + collection.deepForEach(x, function (value) { + var v = math.abs(value); + if (math.larger(v, n)) + n = v; + }); + return n; + } + else if (isNumber(p) && !isNaN(p)) { + // check p != 0 + if (!math.equal(p, 0)) { + // norm(x, p) = sum(abs(xi) ^ p) ^ 1/p + var n = 0; + collection.deepForEach(x, function (value) { + n += math.pow(math.abs(value), p); + }); + return math.pow(n, 1 / p); + } + return Number.POSITIVE_INFINITY; + } + else { + // invalid parameter value + throw new Error('Parameter [p] in function norm must be a Number'); + } + } + + } + + if (x instanceof Matrix) { + return norm(x.valueOf(), p); + } + + throw new math.error.UnsupportedTypeError('norm', x); + }; +}; diff --git a/lib/math.js b/lib/math.js index 7eeacf3e9..fc89adfd8 100644 --- a/lib/math.js +++ b/lib/math.js @@ -181,6 +181,7 @@ function mathjs (config) { require('./function/arithmetic/log10.js')(math, _config); require('./function/arithmetic/mod.js')(math, _config); require('./function/arithmetic/multiply.js')(math, _config); + require('./function/arithmetic/norm.js')(math, _config); require('./function/arithmetic/pow.js')(math, _config); require('./function/arithmetic/round.js')(math, _config); require('./function/arithmetic/sign.js')(math, _config); diff --git a/test/function/arithmetic/norm.test.js b/test/function/arithmetic/norm.test.js new file mode 100644 index 000000000..42fc2bf9c --- /dev/null +++ b/test/function/arithmetic/norm.test.js @@ -0,0 +1,54 @@ +// test norm +var assert = require('assert'), + error = require('../../../lib/util/error'), + math = require('../../../index')(); + +describe('norm', function () { + + it('should return the absolute value of a boolean', function () { + assert.equal(math.norm(true), 1); + assert.equal(math.norm(true, 10), 1); + assert.equal(math.norm(false), 0); + assert.equal(math.norm(false, 10), 0); + }); + + it('should return the absolute value of a number', function () { + assert.equal(math.norm(-4.2), 4.2); + assert.equal(math.norm(-3.5), 3.5); + assert.equal(math.norm(100), 100); + assert.equal(math.norm(0), 0); + assert.equal(math.norm(100, 10), 100); + }); + + it('should return the absolute value of a big number', function () { + // assert.equal(math.norm(math.bignumber(-2.3)), math.bignumber(2.3)); + // assert.deepEqual(math.norm(math.bignumber('5e500')), math.bignumber('5e500')); + // assert.deepEqual(math.norm(math.bignumber('-5e500')), math.bignumber('5e500')); + }); + + it('should return the norm of a complex number', function () { + assert.equal(math.norm(math.complex(3, -4)), 5); + }); + + it('should return the norm of a vector', function () { + // p = 0 + assert.equal(math.norm([]), 0.0); + // p = Infinity + assert.equal(math.norm([1, 2, -3], Number.POSITIVE_INFINITY), 3); + // p - positive + assert.equal(math.norm([3, 4], 2), 5.0); + // p - negative + assert.equal(math.norm([3, 4], -2), 2.4); + }); + + it('should throw an error in case of invalid number of arguments', function() { + // assert.throws(function () {math.norm()}, error.ArgumentsError); + // assert.throws(function () {math.norm(1, 2, 3)}, error.ArgumentsError); + }); + + it('should throw an error with a string', function () { + assert.throws(function () { + math.norm('a string'); + }); + }); +}); From 1c6dfac04da032c2e8f673039a424ac95b060a20 Mon Sep 17 00:00:00 2001 From: rjbaucells Date: Sat, 12 Apr 2014 12:38:24 -0400 Subject: [PATCH 33/48] norm tests and documentation --- .../docs/function/arithmetic/norm.js | 14 ++++++ lib/expression/docs/index.js | 1 + lib/function/arithmetic/norm.js | 46 +++++++++++++++++-- test/function/arithmetic/norm.test.js | 28 +++++++++-- 4 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 lib/expression/docs/function/arithmetic/norm.js diff --git a/lib/expression/docs/function/arithmetic/norm.js b/lib/expression/docs/function/arithmetic/norm.js new file mode 100644 index 000000000..b874abfc3 --- /dev/null +++ b/lib/expression/docs/function/arithmetic/norm.js @@ -0,0 +1,14 @@ +module.exports = { + 'name': 'norm', + 'category': 'Arithmetic', + 'syntax': [ + 'norm(x)', + 'norm(x, p)' + ], + 'description': 'Calculate the norm of a number, vector or matrix.', + 'examples': [ + 'norm([[1, 2], [3, 4]])', + 'norm([[1, 2, 3, 4]], 3.5)', + 'norm(-4.2)' + ] +}; diff --git a/lib/expression/docs/index.js b/lib/expression/docs/index.js index ece5d11b9..2ff921e79 100644 --- a/lib/expression/docs/index.js +++ b/lib/expression/docs/index.js @@ -38,6 +38,7 @@ exports.log = require('./function/arithmetic/log'); exports.log10 = require('./function/arithmetic/log10'); exports.mod = require('./function/arithmetic/mod'); exports.multiply = require('./function/arithmetic/multiply'); +exports.norm = require('./function/arithmetic/norm'); exports.pow = require('./function/arithmetic/pow'); exports.round = require('./function/arithmetic/round'); exports.sign = require('./function/arithmetic/sign'); diff --git a/lib/function/arithmetic/norm.js b/lib/function/arithmetic/norm.js index 3220a5004..8cb88ff98 100644 --- a/lib/function/arithmetic/norm.js +++ b/lib/function/arithmetic/norm.js @@ -3,7 +3,7 @@ module.exports = function (math) { array = require('../../../lib/util/array'), - BigNumber = require('bignumber.js'), + BigNumber = math.type.BigNumber, Complex = require('../../type/Complex'), Matrix = require('../../type/Matrix'), collection = require('../../type/collection'), @@ -16,10 +16,13 @@ module.exports = function (math) { /** * Calculate the norm of a number, vector or matrix. * - * norm(x, [p]) + * norm(x) + * norm(x, p) + * + * p is optional. If not provided, defaults to 2. * * @param {Number | BigNumber | Complex | Boolean | Array | Matrix} x - * @param {Number | Infinity} p, optional defaults to 2 + * @param {Number | Infinity} [p] * @return {Number} the p-norm */ math.norm = function norm(x, p) { @@ -82,7 +85,42 @@ module.exports = function (math) { throw new Error('Parameter [p] in function norm must be a Number'); } } - + else if (sizeX.length == 2) { + // check p + if (p == 1) { + // norm(x) = the largest column sum + var c = []; + // loop rows + for (var i = 0; i < x.length; i++) { + var r = x[i]; + // loop columns + for (var j = 0; j < r.length; j++) { + c[j] = (c[j] || 0) + math.abs(r[j]); + } + } + return math.max(c); + } + else if (p == Number.POSITIVE_INFINITY) { + // norm(x) = the largest row sum + var n = 0; + // loop rows + for (var i = 0; i < x.length; i++) { + var rs = 0; + var r = x[i]; + // loop columns + for (var j = 0; j < r.length; j++) { + rs = math.add(rs, math.abs(r[j])); + } + if (math.larger(rs, n)) + n = rs; + } + return n; + } + else { + // not implemented + throw new Error('Unsupported parameter value, missing implementation of matrix singular value decomposition'); + } + } } if (x instanceof Matrix) { diff --git a/test/function/arithmetic/norm.test.js b/test/function/arithmetic/norm.test.js index 42fc2bf9c..7024e2b95 100644 --- a/test/function/arithmetic/norm.test.js +++ b/test/function/arithmetic/norm.test.js @@ -21,9 +21,9 @@ describe('norm', function () { }); it('should return the absolute value of a big number', function () { - // assert.equal(math.norm(math.bignumber(-2.3)), math.bignumber(2.3)); - // assert.deepEqual(math.norm(math.bignumber('5e500')), math.bignumber('5e500')); - // assert.deepEqual(math.norm(math.bignumber('-5e500')), math.bignumber('5e500')); + assert.deepEqual(math.norm(math.bignumber(-2.3)), math.bignumber(2.3)); + assert.deepEqual(math.norm(math.bignumber('5e500')), math.bignumber('5e500')); + assert.deepEqual(math.norm(math.bignumber('-5e500')), math.bignumber('5e500')); }); it('should return the norm of a complex number', function () { @@ -31,16 +31,36 @@ describe('norm', function () { }); it('should return the norm of a vector', function () { - // p = 0 + // empty vector assert.equal(math.norm([]), 0.0); + assert.equal(math.norm(math.matrix([])), 0.0); // p = Infinity assert.equal(math.norm([1, 2, -3], Number.POSITIVE_INFINITY), 3); + assert.equal(math.norm(math.matrix([1, 2, -3]), Number.POSITIVE_INFINITY), 3); // p - positive assert.equal(math.norm([3, 4], 2), 5.0); + assert.equal(math.norm(math.matrix([3, 4]), 2), 5.0); // p - negative assert.equal(math.norm([3, 4], -2), 2.4); + assert.equal(math.norm(math.matrix([3, 4]), -2), 2.4); + // missing p (defaults to 2) + assert.equal(math.norm([3, 4], 2), 5.0); + assert.equal(math.norm(math.matrix([3, 4]), 2), 5.0); }); + it('should return the norm of a matrix', function () { + // p = 1 + assert.equal(math.norm([[1, 2], [3, 4]], 1), 6); + assert.equal(math.norm(math.matrix([[1, 2], [3, 4]]), 1), 6); + // p = Infinity + assert.equal(math.norm([[1, 2], [3, 4]], Number.POSITIVE_INFINITY), 7); + assert.equal(math.norm(math.matrix([[1, 2], [3, 4]]), Number.POSITIVE_INFINITY), 7); + // p - not implemented yet! + assert.throws(function() { + math.norm(math.norm([[1, 2], [3, 4]], 2), 6); + }); + }); + it('should throw an error in case of invalid number of arguments', function() { // assert.throws(function () {math.norm()}, error.ArgumentsError); // assert.throws(function () {math.norm(1, 2, 3)}, error.ArgumentsError); From 49e7e00a6532d7bfcc682ef95a1be0e8281dfc85 Mon Sep 17 00:00:00 2001 From: josdejong Date: Sat, 12 Apr 2014 19:34:38 +0200 Subject: [PATCH 34/48] Added tests checking that the expression parser throws one-based IndexErrors. --- HISTORY.md | 2 ++ test/expression/parse.test.js | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/HISTORY.md b/HISTORY.md index c60e7eceb..a99b26379 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -17,6 +17,8 @@ https://github.com/josdejong/mathjs - Changed configuration option `decimals` to `precision` (applies to BigNumbers only). - Fixed support for element-wise comparisons between a string and a matrix. +- Fixed: expression parser now trows IndexErrors with one-based indices instead + of zero-based. - Minor bug fixes. diff --git a/test/expression/parse.test.js b/test/expression/parse.test.js index 489c443db..84a8bb5da 100644 --- a/test/expression/parse.test.js +++ b/test/expression/parse.test.js @@ -906,6 +906,18 @@ describe('parse', function() { }); + describe('errors', function () { + + it('should return IndexErrors with one based indices', function () { + // functions throw a zero-based error + assert.throws(function () {math.subset([1,2,3], math.index(4))}, /Index out of range \(4 > 2\)/); + assert.throws(function () {math.subset([1,2,3], math.index(-2))}, /Index out of range \(-2 < 0\)/); + + // evaluation via parser throws one-based error + assert.throws(function () {math.eval('[1,2,3][4]')}, /Index out of range \(4 > 3\)/); + assert.throws(function () {math.eval('[1,2,3][-2]')}, /Index out of range \(-2 < 1\)/); + }) + }); describe('node tree', function () { From 9b0154fa700966ca13308d2c950ff6a1d16d84ea Mon Sep 17 00:00:00 2001 From: josdejong Date: Sat, 12 Apr 2014 19:43:31 +0200 Subject: [PATCH 35/48] Upgraded to decimal.js 2.0.1 --- lib/util/bignumber.js | 10 ++++------ package.json | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/util/bignumber.js b/lib/util/bignumber.js index 04fbb4b11..9eca6e53d 100644 --- a/lib/util/bignumber.js +++ b/lib/util/bignumber.js @@ -128,10 +128,9 @@ exports.format = function format(value, options) { } // adjust the configuration of the BigNumber constructor (yeah, this is quite tricky...) - var oldConfig = value.constructor.config({}); - oldConfig = { - toExpNeg: oldConfig.toExpNeg, - toExpPos: oldConfig.toExpPos + var oldConfig = { + toExpNeg: value.constructor.toExpNeg, + toExpPos: value.constructor.toExpPos }; value.constructor.config({ @@ -147,8 +146,7 @@ exports.format = function format(value, options) { var abs = value.abs(); if (abs.gte(lower) && abs.lt(upper)) { // normal number notation - // Note: in bignumber.js, function round rounds to significant digits - str = value.round(precision).toFixed(); + str = value.toSignificantDigits(precision).toFixed(); } else { // exponential notation diff --git a/package.json b/package.json index 00b80d34c..c6987c0da 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "unit" ], "dependencies": { - "decimal.js": "^1.0.0" + "decimal.js": "^2.0.1" }, "devDependencies": { "webpack": "latest", From 423b159283539d74bcf4934e0faff7f864447f24 Mon Sep 17 00:00:00 2001 From: rjbaucells Date: Sat, 12 Apr 2014 20:18:23 -0400 Subject: [PATCH 36/48] norm documentation --- docs/functions.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/functions.md b/docs/functions.md index 47e682351..0393ec31f 100644 --- a/docs/functions.md +++ b/docs/functions.md @@ -44,6 +44,7 @@ math.add('hello ', 'world!'); // String 'hello world!' - math.log10(x) - math.mod(x, y) - math.multiply(x, y) +- math.norm(x [, p]) - math.pow(x, y) - math.round(x [, n]) - math.sign() From 7f2585f1a6fa8613818308065b34e0a8abf8a037 Mon Sep 17 00:00:00 2001 From: rjbaucells Date: Sun, 13 Apr 2014 22:19:32 -0400 Subject: [PATCH 37/48] unit tests --- lib/function/arithmetic/norm.js | 2 +- test/function/arithmetic/norm.test.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/function/arithmetic/norm.js b/lib/function/arithmetic/norm.js index 8cb88ff98..9fa5e73dc 100644 --- a/lib/function/arithmetic/norm.js +++ b/lib/function/arithmetic/norm.js @@ -27,7 +27,7 @@ module.exports = function (math) { */ math.norm = function norm(x, p) { if (arguments.length < 1 || arguments.length > 2) { - throw new math.error.ArgumentsError('norm', arguments.length, 1, 2); + throw new util.error.ArgumentsError('norm', arguments.length, 1, 2); } if (isNumber(x)) { diff --git a/test/function/arithmetic/norm.test.js b/test/function/arithmetic/norm.test.js index 7024e2b95..cbfb9474c 100644 --- a/test/function/arithmetic/norm.test.js +++ b/test/function/arithmetic/norm.test.js @@ -44,7 +44,7 @@ describe('norm', function () { assert.equal(math.norm([3, 4], -2), 2.4); assert.equal(math.norm(math.matrix([3, 4]), -2), 2.4); // missing p (defaults to 2) - assert.equal(math.norm([3, 4], 2), 5.0); + assert.equal(math.norm([3, 4]), 5.0); assert.equal(math.norm(math.matrix([3, 4]), 2), 5.0); }); @@ -62,8 +62,8 @@ describe('norm', function () { }); it('should throw an error in case of invalid number of arguments', function() { - // assert.throws(function () {math.norm()}, error.ArgumentsError); - // assert.throws(function () {math.norm(1, 2, 3)}, error.ArgumentsError); + assert.throws(function () {math.norm()}, error.ArgumentsError); + assert.throws(function () {math.norm(1, 2, 3)}, error.ArgumentsError); }); it('should throw an error with a string', function () { From 902c4ac1639dcc4539c9c0d1fce7440784a36e3a Mon Sep 17 00:00:00 2001 From: rjbaucells Date: Sun, 13 Apr 2014 23:30:57 -0400 Subject: [PATCH 38/48] unit tests and documentation --- .../docs/function/arithmetic/norm.js | 7 +-- lib/function/arithmetic/norm.js | 51 +++++++++++++------ test/function/arithmetic/norm.test.js | 20 +++++++- 3 files changed, 59 insertions(+), 19 deletions(-) diff --git a/lib/expression/docs/function/arithmetic/norm.js b/lib/expression/docs/function/arithmetic/norm.js index b874abfc3..d15efe6fd 100644 --- a/lib/expression/docs/function/arithmetic/norm.js +++ b/lib/expression/docs/function/arithmetic/norm.js @@ -3,12 +3,13 @@ module.exports = { 'category': 'Arithmetic', 'syntax': [ 'norm(x)', - 'norm(x, p)' + 'norm(x, p)' ], 'description': 'Calculate the norm of a number, vector or matrix.', 'examples': [ 'norm([[1, 2], [3, 4]])', - 'norm([[1, 2, 3, 4]], 3.5)', - 'norm(-4.2)' + 'norm([[1, 2, 3, 4]], 3.5)', + 'norm(-4.2)', + 'norm([[1, 2], [-3, -4]], \'fro\')' ] }; diff --git a/lib/function/arithmetic/norm.js b/lib/function/arithmetic/norm.js index 9fa5e73dc..b9d988fcf 100644 --- a/lib/function/arithmetic/norm.js +++ b/lib/function/arithmetic/norm.js @@ -22,7 +22,7 @@ module.exports = function (math) { * p is optional. If not provided, defaults to 2. * * @param {Number | BigNumber | Complex | Boolean | Array | Matrix} x - * @param {Number | Infinity} [p] + * @param {Number | Infinity | -Infinity, 'inf', '-inf', 'fro'} [p] * @return {Number} the p-norm */ math.norm = function norm(x, p) { @@ -58,32 +58,42 @@ module.exports = function (math) { // check it is a Vector if (sizeX.length == 1) { // check p - if (p == Number.POSITIVE_INFINITY) { + if (p === Number.POSITIVE_INFINITY || p === 'inf') { // norm(x, Infinity) = max(abs(x)) - var n = 0; - collection.deepForEach(x, function (value) { + var n; + math.forEach(x, function (value) { var v = math.abs(value); - if (math.larger(v, n)) + if (!n || math.larger(v, n)) n = v; }); return n; } - else if (isNumber(p) && !isNaN(p)) { + if (p === Number.NEGATIVE_INFINITY || p === '-inf') { + // norm(x, -Infinity) = min(abs(x)) + var n; + math.forEach(x, function (value) { + var v = math.abs(value); + if (!n || math.smaller(v, n)) + n = v; + }); + return n; + } + if (p === 'fro') + return norm(x); + if (isNumber(p) && !isNaN(p)) { // check p != 0 if (!math.equal(p, 0)) { // norm(x, p) = sum(abs(xi) ^ p) ^ 1/p var n = 0; - collection.deepForEach(x, function (value) { - n += math.pow(math.abs(value), p); + math.forEach(x, function (value) { + n = math.add(math.pow(math.abs(value), p), n); }); return math.pow(n, 1 / p); } return Number.POSITIVE_INFINITY; } - else { - // invalid parameter value - throw new Error('Parameter [p] in function norm must be a Number'); - } + // invalid parameter value + throw new Error('Unsupported parameter value'); } else if (sizeX.length == 2) { // check p @@ -95,12 +105,12 @@ module.exports = function (math) { var r = x[i]; // loop columns for (var j = 0; j < r.length; j++) { - c[j] = (c[j] || 0) + math.abs(r[j]); + c[j] = math.add(c[j] || 0, math.abs(r[j])); } } return math.max(c); } - else if (p == Number.POSITIVE_INFINITY) { + if (p == Number.POSITIVE_INFINITY || p === 'inf') { // norm(x) = the largest row sum var n = 0; // loop rows @@ -116,10 +126,21 @@ module.exports = function (math) { } return n; } - else { + if (p === 'fro') { + // norm(x) = sqrt(sum(diag(x'x))) + var d = math.diag(math.multiply(math.transpose(x), x)); + var s = 0; + math.forEach(d, function (value) { + s = math.add(value, s); + }); + return math.sqrt(s); + } + if (p == 2) { // not implemented throw new Error('Unsupported parameter value, missing implementation of matrix singular value decomposition'); } + // invalid parameter value + throw new Error('Unsupported parameter value'); } } diff --git a/test/function/arithmetic/norm.test.js b/test/function/arithmetic/norm.test.js index cbfb9474c..b91798676 100644 --- a/test/function/arithmetic/norm.test.js +++ b/test/function/arithmetic/norm.test.js @@ -37,6 +37,16 @@ describe('norm', function () { // p = Infinity assert.equal(math.norm([1, 2, -3], Number.POSITIVE_INFINITY), 3); assert.equal(math.norm(math.matrix([1, 2, -3]), Number.POSITIVE_INFINITY), 3); + assert.equal(math.norm([1, 2, -3], 'inf'), 3); + assert.equal(math.norm(math.matrix([1, 2, -3]), 'inf'), 3); + // p = -Infinity + assert.equal(math.norm([1, 2, -3], Number.NEGATIVE_INFINITY), 1); + assert.equal(math.norm(math.matrix([1, 2, -3]), Number.NEGATIVE_INFINITY), 1); + assert.equal(math.norm([1, 2, -3], '-inf'), 1); + assert.equal(math.norm(math.matrix([1, 2, -3]), '-inf'), 1); + // p == 1 + assert.equal(math.norm([-3, -4], 1), 7.0); + assert.equal(math.norm(math.matrix([-3, -4]), 1), 7.0); // p - positive assert.equal(math.norm([3, 4], 2), 5.0); assert.equal(math.norm(math.matrix([3, 4]), 2), 5.0); @@ -45,7 +55,10 @@ describe('norm', function () { assert.equal(math.norm(math.matrix([3, 4]), -2), 2.4); // missing p (defaults to 2) assert.equal(math.norm([3, 4]), 5.0); - assert.equal(math.norm(math.matrix([3, 4]), 2), 5.0); + assert.equal(math.norm(math.matrix([3, 4])), 5.0); + // p == 'fro' + assert.equal(math.norm([3, 4], 'fro'), 5.0); + assert.equal(math.norm(math.matrix([3, 4]), 'fro'), 5.0); }); it('should return the norm of a matrix', function () { @@ -55,6 +68,11 @@ describe('norm', function () { // p = Infinity assert.equal(math.norm([[1, 2], [3, 4]], Number.POSITIVE_INFINITY), 7); assert.equal(math.norm(math.matrix([[1, 2], [3, 4]]), Number.POSITIVE_INFINITY), 7); + assert.equal(math.norm([[1, 2], [3, 4]], 'inf'), 7); + assert.equal(math.norm(math.matrix([[1, 2], [3, 4]]), 'inf'), 7); + // p = 'fro' + assert.equal(math.norm([[1, 2], [-3, -4]], 'fro'), math.sqrt(30)); + assert.equal(math.norm(math.matrix([[1, 2], [-3, -4]]), 'fro'), math.sqrt(30)); // p - not implemented yet! assert.throws(function() { math.norm(math.norm([[1, 2], [3, 4]], 2), 6); From cf5c4053818f15a802edd98be698e776b10bbf5a Mon Sep 17 00:00:00 2001 From: rjbaucells Date: Sun, 13 Apr 2014 23:41:07 -0400 Subject: [PATCH 39/48] formatting fixes --- lib/function/arithmetic/norm.js | 18 +++++++++--------- test/function/arithmetic/norm.test.js | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/function/arithmetic/norm.js b/lib/function/arithmetic/norm.js index b9d988fcf..6c981d764 100644 --- a/lib/function/arithmetic/norm.js +++ b/lib/function/arithmetic/norm.js @@ -1,17 +1,17 @@ module.exports = function (math) { var util = require('../../util/index'), - array = require('../../../lib/util/array'), + array = require('../../../lib/util/array'), - BigNumber = math.type.BigNumber, - Complex = require('../../type/Complex'), - Matrix = require('../../type/Matrix'), - collection = require('../../type/collection'), + BigNumber = math.type.BigNumber, + Complex = require('../../type/Complex'), + Matrix = require('../../type/Matrix'), + collection = require('../../type/collection'), - isNumber = util.number.isNumber, - isBoolean = util['boolean'].isBoolean, - isComplex = Complex.isComplex, - isCollection = collection.isCollection; + isNumber = util.number.isNumber, + isBoolean = util['boolean'].isBoolean, + isComplex = Complex.isComplex, + isCollection = collection.isCollection; /** * Calculate the norm of a number, vector or matrix. diff --git a/test/function/arithmetic/norm.test.js b/test/function/arithmetic/norm.test.js index b91798676..e7e70827c 100644 --- a/test/function/arithmetic/norm.test.js +++ b/test/function/arithmetic/norm.test.js @@ -1,7 +1,7 @@ // test norm var assert = require('assert'), - error = require('../../../lib/util/error'), - math = require('../../../index')(); + error = require('../../../lib/util/error'), + math = require('../../../index')(); describe('norm', function () { @@ -75,7 +75,7 @@ describe('norm', function () { assert.equal(math.norm(math.matrix([[1, 2], [-3, -4]]), 'fro'), math.sqrt(30)); // p - not implemented yet! assert.throws(function() { - math.norm(math.norm([[1, 2], [3, 4]], 2), 6); + math.norm(math.norm([[1, 2], [3, 4]], 2), 6); }); }); From ca750520d1ff68e0c8b49b9de34e68dd7d706c2d Mon Sep 17 00:00:00 2001 From: rjbaucells Date: Sun, 13 Apr 2014 23:49:45 -0400 Subject: [PATCH 40/48] fixed build errors --- test/function/arithmetic/abs.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/function/arithmetic/abs.test.js b/test/function/arithmetic/abs.test.js index a63f82baa..865d0edf4 100644 --- a/test/function/arithmetic/abs.test.js +++ b/test/function/arithmetic/abs.test.js @@ -1,6 +1,6 @@ // test abs var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error'), math = require('../../../index')(); describe('abs', function () { From 5e051cb5e833aecfc4f80e7b912bc150d8fdb47c Mon Sep 17 00:00:00 2001 From: "Rogelio J. Baucells" Date: Mon, 14 Apr 2014 16:31:40 -0400 Subject: [PATCH 41/48] fixed build errors --- test/function/arithmetic/norm.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/function/arithmetic/norm.test.js b/test/function/arithmetic/norm.test.js index e7e70827c..ff7068d84 100644 --- a/test/function/arithmetic/norm.test.js +++ b/test/function/arithmetic/norm.test.js @@ -1,6 +1,6 @@ // test norm var assert = require('assert'), - error = require('../../../lib/util/error'), + error = require('../../../lib/error'), math = require('../../../index')(); describe('norm', function () { From b21688782a9a86be08e79d430573cbd9eca20c42 Mon Sep 17 00:00:00 2001 From: "Rogelio J. Baucells" Date: Mon, 14 Apr 2014 17:16:25 -0400 Subject: [PATCH 42/48] fixed formatting and compile problems --- test/function/arithmetic/norm.test.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/function/arithmetic/norm.test.js b/test/function/arithmetic/norm.test.js index ff7068d84..2893e7fe6 100644 --- a/test/function/arithmetic/norm.test.js +++ b/test/function/arithmetic/norm.test.js @@ -1,6 +1,6 @@ // test norm var assert = require('assert'), - error = require('../../../lib/error'), + error = require('../../../lib/error/index'), math = require('../../../index')(); describe('norm', function () { @@ -73,10 +73,10 @@ describe('norm', function () { // p = 'fro' assert.equal(math.norm([[1, 2], [-3, -4]], 'fro'), math.sqrt(30)); assert.equal(math.norm(math.matrix([[1, 2], [-3, -4]]), 'fro'), math.sqrt(30)); - // p - not implemented yet! - assert.throws(function() { - math.norm(math.norm([[1, 2], [3, 4]], 2), 6); - }); + // p - not implemented yet! + assert.throws(function() { + math.norm(math.norm([[1, 2], [3, 4]], 2), 6); + }); }); it('should throw an error in case of invalid number of arguments', function() { From ccc739c238ec257ec1ada4c5cb6038e097f8e02c Mon Sep 17 00:00:00 2001 From: "Rogelio J. Baucells" Date: Mon, 14 Apr 2014 17:45:43 -0400 Subject: [PATCH 43/48] updated norm() to latest branch code --- lib/function/arithmetic/norm.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/function/arithmetic/norm.js b/lib/function/arithmetic/norm.js index 6c981d764..f46d6d425 100644 --- a/lib/function/arithmetic/norm.js +++ b/lib/function/arithmetic/norm.js @@ -27,7 +27,7 @@ module.exports = function (math) { */ math.norm = function norm(x, p) { if (arguments.length < 1 || arguments.length > 2) { - throw new util.error.ArgumentsError('norm', arguments.length, 1, 2); + throw new math.error.ArgumentsError('abs', arguments.length, 1, 2); } if (isNumber(x)) { From 3e625169097d6aef5b0271b7a958bff378c90509 Mon Sep 17 00:00:00 2001 From: jos Date: Wed, 16 Apr 2014 09:28:03 +0200 Subject: [PATCH 44/48] Documented new option epsilon for comparison. Changed default value to 1e-14 --- HISTORY.md | 3 + docs/configuration.md | 7 ++- docs/datatypes/numbers.md | 46 +++++++++++++++ lib/function/arithmetic/compare.js | 4 ++ lib/function/arithmetic/equal.js | 4 ++ lib/function/arithmetic/larger.js | 4 ++ lib/function/arithmetic/largereq.js | 4 ++ lib/function/arithmetic/smaller.js | 4 ++ lib/function/arithmetic/smallereq.js | 10 +++- lib/function/arithmetic/unequal.js | 5 ++ lib/math.js | 5 +- lib/util/number.js | 35 ++++++----- package.json | 4 +- test/math.test.js | 6 +- test/util/number.test.js | 87 +++++++++++++++++++++++++++- 15 files changed, 203 insertions(+), 25 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index a99b26379..43cd7e14f 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -10,6 +10,9 @@ https://github.com/josdejong/mathjs Thanks Finn Pauls (@finnp). - Implemented BigNumber support for functions `exp`, `log`, and `log10`. - Implemented conditional operator `a ? b : c` in expression parser. +- Improved floating point comparison: the functions now check whether values + are nearly equal, against a configured maximum relative difference `epsilon`. + Thanks Rogelio J. Baucells (@rjbaucells). - Improved function `ifElse`, is now specified for special data types too. - Improved function `det`. Thanks Bryan Cuccioli (@bcuccioli). - Implemented `BigNumber` support for functions `det` and `diag`. diff --git a/docs/configuration.md b/docs/configuration.md index 966ad20bf..8f2e88a37 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -4,6 +4,10 @@ Math.js contains a number of configuration options. Configuration can be set when creating a math.js instance, or later on using the function `config`. Available configuration options are: +- `epsilon`. The minimum relative difference used to test equality between two + compared values. This value is used by all comparison functions. + Default value is `1e-14`. + - `matrix`. The default type of matrix output for functions. Available values are: `'matrix'` (default) or `'array'`. Where possible, the type of matrix output from functions is determined from @@ -21,7 +25,8 @@ Available configuration options are: BigNumbers have higher precision than the default numbers of JavaScript. - `precision`. The maximum number of significant digits for bigNumbers. - This setting only applies to BigNumbers, not to numbers. Default value is 20. + This setting only applies to BigNumbers, not to numbers. + Default value is `20`. ## Examples diff --git a/docs/datatypes/numbers.md b/docs/datatypes/numbers.md index 256d0fdb3..c6895efa9 100644 --- a/docs/datatypes/numbers.md +++ b/docs/datatypes/numbers.md @@ -6,6 +6,8 @@ Math.js supports two types of numbers: - BigNumber for arbitrary precision arithmetic, describe on the page [BigNumbers](bignumbers.md). +## Configuration + Most functions can determine the type of output from the type of input: a number as input will return a number as output, a BigNumber as input returns a BigNumber as output. Functions which cannot determine the type of output @@ -19,6 +21,8 @@ var mathjs = require('mathjs'), }); ``` +## Round-off errors + Math.js uses the built-in JavaScript Number type. A Number is a floating point number with a limited precision of 64 bits, about 16 digits. The largest integer number which can be represented by a JavaScript Number @@ -43,6 +47,8 @@ var ans = math.add(0.1, 0.2); // 0.30000000000000004 math.format(ans, {precision: 14}); // '0.3' ``` +## Minimum and maximum + A Number can store values between `5e-324` and `1.7976931348623157e+308`. Values smaller than the minimum are stored as `0`, and values larger than the maximum are stored as `+/- Infinity`. @@ -52,3 +58,43 @@ maximum are stored as `+/- Infinity`. console.log(1e309); // Infinity console.log(1e-324); // 0 ``` + +## Comparison + +Because of rounding errors in calculations, it is unsafe to compare JavaScript +Numbers. For example executing `0.1 + 0.2 == 0.3` in JavaScript will return +false, as the addition `0.1 + 0.2` introduces a round-off error and does not +return exactly `0.3`. + +To solve this problem, the comparison functions of math.js check whether the +relative difference between the compared values is smaller than the configured +option `epsilon`. In pseudo code (without exceptions for 0, Infinity and NaN): + + diff = abs(x - y) + nearlyEqual = (diff <= max(abs(x), abs(y)) * EPSILON) OR (diff < DBL_EPSILON) + +where: + + - `EPSILON` is the relative difference between x and y. Epsilon is configurable + and is `1e-14` by default. See [Configuration](../configuration.md). + - `DBL_EPSILON` is the minimum positive floating point number such that + `1.0 + DBL_EPSILON != 1.0`. This is a constant with a value of approximately + `2.2204460492503130808472633361816e-16`; + +Note that the comparison functions cannot be used to compare small values +(`< 2.22e-16`). These values are all considered equal to zero. + +Examples: + +```js +// compare values having a round-off error +console.log(0.1 + 0.2 == 0.3); // false +console.log(math.equal(0.1 + 0.2, 0.3)); // true + +// small values (< 2.22e-16) cannot be compared +console.log(3e-20 == 3.1e-20); // false +console.log(math.equal(3e-20, 3.1e-20)); // true +``` + +The available comparison functions are: `compare`, `equal`, `larger`, +`largereq`, `smaller`, `smallereq`, `unequal`. diff --git a/lib/function/arithmetic/compare.js b/lib/function/arithmetic/compare.js index 271bf5a4e..0d3dc6b42 100644 --- a/lib/function/arithmetic/compare.js +++ b/lib/function/arithmetic/compare.js @@ -21,6 +21,10 @@ module.exports = function (math, config) { * * compare(x, y) * + * x and y are considered equal when the relative difference between x and y + * is smaller than the configured epsilon. The function cannot be used to + * compare values smaller than approximately 2.22e-16. + * * @param {Number | BigNumber | Boolean | Unit | String | Array | Matrix} x * @param {Number | BigNumber | Boolean | Unit | String | Array | Matrix} y * @return {Number | BigNumber | Array | Matrix} res diff --git a/lib/function/arithmetic/equal.js b/lib/function/arithmetic/equal.js index 7160d8d22..f7fecf129 100644 --- a/lib/function/arithmetic/equal.js +++ b/lib/function/arithmetic/equal.js @@ -24,6 +24,10 @@ module.exports = function (math, config) { * For matrices, the function is evaluated element wise. * In case of complex numbers, x.re must equal y.re, and x.im must equal y.im. * + * The function checks whether the relative difference between x and y is + * smaller than the configured epsilon. The function cannot be used to + * compare values smaller than approximately 2.22e-16. + * * @param {Number | BigNumber | Boolean | Complex | Unit | String | Array | Matrix} x * @param {Number | BigNumber | Boolean | Complex | Unit | String | Array | Matrix} y * @return {Boolean | Array | Matrix} res diff --git a/lib/function/arithmetic/larger.js b/lib/function/arithmetic/larger.js index efb57648e..1589ada30 100644 --- a/lib/function/arithmetic/larger.js +++ b/lib/function/arithmetic/larger.js @@ -23,6 +23,10 @@ module.exports = function (math, config) { * * For matrices, the function is evaluated element wise. * + * The function returns true when x is larger than y and the relative + * difference between x and y is larger than the configured epsilon. The + * function cannot be used to compare values smaller than approximately 2.22e-16. + * * @param {Number | BigNumber | Boolean | Unit | String | Array | Matrix} x * @param {Number | BigNumber | Boolean | Unit | String | Array | Matrix} y * @return {Boolean | Array | Matrix} res diff --git a/lib/function/arithmetic/largereq.js b/lib/function/arithmetic/largereq.js index 5a0f712ff..76bd620cf 100644 --- a/lib/function/arithmetic/largereq.js +++ b/lib/function/arithmetic/largereq.js @@ -23,6 +23,10 @@ module.exports = function (math, config) { * * For matrices, the function is evaluated element wise. * + * The function returns true when x is larger than y or the relative + * difference between x and y is smaller than the configured epsilon. The + * function cannot be used to compare values smaller than approximately 2.22e-16. + * * @param {Number | BigNumber | Boolean | Unit | String | Array | Matrix} x * @param {Number | BigNumber | Boolean | Unit | String | Array | Matrix} y * @return {Boolean | Array | Matrix} res diff --git a/lib/function/arithmetic/smaller.js b/lib/function/arithmetic/smaller.js index f48f60cf9..c602f2e12 100644 --- a/lib/function/arithmetic/smaller.js +++ b/lib/function/arithmetic/smaller.js @@ -23,6 +23,10 @@ module.exports = function (math, config) { * * For matrices, the function is evaluated element wise. * + * The function returns true when x is smaller than y and the relative + * difference between x and y is larger than the configured epsilon. The + * function cannot be used to compare values smaller than approximately 2.22e-16. + * * @param {Number | BigNumber | Boolean | Unit | String | Array | Matrix} x * @param {Number | BigNumber | Boolean | Unit | String | Array | Matrix} y * @return {Boolean | Array | Matrix} res diff --git a/lib/function/arithmetic/smallereq.js b/lib/function/arithmetic/smallereq.js index 0e2cbcb98..b39ab7eb2 100644 --- a/lib/function/arithmetic/smallereq.js +++ b/lib/function/arithmetic/smallereq.js @@ -16,13 +16,17 @@ module.exports = function (math, config) { epsilon = config.epsilon; /** - * Check if value a is smaller or equal to b + * Check if value x is smaller or equal to y * - * a <= b - * smallereq(a, b) + * x <= y + * smallereq(x, y) * * For matrices, the function is evaluated element wise. * + * The function returns true when x is smaller than y or the relative + * difference between x and y is smaller than the configured epsilon. The + * function cannot be used to compare values smaller than approximately 2.22e-16. + * * @param {Number | BigNumber | Boolean | Complex | Unit | String | Array | Matrix} x * @param {Number | BigNumber | Boolean | Complex | Unit | String | Array | Matrix} y * @return {Boolean | Array | Matrix} res diff --git a/lib/function/arithmetic/unequal.js b/lib/function/arithmetic/unequal.js index 9709e7ca6..5c062c5ec 100644 --- a/lib/function/arithmetic/unequal.js +++ b/lib/function/arithmetic/unequal.js @@ -18,6 +18,11 @@ module.exports = function (math, config) { /** * Check if value x unequals y, x != y * In case of complex numbers, x.re must unequal y.re, or x.im must unequal y.im + * + * The function checks whether the relative difference between x and y is + * larger than the configured epsilon. The function cannot be used to compare + * values smaller than approximately 2.22e-16. + * * @param {Number | BigNumber | Boolean | Complex | Unit | String | Array | Matrix} x * @param {Number | BigNumber | Boolean | Complex | Unit | String | Array | Matrix} y * @return {Boolean | Array | Matrix} res diff --git a/lib/math.js b/lib/math.js index f166ee400..df564516c 100644 --- a/lib/math.js +++ b/lib/math.js @@ -38,8 +38,9 @@ function mathjs (config) { // number of significant digits in BigNumbers precision: 20, - // relative difference between values to test equality for numbers - epsilon: 1e-6 + // minimum relative difference between two compared values, + // used by all comparison functions + epsilon: 1e-14 }; /** diff --git a/lib/util/number.js b/lib/util/number.js index 19e0892e5..890c28cd7 100644 --- a/lib/util/number.js +++ b/lib/util/number.js @@ -240,28 +240,37 @@ exports.digits = function digits (value) { exports.DBL_EPSILON = Number.EPSILON || 2.2204460492503130808472633361816E-16; /** -* Compares two floating point numbers. -* @param {Number} value1 -* @param {Number} value1 -* @param {Number} maximumRelativeDifference -* @return {boolean} wether the two numbers are equal + * Compares two floating point numbers. + * @param {Number} x First value to compare + * @param {Number} y Second value to compare + * @param {Number} [epsilon] The maximum relative difference between x and y + * If epsilon is undefined or null, the function will + * test whether x and y are exactly equal. + * @return {boolean} whether the two numbers are equal */ -exports.nearlyEqual = function(x, y, maximumRelativeDifference) { +exports.nearlyEqual = function(x, y, epsilon) { + // if epsilon is null or undefined, test whether x and y are exactly equal + if (epsilon == null) return x == y; + // use "==" operator, handles infinities - if (x == y) - return true; + if (x == y) return true; + // NaN - if (isNaN(x) || isNaN(y)) - return false; + if (isNaN(x) || isNaN(y)) return false; + // at this point x and y should be finite if(isFinite(x) && isFinite(y)) { // check numbers are very close, needed when comparing numbers near zero var diff = Math.abs(x - y); - if (diff < exports.DBL_EPSILON) + if (diff < exports.DBL_EPSILON) { return true; - // use relative error - return diff <= Math.max(Math.abs(x) + Math.abs(y)) * maximumRelativeDifference; + } + else { + // use relative error + return diff <= Math.max(Math.abs(x), Math.abs(y)) * epsilon; + } } + // Infinite and Number or negative Infinite and positive Infinite cases return false; }; diff --git a/package.json b/package.json index c6987c0da..b6f1669a2 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "unit" ], "dependencies": { - "decimal.js": "^2.0.1" + "decimal.js": "~2.0.1" }, "devDependencies": { "webpack": "latest", @@ -51,7 +51,7 @@ "seed-random": "latest", "gulp": "latest", "gulp-util": "latest", - "exec": "^0.1.0" + "exec": "latest" }, "main": "./index", "scripts": { diff --git a/test/math.test.js b/test/math.test.js index 9009ae6d1..62a39ca2d 100644 --- a/test/math.test.js +++ b/test/math.test.js @@ -12,7 +12,7 @@ describe('factory', function() { matrix: 'matrix', number: 'number', precision: 20, - epsilon: 1e-6 + epsilon: 1e-14 }); }); @@ -27,7 +27,7 @@ describe('factory', function() { matrix: 'array', number: 'bignumber', precision: 20, - epsilon: 1e-6 + epsilon: 1e-14 }); }); @@ -54,7 +54,7 @@ describe('factory', function() { matrix: 'matrix', number: 'number', precision: 20, - epsilon: 1e-6 + epsilon: 1e-14 }); math.config({ diff --git a/test/util/number.test.js b/test/util/number.test.js index 84592495b..e0d2626e3 100644 --- a/test/util/number.test.js +++ b/test/util/number.test.js @@ -90,7 +90,7 @@ describe('number', function() { describe('format', function () { - it ('should format special values Infinity, NaN', function () { + it('should format special values Infinity, NaN', function () { assert.equal(number.format(Infinity), 'Infinity'); assert.equal(number.format(-Infinity), '-Infinity'); assert.equal(number.format('no number'), 'NaN'); @@ -284,4 +284,89 @@ describe('number', function() { }); + describe('nearlyEqual', function () { + + it('should test whether two numbers are nearly equal', function () { + var epsilon = 1e-2; + assert.equal(number.nearlyEqual(1, 0.9, epsilon), false); + assert.equal(number.nearlyEqual(1, 0.95, epsilon), false); + assert.equal(number.nearlyEqual(1, 0.98, epsilon), false); + assert.equal(number.nearlyEqual(1, 0.99, epsilon), false); + assert.equal(number.nearlyEqual(1, 0.991, epsilon), true); + assert.equal(number.nearlyEqual(1, 1.1, epsilon), false); + assert.equal(number.nearlyEqual(1, 1.05, epsilon), false); + assert.equal(number.nearlyEqual(1, 1.02, epsilon), false); + assert.equal(number.nearlyEqual(1, 1.01, epsilon), true); + assert.equal(number.nearlyEqual(1, 1, epsilon), true); + + // smaller epsilon + var epsilon2 = 1e-4; + assert.equal(number.nearlyEqual(1, 0.99, epsilon2), false); + assert.equal(number.nearlyEqual(1, 0.999, epsilon2), false); + assert.equal(number.nearlyEqual(1, 0.9999, epsilon2), true); + + // test one of these famous round-off errors + assert.equal((0.1+0.2) == 0.3, false); + assert.equal(number.nearlyEqual(0.1+0.2, 0.3, 1e-14), true); + }); + + it('should test whether a positive and negative number are nearly equal', function () { + var epsilon = 1e-3; + assert.equal(number.nearlyEqual( 1.2, 1.2, epsilon), true); + assert.equal(number.nearlyEqual( 1.2, -1.2, epsilon), false); + assert.equal(number.nearlyEqual(-1.2, 1.2, epsilon), false); + assert.equal(number.nearlyEqual(-1.2, -1.2, epsilon), true); + }); + + it('should test whether two large numbers are nearly equal', function () { + var epsilon = 1e-2; + assert.equal(number.nearlyEqual(1e200, 0.90e200, epsilon), false); + assert.equal(number.nearlyEqual(1e200, 0.95e200, epsilon), false); + assert.equal(number.nearlyEqual(1e200, 0.98e200, epsilon), false); + assert.equal(number.nearlyEqual(1e200, 0.99e200, epsilon), true); + }); + + it('should test whether two small numbers are nearly equal (always true)', function () { + var epsilon = 1e-2; + assert.equal(number.nearlyEqual(1e-200, 0.99e-200, epsilon), true); + assert.equal(number.nearlyEqual(1e-200, 10e-200, epsilon), true); + }); + + it('should compare with zero', function () { + var epsilon = 1e-3; + assert.equal(number.nearlyEqual(0, 0, epsilon), true); + assert.equal(number.nearlyEqual(0, -0, epsilon), true); + assert.equal(number.nearlyEqual(0, 1.2, epsilon), false); + assert.equal(number.nearlyEqual(0, 1e30, epsilon), false); + assert.equal(number.nearlyEqual(0, 1e-30, epsilon), true); + }); + + it('should compare with Infinity', function () { + var epsilon = 1e-3; + + assert.equal(number.nearlyEqual(1.2, Infinity, epsilon), false); + assert.equal(number.nearlyEqual(Infinity, 1.2, epsilon), false); + assert.equal(number.nearlyEqual(Infinity, Infinity, epsilon), true); + assert.equal(number.nearlyEqual(Infinity, -Infinity, epsilon), false); + assert.equal(number.nearlyEqual(-Infinity, Infinity, epsilon), false); + assert.equal(number.nearlyEqual(-Infinity, -Infinity, epsilon), true); + }); + + it('should compare with NaN', function () { + var epsilon = 1e-3; + assert.equal(number.nearlyEqual(1.2, NaN, epsilon), false); + assert.equal(number.nearlyEqual(NaN, 1.2, epsilon), false); + assert.equal(number.nearlyEqual(NaN, NaN, epsilon), false); + }); + + it('should do exact comparison when epsilon is null or undefined', function () { + assert.equal(number.nearlyEqual(1.2, 1.2), true); + assert.equal(number.nearlyEqual(1.2, 1.2, null), true); + + assert.equal(number.nearlyEqual(0.1 + 0.2, 0.3), false); + assert.equal(number.nearlyEqual(0.1 + 0.2, 0.3, null), false); + }); + + }); + }); From d369733d0934e99d433c921639f12deee9c94431 Mon Sep 17 00:00:00 2001 From: jos Date: Wed, 16 Apr 2014 09:55:55 +0200 Subject: [PATCH 45/48] Documented complex polar coordinates --- HISTORY.md | 1 + docs/datatypes/complex_numbers.md | 21 +++++++++++++++++---- lib/function/arithmetic/norm.js | 2 +- lib/type/Complex.js | 9 ++++++++- package.json | 1 + 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 43cd7e14f..11dd7ed3d 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -13,6 +13,7 @@ https://github.com/josdejong/mathjs - Improved floating point comparison: the functions now check whether values are nearly equal, against a configured maximum relative difference `epsilon`. Thanks Rogelio J. Baucells (@rjbaucells). +- Implemented function `norm`. Thanks Rogelio J. Baucells (@rjbaucells). - Improved function `ifElse`, is now specified for special data types too. - Improved function `det`. Thanks Bryan Cuccioli (@bcuccioli). - Implemented `BigNumber` support for functions `det` and `diag`. diff --git a/docs/datatypes/complex_numbers.md b/docs/datatypes/complex_numbers.md index 1e962b17c..0a7514e1d 100644 --- a/docs/datatypes/complex_numbers.md +++ b/docs/datatypes/complex_numbers.md @@ -14,9 +14,14 @@ signal analysis, fluid dynamics and other fields. ## API A complex number is created using the function `math.complex`. This function -accepts two numbers representing the real and imaginary part of the value, -or a single string containing a complex value in the form `a + bi` where `a` -and `b` respectively represent the real and imaginary part of the complex number. +accepts: + +- two numbers representing the real and imaginary part of the value, +- a single string containing a complex value in the form `a + bi` where `a` + and `b` respectively represent the real and imaginary part of the complex number. +- an object with either properties `re` and `im` for the real and imaginary + part of the value, or two properties `r` and `phi` containing the polar + coordinates of a complex value. The function returns a `Complex` object. Syntax: @@ -25,6 +30,8 @@ Syntax: math.complex(re: number) : Complex math.complex(re: number, im: number) : Complex math.complex(complex: Complex) : Complex +math.complex({re: Number, im: Number}) : Complex +math.complex({r: number, phi: number}) : Complex math.complex(str: string) : Complex ``` @@ -53,7 +60,13 @@ A `Complex` object has the following functions: - `equals(other)`. Test whether a complex number equals an other complex value. Two complex numbers are equal when both their real and imaginary parts are equal. -- `format([precision])`. Get a string representation of the complex number, +- `fromPolar(r: number, phi: number)`. Create a complex number from polar + coordinates. +- `fromPolar({r: number, phi: number})`. Create a complex number from polar + coordinates. +- `toPolar()`. Get the polar coordinates of the complex number, returns + an object with properties `r` and `phi`. +- `format([precision: number])`. Get a string representation of the complex number, formatted as `a + bi` where `a` is the real part and `b` the imaginary part. If precision is defined, the units value will be rounded to the provided number of digits. diff --git a/lib/function/arithmetic/norm.js b/lib/function/arithmetic/norm.js index f46d6d425..a2476b503 100644 --- a/lib/function/arithmetic/norm.js +++ b/lib/function/arithmetic/norm.js @@ -19,7 +19,7 @@ module.exports = function (math) { * norm(x) * norm(x, p) * - * p is optional. If not provided, defaults to 2. + * p is optional. If not provided, defaults to 2 (The Frobenius norm or 'fro')). * * @param {Number | BigNumber | Complex | Boolean | Array | Matrix} x * @param {Number | Infinity | -Infinity, 'inf', '-inf', 'fro'} [p] diff --git a/lib/type/Complex.js b/lib/type/Complex.js index a27c4ab28..a9ec83f99 100644 --- a/lib/type/Complex.js +++ b/lib/type/Complex.js @@ -293,6 +293,13 @@ Complex.parse = function parse (str) { /** * Create a complex number from polar coordinates + * + * Usage: + * + * Complex.fromPolar(r: Number, phi: Number) : Complex + * Complex.fromPolar({r: Number, phi: Number}) : Complex + * + * @param {*} args... * @return {Complex} */ Complex.fromPolar = function fromPolar(args) { @@ -330,7 +337,7 @@ Complex.fromPolar = function fromPolar(args) { /* * Return the value of the complex number in polar notation * The angle phi will be set in the interval of [-pi, pi]. - * @return {Object} Object with r and phi keys. + * @return {{r: number, phi: number}} Returns and object with properties r and phi. */ Complex.prototype.toPolar = function() { return { diff --git a/package.json b/package.json index b6f1669a2..16dafa48a 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "Guillermo Indalecio Fernández (https://github.com/guillermobox)", "Huseyn Guliyev (https://github.com/husayt)", "Daniel Levin (https://github.com/daniel-levin)", + "Rogelio J. Baucells (https://github.com/rjbaucells)", "Fabrice Colas (https://github.com/fcolas6013)", "Marcus Andre (https://github.com/marcusandre)", "Jim Garrison (https://github.com/garrison)", From 6d4a997ef4e3de371ac4a9bec219f25eda5e38d1 Mon Sep 17 00:00:00 2001 From: jos Date: Wed, 16 Apr 2014 10:13:11 +0200 Subject: [PATCH 46/48] Fixed comparison functions not applying option `epsilon` --- lib/function/arithmetic/compare.js | 5 ++--- lib/function/arithmetic/equal.js | 11 +++++------ lib/function/arithmetic/larger.js | 5 ++--- lib/function/arithmetic/largereq.js | 5 ++--- lib/function/arithmetic/smaller.js | 5 ++--- lib/function/arithmetic/smallereq.js | 5 ++--- lib/function/arithmetic/unequal.js | 11 +++++------ test/function/arithmetic/compare.test.js | 10 +++++++++- test/function/arithmetic/equal.test.js | 10 +++++++++- test/function/arithmetic/larger.test.js | 10 +++++++++- test/function/arithmetic/largereq.test.js | 10 +++++++++- test/function/arithmetic/smaller.test.js | 10 +++++++++- test/function/arithmetic/smallereq.test.js | 10 +++++++++- test/function/arithmetic/unequal.test.js | 10 +++++++++- 14 files changed, 83 insertions(+), 34 deletions(-) diff --git a/lib/function/arithmetic/compare.js b/lib/function/arithmetic/compare.js index 0d3dc6b42..822d72f3d 100644 --- a/lib/function/arithmetic/compare.js +++ b/lib/function/arithmetic/compare.js @@ -12,8 +12,7 @@ module.exports = function (math, config) { isString = util.string.isString, isComplex = Complex.isComplex, isUnit = Unit.isUnit, - isCollection = collection.isCollection, - epsilon = config.epsilon; + isCollection = collection.isCollection; /** * Compare two values. Returns 1 when x > y, -1 when x < y, and 0 when x == y @@ -35,7 +34,7 @@ module.exports = function (math, config) { } if (isNumber(x) && isNumber(y)) { - return nearlyEqual(x, y, epsilon) ? 0 : (x > y ? 1 : -1); + return nearlyEqual(x, y, config.epsilon) ? 0 : (x > y ? 1 : -1); } if (x instanceof BigNumber) { diff --git a/lib/function/arithmetic/equal.js b/lib/function/arithmetic/equal.js index f7fecf129..82b1762a6 100644 --- a/lib/function/arithmetic/equal.js +++ b/lib/function/arithmetic/equal.js @@ -12,8 +12,7 @@ module.exports = function (math, config) { isString = util.string.isString, isComplex = Complex.isComplex, isUnit = Unit.isUnit, - isCollection = collection.isCollection, - epsilon = config.epsilon; + isCollection = collection.isCollection; /** * Check if value x equals y, @@ -39,19 +38,19 @@ module.exports = function (math, config) { if (isNumber(x)) { if (isNumber(y)) { - return nearlyEqual(x, y, epsilon); + return nearlyEqual(x, y, config.epsilon); } else if (isComplex(y)) { - return nearlyEqual(x, y.re, epsilon) && nearlyEqual(y.im, 0, epsilon); + return nearlyEqual(x, y.re, config.epsilon) && nearlyEqual(y.im, 0, config.epsilon); } } if (isComplex(x)) { if (isNumber(y)) { - return nearlyEqual(x.re, y, epsilon) && nearlyEqual(x.im, 0, epsilon); + return nearlyEqual(x.re, y, config.epsilon) && nearlyEqual(x.im, 0, config.epsilon); } else if (isComplex(y)) { - return nearlyEqual(x.re, y.re, epsilon) && nearlyEqual(x.im, y.im, epsilon); + return nearlyEqual(x.re, y.re, config.epsilon) && nearlyEqual(x.im, y.im, config.epsilon); } } diff --git a/lib/function/arithmetic/larger.js b/lib/function/arithmetic/larger.js index 1589ada30..871ee0354 100644 --- a/lib/function/arithmetic/larger.js +++ b/lib/function/arithmetic/larger.js @@ -12,8 +12,7 @@ module.exports = function (math, config) { isString = util.string.isString, isComplex = Complex.isComplex, isUnit = Unit.isUnit, - isCollection = collection.isCollection, - epsilon = config.epsilon; + isCollection = collection.isCollection; /** * Check if value x is larger y @@ -37,7 +36,7 @@ module.exports = function (math, config) { } if (isNumber(x) && isNumber(y)) { - return !nearlyEqual(x, y, epsilon) && x > y; + return !nearlyEqual(x, y, config.epsilon) && x > y; } if (x instanceof BigNumber) { diff --git a/lib/function/arithmetic/largereq.js b/lib/function/arithmetic/largereq.js index 76bd620cf..453690fb2 100644 --- a/lib/function/arithmetic/largereq.js +++ b/lib/function/arithmetic/largereq.js @@ -12,8 +12,7 @@ module.exports = function (math, config) { isString = util.string.isString, isComplex = Complex.isComplex, isUnit = Unit.isUnit, - isCollection = collection.isCollection, - epsilon = config.epsilon; + isCollection = collection.isCollection; /** * Check if value x is larger or equal to y @@ -37,7 +36,7 @@ module.exports = function (math, config) { } if (isNumber(x) && isNumber(y)) { - return nearlyEqual(x, y, epsilon) || x > y; + return nearlyEqual(x, y, config.epsilon) || x > y; } if (x instanceof BigNumber) { diff --git a/lib/function/arithmetic/smaller.js b/lib/function/arithmetic/smaller.js index c602f2e12..ab99f15b1 100644 --- a/lib/function/arithmetic/smaller.js +++ b/lib/function/arithmetic/smaller.js @@ -12,8 +12,7 @@ module.exports = function (math, config) { isString = util.string.isString, isComplex = Complex.isComplex, isUnit = Unit.isUnit, - isCollection = collection.isCollection, - epsilon = config.epsilon; + isCollection = collection.isCollection; /** * Check if value x is smaller y @@ -37,7 +36,7 @@ module.exports = function (math, config) { } if (isNumber(x) && isNumber(y)) { - return !nearlyEqual(x, y, epsilon) && x < y; + return !nearlyEqual(x, y, config.epsilon) && x < y; } if (x instanceof BigNumber) { diff --git a/lib/function/arithmetic/smallereq.js b/lib/function/arithmetic/smallereq.js index b39ab7eb2..843ef9dff 100644 --- a/lib/function/arithmetic/smallereq.js +++ b/lib/function/arithmetic/smallereq.js @@ -12,8 +12,7 @@ module.exports = function (math, config) { isString = util.string.isString, isComplex = Complex.isComplex, isUnit = Unit.isUnit, - isCollection = collection.isCollection, - epsilon = config.epsilon; + isCollection = collection.isCollection; /** * Check if value x is smaller or equal to y @@ -37,7 +36,7 @@ module.exports = function (math, config) { } if (isNumber(x) && isNumber(y)) { - return nearlyEqual(x, y, epsilon) || x < y; + return nearlyEqual(x, y, config.epsilon) || x < y; } if (x instanceof BigNumber) { diff --git a/lib/function/arithmetic/unequal.js b/lib/function/arithmetic/unequal.js index 5c062c5ec..ffce95561 100644 --- a/lib/function/arithmetic/unequal.js +++ b/lib/function/arithmetic/unequal.js @@ -12,8 +12,7 @@ module.exports = function (math, config) { isString = util.string.isString, isComplex = Complex.isComplex, isUnit = Unit.isUnit, - isCollection = collection.isCollection, - epsilon = config.epsilon; + isCollection = collection.isCollection; /** * Check if value x unequals y, x != y @@ -34,19 +33,19 @@ module.exports = function (math, config) { if (isNumber(x)) { if (isNumber(y)) { - return !nearlyEqual(x, y, epsilon); + return !nearlyEqual(x, y, config.epsilon); } else if (isComplex(y)) { - return !nearlyEqual(x, y.re, epsilon) || !nearlyEqual(y.im, 0, epsilon); + return !nearlyEqual(x, y.re, config.epsilon) || !nearlyEqual(y.im, 0, config.epsilon); } } if (isComplex(x)) { if (isNumber(y)) { - return !nearlyEqual(x.re, y, epsilon) || !nearlyEqual(x.im, 0, epsilon); + return !nearlyEqual(x.re, y, config.epsilon) || !nearlyEqual(x.im, 0, config.epsilon); } else if (isComplex(y)) { - return !nearlyEqual(x.re, y.re, epsilon) || !nearlyEqual(x.im, y.im, epsilon); + return !nearlyEqual(x.re, y.re, config.epsilon) || !nearlyEqual(x.im, y.im, config.epsilon); } } diff --git a/test/function/arithmetic/compare.test.js b/test/function/arithmetic/compare.test.js index a645f6080..098dc9868 100644 --- a/test/function/arithmetic/compare.test.js +++ b/test/function/arithmetic/compare.test.js @@ -1,6 +1,7 @@ // test compare var assert = require('assert'), - math = require('../../../index')(), + mathjs = require('../../../index'), + math = mathjs(), error = require('../../../lib/error/index'), bignumber = math.bignumber, complex = math.complex, @@ -105,6 +106,13 @@ describe('compare', function() { assert.deepEqual(compare([1,4,6], matrix([3,4,5])), matrix([-1, 0, 1])); }); + it('should apply configuration option epsilon', function() { + var mymath = mathjs(); + assert.equal(mymath.compare(1, 0.991), 1); + mymath.config({epsilon: 1e-2}); + assert.equal(mymath.compare(1, 0.991), 0); + }); + it('should throw an error when comparing complex numbers', function() { assert.throws(function () {compare(complex(1,1), complex(1,2))}, TypeError); assert.throws(function () {compare(complex(2,1), 3)}, TypeError); diff --git a/test/function/arithmetic/equal.test.js b/test/function/arithmetic/equal.test.js index 02819b34b..01852a54c 100644 --- a/test/function/arithmetic/equal.test.js +++ b/test/function/arithmetic/equal.test.js @@ -1,6 +1,7 @@ // test equal var assert = require('assert'), - math = require('../../../index')(), + mathjs = require('../../../index'), + math = mathjs(), error = require('../../../lib/error/index'), bignumber = math.bignumber, complex = math.complex, @@ -104,6 +105,13 @@ describe('equal', function() { //assert.equal(equal(unit('2.54cm'), unit('1inch')), true); // round-off error :( }); + it('should apply configuration option epsilon', function() { + var mymath = mathjs(); + assert.equal(mymath.equal(1, 0.991), false); + mymath.config({epsilon: 1e-2}); + assert.equal(mymath.equal(1, 0.991), true); + }); + it('should throw an error when comparing a unit with a big number', function() { assert.throws( function () {equal(math.unit('5 m'), bignumber(10)).toString() }); }); diff --git a/test/function/arithmetic/larger.test.js b/test/function/arithmetic/larger.test.js index cf3a08937..a6900611f 100644 --- a/test/function/arithmetic/larger.test.js +++ b/test/function/arithmetic/larger.test.js @@ -1,6 +1,7 @@ // test larger var assert = require('assert'), - math = require('../../../index')(), + mathjs = require('../../../index'), + math = mathjs(), error = require('../../../lib/error/index'), bignumber = math.bignumber, complex = math.complex, @@ -78,6 +79,13 @@ describe('larger', function() { assert.equal(larger(unit('101cm'), unit('1m')), true); }); + it('should apply configuration option epsilon', function() { + var mymath = mathjs(); + assert.equal(mymath.larger(1, 0.991), true); + mymath.config({epsilon: 1e-2}); + assert.equal(mymath.larger(1, 0.991), false); + }); + it('should throw an error if comparing a unit with a number', function() { assert.throws(function () {larger(unit('100cm'), 22)}); }); diff --git a/test/function/arithmetic/largereq.test.js b/test/function/arithmetic/largereq.test.js index 7df04f1b5..57a4e7f1a 100644 --- a/test/function/arithmetic/largereq.test.js +++ b/test/function/arithmetic/largereq.test.js @@ -1,6 +1,7 @@ // test largereq var assert = require('assert'), - math = require('../../../index')(), + mathjs = require('../../../index') + math = mathjs(), error = require('../../../lib/error/index'), bignumber = math.bignumber, complex = math.complex, @@ -81,6 +82,13 @@ describe('largereq', function() { assert.equal(largereq(unit('101cm'), unit('1m')), true); }); + it('should apply configuration option epsilon', function() { + var mymath = mathjs(); + assert.equal(mymath.largereq(1, 1.01), false); + mymath.config({epsilon: 1e-2}); + assert.equal(mymath.largereq(1, 1.01), true); + }); + it('should throw an error if comparing a unit with a number', function() { assert.throws(function () {largereq(unit('100cm'), 22)}); }); diff --git a/test/function/arithmetic/smaller.test.js b/test/function/arithmetic/smaller.test.js index ec41da081..9ac6a9f16 100644 --- a/test/function/arithmetic/smaller.test.js +++ b/test/function/arithmetic/smaller.test.js @@ -1,6 +1,7 @@ // test smaller var assert = require('assert'), - math = require('../../../index')(), + mathjs = require('../../../index'), + math = mathjs(), error = require('../../../lib/error/index'), bignumber = math.bignumber, complex = math.complex, @@ -83,6 +84,13 @@ describe('smaller', function() { assert.equal(smaller(unit('101cm'), unit('1m')), false); }); + it('should apply configuration option epsilon', function() { + var mymath = mathjs(); + assert.equal(mymath.smaller(0.991, 1), true); + mymath.config({epsilon: 1e-2}); + assert.equal(mymath.smaller(0.991, 1), false); + }); + it('should throw an error if comparing a unit and a number', function() { assert.throws(function () {smaller(unit('100cm'), 22)}); }); diff --git a/test/function/arithmetic/smallereq.test.js b/test/function/arithmetic/smallereq.test.js index 90730aec1..f8b67e7bc 100644 --- a/test/function/arithmetic/smallereq.test.js +++ b/test/function/arithmetic/smallereq.test.js @@ -1,6 +1,7 @@ // test smaller var assert = require('assert'), - math = require('../../../index')(), + mathjs = require('../../../index'), + math = mathjs(), error = require('../../../lib/error/index'), bignumber = math.bignumber, complex = math.complex, @@ -84,6 +85,13 @@ describe('smallereq', function() { assert.equal(smallereq(unit('101cm'), unit('1m')), false); }); + it('should apply configuration option epsilon', function() { + var mymath = mathjs(); + assert.equal(mymath.smallereq(1.01, 1), false); + mymath.config({epsilon: 1e-2}); + assert.equal(mymath.smallereq(1.01, 1), true); + }); + it('should throw an error if comparing a unit with a number', function() { assert.throws(function () {smallereq(unit('100cm'), 22)}); assert.throws(function () {smallereq(22, unit('100cm'))}); diff --git a/test/function/arithmetic/unequal.test.js b/test/function/arithmetic/unequal.test.js index 0307c20e8..9792666ae 100644 --- a/test/function/arithmetic/unequal.test.js +++ b/test/function/arithmetic/unequal.test.js @@ -1,7 +1,8 @@ // test equal var assert = require('assert'), error = require('../../../lib/error/index'), - math = require('../../../index')(), + mathjs = require('../../../index'), + math = mathjs(), bignumber = math.bignumber, complex = math.complex, matrix = math.matrix, @@ -106,6 +107,13 @@ describe('unequal', function() { //assert.equal(unequal(unit('2.54cm'), unit('1inch')), false); // round-off error :( }); + it('should apply configuration option epsilon', function() { + var mymath = mathjs(); + assert.equal(mymath.unequal(1, 0.991), true); + mymath.config({epsilon: 1e-2}); + assert.equal(mymath.unequal(1, 0.991), false); + }); + it('should throw an error when comparing numbers and units', function() { assert.throws(function () {unequal(unit('100cm'), 22)}); assert.throws(function () {unequal(22, unit('100cm'))}); From 127f00cbfb19fa1c9b0fd45b570e4996c1bc0881 Mon Sep 17 00:00:00 2001 From: jos Date: Wed, 16 Apr 2014 10:22:31 +0200 Subject: [PATCH 47/48] Added example code for polar coordinates --- examples/complex_numbers.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/examples/complex_numbers.js b/examples/complex_numbers.js index f9881b511..083c8c477 100644 --- a/examples/complex_numbers.js +++ b/examples/complex_numbers.js @@ -44,3 +44,12 @@ print(math.sin(a)); // -9.6541 + 2.8417i // some operations will return a complex number depending on the arguments print(math.sqrt(4)); // 2 print(math.sqrt(-4)); // 2i + +// create a complex number from polar coordinates +console.log('create complex numbers with polar coordinates'); +var c = math.complex({r: math.sqrt(2), phi: math.pi / 4}); +print(c); // 1 + i + +// get polar coordinates of a complex number +var d = math.complex(3, 4); +console.log(d.toPolar()); // { r: 5, phi: 0.9272952180016122 } From f63f1b8f2c25c8fd9504ac08e327eea2bec4f1f1 Mon Sep 17 00:00:00 2001 From: jos Date: Wed, 16 Apr 2014 10:25:14 +0200 Subject: [PATCH 48/48] Released version 0.20.0 --- HISTORY.md | 2 +- bower.json | 2 +- dist/math.js | 17973 +++++++++++++++++++++++++-------------- dist/math.map | 2 +- dist/math.min.js | 17 +- misc/how_to_publish.md | 15 +- package.json | 2 +- 7 files changed, 11683 insertions(+), 6330 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 11dd7ed3d..d5845c8e2 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,7 +2,7 @@ https://github.com/josdejong/mathjs -## not yet released, version 0.20.0 +## 2014-04-16, version 0.20.0 - Switched to module `decimal.js` for BigNumber support, instead of `bignumber.js`. diff --git a/bower.json b/bower.json index b5ec1006a..0006e742d 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "mathjs", - "version": "0.20.0-SNAPSHOT", + "version": "0.20.0", "main": "./dist/math.js", "ignore": [ "coverage", diff --git a/dist/math.js b/dist/math.js index 2657b5a1b..6dd56db63 100644 --- a/dist/math.js +++ b/dist/math.js @@ -6,8 +6,8 @@ * It features real and complex numbers, units, matrices, a large set of * mathematical functions, and a flexible expression parser. * - * @version 0.19.0 - * @date 2014-03-30 + * @version 0.20.0 + * @date 2014-04-16 * * @license * Copyright (C) 2013-2014 Jos de Jong @@ -97,18 +97,18 @@ return /******/ (function(modules) { // webpackBootstrap * Usage: * * var math = mathjs(); - * var math = mathjs(settings); + * var math = mathjs(config); * - * @param {Object} [settings] Available settings: + * @param {Object} [config] Available configuration options: * {String} matrix * A string 'matrix' (default) or 'array'. * {String} number * A string 'number' (default) or 'bignumber' - * {Number} decimals - * The number of decimals behind the decimal - * point for BigNumber. Not applicable for Numbers. + * {Number} precision + * The number of significant digits for BigNumbers. + * Not applicable for Numbers. */ - function mathjs (settings) { + function mathjs (config) { // simple test for ES5 support if (typeof Object.create !== 'function') { throw new Error('ES5 not supported by this JavaScript engine. ' + @@ -118,219 +118,260 @@ return /******/ (function(modules) { // webpackBootstrap // create new namespace var math = {}; - // create configuration settings. These are private - var _settings = { + // create configuration options. These are private + var _config = { // type of default matrix output. Choose 'matrix' (default) or 'array' matrix: 'matrix', // type of default number output. Choose 'number' (default) or 'bignumber' - number: 'number' + number: 'number', + + // number of significant digits in BigNumbers + precision: 20, + + // minimum relative difference between two compared values, + // used by all comparison functions + epsilon: 1e-14 }; /** - * Set configuration settings for math.js, and get current settings - * @param {Object} [settings] Available settings: + * Set configuration options for math.js, and get current options + * @param {Object} [options] Available options: * {String} matrix * A string 'matrix' (default) or 'array'. * {String} number * A string 'number' (default) or 'bignumber' - * {Number} decimals - * The number of decimals behind the decimal - * point for BigNumber. Not applicable for Numbers. - * @return {Object} settings The currently applied settings + * {Number} precision + * The number of significant digits for BigNumbers. + * Not applicable for Numbers. + * @return {Object} Returns the current configuration */ - math.config = function config (settings) { - var BigNumber = __webpack_require__(111); + math.config = function config (options) { + if (options) { + // merge options + object.deepExtend(_config, options); - if (settings) { - // merge settings - object.deepExtend(_settings, settings); - - if (settings.decimals) { - BigNumber.config({ - DECIMAL_PLACES: settings.decimals + if (options.precision) { + math.type.BigNumber.config({ + precision: options.precision }); } // TODO: remove deprecated setting some day (deprecated since version 0.17.0) - if (settings.number && settings.number.defaultType) { - throw new Error('setting `number.defaultType` is deprecated. ' + - 'Use `number` instead.') + if (options.number && options.number.defaultType) { + throw new Error('setting `number.defaultType` is deprecated. Use `number` instead.') } // TODO: remove deprecated setting some day (deprecated since version 0.17.0) - if (settings.number && settings.number.precision) { - throw new Error('setting `number.precision` is deprecated. ' + - 'Use `decimals` instead.') + if (options.number && options.number.precision) { + throw new Error('setting `number.precision` is deprecated. Use `precision` instead.') } // TODO: remove deprecated setting some day (deprecated since version 0.17.0) - if (settings.matrix && settings.matrix.defaultType) { - throw new Error('setting `matrix.defaultType` is deprecated. ' + - 'Use `matrix` instead.') + if (options.matrix && options.matrix.defaultType) { + throw new Error('setting `matrix.defaultType` is deprecated. Use `matrix` instead.') } // TODO: remove deprecated setting some day (deprecated since version 0.15.0) - if (settings.matrix && settings.matrix['default']) { - throw new Error('setting `matrix.default` is deprecated. ' + - 'Use `matrix` instead.') + if (options.matrix && options.matrix['default']) { + throw new Error('setting `matrix.default` is deprecated. Use `matrix` instead.') + } + + // TODO: remove deprecated setting some day (deprecated since version 0.20.0) + if (options.decimals) { + throw new Error('setting `decimals` is deprecated. Use `precision` instead.') } } // return a clone of the settings - var current = object.clone(_settings); - current.decimals = BigNumber.config().DECIMAL_PLACES; - return current; + return object.clone(_config); }; - // apply provided configuration settings - math.config(settings); + // create a new BigNumber factory for this instance of math.js + var BigNumber = __webpack_require__(112).constructor(); - // expression (parse, Parser, nodes, docs) - math.expression = {}; - math.expression.node = __webpack_require__(6); - math.expression.parse = __webpack_require__(4); - math.expression.Scope = function () { - throw new Error('Scope is deprecated. Use a regular Object instead'); - }; - math.expression.Parser = __webpack_require__(5); - math.expression.docs = __webpack_require__(7); + // extend BigNumber with a function clone + if (typeof BigNumber.prototype.clone !== 'function') { + /** + * Clone a bignumber + * @return {BigNumber} clone + */ + BigNumber.prototype.clone = function clone () { + return new BigNumber(this); + }; + } + + // extend BigNumber with a function convert + if (typeof BigNumber.convert !== 'function') { + /** + * Try to convert a Number in to a BigNumber. + * If the number has 15 or mor significant digits, the Number cannot be + * converted to BigNumber and will return the original number. + * @param {Number} number + * @return {BigNumber | Number} bignumber + */ + BigNumber.convert = function convert(number) { + if (digits(number) > 15) { + return number; + } + else { + return new BigNumber(number); + } + }; + } + else { + throw new Error('Cannot add function convert to BigNumber: function already exists'); + } + + // errors + math.error = __webpack_require__(4); // types (Matrix, Complex, Unit, ...) math.type = {}; - math.type.BigNumber = __webpack_require__(111); - math.type.Complex = __webpack_require__(8); - math.type.Range = __webpack_require__(9); - math.type.Index = __webpack_require__(10); - math.type.Matrix = __webpack_require__(11); - math.type.Unit = __webpack_require__(12); - math.type.Help = __webpack_require__(13); + math.type.Complex = __webpack_require__(5); + math.type.Range = __webpack_require__(6); + math.type.Index = __webpack_require__(7); + math.type.Matrix = __webpack_require__(8); + math.type.Unit = __webpack_require__(9); + math.type.Help = __webpack_require__(10); + math.type.BigNumber = BigNumber; - math.collection = __webpack_require__(14); + math.collection = __webpack_require__(11); - // error utility functions - __webpack_require__(15)(math); + // expression (parse, Parser, nodes, docs) + math.expression = {}; + math.expression.node = __webpack_require__(14); + math.expression.parse = __webpack_require__(12); + math.expression.Scope = function () { + throw new Error('Scope is deprecated. Use a regular Object instead'); + }; + math.expression.Parser = __webpack_require__(13); + math.expression.docs = __webpack_require__(15); // expression parser - __webpack_require__(17)(math, _settings); - __webpack_require__(18)(math, _settings); - __webpack_require__(19)(math, _settings); - __webpack_require__(20)(math, _settings); + __webpack_require__(17)(math, _config); + __webpack_require__(18)(math, _config); + __webpack_require__(19)(math, _config); + __webpack_require__(20)(math, _config); // functions - arithmetic - __webpack_require__(21)(math, _settings); - __webpack_require__(22)(math, _settings); - __webpack_require__(23)(math, _settings); - __webpack_require__(24)(math, _settings); - __webpack_require__(25)(math, _settings); - __webpack_require__(26)(math, _settings); - __webpack_require__(27)(math, _settings); - __webpack_require__(28)(math, _settings); - __webpack_require__(29)(math, _settings); - __webpack_require__(30)(math, _settings); - __webpack_require__(31)(math, _settings); - __webpack_require__(32)(math, _settings); - __webpack_require__(33)(math, _settings); - __webpack_require__(34)(math, _settings); - __webpack_require__(35)(math, _settings); - __webpack_require__(36)(math, _settings); - __webpack_require__(37)(math, _settings); - __webpack_require__(38)(math, _settings); - __webpack_require__(39)(math, _settings); - __webpack_require__(40)(math, _settings); - __webpack_require__(41)(math, _settings); - __webpack_require__(42)(math, _settings); - __webpack_require__(43)(math, _settings); - __webpack_require__(44)(math, _settings); - __webpack_require__(45)(math, _settings); - __webpack_require__(46)(math, _settings); - __webpack_require__(47)(math, _settings); - __webpack_require__(48)(math, _settings); - __webpack_require__(49)(math, _settings); - __webpack_require__(50)(math, _settings); - __webpack_require__(51)(math, _settings); - __webpack_require__(52)(math, _settings); + __webpack_require__(21)(math, _config); + __webpack_require__(22)(math, _config); + __webpack_require__(23)(math, _config); + __webpack_require__(24)(math, _config); + __webpack_require__(25)(math, _config); + __webpack_require__(26)(math, _config); + __webpack_require__(27)(math, _config); + __webpack_require__(28)(math, _config); + __webpack_require__(29)(math, _config); + __webpack_require__(30)(math, _config); + __webpack_require__(31)(math, _config); + __webpack_require__(32)(math, _config); + __webpack_require__(33)(math, _config); + __webpack_require__(34)(math, _config); + __webpack_require__(35)(math, _config); + __webpack_require__(36)(math, _config); + __webpack_require__(37)(math, _config); + __webpack_require__(38)(math, _config); + __webpack_require__(39)(math, _config); + __webpack_require__(40)(math, _config); + __webpack_require__(41)(math, _config); + __webpack_require__(42)(math, _config); + __webpack_require__(43)(math, _config); + __webpack_require__(44)(math, _config); + __webpack_require__(45)(math, _config); + __webpack_require__(46)(math, _config); + __webpack_require__(47)(math, _config); + __webpack_require__(48)(math, _config); + __webpack_require__(49)(math, _config); + __webpack_require__(50)(math, _config); + __webpack_require__(51)(math, _config); + __webpack_require__(52)(math, _config); + __webpack_require__(53)(math, _config); // functions - complex - __webpack_require__(53)(math, _settings); - __webpack_require__(54)(math, _settings); - __webpack_require__(55)(math, _settings); - __webpack_require__(56)(math, _settings); + __webpack_require__(54)(math, _config); + __webpack_require__(55)(math, _config); + __webpack_require__(56)(math, _config); + __webpack_require__(57)(math, _config); // functions - construction - __webpack_require__(57)(math, _settings); - __webpack_require__(58)(math, _settings); - __webpack_require__(59)(math, _settings); - __webpack_require__(60)(math, _settings); - __webpack_require__(61)(math, _settings); - __webpack_require__(62)(math, _settings); - __webpack_require__(63)(math, _settings); - __webpack_require__(64)(math, _settings); - __webpack_require__(65)(math, _settings); - __webpack_require__(66)(math, _settings); + __webpack_require__(58)(math, _config); + __webpack_require__(59)(math, _config); + __webpack_require__(60)(math, _config); + __webpack_require__(61)(math, _config); + __webpack_require__(62)(math, _config); + __webpack_require__(63)(math, _config); + __webpack_require__(64)(math, _config); + __webpack_require__(65)(math, _config); + __webpack_require__(66)(math, _config); + __webpack_require__(67)(math, _config); // functions - matrix - __webpack_require__(67)(math, _settings); - __webpack_require__(68)(math, _settings); - __webpack_require__(69)(math, _settings); - __webpack_require__(70)(math, _settings); - __webpack_require__(71)(math, _settings); - __webpack_require__(72)(math, _settings); - __webpack_require__(73)(math, _settings); - __webpack_require__(74)(math, _settings); - __webpack_require__(75)(math, _settings); - __webpack_require__(76)(math, _settings); - __webpack_require__(77)(math, _settings); - __webpack_require__(78)(math, _settings); - __webpack_require__(79)(math, _settings); + __webpack_require__(68)(math, _config); + __webpack_require__(69)(math, _config); + __webpack_require__(70)(math, _config); + __webpack_require__(71)(math, _config); + __webpack_require__(72)(math, _config); + __webpack_require__(73)(math, _config); + __webpack_require__(74)(math, _config); + __webpack_require__(75)(math, _config); + __webpack_require__(76)(math, _config); + __webpack_require__(77)(math, _config); + __webpack_require__(78)(math, _config); + __webpack_require__(79)(math, _config); + __webpack_require__(80)(math, _config); // functions - probability - __webpack_require__(80)(math, _settings); - __webpack_require__(81)(math, _settings); - __webpack_require__(82)(math, _settings); - __webpack_require__(83)(math, _settings); + __webpack_require__(81)(math, _config); + __webpack_require__(82)(math, _config); + __webpack_require__(83)(math, _config); + __webpack_require__(84)(math, _config); // functions - statistics - __webpack_require__(84)(math, _settings); - __webpack_require__(85)(math, _settings); - __webpack_require__(86)(math, _settings); - __webpack_require__(87)(math, _settings); - __webpack_require__(88)(math, _settings); - __webpack_require__(89)(math, _settings); - __webpack_require__(90)(math, _settings); - __webpack_require__(91)(math, _settings); + __webpack_require__(85)(math, _config); + __webpack_require__(86)(math, _config); + __webpack_require__(87)(math, _config); + __webpack_require__(88)(math, _config); + __webpack_require__(89)(math, _config); + __webpack_require__(90)(math, _config); + __webpack_require__(91)(math, _config); + __webpack_require__(92)(math, _config); // functions - trigonometry - __webpack_require__(92)(math, _settings); - __webpack_require__(93)(math, _settings); - __webpack_require__(94)(math, _settings); - __webpack_require__(95)(math, _settings); - __webpack_require__(96)(math, _settings); - __webpack_require__(97)(math, _settings); - __webpack_require__(98)(math, _settings); - __webpack_require__(99)(math, _settings); - __webpack_require__(100)(math, _settings); - __webpack_require__(101)(math, _settings); + __webpack_require__(93)(math, _config); + __webpack_require__(94)(math, _config); + __webpack_require__(95)(math, _config); + __webpack_require__(96)(math, _config); + __webpack_require__(97)(math, _config); + __webpack_require__(98)(math, _config); + __webpack_require__(99)(math, _config); + __webpack_require__(100)(math, _config); + __webpack_require__(101)(math, _config); + __webpack_require__(102)(math, _config); // functions - units - __webpack_require__(102)(math, _settings); + __webpack_require__(103)(math, _config); // functions - utils - __webpack_require__(103)(math, _settings); - __webpack_require__(104)(math, _settings); - __webpack_require__(105)(math, _settings); - __webpack_require__(106)(math, _settings); - __webpack_require__(107)(math, _settings); - __webpack_require__(108)(math, _settings); - __webpack_require__(109)(math, _settings); - __webpack_require__(110)(math, _settings); + __webpack_require__(104)(math, _config); + __webpack_require__(105)(math, _config); + __webpack_require__(106)(math, _config); + __webpack_require__(107)(math, _config); + __webpack_require__(108)(math, _config); + __webpack_require__(109)(math, _config); + __webpack_require__(110)(math, _config); + __webpack_require__(111)(math, _config); // constants - __webpack_require__(2)(math, _settings); + __webpack_require__(2)(math, _config); // selector (we initialize after all functions are loaded) math.chaining = {}; - math.chaining.Selector = __webpack_require__(16)(math, _settings); + math.chaining.Selector = __webpack_require__(16)(math, _config); + + // apply provided configuration options + math.config(config); // return the new instance return math; @@ -346,7 +387,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var Complex = __webpack_require__(8); + var Complex = __webpack_require__(5); math.pi = Math.PI; math.e = Math.E; @@ -524,32 +565,2758 @@ return /******/ (function(modules) { // webpackBootstrap /* 4 */ /***/ function(module, exports, __webpack_require__) { - var util = __webpack_require__(112), + exports.ArgumentsError = __webpack_require__(113); + exports.DimensionError = __webpack_require__(114); + exports.IndexError = __webpack_require__(115); + exports.UnsupportedTypeError = __webpack_require__(116); + + // TODO: implement an InvalidValueError? + + +/***/ }, +/* 5 */ +/***/ function(module, exports, __webpack_require__) { + + var util = __webpack_require__(117), + Unit = __webpack_require__(9), + number = util.number, + + isNumber = util.number.isNumber, + isUnit = Unit.isUnit, + isString = util.string.isString; + + /** + * @constructor Complex + * + * A complex value can be constructed in the following ways: + * var a = new Complex(); + * var b = new Complex(re, im); + * var c = Complex.parse(str); + * + * Example usage: + * var a = new Complex(3, -4); // 3 - 4i + * a.re = 5; // a = 5 - 4i + * var i = a.im; // -4; + * var b = Complex.parse('2 + 6i'); // 2 + 6i + * var c = new Complex(); // 0 + 0i + * var d = math.add(a, b); // 5 + 2i + * + * @param {Number} re The real part of the complex value + * @param {Number} [im] The imaginary part of the complex value + */ + function Complex(re, im) { + if (!(this instanceof Complex)) { + throw new SyntaxError('Constructor must be called with the new operator'); + } + + switch (arguments.length) { + case 0: + this.re = 0; + this.im = 0; + break; + + case 1: + var arg = arguments[0]; + if (typeof arg === 'object') { + if('re' in arg && 'im' in arg) { + var construct = new Complex(arg.re, arg.im); // pass on input validation + this.re = construct.re; + this.im = construct.im; + break; + } else if ('r' in arg && 'phi' in arg) { + var construct = Complex.fromPolar(arg.r, arg.phi); + this.re = construct.re; + this.im = construct.im; + break; + } + } + throw new SyntaxError('Object with the re and im or r and phi properties expected.'); + + case 2: + if (!isNumber(re) || !isNumber(im)) { + throw new TypeError('Two numbers expected in Complex constructor'); + } + this.re = re; + this.im = im; + break; + + default: + throw new SyntaxError('One, two or three arguments expected in Complex constructor'); + } + } + + /** + * Test whether value is a Complex value + * @param {*} value + * @return {Boolean} isComplex + */ + Complex.isComplex = function isComplex(value) { + return (value instanceof Complex); + }; + + // private variables and functions for the parser + var text, index, c; + + function skipWhitespace() { + while (c == ' ' || c == '\t') { + next(); + } + } + + function isDigitDot (c) { + return ((c >= '0' && c <= '9') || c == '.'); + } + + function isDigit (c) { + return ((c >= '0' && c <= '9')); + } + + function next() { + index++; + c = text.charAt(index); + } + + function revert(oldIndex) { + index = oldIndex; + c = text.charAt(index); + } + + function parseNumber () { + var number = ''; + var oldIndex; + oldIndex = index; + + if (c == '+') { + next(); + } + else if (c == '-') { + number += c; + next(); + } + + if (!isDigitDot(c)) { + // a + or - must be followed by a digit + revert(oldIndex); + return null; + } + + // get number, can have a single dot + if (c == '.') { + number += c; + next(); + if (!isDigit(c)) { + // this is no legal number, it is just a dot + revert(oldIndex); + return null; + } + } + else { + while (isDigit(c)) { + number += c; + next(); + } + if (c == '.') { + number += c; + next(); + } + } + while (isDigit(c)) { + number += c; + next(); + } + + // check for exponential notation like "2.3e-4" or "1.23e50" + if (c == 'E' || c == 'e') { + number += c; + next(); + + if (c == '+' || c == '-') { + number += c; + next(); + } + + // Scientific notation MUST be followed by an exponent + if (!isDigit(c)) { + // this is no legal number, exponent is missing. + revert(oldIndex); + return null; + } + + while (isDigit(c)) { + number += c; + next(); + } + } + + return number; + } + + function parseComplex () { + // check for 'i', '-i', '+i' + var cnext = text.charAt(index + 1); + if (c == 'I' || c == 'i') { + next(); + return '1'; + } + else if ((c == '+' || c == '-') && (cnext == 'I' || cnext == 'i')) { + var number = (c == '+') ? '1' : '-1'; + next(); + next(); + return number; + } + + return null; + } + + /** + * Parse a complex number from a string. For example Complex.parse("2 + 3i") + * will return a Complex value where re = 2, im = 3. + * Returns null if provided string does not contain a valid complex number. + * @param {String} str + * @returns {Complex | null} complex + */ + Complex.parse = function parse (str) { + text = str; + index = -1; + c = ''; + + if (!isString(text)) { + return null; + } + + next(); + skipWhitespace(); + var first = parseNumber(); + if (first) { + if (c == 'I' || c == 'i') { + // pure imaginary number + next(); + skipWhitespace(); + if (c) { + // garbage at the end. not good. + return null; + } + + return new Complex(0, Number(first)); + } + else { + // complex and real part + skipWhitespace(); + var separator = c; + if (separator != '+' && separator != '-') { + // pure real number + skipWhitespace(); + if (c) { + // garbage at the end. not good. + return null; + } + + return new Complex(Number(first), 0); + } + else { + // complex and real part + next(); + skipWhitespace(); + var second = parseNumber(); + if (second) { + if (c != 'I' && c != 'i') { + // 'i' missing at the end of the complex number + return null; + } + next(); + } + else { + second = parseComplex(); + if (!second) { + // imaginary number missing after separator + return null; + } + } + + if (separator == '-') { + if (second[0] == '-') { + second = '+' + second.substring(1); + } + else { + second = '-' + second; + } + } + + next(); + skipWhitespace(); + if (c) { + // garbage at the end. not good. + return null; + } + + return new Complex(Number(first), Number(second)); + } + } + } + else { + // check for 'i', '-i', '+i' + first = parseComplex(); + if (first) { + skipWhitespace(); + if (c) { + // garbage at the end. not good. + return null; + } + + return new Complex(0, Number(first)); + } + } + + return null; + }; + + /** + * Create a complex number from polar coordinates + * + * Usage: + * + * Complex.fromPolar(r: Number, phi: Number) : Complex + * Complex.fromPolar({r: Number, phi: Number}) : Complex + * + * @param {*} args... + * @return {Complex} + */ + Complex.fromPolar = function fromPolar(args) { + switch (arguments.length) { + case 1: + var arg = arguments[0]; + if(typeof arg === 'object') { + return Complex.fromPolar(arg.r, arg.phi); + } + throw new TypeError('Input has to be an object with r and phi keys.'); + + case 2: + var r = arguments[0], + phi = arguments[1]; + if(isNumber(r)) { + if (isUnit(phi) && phi.hasBase(Unit.BASE_UNITS.ANGLE)) { + // convert unit to a number in radians + phi = phi.toNumber('rad'); + } + + if(isNumber(phi)) { + return new Complex(r * Math.cos(phi), r * Math.sin(phi)); + } + + throw new TypeError('Phi is not a number nor an angle unit.'); + } else { + throw new TypeError('Radius r is not a number.'); + } + + default: + throw new SyntaxError('Wrong number of arguments in function fromPolar'); + } + }; + + /* + * Return the value of the complex number in polar notation + * The angle phi will be set in the interval of [-pi, pi]. + * @return {{r: number, phi: number}} Returns and object with properties r and phi. + */ + Complex.prototype.toPolar = function() { + return { + r: Math.sqrt(this.re * this.re + this.im * this.im), + phi: Math.atan2(this.im, this.re) + }; + }; + + /** + * Create a copy of the complex value + * @return {Complex} clone + */ + Complex.prototype.clone = function clone () { + return new Complex(this.re, this.im); + }; + + /** + * Test whether this complex number equals an other complex value. + * Two complex numbers are equal when both their real and imaginary parts + * are equal. + * @param {Complex} other + * @return {boolean} isEqual + */ + Complex.prototype.equals = function equals (other) { + return (this.re === other.re) && (this.im === other.im); + }; + + /** + * Get a string representation of the complex number, + * with optional formatting options. + * @param {Object | Number | Function} [options] Formatting options. See + * lib/util/number:format for a + * description of the available + * options. + * @return {String} str + */ + Complex.prototype.format = function format (options) { + var str = '', + strRe = number.format(this.re, options), + strIm = number.format(this.im, options); + + if (this.im == 0) { + // real value + str = strRe; + } + else if (this.re == 0) { + // purely complex value + if (this.im == 1) { + str = 'i'; + } + else if (this.im == -1) { + str = '-i'; + } + else { + str = strIm + 'i'; + } + } + else { + // complex value + if (this.im > 0) { + if (this.im == 1) { + str = strRe + ' + i'; + } + else { + str = strRe + ' + ' + strIm + 'i'; + } + } + else { + if (this.im == -1) { + str = strRe + ' - i'; + } + else { + str = strRe + ' - ' + strIm.substring(1) + 'i'; + } + } + } + + return str; + }; + + /** + * Get a string representation of the complex number. + * @return {String} str + */ + Complex.prototype.toString = function toString () { + return this.format(); + }; + + // exports + module.exports = Complex; + + +/***/ }, +/* 6 */ +/***/ function(module, exports, __webpack_require__) { + + var util = __webpack_require__(117), + + number = util.number, + string = util.string, + array = util.array; + + /** + * @constructor Range + * Create a range. A range has a start, step, and end, and contains functions + * to iterate over the range. + * + * A range can be constructed as: + * var range = new Range(start, end); + * var range = new Range(start, end, step); + * + * To get the result of the range: + * range.forEach(function (x) { + * console.log(x); + * }); + * range.map(function (x) { + * return math.sin(x); + * }); + * range.toArray(); + * + * Example usage: + * var c = new Range(2, 6); // 2:1:5 + * c.toArray(); // [2, 3, 4, 5] + * var d = new Range(2, -3, -1); // 2:-1:-2 + * d.toArray(); // [2, 1, 0, -1, -2] + * + * @param {Number} start included lower bound + * @param {Number} end excluded upper bound + * @param {Number} [step] step size, default value is 1 + */ + function Range(start, end, step) { + if (!(this instanceof Range)) { + throw new SyntaxError('Constructor must be called with the new operator'); + } + + if (start != null && !number.isNumber(start)) { + throw new TypeError('Parameter start must be a number'); + } + if (end != null && !number.isNumber(end)) { + throw new TypeError('Parameter end must be a number'); + } + if (step != null && !number.isNumber(step)) { + throw new TypeError('Parameter step must be a number'); + } + + this.start = (start != null) ? parseFloat(start) : 0; + this.end = (end != null) ? parseFloat(end) : 0; + this.step = (step != null) ? parseFloat(step) : 1; + } + + /** + * Parse a string into a range, + * The string contains the start, optional step, and end, separated by a colon. + * If the string does not contain a valid range, null is returned. + * For example str='0:2:11'. + * @param {String} str + * @return {Range | null} range + */ + Range.parse = function parse (str) { + if (!string.isString(str)) { + return null; + } + + var args = str.split(':'); + var nums = args.map(function (arg) { + return parseFloat(arg); + }); + + var invalid = nums.some(function (num) { + return isNaN(num); + }); + if(invalid) { + return null; + } + + switch (nums.length) { + case 2: return new Range(nums[0], nums[1]); + case 3: return new Range(nums[0], nums[2], nums[1]); + default: return null; + } + }; + + /** + * Create a clone of the range + * @return {Range} clone + */ + Range.prototype.clone = function clone() { + return new Range(this.start, this.end, this.step); + }; + + /** + * Test whether an object is a Range + * @param {*} object + * @return {Boolean} isRange + */ + Range.isRange = function isRange(object) { + return (object instanceof Range); + }; + + /** + * Retrieve the size of the range. + * Returns an array containing one number, the number of elements in the range. + * @returns {Number[]} size + */ + Range.prototype.size = function size() { + var len = 0, + start = this.start, + step = this.step, + end = this.end, + diff = end - start; + + if (number.sign(step) == number.sign(diff)) { + len = Math.ceil((diff) / step); + } + else if (diff == 0) { + len = 0; + } + + if (isNaN(len)) { + len = 0; + } + return [len]; + }; + + /** + * Calculate the minimum value in the range + * @return {Number | undefined} min + */ + Range.prototype.min = function min () { + var size = this.size()[0]; + + if (size > 0) { + if (this.step > 0) { + // positive step + return this.start; + } + else { + // negative step + return this.start + (size - 1) * this.step; + } + } + else { + return undefined; + } + }; + + /** + * Calculate the maximum value in the range + * @return {Number | undefined} max + */ + Range.prototype.max = function max () { + var size = this.size()[0]; + + if (size > 0) { + if (this.step > 0) { + // positive step + return this.start + (size - 1) * this.step; + } + else { + // negative step + return this.start; + } + } + else { + return undefined; + } + }; + + + /** + * Execute a callback function for each value in the range. + * @param {function} callback The callback method is invoked with three + * parameters: the value of the element, the index + * of the element, and the Matrix being traversed. + */ + Range.prototype.forEach = function forEach(callback) { + var x = this.start; + var step = this.step; + var end = this.end; + var i = 0; + + if (step > 0) { + while (x < end) { + callback(x, i, this); + x += step; + i++; + } + } + else if (step < 0) { + while (x > end) { + callback(x, i, this); + x += step; + i++; + } + } + }; + + /** + * Execute a callback function for each value in the Range, and return the + * results as an array + * @param {function} callback The callback method is invoked with three + * parameters: the value of the element, the index + * of the element, and the Matrix being traversed. + * @returns {Array} array + */ + Range.prototype.map = function map(callback) { + var array = []; + this.forEach(function (value, index, obj) { + array[index] = callback(value, index, obj); + }); + return array; + }; + + /** + * Create an Array with a copy of the Ranges data + * @returns {Array} array + */ + Range.prototype.toArray = function toArray() { + var array = []; + this.forEach(function (value, index) { + array[index] = value; + }); + return array; + }; + + /** + * Get the primitive value of the Range, a one dimensional array + * @returns {Array} array + */ + Range.prototype.valueOf = function valueOf() { + // TODO: implement a caching mechanism for range.valueOf() + return this.toArray(); + }; + + /** + * Get a string representation of the range, with optional formatting options. + * Output is formatted as 'start:step:end', for example '2:6' or '0:0.2:11' + * @param {Object | Number | Function} [options] Formatting options. See + * lib/util/number:format for a + * description of the available + * options. + * @returns {String} str + */ + Range.prototype.format = function format(options) { + var str = number.format(this.start, options); + + if (this.step != 1) { + str += ':' + number.format(this.step, options); + } + str += ':' + number.format(this.end, options); + return str; + }; + + /** + * Get a string representation of the range. + * @returns {String} + */ + Range.prototype.toString = function toString() { + return this.format(); + }; + + // exports + module.exports = Range; + + +/***/ }, +/* 7 */ +/***/ function(module, exports, __webpack_require__) { + + var util = __webpack_require__(117), + + Range = __webpack_require__(6), + + number = util.number, + + isNumber = number.isNumber, + isInteger = number.isInteger, + isArray = Array.isArray, + validateIndex = util.array.validateIndex; + + /** + * @Constructor Index + * Create an index. An Index can store ranges having start, step, and end + * for multiple dimensions. + * Matrix.get, Matrix.set, and math.subset accept an Index as input. + * + * Usage: + * var index = new Index(range1, range2, ...); + * + * Where each range can be any of: + * An array [start, end] + * An array [start, end, step] + * A number + * An instance of Range + * + * The parameters start, end, and step must be integer numbers. + * + * @param {...*} ranges + */ + function Index(ranges) { + if (!(this instanceof Index)) { + throw new SyntaxError('Constructor must be called with the new operator'); + } + + this._ranges = []; + + for (var i = 0, ii = arguments.length; i < ii; i++) { + var arg = arguments[i]; + + if (arg instanceof Range) { + this._ranges.push(arg); + } + else { + if (isArray(arg)) { + this._ranges.push(_createRange(arg)); + } + else if (isNumber(arg)) { + this._ranges.push(_createRange([arg, arg + 1])); + } + // TODO: implement support for wildcard '*' + else { + throw new TypeError('Ranges must be an Array, Number, or Range'); + } + } + } + } + + /** + * Parse an argument into a range and validate the range + * @param {Array} arg An array with [start: Number, end: Number] and + * optional a third element step:Number + * @return {Range} range + * @private + */ + function _createRange(arg) { + // TODO: make function _createRange simpler/faster + + // test whether all arguments are integers + var num = arg.length; + for (var i = 0; i < num; i++) { + if (!isNumber(arg[i]) || !isInteger(arg[i])) { + throw new TypeError('Index parameters must be integer numbers'); + } + } + + switch (arg.length) { + case 2: + return new Range(arg[0], arg[1]); // start, end + case 3: + return new Range(arg[0], arg[1], arg[2]); // start, end, step + default: + // TODO: improve error message + throw new SyntaxError('Wrong number of arguments in Index (2 or 3 expected)'); + } + } + + /** + * Create a clone of the index + * @return {Index} clone + */ + Index.prototype.clone = function clone () { + var index = new Index(); + index._ranges = util.object.clone(this._ranges); + return index; + }; + + /** + * Test whether an object is an Index + * @param {*} object + * @return {Boolean} isIndex + */ + Index.isIndex = function isIndex(object) { + return (object instanceof Index); + }; + + /** + * Create an index from an array with ranges/numbers + * @param {Array.} ranges + * @return {Index} index + * @private + */ + Index.create = function create(ranges) { + var index = new Index(); + Index.apply(index, ranges); + return index; + }; + + /** + * Retrieve the size of the index, the number of elements for each dimension. + * @returns {Number[]} size + */ + Index.prototype.size = function size () { + var size = []; + + for (var i = 0, ii = this._ranges.length; i < ii; i++) { + var range = this._ranges[i]; + + size[i] = range.size()[0]; + } + + return size; + }; + + /** + * Get the maximum value for each of the indexes ranges. + * @returns {Number[]} max + */ + Index.prototype.max = function max () { + var values = []; + + for (var i = 0, ii = this._ranges.length; i < ii; i++) { + var range = this._ranges[i]; + values[i] = range.max(); + } + + return values; + }; + + /** + * Get the minimum value for each of the indexes ranges. + * @returns {Number[]} min + */ + Index.prototype.min = function min () { + var values = []; + + for (var i = 0, ii = this._ranges.length; i < ii; i++) { + var range = this._ranges[i]; + + values[i] = range.min(); + } + + return values; + }; + + /** + * Loop over each of the ranges of the index + * @param {function} callback Called for each range with a Range as first + * argument, the dimension as second, and the + * index object as third. + */ + Index.prototype.forEach = function forEach(callback) { + for (var i = 0, ii = this._ranges.length; i < ii; i++) { + callback(this._ranges[i], i, this); + } + }; + + /** + * Retrieve the range for a given dimension number from the index + * @param {Number} dim Number of the dimension + * @returns {Range | null} range + */ + Index.prototype.range = function range (dim) { + return this._ranges[dim] || null; + }; + + /** + * Test whether this index contains only a single value + * @return {boolean} isScalar + */ + Index.prototype.isScalar = function isScalar () { + var size = this.size(); + + for (var i = 0, ii = size.length; i < ii; i++) { + if (size[i] !== 1) { + return false; + } + } + + return true; + }; + + /** + * Expand the Index into an array. + * For example new Index([0,3], [2,7]) returns [[0,1,2], [2,3,4,5,6]] + * @returns {Array} array + */ + Index.prototype.toArray = function toArray() { + var array = []; + for (var i = 0, ii = this._ranges.length; i < ii; i++) { + var range = this._ranges[i], + row = [], + x = range.start, + end = range.end, + step = range.step; + + if (step > 0) { + while (x < end) { + row.push(x); + x += step; + } + } + else if (step < 0) { + while (x > end) { + row.push(x); + x += step; + } + } + + array.push(row); + } + + return array; + }; + + /** + * Get the primitive value of the Index, a two dimensional array. + * Equivalent to Index.toArray(). + * @returns {Array} array + */ + Index.prototype.valueOf = Index.prototype.toArray; + + /** + * Get the string representation of the index, for example '[2:6]' or '[0:2:10, 4:7]' + * @returns {String} str + */ + Index.prototype.toString = function () { + var strings = []; + + for (var i = 0, ii = this._ranges.length; i < ii; i++) { + var range = this._ranges[i]; + var str = number.format(range.start); + if (range.step != 1) { + str += ':' + number.format(range.step); + } + str += ':' + number.format(range.end); + strings.push(str); + } + + return '[' + strings.join(', ') + ']'; + }; + + // exports + module.exports = Index; + + +/***/ }, +/* 8 */ +/***/ function(module, exports, __webpack_require__) { + + var util = __webpack_require__(117), + DimensionError = __webpack_require__(114), + + Index = __webpack_require__(7), + + number = util.number, + string = util.string, + array = util.array, + object = util.object, + + isArray = Array.isArray, + validateIndex = array.validateIndex; + + /** + * @constructor Matrix + * + * A Matrix is a wrapper around an Array. A matrix can hold a multi dimensional + * array. A matrix can be constructed as: + * var matrix = new Matrix(data) + * + * Matrix contains the functions to resize, get and set values, get the size, + * clone the matrix and to convert the matrix to a vector, array, or scalar. + * Furthermore, one can iterate over the matrix using map and forEach. + * The internal Array of the Matrix can be accessed using the function valueOf. + * + * Example usage: + * var matrix = new Matrix([[1, 2], [3, 4]); + * matix.size(); // [2, 2] + * matrix.resize([3, 2], 5); + * matrix.valueOf(); // [[1, 2], [3, 4], [5, 5]] + * matrix.subset([1,2]) // 3 (indexes are zero-based) + * + * @param {Array | Matrix} [data] A multi dimensional array + */ + function Matrix(data) { + if (!(this instanceof Matrix)) { + throw new SyntaxError('Constructor must be called with the new operator'); + } + + if (data instanceof Matrix) { + // clone data from a Matrix + this._data = data.clone()._data; + } + else if (isArray(data)) { + // use array + // replace nested Matrices with Arrays + this._data = preprocess(data); + } + else if (data != null) { + // unsupported type + throw new TypeError('Unsupported type of data (' + util.types.type(data) + ')'); + } + else { + // nothing provided + this._data = []; + } + + // verify the size of the array + this._size = array.size(this._data); + } + + /** + * Test whether an object is a Matrix + * @param {*} object + * @return {Boolean} isMatrix + */ + Matrix.isMatrix = function isMatrix(object) { + return (object instanceof Matrix); + }; + + /** + * Get a subset of the matrix, or replace a subset of the matrix. + * + * Usage: + * var subset = matrix.subset(index) // retrieve subset + * var value = matrix.subset(index, replacement) // replace subset + * + * @param {Index} index + * @param {Array | Matrix | *} [replacement] + * @param {*} [defaultValue] Default value, filled in on new entries when + * the matrix is resized. If not provided, + * new matrix elements will be left undefined. + */ + Matrix.prototype.subset = function subset(index, replacement, defaultValue) { + switch (arguments.length) { + case 1: + return _get(this, index); + + // intentional fall through + case 2: + case 3: + return _set(this, index, replacement, defaultValue); + + default: + throw new SyntaxError('Wrong number of arguments'); + } + }; + + /** + * Get a single element from the matrix. + * @param {Number[]} index Zero-based index + * @return {*} value + */ + Matrix.prototype.get = function get(index) { + if (!isArray(index)) { + throw new TypeError('Array expected'); + } + if (index.length != this._size.length) { + throw new DimensionError(index.length, this._size.length); + } + + var data = this._data; + for (var i = 0, ii = index.length; i < ii; i++) { + var index_i = index[i]; + validateIndex(index_i, data.length); + data = data[index_i]; + } + + return object.clone(data); + }; + + /** + * Replace a single element in the matrix. + * @param {Number[]} index Zero-based index + * @param {*} value + * @param {*} [defaultValue] Default value, filled in on new entries when + * the matrix is resized. If not provided, + * new matrix elements will be left undefined. + * @return {Matrix} self + */ + Matrix.prototype.set = function set (index, value, defaultValue) { + var i, ii; + + // validate input type and dimensions + if (!isArray(index)) { + throw new Error('Array expected'); + } + if (index.length < this._size.length) { + throw new DimensionError(index.length, this._size.length, '<'); + } + + // enlarge matrix when needed + var size = index.map(function (i) { + return i + 1; + }); + _fit(this, size, defaultValue); + + // traverse over the dimensions + var data = this._data; + for (i = 0, ii = index.length - 1; i < ii; i++) { + var index_i = index[i]; + validateIndex(index_i, data.length); + data = data[index_i]; + } + + // set new value + index_i = index[index.length - 1]; + validateIndex(index_i, data.length); + data[index_i] = value; + + return this; + }; + + /** + * Get a submatrix of this matrix + * @param {Matrix} matrix + * @param {Index} index Zero-based index + * @private + */ + function _get (matrix, index) { + if (!(index instanceof Index)) { + throw new TypeError('Invalid index'); + } + + var isScalar = index.isScalar(); + if (isScalar) { + // return a scalar + return matrix.get(index.min()); + } + else { + // validate dimensions + var size = index.size(); + if (size.length != matrix._size.length) { + throw new DimensionError(size.length, matrix._size.length); + } + + // retrieve submatrix + var submatrix = new Matrix(_getSubmatrix(matrix._data, index, size.length, 0)); + // TODO: more efficient when creating an empty matrix and setting _data and _size manually + + // squeeze matrix output + while (isArray(submatrix._data) && submatrix._data.length == 1) { + submatrix._data = submatrix._data[0]; + submatrix._size.shift(); + } + + return submatrix; + } + } + + /** + * Recursively get a submatrix of a multi dimensional matrix. + * Index is not checked for correct number of dimensions. + * @param {Array} data + * @param {Index} index + * @param {number} dims Total number of dimensions + * @param {number} dim Current dimension + * @return {Array} submatrix + * @private + */ + function _getSubmatrix (data, index, dims, dim) { + var last = (dim == dims - 1); + var range = index.range(dim); + + if (last) { + return range.map(function (i) { + validateIndex(i, data.length); + return data[i]; + }); + } + else { + return range.map(function (i) { + validateIndex(i, data.length); + var child = data[i]; + return _getSubmatrix(child, index, dims, dim + 1); + }); + } + } + + /** + * Replace a submatrix in this matrix + * Indexes are zero-based. + * @param {Matrix} matrix + * @param {Index} index + * @param {Matrix | Array | *} submatrix + * @param {*} [defaultValue] Default value, filled in on new entries when + * the matrix is resized. If not provided, + * new matrix elements will be left undefined. + * @return {Matrix} matrix + * @private + */ + function _set (matrix, index, submatrix, defaultValue) { + if (!(index instanceof Index)) { + throw new TypeError('Invalid index'); + } + + // get index size and check whether the index contains a single value + var iSize = index.size(), + isScalar = index.isScalar(); + + // calculate the size of the submatrix, and convert it into an Array if needed + var sSize; + if (submatrix instanceof Matrix) { + sSize = submatrix.size(); + submatrix = submatrix.valueOf(); + } + else { + sSize = array.size(submatrix); + } + + if (isScalar) { + // set a scalar + + // check whether submatrix is a scalar + if (sSize.length != 0) { + throw new TypeError('Scalar expected'); + } + + matrix.set(index.min(), submatrix, defaultValue); + } + else { + // set a submatrix + + // validate dimensions + if (iSize.length < matrix._size.length) { + throw new DimensionError(iSize.length, matrix._size.length, '<'); + } + + // unsqueeze the submatrix when needed + for (var i = 0, ii = iSize.length - sSize.length; i < ii; i++) { + submatrix = [submatrix]; + sSize.unshift(1); + } + + // check whether the size of the submatrix matches the index size + if (!object.deepEqual(iSize, sSize)) { + throw new DimensionError(iSize, sSize); + } + + // enlarge matrix when needed + var size = index.max().map(function (i) { + return i + 1; + }); + _fit(matrix, size, defaultValue); + + // insert the sub matrix + var dims = iSize.length, + dim = 0; + _setSubmatrix (matrix._data, index, submatrix, dims, dim); + } + + return matrix; + } + + /** + * Replace a submatrix of a multi dimensional matrix. + * @param {Array} data + * @param {Index} index + * @param {Array} submatrix + * @param {number} dims Total number of dimensions + * @param {number} dim + * @private + */ + function _setSubmatrix (data, index, submatrix, dims, dim) { + var last = (dim == dims - 1), + range = index.range(dim); + + if (last) { + range.forEach(function (dataIndex, subIndex) { + validateIndex(dataIndex); + data[dataIndex] = submatrix[subIndex]; + }); + } + else { + range.forEach(function (dataIndex, subIndex) { + validateIndex(dataIndex); + _setSubmatrix(data[dataIndex], index, submatrix[subIndex], dims, dim + 1); + }); + } + } + + /** + * Resize the matrix + * @param {Number[]} size + * @param {*} [defaultValue] Default value, filled in on new entries. + * If not provided, the matrix elements will + * be left undefined. + * @return {Matrix} self The matrix itself is returned + */ + Matrix.prototype.resize = function resize(size, defaultValue) { + this._size = object.clone(size); + this._data = array.resize(this._data, this._size, defaultValue); + + // return the matrix itself + return this; + }; + + /** + * Enlarge the matrix when it is smaller than given size. + * If the matrix is larger or equal sized, nothing is done. + * @param {Matrix} matrix The matrix to be resized + * @param {Number[]} size + * @param {*} [defaultValue] Default value, filled in on new entries. + * If not provided, the matrix elements will + * be left undefined. + * @private + */ + function _fit(matrix, size, defaultValue) { + var newSize = object.clone(matrix._size), + changed = false; + + // add dimensions when needed + while (newSize.length < size.length) { + newSize.unshift(0); + changed = true; + } + + // enlarge size when needed + for (var i = 0, ii = size.length; i < ii; i++) { + if (size[i] > newSize[i]) { + newSize[i] = size[i]; + changed = true; + } + } + + if (changed) { + // resize only when size is changed + matrix.resize(newSize, defaultValue); + } + } + + /** + * Create a clone of the matrix + * @return {Matrix} clone + */ + Matrix.prototype.clone = function clone() { + var matrix = new Matrix(); + matrix._data = object.clone(this._data); + matrix._size = object.clone(this._size); + return matrix; + }; + + /** + * Retrieve the size of the matrix. + * @returns {Number[]} size + */ + Matrix.prototype.size = function size() { + return this._size; + }; + + /** + * Create a new matrix with the results of the callback function executed on + * each entry of the matrix. + * @param {function} callback The callback function is invoked with three + * parameters: the value of the element, the index + * of the element, and the Matrix being traversed. + * @return {Matrix} matrix + */ + Matrix.prototype.map = function map(callback) { + var me = this; + var matrix = new Matrix(); + var index = []; + var recurse = function (value, dim) { + if (isArray(value)) { + return value.map(function (child, i) { + index[dim] = i; + return recurse(child, dim + 1); + }); + } + else { + return callback(value, index, me); + } + }; + matrix._data = recurse(this._data, 0); + matrix._size = object.clone(this._size); + + return matrix; + }; + + /** + * Execute a callback function on each entry of the matrix. + * @param {function} callback The callback function is invoked with three + * parameters: the value of the element, the index + * of the element, and the Matrix being traversed. + */ + Matrix.prototype.forEach = function forEach(callback) { + var me = this; + var index = []; + var recurse = function (value, dim) { + if (isArray(value)) { + value.forEach(function (child, i) { + index[dim] = i; + recurse(child, dim + 1); + }); + } + else { + callback(value, index, me); + } + }; + recurse(this._data, 0); + }; + + /** + * Create an Array with a copy of the data of the Matrix + * @returns {Array} array + */ + Matrix.prototype.toArray = function toArray() { + return object.clone(this._data); + }; + + /** + * Get the primitive value of the Matrix: a multidimensional array + * @returns {Array} array + */ + Matrix.prototype.valueOf = function valueOf() { + return this._data; + }; + + /** + * Get a string representation of the matrix, with optional formatting options. + * @param {Object | Number | Function} [options] Formatting options. See + * lib/util/number:format for a + * description of the available + * options. + * @returns {String} str + */ + Matrix.prototype.format = function format(options) { + return string.format(this._data, options); + }; + + /** + * Get a string representation of the matrix + * @returns {String} str + */ + Matrix.prototype.toString = function toString() { + return string.format(this._data); + }; + + /** + * Preprocess data, which can be an Array or Matrix with nested Arrays and + * Matrices. Replaces all nested Matrices with Arrays + * @param {Array} data + * @return {Array} data + */ + function preprocess(data) { + for (var i = 0, ii = data.length; i < ii; i++) { + var elem = data[i]; + if (isArray(elem)) { + data[i] = preprocess(elem); + } + else if (elem instanceof Matrix) { + data[i] = preprocess(elem._data); + } + } + + return data; + } + + // exports + module.exports = Matrix; + + +/***/ }, +/* 9 */ +/***/ function(module, exports, __webpack_require__) { + + var util = __webpack_require__(117), + + number = util.number, + string = util.string, + isNumber = util.number.isNumber, + isString = util.string.isString; + + /** + * @constructor Unit + * + * A unit can be constructed in the following ways: + * var a = new Unit(value, name); + * var b = new Unit(null, name); + * var c = Unit.parse(str); + * + * Example usage: + * var a = new Unit(5, 'cm'); // 50 mm + * var b = Unit.parse('23 kg'); // 23 kg + * var c = math.in(a, new Unit(null, 'm'); // 0.05 m + * + * @param {Number} [value] A value like 5.2 + * @param {String} [unit] A unit like "cm" or "inch" + */ + function Unit(value, name) { + if (!(this instanceof Unit)) { + throw new Error('Constructor must be called with the new operator'); + } + + if (value != null && !isNumber(value)) { + throw new TypeError('First parameter in Unit constructor must be a number'); + } + if (name != null && (!isString(name) || name == '')) { + throw new TypeError('Second parameter in Unit constructor must be a string'); + } + + if (name != null) { + // find the unit and prefix from the string + var res = _findUnit(name); + if (!res) { + throw new SyntaxError('Unknown unit "' + name + '"'); + } + this.unit = res.unit; + this.prefix = res.prefix; + } + else { + this.unit = UNIT_NONE; + this.prefix = PREFIX_NONE; // link to a list with supported prefixes + } + + if (value != null) { + this.value = this._normalize(value); + this.fixPrefix = false; // is set true by the methods Unit.in and math.in + } + else { + this.value = null; + this.fixPrefix = true; + } + } + + // private variables and functions for the Unit parser + var text, index, c; + + function skipWhitespace() { + while (c == ' ' || c == '\t') { + next(); + } + } + + function isDigitDot (c) { + return ((c >= '0' && c <= '9') || c == '.'); + } + + function isDigit (c) { + return ((c >= '0' && c <= '9')); + } + + function next() { + index++; + c = text.charAt(index); + } + + function revert(oldIndex) { + index = oldIndex; + c = text.charAt(index); + } + + function parseNumber () { + var number = ''; + var oldIndex; + oldIndex = index; + + if (c == '+') { + next(); + } + else if (c == '-') { + number += c; + next(); + } + + if (!isDigitDot(c)) { + // a + or - must be followed by a digit + revert(oldIndex); + return null; + } + + // get number, can have a single dot + if (c == '.') { + number += c; + next(); + if (!isDigit(c)) { + // this is no legal number, it is just a dot + revert(oldIndex); + return null; + } + } + else { + while (isDigit(c)) { + number += c; + next(); + } + if (c == '.') { + number += c; + next(); + } + } + while (isDigit(c)) { + number += c; + next(); + } + + // check for exponential notation like "2.3e-4" or "1.23e50" + if (c == 'E' || c == 'e') { + number += c; + next(); + + if (c == '+' || c == '-') { + number += c; + next(); + } + + // Scientific notation MUST be followed by an exponent + if (!isDigit(c)) { + // this is no legal number, exponent is missing. + revert(oldIndex); + return null; + } + + while (isDigit(c)) { + number += c; + next(); + } + } + + return number; + } + + function parseUnit() { + var unitName = ''; + + skipWhitespace(); + while (c && c != ' ' && c != '\t') { + unitName += c; + next(); + } + + return unitName || null; + } + + /** + * Parse a string into a unit. Returns null if the provided string does not + * contain a valid unit. + * @param {String} str A string like "5.2 inch", "4e2 kg" + * @return {Unit | null} unit + */ + Unit.parse = function parse(str) { + text = str; + index = -1; + c = ''; + + if (!isString(text)) { + return null; + } + + next(); + skipWhitespace(); + var value = parseNumber(); + var name; + if (value) { + name = parseUnit(); + + next(); + skipWhitespace(); + if (c) { + // garbage at the end. not good. + return null; + } + + if (value && name) { + try { + // constructor will throw an error when unit is not found + return new Unit(Number(value), name); + } + catch (err) {} + } + } + else { + name = parseUnit(); + + next(); + skipWhitespace(); + if (c) { + // garbage at the end. not good. + return null; + } + + if (name) { + try { + // constructor will throw an error when unit is not found + return new Unit(null, name); + } + catch (err) {} + } + } + + return null; + }; + + /** + * Test whether value is of type Unit + * @param {*} value + * @return {Boolean} isUnit + */ + Unit.isUnit = function isUnit(value) { + return (value instanceof Unit); + }; + + /** + * create a copy of this unit + * @return {Unit} clone + */ + Unit.prototype.clone = function () { + var clone = new Unit(); + + for (var p in this) { + if (this.hasOwnProperty(p)) { + clone[p] = this[p]; + } + } + + return clone; + }; + + /** + * Normalize a value, based on its currently set unit + * @param {Number} value + * @return {Number} normalized value + * @private + */ + Unit.prototype._normalize = function(value) { + return (value + this.unit.offset) * + this.unit.value * this.prefix.value; + }; + + /** + * Unnormalize a value, based on its currently set unit + * @param {Number} value + * @param {Number} [prefixValue] Optional prefix value to be used + * @return {Number} unnormalized value + * @private + */ + Unit.prototype._unnormalize = function (value, prefixValue) { + if (prefixValue == undefined) { + return value / this.unit.value / this.prefix.value - + this.unit.offset; + } + else { + return value / this.unit.value / prefixValue - + this.unit.offset; + } + }; + + /** + * Find a unit from a string + * @param {String} str A string like 'cm' or 'inch' + * @returns {Object | null} result When found, an object with fields unit and + * prefix is returned. Else, null is returned. + * @private + */ + function _findUnit(str) { + for (var name in UNITS) { + if (UNITS.hasOwnProperty(name)) { + if (string.endsWith(str, name) ) { + var unit = UNITS[name]; + var prefixLen = (str.length - name.length); + var prefixName = str.substring(0, prefixLen); + var prefix = unit.prefixes[prefixName]; + if (prefix !== undefined) { + // store unit, prefix, and value + return { + unit: unit, + prefix: prefix + }; + } + } + } + } + + return null; + } + + /** + * Test if the given expression is a unit. + * The unit can have a prefix but cannot have a value. + * @param {String} name A string to be tested whether it is a value less unit. + * The unit can have prefix, like "cm" + * @return {Boolean} true if the given string is a unit + */ + Unit.isValuelessUnit = function (name) { + return (_findUnit(name) != null); + }; + + /** + * check if this unit has given base unit + * @param {BASE_UNITS | undefined} base + */ + Unit.prototype.hasBase = function(base) { + return (this.unit.base === base); + }; + + /** + * Check if this unit has a base equal to another base + * @param {Unit} other + * @return {Boolean} true if equal base + */ + Unit.prototype.equalBase = function(other) { + return (this.unit.base === other.unit.base); + }; + + /** + * Check if this unit equals another unit + * @param {Unit} other + * @return {Boolean} true if both units are equal + */ + Unit.prototype.equals = function(other) { + return (this.equalBase(other) && this.value == other.value); + }; + + /** + * Create a clone of this unit with a representation + * @param {String | Unit} valuelessUnit A unit without value. Can have prefix, like "cm" + * @returns {Unit} unit having fixed, specified unit + */ + Unit.prototype.to = function (valuelessUnit) { + var other; + if (isString(valuelessUnit)) { + other = new Unit(null, valuelessUnit); + + if (!this.equalBase(other)) { + throw new Error('Units do not match'); + } + + other.value = this.value; + return other; + } + else if (valuelessUnit instanceof Unit) { + if (!this.equalBase(valuelessUnit)) { + throw new Error('Units do not match'); + } + if (valuelessUnit.value != null) { + throw new Error('Cannot convert to a unit with a value'); + } + + other = valuelessUnit.clone(); + other.value = this.value; + other.fixPrefix = true; + return other; + } + else { + throw new Error('String or Unit expected as parameter'); + } + }; + + /** + * Return the value of the unit when represented with given valueless unit + * @param {String | Unit} valuelessUnit For example 'cm' or 'inch' + * @return {Number} value + */ + Unit.prototype.toNumber = function (valuelessUnit) { + var other = this.to(valuelessUnit); + return other._unnormalize(other.value, other.prefix.value); + }; + + + /** + * Get a string representation of the unit. + * @return {String} + */ + Unit.prototype.toString = function toString() { + return this.format(); + }; + + /** + * Get a string representation of the Unit, with optional formatting options. + * @param {Object | Number | Function} [options] Formatting options. See + * lib/util/number:format for a + * description of the available + * options. + * @return {String} + */ + Unit.prototype.format = function format(options) { + var value, + str; + + if (!this.fixPrefix) { + var bestPrefix = this._bestPrefix(); + value = this._unnormalize(this.value, bestPrefix.value); + str = number.format(value, options) + ' '; + str += bestPrefix.name + this.unit.name; + } + else { + value = this._unnormalize(this.value); + str = (this.value != null) ? number.format(value, options) + ' ' : ''; + str += this.prefix.name + this.unit.name; + } + return str; + }; + + /** + * Calculate the best prefix using current value. + * @returns {Object} prefix + * @private + */ + Unit.prototype._bestPrefix = function () { + // find the best prefix value (resulting in the value of which + // the absolute value of the log10 is closest to zero, + // though with a little offset of 1.2 for nicer values: you get a + // sequence 1mm 100mm 500mm 0.6m 1m 10m 100m 500m 0.6km 1km ... + var absValue = Math.abs(this.value / this.unit.value); + var bestPrefix = PREFIX_NONE; + var bestDiff = Math.abs( + Math.log(absValue / bestPrefix.value) / Math.LN10 - 1.2); + + var prefixes = this.unit.prefixes; + for (var p in prefixes) { + if (prefixes.hasOwnProperty(p)) { + var prefix = prefixes[p]; + if (prefix.scientific) { + var diff = Math.abs( + Math.log(absValue / prefix.value) / Math.LN10 - 1.2); + + if (diff < bestDiff) { + bestPrefix = prefix; + bestDiff = diff; + } + } + } + } + + return bestPrefix; + }; + + var PREFIXES = { + NONE: { + '': {name: '', value: 1, scientific: true} + }, + SHORT: { + '': {name: '', value: 1, scientific: true}, + + 'da': {name: 'da', value: 1e1, scientific: false}, + 'h': {name: 'h', value: 1e2, scientific: false}, + 'k': {name: 'k', value: 1e3, scientific: true}, + 'M': {name: 'M', value: 1e6, scientific: true}, + 'G': {name: 'G', value: 1e9, scientific: true}, + 'T': {name: 'T', value: 1e12, scientific: true}, + 'P': {name: 'P', value: 1e15, scientific: true}, + 'E': {name: 'E', value: 1e18, scientific: true}, + 'Z': {name: 'Z', value: 1e21, scientific: true}, + 'Y': {name: 'Y', value: 1e24, scientific: true}, + + 'd': {name: 'd', value: 1e-1, scientific: false}, + 'c': {name: 'c', value: 1e-2, scientific: false}, + 'm': {name: 'm', value: 1e-3, scientific: true}, + 'u': {name: 'u', value: 1e-6, scientific: true}, + 'n': {name: 'n', value: 1e-9, scientific: true}, + 'p': {name: 'p', value: 1e-12, scientific: true}, + 'f': {name: 'f', value: 1e-15, scientific: true}, + 'a': {name: 'a', value: 1e-18, scientific: true}, + 'z': {name: 'z', value: 1e-21, scientific: true}, + 'y': {name: 'y', value: 1e-24, scientific: true} + }, + LONG: { + '': {name: '', value: 1, scientific: true}, + + 'deca': {name: 'deca', value: 1e1, scientific: false}, + 'hecto': {name: 'hecto', value: 1e2, scientific: false}, + 'kilo': {name: 'kilo', value: 1e3, scientific: true}, + 'mega': {name: 'mega', value: 1e6, scientific: true}, + 'giga': {name: 'giga', value: 1e9, scientific: true}, + 'tera': {name: 'tera', value: 1e12, scientific: true}, + 'peta': {name: 'peta', value: 1e15, scientific: true}, + 'exa': {name: 'exa', value: 1e18, scientific: true}, + 'zetta': {name: 'zetta', value: 1e21, scientific: true}, + 'yotta': {name: 'yotta', value: 1e24, scientific: true}, + + 'deci': {name: 'deci', value: 1e-1, scientific: false}, + 'centi': {name: 'centi', value: 1e-2, scientific: false}, + 'milli': {name: 'milli', value: 1e-3, scientific: true}, + 'micro': {name: 'micro', value: 1e-6, scientific: true}, + 'nano': {name: 'nano', value: 1e-9, scientific: true}, + 'pico': {name: 'pico', value: 1e-12, scientific: true}, + 'femto': {name: 'femto', value: 1e-15, scientific: true}, + 'atto': {name: 'atto', value: 1e-18, scientific: true}, + 'zepto': {name: 'zepto', value: 1e-21, scientific: true}, + 'yocto': {name: 'yocto', value: 1e-24, scientific: true} + }, + SQUARED: { + '': {name: '', value: 1, scientific: true}, + + 'da': {name: 'da', value: 1e2, scientific: false}, + 'h': {name: 'h', value: 1e4, scientific: false}, + 'k': {name: 'k', value: 1e6, scientific: true}, + 'M': {name: 'M', value: 1e12, scientific: true}, + 'G': {name: 'G', value: 1e18, scientific: true}, + 'T': {name: 'T', value: 1e24, scientific: true}, + 'P': {name: 'P', value: 1e30, scientific: true}, + 'E': {name: 'E', value: 1e36, scientific: true}, + 'Z': {name: 'Z', value: 1e42, scientific: true}, + 'Y': {name: 'Y', value: 1e48, scientific: true}, + + 'd': {name: 'd', value: 1e-2, scientific: false}, + 'c': {name: 'c', value: 1e-4, scientific: false}, + 'm': {name: 'm', value: 1e-6, scientific: true}, + 'u': {name: 'u', value: 1e-12, scientific: true}, + 'n': {name: 'n', value: 1e-18, scientific: true}, + 'p': {name: 'p', value: 1e-24, scientific: true}, + 'f': {name: 'f', value: 1e-30, scientific: true}, + 'a': {name: 'a', value: 1e-36, scientific: true}, + 'z': {name: 'z', value: 1e-42, scientific: true}, + 'y': {name: 'y', value: 1e-42, scientific: true} + }, + CUBIC: { + '': {name: '', value: 1, scientific: true}, + + 'da': {name: 'da', value: 1e3, scientific: false}, + 'h': {name: 'h', value: 1e6, scientific: false}, + 'k': {name: 'k', value: 1e9, scientific: true}, + 'M': {name: 'M', value: 1e18, scientific: true}, + 'G': {name: 'G', value: 1e27, scientific: true}, + 'T': {name: 'T', value: 1e36, scientific: true}, + 'P': {name: 'P', value: 1e45, scientific: true}, + 'E': {name: 'E', value: 1e54, scientific: true}, + 'Z': {name: 'Z', value: 1e63, scientific: true}, + 'Y': {name: 'Y', value: 1e72, scientific: true}, + + 'd': {name: 'd', value: 1e-3, scientific: false}, + 'c': {name: 'c', value: 1e-6, scientific: false}, + 'm': {name: 'm', value: 1e-9, scientific: true}, + 'u': {name: 'u', value: 1e-18, scientific: true}, + 'n': {name: 'n', value: 1e-27, scientific: true}, + 'p': {name: 'p', value: 1e-36, scientific: true}, + 'f': {name: 'f', value: 1e-45, scientific: true}, + 'a': {name: 'a', value: 1e-54, scientific: true}, + 'z': {name: 'z', value: 1e-63, scientific: true}, + 'y': {name: 'y', value: 1e-72, scientific: true} + }, + BINARY_SHORT: { + '': {name: '', value: 1, scientific: true}, + 'k': {name: 'k', value: 1024, scientific: true}, + 'M': {name: 'M', value: Math.pow(1024, 2), scientific: true}, + 'G': {name: 'G', value: Math.pow(1024, 3), scientific: true}, + 'T': {name: 'T', value: Math.pow(1024, 4), scientific: true}, + 'P': {name: 'P', value: Math.pow(1024, 5), scientific: true}, + 'E': {name: 'E', value: Math.pow(1024, 6), scientific: true}, + 'Z': {name: 'Z', value: Math.pow(1024, 7), scientific: true}, + 'Y': {name: 'Y', value: Math.pow(1024, 8), scientific: true}, + + 'Ki': {name: 'Ki', value: 1024, scientific: true}, + 'Mi': {name: 'Mi', value: Math.pow(1024, 2), scientific: true}, + 'Gi': {name: 'Gi', value: Math.pow(1024, 3), scientific: true}, + 'Ti': {name: 'Ti', value: Math.pow(1024, 4), scientific: true}, + 'Pi': {name: 'Pi', value: Math.pow(1024, 5), scientific: true}, + 'Ei': {name: 'Ei', value: Math.pow(1024, 6), scientific: true}, + 'Zi': {name: 'Zi', value: Math.pow(1024, 7), scientific: true}, + 'Yi': {name: 'Yi', value: Math.pow(1024, 8), scientific: true} + }, + BINARY_LONG: { + '': {name: '', value: 1, scientific: true}, + 'kilo': {name: 'kilo', value: 1024, scientific: true}, + 'mega': {name: 'mega', value: Math.pow(1024, 2), scientific: true}, + 'giga': {name: 'giga', value: Math.pow(1024, 3), scientific: true}, + 'tera': {name: 'tera', value: Math.pow(1024, 4), scientific: true}, + 'peta': {name: 'peta', value: Math.pow(1024, 5), scientific: true}, + 'exa': {name: 'exa', value: Math.pow(1024, 6), scientific: true}, + 'zetta': {name: 'zetta', value: Math.pow(1024, 7), scientific: true}, + 'yotta': {name: 'yotta', value: Math.pow(1024, 8), scientific: true}, + + 'kibi': {name: 'kibi', value: 1024, scientific: true}, + 'mebi': {name: 'mebi', value: Math.pow(1024, 2), scientific: true}, + 'gibi': {name: 'gibi', value: Math.pow(1024, 3), scientific: true}, + 'tebi': {name: 'tebi', value: Math.pow(1024, 4), scientific: true}, + 'pebi': {name: 'pebi', value: Math.pow(1024, 5), scientific: true}, + 'exi': {name: 'exi', value: Math.pow(1024, 6), scientific: true}, + 'zebi': {name: 'zebi', value: Math.pow(1024, 7), scientific: true}, + 'yobi': {name: 'yobi', value: Math.pow(1024, 8), scientific: true} + } + }; + + var PREFIX_NONE = {name: '', value: 1, scientific: true}; + + var BASE_UNITS = { + NONE: {}, + + LENGTH: {}, // meter + MASS: {}, // kilogram + TIME: {}, // second + CURRENT: {}, // ampere + TEMPERATURE: {}, // kelvin + LUMINOUS_INTENSITY: {}, // candela + AMOUNT_OF_SUBSTANCE: {}, // mole + + FORCE: {}, // Newton + SURFACE: {}, // m2 + VOLUME: {}, // m3 + ANGLE: {}, // rad + BIT: {} // bit (digital) + }; + + BASE_UNIT_NONE = {}; + + UNIT_NONE = {name: '', base: BASE_UNIT_NONE, value: 1, offset: 0}; + + var UNITS = { + // length + meter: {name: 'meter', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.LONG, value: 1, offset: 0}, + inch: {name: 'inch', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.NONE, value: 0.0254, offset: 0}, + foot: {name: 'foot', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.NONE, value: 0.3048, offset: 0}, + yard: {name: 'yard', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.NONE, value: 0.9144, offset: 0}, + mile: {name: 'mile', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.NONE, value: 1609.344, offset: 0}, + link: {name: 'link', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.NONE, value: 0.201168, offset: 0}, + rod: {name: 'rod', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.NONE, value: 5.029210, offset: 0}, + chain: {name: 'chain', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.NONE, value: 20.1168, offset: 0}, + angstrom: {name: 'angstrom', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.NONE, value: 1e-10, offset: 0}, + + m: {name: 'm', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.SHORT, value: 1, offset: 0}, + 'in': {name: 'in', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.NONE, value: 0.0254, offset: 0}, + ft: {name: 'ft', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.NONE, value: 0.3048, offset: 0}, + yd: {name: 'yd', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.NONE, value: 0.9144, offset: 0}, + mi: {name: 'mi', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.NONE, value: 1609.344, offset: 0}, + li: {name: 'li', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.NONE, value: 0.201168, offset: 0}, + rd: {name: 'rd', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.NONE, value: 5.029210, offset: 0}, + ch: {name: 'ch', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.NONE, value: 20.1168, offset: 0}, + mil: {name: 'mil', base: BASE_UNITS.LENGTH, prefixes: PREFIXES.NONE, value: 0.0000254, offset: 0}, // 1/1000 inch + + // Surface + m2: {name: 'm2', base: BASE_UNITS.SURFACE, prefixes: PREFIXES.SQUARED, value: 1, offset: 0}, + sqin: {name: 'sqin', base: BASE_UNITS.SURFACE, prefixes: PREFIXES.NONE, value: 0.00064516, offset: 0}, // 645.16 mm2 + sqft: {name: 'sqft', base: BASE_UNITS.SURFACE, prefixes: PREFIXES.NONE, value: 0.09290304, offset: 0}, // 0.09290304 m2 + sqyd: {name: 'sqyd', base: BASE_UNITS.SURFACE, prefixes: PREFIXES.NONE, value: 0.83612736, offset: 0}, // 0.83612736 m2 + sqmi: {name: 'sqmi', base: BASE_UNITS.SURFACE, prefixes: PREFIXES.NONE, value: 2589988.110336, offset: 0}, // 2.589988110336 km2 + sqrd: {name: 'sqrd', base: BASE_UNITS.SURFACE, prefixes: PREFIXES.NONE, value: 25.29295, offset: 0}, // 25.29295 m2 + sqch: {name: 'sqch', base: BASE_UNITS.SURFACE, prefixes: PREFIXES.NONE, value: 404.6873, offset: 0}, // 404.6873 m2 + sqmil: {name: 'sqmil', base: BASE_UNITS.SURFACE, prefixes: PREFIXES.NONE, value: 6.4516e-10, offset: 0}, // 6.4516 * 10^-10 m2 + + // Volume + m3: {name: 'm3', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.CUBIC, value: 1, offset: 0}, + L: {name: 'L', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.SHORT, value: 0.001, offset: 0}, // litre + l: {name: 'l', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.SHORT, value: 0.001, offset: 0}, // litre + litre: {name: 'litre', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.LONG, value: 0.001, offset: 0}, + cuin: {name: 'cuin', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 1.6387064e-5, offset: 0}, // 1.6387064e-5 m3 + cuft: {name: 'cuft', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.028316846592, offset: 0}, // 28.316 846 592 L + cuyd: {name: 'cuyd', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.764554857984, offset: 0}, // 764.554 857 984 L + teaspoon: {name: 'teaspoon', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.000005, offset: 0}, // 5 mL + tablespoon: {name: 'tablespoon', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.000015, offset: 0}, // 15 mL + //{name: 'cup', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.000240, offset: 0}, // 240 mL // not possible, we have already another cup + + // Liquid volume + minim: {name: 'minim', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.00000006161152, offset: 0}, // 0.06161152 mL + fluiddram: {name: 'fluiddram', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.0000036966911, offset: 0}, // 3.696691 mL + fluidounce: {name: 'fluidounce', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.00002957353, offset: 0}, // 29.57353 mL + gill: {name: 'gill', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.0001182941, offset: 0}, // 118.2941 mL + cc: {name: 'cc', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 1e-6, offset: 0}, // 1e-6 L + cup: {name: 'cup', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.0002365882, offset: 0}, // 236.5882 mL + pint: {name: 'pint', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.0004731765, offset: 0}, // 473.1765 mL + quart: {name: 'quart', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.0009463529, offset: 0}, // 946.3529 mL + gallon: {name: 'gallon', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.003785412, offset: 0}, // 3.785412 L + beerbarrel: {name: 'beerbarrel', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.1173478, offset: 0}, // 117.3478 L + oilbarrel: {name: 'oilbarrel', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.1589873, offset: 0}, // 158.9873 L + hogshead: {name: 'hogshead', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.2384810, offset: 0}, // 238.4810 L + + //{name: 'min', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.00000006161152, offset: 0}, // 0.06161152 mL // min is already in use as minute + fldr: {name: 'fldr', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.0000036966911, offset: 0}, // 3.696691 mL + floz: {name: 'floz', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.00002957353, offset: 0}, // 29.57353 mL + gi: {name: 'gi', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.0001182941, offset: 0}, // 118.2941 mL + cp: {name: 'cp', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.0002365882, offset: 0}, // 236.5882 mL + pt: {name: 'pt', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.0004731765, offset: 0}, // 473.1765 mL + qt: {name: 'qt', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.0009463529, offset: 0}, // 946.3529 mL + gal: {name: 'gal', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.003785412, offset: 0}, // 3.785412 L + bbl: {name: 'bbl', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.1173478, offset: 0}, // 117.3478 L + obl: {name: 'obl', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.1589873, offset: 0}, // 158.9873 L + //{name: 'hogshead', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.2384810, offset: 0}, // 238.4810 L // TODO: hh? + + // Mass + g: {name: 'g', base: BASE_UNITS.MASS, prefixes: PREFIXES.SHORT, value: 0.001, offset: 0}, + gram: {name: 'gram', base: BASE_UNITS.MASS, prefixes: PREFIXES.LONG, value: 0.001, offset: 0}, + + ton: {name: 'ton', base: BASE_UNITS.MASS, prefixes: PREFIXES.SHORT, value: 907.18474, offset: 0}, + tonne: {name: 'tonne', base: BASE_UNITS.MASS, prefixes: PREFIXES.SHORT, value: 1000, offset: 0}, + + grain: {name: 'grain', base: BASE_UNITS.MASS, prefixes: PREFIXES.NONE, value: 64.79891e-6, offset: 0}, + dram: {name: 'dram', base: BASE_UNITS.MASS, prefixes: PREFIXES.NONE, value: 1.7718451953125e-3, offset: 0}, + ounce: {name: 'ounce', base: BASE_UNITS.MASS, prefixes: PREFIXES.NONE, value: 28.349523125e-3, offset: 0}, + poundmass: {name: 'poundmass', base: BASE_UNITS.MASS, prefixes: PREFIXES.NONE, value: 453.59237e-3, offset: 0}, + hundredweight: {name: 'hundredweight', base: BASE_UNITS.MASS, prefixes: PREFIXES.NONE, value: 45.359237, offset: 0}, + stick: {name: 'stick', base: BASE_UNITS.MASS, prefixes: PREFIXES.NONE, value: 115e-3, offset: 0}, + + gr: {name: 'gr', base: BASE_UNITS.MASS, prefixes: PREFIXES.NONE, value: 64.79891e-6, offset: 0}, + dr: {name: 'dr', base: BASE_UNITS.MASS, prefixes: PREFIXES.NONE, value: 1.7718451953125e-3, offset: 0}, + oz: {name: 'oz', base: BASE_UNITS.MASS, prefixes: PREFIXES.NONE, value: 28.349523125e-3, offset: 0}, + lbm: {name: 'lbm', base: BASE_UNITS.MASS, prefixes: PREFIXES.NONE, value: 453.59237e-3, offset: 0}, + cwt: {name: 'cwt', base: BASE_UNITS.MASS, prefixes: PREFIXES.NONE, value: 45.359237, offset: 0}, + + // Time + s: {name: 's', base: BASE_UNITS.TIME, prefixes: PREFIXES.SHORT, value: 1, offset: 0}, + min: {name: 'min', base: BASE_UNITS.TIME, prefixes: PREFIXES.NONE, value: 60, offset: 0}, + h: {name: 'h', base: BASE_UNITS.TIME, prefixes: PREFIXES.NONE, value: 3600, offset: 0}, + second: {name: 'second', base: BASE_UNITS.TIME, prefixes: PREFIXES.LONG, value: 1, offset: 0}, + sec: {name: 'sec', base: BASE_UNITS.TIME, prefixes: PREFIXES.LONG, value: 1, offset: 0}, + minute: {name: 'minute', base: BASE_UNITS.TIME, prefixes: PREFIXES.NONE, value: 60, offset: 0}, + hour: {name: 'hour', base: BASE_UNITS.TIME, prefixes: PREFIXES.NONE, value: 3600, offset: 0}, + day: {name: 'day', base: BASE_UNITS.TIME, prefixes: PREFIXES.NONE, value: 86400, offset: 0}, + + // Angle + rad: {name: 'rad', base: BASE_UNITS.ANGLE, prefixes: PREFIXES.NONE, value: 1, offset: 0}, + // deg = rad / (2*pi) * 360 = rad / 0.017453292519943295769236907684888 + deg: {name: 'deg', base: BASE_UNITS.ANGLE, prefixes: PREFIXES.NONE, value: 0.017453292519943295769236907684888, offset: 0}, + // grad = rad / (2*pi) * 400 = rad / 0.015707963267948966192313216916399 + grad: {name: 'grad', base: BASE_UNITS.ANGLE, prefixes: PREFIXES.NONE, value: 0.015707963267948966192313216916399, offset: 0}, + // cycle = rad / (2*pi) = rad / 6.2831853071795864769252867665793 + cycle: {name: 'cycle', base: BASE_UNITS.ANGLE, prefixes: PREFIXES.NONE, value: 6.2831853071795864769252867665793, offset: 0}, + + // Electric current + A: {name: 'A', base: BASE_UNITS.CURRENT, prefixes: PREFIXES.SHORT, value: 1, offset: 0}, + ampere: {name: 'ampere', base: BASE_UNITS.CURRENT, prefixes: PREFIXES.LONG, value: 1, offset: 0}, + + // Temperature + // K(C) = °C + 273.15 + // K(F) = (°F + 459.67) / 1.8 + // K(R) = °R / 1.8 + K: {name: 'K', base: BASE_UNITS.TEMPERATURE, prefixes: PREFIXES.NONE, value: 1, offset: 0}, + degC: {name: 'degC', base: BASE_UNITS.TEMPERATURE, prefixes: PREFIXES.NONE, value: 1, offset: 273.15}, + degF: {name: 'degF', base: BASE_UNITS.TEMPERATURE, prefixes: PREFIXES.NONE, value: 1/1.8, offset: 459.67}, + degR: {name: 'degR', base: BASE_UNITS.TEMPERATURE, prefixes: PREFIXES.NONE, value: 1/1.8, offset: 0}, + kelvin: {name: 'kelvin', base: BASE_UNITS.TEMPERATURE, prefixes: PREFIXES.NONE, value: 1, offset: 0}, + celsius: {name: 'celsius', base: BASE_UNITS.TEMPERATURE, prefixes: PREFIXES.NONE, value: 1, offset: 273.15}, + fahrenheit: {name: 'fahrenheit', base: BASE_UNITS.TEMPERATURE, prefixes: PREFIXES.NONE, value: 1/1.8, offset: 459.67}, + rankine: {name: 'rankine', base: BASE_UNITS.TEMPERATURE, prefixes: PREFIXES.NONE, value: 1/1.8, offset: 0}, + + // amount of substance + mol: {name: 'mol', base: BASE_UNITS.AMOUNT_OF_SUBSTANCE, prefixes: PREFIXES.NONE, value: 1, offset: 0}, + mole: {name: 'mole', base: BASE_UNITS.AMOUNT_OF_SUBSTANCE, prefixes: PREFIXES.NONE, value: 1, offset: 0}, + + // luminous intensity + cd: {name: 'cd', base: BASE_UNITS.LUMINOUS_INTENSITY, prefixes: PREFIXES.NONE, value: 1, offset: 0}, + candela: {name: 'candela', base: BASE_UNITS.LUMINOUS_INTENSITY, prefixes: PREFIXES.NONE, value: 1, offset: 0}, + // TODO: units STERADIAN + //{name: 'sr', base: BASE_UNITS.STERADIAN, prefixes: PREFIXES.NONE, value: 1, offset: 0}, + //{name: 'steradian', base: BASE_UNITS.STERADIAN, prefixes: PREFIXES.NONE, value: 1, offset: 0}, + + // Force + N: {name: 'N', base: BASE_UNITS.FORCE, prefixes: PREFIXES.SHORT, value: 1, offset: 0}, + newton: {name: 'newton', base: BASE_UNITS.FORCE, prefixes: PREFIXES.LONG, value: 1, offset: 0}, + lbf: {name: 'lbf', base: BASE_UNITS.FORCE, prefixes: PREFIXES.NONE, value: 4.4482216152605, offset: 0}, + poundforce: {name: 'poundforce', base: BASE_UNITS.FORCE, prefixes: PREFIXES.NONE, value: 4.4482216152605, offset: 0}, + + // Binary + b: {name: 'b', base: BASE_UNITS.BIT, prefixes: PREFIXES.BINARY_SHORT, value: 1, offset: 0}, + bits: {name: 'bits', base: BASE_UNITS.BIT, prefixes: PREFIXES.BINARY_LONG, value: 1, offset: 0}, + B: {name: 'B', base: BASE_UNITS.BIT, prefixes: PREFIXES.BINARY_SHORT, value: 8, offset: 0}, + bytes: {name: 'bytes', base: BASE_UNITS.BIT, prefixes: PREFIXES.BINARY_LONG, value: 8, offset: 0} + }; + + // plurals + var PLURALS = { + meters: 'meter', + inches: 'inch', + feet: 'foot', + yards: 'yard', + miles: 'mile', + links: 'link', + rods: 'rod', + chains: 'chain', + angstroms: 'angstrom', + + litres: 'litre', + teaspoons: 'teaspoon', + tablespoons: 'tablespoon', + minims: 'minim', + fluiddrams: 'fluiddram', + fluidounces: 'fluidounce', + gills: 'gill', + cups: 'cup', + pints: 'pint', + quarts: 'quart', + gallons: 'gallon', + beerbarrels: 'beerbarrel', + oilbarrels: 'oilbarrel', + hogsheads: 'hogshead', + + grams: 'gram', + tons: 'ton', + tonnes: 'tonne', + grains: 'grain', + drams: 'dram', + ounces: 'ounce', + poundmasses: 'poundmass', + hundredweights: 'hundredweight', + sticks: 'stick', + + seconds: 'second', + minutes: 'minute', + hours: 'hour', + days: 'day', + + radians: 'rad', + degrees: 'deg', + gradients: 'grad', + cycles: 'cycle', + + amperes: 'ampere', + moles: 'mole' + }; + + for (var name in PLURALS) { + /* istanbul ignore next (we cannot really test next statement) */ + if (PLURALS.hasOwnProperty(name)) { + var unit = UNITS[PLURALS[name]]; + var plural = Object.create(unit); + plural.name = name; + UNITS[name] = plural; + } + } + + // aliases + UNITS.lt = UNITS.l; + UNITS.liter = UNITS.litre; + UNITS.liters = UNITS.litres; + UNITS.lb = UNITS.lbm; + UNITS.lbs = UNITS.lbm; + + + Unit.PREFIXES = PREFIXES; + Unit.BASE_UNITS = BASE_UNITS; + Unit.UNITS = UNITS; + + // end of unit aliases + + + // exports + module.exports = Unit; + + +/***/ }, +/* 10 */ +/***/ function(module, exports, __webpack_require__) { + + var util = __webpack_require__(117), + object = util.object, + string = util.string; + + /** + * Documentation object + * @param {Object} math The math.js namespace + * @param {Object} doc Object containing properties: + * {String} name + * {String} category + * {String[]} syntax + * {String[]} examples + * {String[]} seealso + * @constructor + */ + function Help (math, doc) { + if (!(this instanceof Help)) { + throw new SyntaxError('Constructor must be called with the new operator'); + } + + // TODO: throw an error when math or doc is not provided + + this.math = math; + this.doc = doc; + } + + /** + * Test whether a value is an instance of Help + * @param {*} value + * @return {Boolean} isHelp + */ + Help.isHelp = function isHelp (value) { + return (value instanceof Help); + }; + + /** + * Generate readable description from a Help object + * @return {String} readableDoc + * @private + */ + Help.prototype.toString = function () { + var doc = this.doc || {}; + var desc = '\n'; + + if (doc.name) { + desc += 'Name: ' + doc.name + '\n\n'; + } + if (doc.category) { + desc += 'Category: ' + doc.category + '\n\n'; + } + if (doc.description) { + desc += 'Description:\n ' + doc.description + '\n\n'; + } + if (doc.syntax) { + desc += 'Syntax:\n ' + doc.syntax.join('\n ') + '\n\n'; + } + if (doc.examples) { + var parser = this.math.parser(); + desc += 'Examples:\n'; + for (var i = 0; i < doc.examples.length; i++) { + var expr = doc.examples[i]; + var res; + try { + res = parser.eval(expr); + } + catch (e) { + res = e; + } + desc += ' ' + expr + '\n'; + if (res && !(res instanceof Help)) { + desc += ' ' + string.format(res) + '\n'; + } + } + desc += '\n'; + } + if (doc.seealso) { + desc += 'See also: ' + doc.seealso.join(', ') + '\n'; + } + + return desc; + }; + + // TODO: implement a toHTML function in Help + + /** + * Export the help object to JSON + */ + Help.prototype.toJSON = function () { + return object.clone(this.doc); + }; + + // exports + module.exports = Help; + + +/***/ }, +/* 11 */ +/***/ function(module, exports, __webpack_require__) { + + // utility methods for arrays and matrices + + var util = __webpack_require__(117), + + DimensionError = __webpack_require__(114), + + Matrix = __webpack_require__(8), + + isArray = util.array.isArray, + isString = util.string.isString; + + /** + * Convert function arguments to an array. Arguments can have the following + * signature: + * fn() + * fn(n) + * fn(m, n, p, ...) + * fn([m, n, p, ...]) + * @param {...Number | Array | Matrix} args + * @returns {Array} array + */ + exports.argsToArray = function argsToArray(args) { + var array; + if (args.length == 0) { + // fn() + array = []; + } + else if (args.length == 1) { + // fn(n) + // fn([m, n, p, ...]) + array = args[0]; + if (array instanceof Matrix) { + array = array.valueOf(); + } + if (!isArray(array)) { + array = [array]; + } + } + else { + // fn(m, n, p, ...) + array = Array.prototype.slice.apply(args); + } + return array; + }; + + + /** + * Test whether a value is a collection: an Array or Matrix + * @param {*} x + * @returns {boolean} isCollection + */ + exports.isCollection = function isCollection (x) { + return (isArray(x) || (x instanceof Matrix)); + }; + + /** + * Execute the callback function element wise for each element in array and any + * nested array + * Returns an array with the results + * @param {Array | Matrix} array + * @param {function} callback The callback is called with two parameters: + * value1 and value2, which contain the current + * element of both arrays. + * @return {Array | Matrix} res + */ + exports.deepMap = function deepMap(array, callback) { + if (array && (typeof array.map === 'function')) { + return array.map(function (x) { + return deepMap(x, callback); + }); + } + else { + return callback(array); + } + }; + + /** + * Execute the callback function element wise for each entry in two given arrays, + * and for any nested array. Objects can also be scalar objects. + * Returns an array with the results. + * @param {Array | Matrix | Object} array1 + * @param {Array | Matrix | Object} array2 + * @param {function} callback The callback is called with two parameters: + * value1 and value2, which contain the current + * element of both arrays. + * @return {Array | Matrix} res + */ + exports.deepMap2 = function deepMap2(array1, array2, callback) { + var res, len, i; + + if (isArray(array1)) { + if (isArray(array2)) { + // callback(array, array) + if (array1.length != array2.length) { + throw new DimensionError(array1.length, array2.length); + } + + res = []; + len = array1.length; + for (i = 0; i < len; i++) { + res[i] = deepMap2(array1[i], array2[i], callback); + } + } + else if (array2 instanceof Matrix) { + // callback(array, matrix) + res = deepMap2(array1, array2.valueOf(), callback); + return new Matrix(res); + } + else { + // callback(array, object) + res = []; + len = array1.length; + for (i = 0; i < len; i++) { + res[i] = deepMap2(array1[i], array2, callback); + } + } + } + else if (array1 instanceof Matrix) { + if (array2 instanceof Matrix) { + // callback(matrix, matrix) + res = deepMap2(array1.valueOf(), array2.valueOf(), callback); + return new Matrix(res); + } + else { + // callback(matrix, array) + // callback(matrix, object) + res = deepMap2(array1.valueOf(), array2, callback); + return new Matrix(res); + } + } + else { + if (isArray(array2)) { + // callback(object, array) + res = []; + len = array2.length; + for (i = 0; i < len; i++) { + res[i] = deepMap2(array1, array2[i], callback); + } + } + else if (array2 instanceof Matrix) { + // callback(object, matrix) + res = deepMap2(array1, array2.valueOf(), callback); + return new Matrix(res); + } + else { + // callback(object, object) + res = callback(array1, array2); + } + } + + return res; + }; + + /** + * Reduce a given matrix or array to a new matrix or + * array with one less dimension, applying the given + * callback in the selected dimension. + * @param {Array | Matrix} mat + * @param {Number} dim + * @param {function} callback + * @return {Array | Matrix} res + */ + exports.reduce = function reduce (mat, dim, callback) { + if (mat instanceof Matrix) { + return new Matrix(_reduce(mat.valueOf(), dim, callback)); + }else { + return _reduce(mat, dim, callback); + } + }; + + /** + * Recursively reduce a matrix + * @param {Array} mat + * @param {Number} dim + * @param {Function} callback + * @returns {Array} ret + * @private + */ + function _reduce(mat, dim, callback){ + var i, ret, val, tran; + + if(dim<=0){ + if( !isArray(mat[0]) ){ + val = mat[0]; + for(i=1; i= '0' && c <= '9') || c == '.'); - } - - function isDigit (c) { - return ((c >= '0' && c <= '9')); - } - - function next() { - index++; - c = text.charAt(index); - } - - function revert(oldIndex) { - index = oldIndex; - c = text.charAt(index); - } - - function parseNumber () { - var number = ''; - var oldIndex; - oldIndex = index; - - if (c == '+') { - next(); - } - else if (c == '-') { - number += c; - next(); - } - - if (!isDigitDot(c)) { - // a + or - must be followed by a digit - revert(oldIndex); - return null; - } - - // get number, can have a single dot - if (c == '.') { - number += c; - next(); - if (!isDigit(c)) { - // this is no legal number, it is just a dot - revert(oldIndex); - return null; - } - } - else { - while (isDigit(c)) { - number += c; - next(); - } - if (c == '.') { - number += c; - next(); - } - } - while (isDigit(c)) { - number += c; - next(); - } - - // check for exponential notation like "2.3e-4" or "1.23e50" - if (c == 'E' || c == 'e') { - number += c; - next(); - - if (c == '+' || c == '-') { - number += c; - next(); - } - - // Scientific notation MUST be followed by an exponent - if (!isDigit(c)) { - // this is no legal number, exponent is missing. - revert(oldIndex); - return null; - } - - while (isDigit(c)) { - number += c; - next(); - } - } - - return number; - } - - function parseComplex () { - // check for 'i', '-i', '+i' - var cnext = text.charAt(index + 1); - if (c == 'I' || c == 'i') { - next(); - return '1'; - } - else if ((c == '+' || c == '-') && (cnext == 'I' || cnext == 'i')) { - var number = (c == '+') ? '1' : '-1'; - next(); - next(); - return number; - } - - return null; - } - - /** - * Parse a complex number from a string. For example Complex.parse("2 + 3i") - * will return a Complex value where re = 2, im = 3. - * Returns null if provided string does not contain a valid complex number. - * @param {String} str - * @returns {Complex | null} complex - */ - Complex.parse = function parse (str) { - text = str; - index = -1; - c = ''; - - if (!isString(text)) { - return null; - } - - next(); - skipWhitespace(); - var first = parseNumber(); - if (first) { - if (c == 'I' || c == 'i') { - // pure imaginary number - next(); - skipWhitespace(); - if (c) { - // garbage at the end. not good. - return null; - } - - return new Complex(0, Number(first)); - } - else { - // complex and real part - skipWhitespace(); - var separator = c; - if (separator != '+' && separator != '-') { - // pure real number - skipWhitespace(); - if (c) { - // garbage at the end. not good. - return null; - } - - return new Complex(Number(first), 0); - } - else { - // complex and real part - next(); - skipWhitespace(); - var second = parseNumber(); - if (second) { - if (c != 'I' && c != 'i') { - // 'i' missing at the end of the complex number - return null; - } - next(); - } - else { - second = parseComplex(); - if (!second) { - // imaginary number missing after separator - return null; - } - } - - if (separator == '-') { - if (second[0] == '-') { - second = '+' + second.substring(1); - } - else { - second = '-' + second; - } - } - - next(); - skipWhitespace(); - if (c) { - // garbage at the end. not good. - return null; - } - - return new Complex(Number(first), Number(second)); - } - } - } - else { - // check for 'i', '-i', '+i' - first = parseComplex(); - if (first) { - skipWhitespace(); - if (c) { - // garbage at the end. not good. - return null; - } - - return new Complex(0, Number(first)); - } - } - - return null; - }; - - /** - * Create a copy of the complex value - * @return {Complex} clone - */ - Complex.prototype.clone = function clone () { - return new Complex(this.re, this.im); - }; - - /** - * Test whether this complex number equals an other complex value. - * Two complex numbers are equal when both their real and imaginary parts - * are equal. - * @param {Complex} other - * @return {boolean} isEqual - */ - Complex.prototype.equals = function equals (other) { - return (this.re === other.re) && (this.im === other.im); - }; - - /** - * Get a string representation of the complex number, - * with optional formatting options. - * @param {Object | Number | Function} [options] Formatting options. See - * lib/util/number:format for a - * description of the available - * options. - * @return {String} str - */ - Complex.prototype.format = function format (options) { - var str = '', - strRe = number.format(this.re, options), - strIm = number.format(this.im, options); - - if (this.im == 0) { - // real value - str = strRe; - } - else if (this.re == 0) { - // purely complex value - if (this.im == 1) { - str = 'i'; - } - else if (this.im == -1) { - str = '-i'; - } - else { - str = strIm + 'i'; - } - } - else { - // complex value - if (this.im > 0) { - if (this.im == 1) { - str = strRe + ' + i'; - } - else { - str = strRe + ' + ' + strIm + 'i'; - } - } - else { - if (this.im == -1) { - str = strRe + ' - i'; - } - else { - str = strRe + ' - ' + strIm.substring(1) + 'i'; - } - } - } - - return str; - }; - - /** - * Get a string representation of the complex number. - * @return {String} str - */ - Complex.prototype.toString = function toString () { - return this.format(); - }; - - // exports - module.exports = Complex; - - // to trick my IDE which doesn't get it - exports.isComplex = Complex.isComplex; - exports.parse = Complex.parse; - - -/***/ }, -/* 9 */ -/***/ function(module, exports, __webpack_require__) { - - var util = __webpack_require__(112), - - number = util.number, - string = util.string, - array = util.array; - - /** - * @constructor Range - * Create a range. A range has a start, step, and end, and contains functions - * to iterate over the range. - * - * A range can be constructed as: - * var range = new Range(start, end); - * var range = new Range(start, end, step); - * - * To get the result of the range: - * range.forEach(function (x) { - * console.log(x); - * }); - * range.map(function (x) { - * return math.sin(x); - * }); - * range.toArray(); - * - * Example usage: - * var c = new Range(2, 6); // 2:1:5 - * c.toArray(); // [2, 3, 4, 5] - * var d = new Range(2, -3, -1); // 2:-1:-2 - * d.toArray(); // [2, 1, 0, -1, -2] - * - * @param {Number} start included lower bound - * @param {Number} end excluded upper bound - * @param {Number} [step] step size, default value is 1 - */ - function Range(start, end, step) { - if (!(this instanceof Range)) { - throw new SyntaxError('Constructor must be called with the new operator'); - } - - if (start != null && !number.isNumber(start)) { - throw new TypeError('Parameter start must be a number'); - } - if (end != null && !number.isNumber(end)) { - throw new TypeError('Parameter end must be a number'); - } - if (step != null && !number.isNumber(step)) { - throw new TypeError('Parameter step must be a number'); - } - - this.start = (start != null) ? parseFloat(start) : 0; - this.end = (end != null) ? parseFloat(end) : 0; - this.step = (step != null) ? parseFloat(step) : 1; - } - - /** - * Parse a string into a range, - * The string contains the start, optional step, and end, separated by a colon. - * If the string does not contain a valid range, null is returned. - * For example str='0:2:11'. - * @param {String} str - * @return {Range | null} range - */ - Range.parse = function parse (str) { - if (!string.isString(str)) { - return null; - } - - var args = str.split(':'); - var nums = args.map(function (arg) { - return parseFloat(arg); - }); - - var invalid = nums.some(function (num) { - return isNaN(num); - }); - if(invalid) { - return null; - } - - switch (nums.length) { - case 2: return new Range(nums[0], nums[1]); - case 3: return new Range(nums[0], nums[2], nums[1]); - default: return null; - } - }; - - /** - * Create a clone of the range - * @return {Range} clone - */ - Range.prototype.clone = function clone() { - return new Range(this.start, this.end, this.step); - }; - - /** - * Test whether an object is a Range - * @param {*} object - * @return {Boolean} isRange - */ - Range.isRange = function isRange(object) { - return (object instanceof Range); - }; - - /** - * Retrieve the size of the range. - * Returns an array containing one number, the number of elements in the range. - * @returns {Number[]} size - */ - Range.prototype.size = function size() { - var len = 0, - start = this.start, - step = this.step, - end = this.end, - diff = end - start; - - if (number.sign(step) == number.sign(diff)) { - len = Math.ceil((diff) / step); - } - else if (diff == 0) { - len = 0; - } - - if (isNaN(len)) { - len = 0; - } - return [len]; - }; - - /** - * Calculate the minimum value in the range - * @return {Number | undefined} min - */ - Range.prototype.min = function min () { - var size = this.size()[0]; - - if (size > 0) { - if (this.step > 0) { - // positive step - return this.start; - } - else { - // negative step - return this.start + (size - 1) * this.step; - } - } - else { - return undefined; - } - }; - - /** - * Calculate the maximum value in the range - * @return {Number | undefined} max - */ - Range.prototype.max = function max () { - var size = this.size()[0]; - - if (size > 0) { - if (this.step > 0) { - // positive step - return this.start + (size - 1) * this.step; - } - else { - // negative step - return this.start; - } - } - else { - return undefined; - } - }; - - - /** - * Execute a callback function for each value in the range. - * @param {function} callback The callback method is invoked with three - * parameters: the value of the element, the index - * of the element, and the Matrix being traversed. - */ - Range.prototype.forEach = function forEach(callback) { - var x = this.start; - var step = this.step; - var end = this.end; - var i = 0; - - if (step > 0) { - while (x < end) { - callback(x, i, this); - x += step; - i++; - } - } - else if (step < 0) { - while (x > end) { - callback(x, i, this); - x += step; - i++; - } - } - }; - - /** - * Execute a callback function for each value in the Range, and return the - * results as an array - * @param {function} callback The callback method is invoked with three - * parameters: the value of the element, the index - * of the element, and the Matrix being traversed. - * @returns {Array} array - */ - Range.prototype.map = function map(callback) { - var array = []; - this.forEach(function (value, index, obj) { - array[index] = callback(value, index, obj); - }); - return array; - }; - - /** - * Create an Array with a copy of the Ranges data - * @returns {Array} array - */ - Range.prototype.toArray = function toArray() { - var array = []; - this.forEach(function (value, index) { - array[index] = value; - }); - return array; - }; - - /** - * Get the primitive value of the Range, a one dimensional array - * @returns {Array} array - */ - Range.prototype.valueOf = function valueOf() { - // TODO: implement a caching mechanism for range.valueOf() - return this.toArray(); - }; - - /** - * Get a string representation of the range, with optional formatting options. - * Output is formatted as 'start:step:end', for example '2:6' or '0:0.2:11' - * @param {Object | Number | Function} [options] Formatting options. See - * lib/util/number:format for a - * description of the available - * options. - * @returns {String} str - */ - Range.prototype.format = function format(options) { - var str = number.format(this.start, options); - - if (this.step != 1) { - str += ':' + number.format(this.step, options); - } - str += ':' + number.format(this.end, options); - return str; - }; - - /** - * Get a string representation of the range. - * @returns {String} - */ - Range.prototype.toString = function toString() { - return this.format(); - }; - - // exports - module.exports = Range; - - // to trick my IDE which doesn't get it - exports.isRange = Range.isRange; - exports.parse = Range.parse; - - -/***/ }, -/* 10 */ -/***/ function(module, exports, __webpack_require__) { - - var util = __webpack_require__(112), - - Range = __webpack_require__(9), - - number = util.number, - - isNumber = number.isNumber, - isInteger = number.isInteger, - isArray = Array.isArray, - validateIndex = util.array.validateIndex; - - /** - * @Constructor Index - * Create an index. An Index can store ranges having start, step, and end - * for multiple dimensions. - * Matrix.get, Matrix.set, and math.subset accept an Index as input. - * - * Usage: - * var index = new Index(range1, range2, ...); - * - * Where each range can be any of: - * An array [start, end] - * An array [start, end, step] - * A number - * An instance of Range - * - * The parameters start, end, and step must be integer numbers. - * - * @param {...*} ranges - */ - function Index(ranges) { - if (!(this instanceof Index)) { - throw new SyntaxError('Constructor must be called with the new operator'); - } - - this._ranges = []; - - for (var i = 0, ii = arguments.length; i < ii; i++) { - var arg = arguments[i]; - - if (arg instanceof Range) { - this._ranges.push(arg); - } - else { - if (isArray(arg)) { - this._ranges.push(_createRange(arg)); - } - else if (isNumber(arg)) { - this._ranges.push(_createRange([arg, arg + 1])); - } - // TODO: implement support for wildcard '*' - else { - throw new TypeError('Ranges must be an Array, Number, or Range'); - } - } - } - } - - /** - * Parse an argument into a range and validate the range - * @param {Array} arg An array with [start: Number, end: Number] and - * optional a third element step:Number - * @return {Range} range - * @private - */ - function _createRange(arg) { - // TODO: make function _createRange simpler/faster - - // test whether all arguments are integers - var num = arg.length; - for (var i = 0; i < num; i++) { - if (!isNumber(arg[i]) || !isInteger(arg[i])) { - throw new TypeError('Index parameters must be integer numbers'); - } - } - - switch (arg.length) { - case 2: - return new Range(arg[0], arg[1]); // start, end - case 3: - return new Range(arg[0], arg[1], arg[2]); // start, end, step - default: - // TODO: improve error message - throw new SyntaxError('Wrong number of arguments in Index (2 or 3 expected)'); - } - } - - /** - * Create a clone of the index - * @return {Index} clone - */ - Index.prototype.clone = function clone () { - var index = new Index(); - index._ranges = util.object.clone(this._ranges); - return index; - }; - - /** - * Test whether an object is an Index - * @param {*} object - * @return {Boolean} isIndex - */ - Index.isIndex = function isIndex(object) { - return (object instanceof Index); - }; - - /** - * Create an index from an array with ranges/numbers - * @param {Array.} ranges - * @return {Index} index - * @private - */ - Index.create = function create(ranges) { - var index = new Index(); - Index.apply(index, ranges); - return index; - }; - - /** - * Retrieve the size of the index, the number of elements for each dimension. - * @returns {Number[]} size - */ - Index.prototype.size = function size () { - var size = []; - - for (var i = 0, ii = this._ranges.length; i < ii; i++) { - var range = this._ranges[i]; - - size[i] = range.size()[0]; - } - - return size; - }; - - /** - * Get the maximum value for each of the indexes ranges. - * @returns {Number[]} max - */ - Index.prototype.max = function max () { - var values = []; - - for (var i = 0, ii = this._ranges.length; i < ii; i++) { - var range = this._ranges[i]; - values[i] = range.max(); - } - - return values; - }; - - /** - * Get the minimum value for each of the indexes ranges. - * @returns {Number[]} min - */ - Index.prototype.min = function min () { - var values = []; - - for (var i = 0, ii = this._ranges.length; i < ii; i++) { - var range = this._ranges[i]; - - values[i] = range.min(); - } - - return values; - }; - - /** - * Loop over each of the ranges of the index - * @param {function} callback Called for each range with a Range as first - * argument, the dimension as second, and the - * index object as third. - */ - Index.prototype.forEach = function forEach(callback) { - for (var i = 0, ii = this._ranges.length; i < ii; i++) { - callback(this._ranges[i], i, this); - } - }; - - /** - * Retrieve the range for a given dimension number from the index - * @param {Number} dim Number of the dimension - * @returns {Range | null} range - */ - Index.prototype.range = function range (dim) { - return this._ranges[dim] || null; - }; - - /** - * Test whether this index contains only a single value - * @return {boolean} isScalar - */ - Index.prototype.isScalar = function isScalar () { - var size = this.size(); - - for (var i = 0, ii = size.length; i < ii; i++) { - if (size[i] !== 1) { - return false; - } - } - - return true; - }; - - /** - * Expand the Index into an array. - * For example new Index([0,3], [2,7]) returns [[0,1,2], [2,3,4,5,6]] - * @returns {Array} array - */ - Index.prototype.toArray = function toArray() { - var array = []; - for (var i = 0, ii = this._ranges.length; i < ii; i++) { - var range = this._ranges[i], - row = [], - x = range.start, - end = range.end, - step = range.step; - - if (step > 0) { - while (x < end) { - row.push(x); - x += step; - } - } - else if (step < 0) { - while (x > end) { - row.push(x); - x += step; - } - } - - array.push(row); - } - - return array; - }; - - /** - * Get the primitive value of the Index, a two dimensional array. - * Equivalent to Index.toArray(). - * @returns {Array} array - */ - Index.prototype.valueOf = Index.prototype.toArray; - - /** - * Get the string representation of the index, for example '[2:6]' or '[0:2:10, 4:7]' - * @returns {String} str - */ - Index.prototype.toString = function () { - var strings = []; - - for (var i = 0, ii = this._ranges.length; i < ii; i++) { - var range = this._ranges[i]; - var str = number.format(range.start); - if (range.step != 1) { - str += ':' + number.format(range.step); - } - str += ':' + number.format(range.end); - strings.push(str); - } - - return '[' + strings.join(', ') + ']'; - }; - - // exports - module.exports = Index; - - // to trick my IDE which doesn't get it - exports.isIndex = Index.isIndex; - exports.create = Index.create; - - -/***/ }, -/* 11 */ -/***/ function(module, exports, __webpack_require__) { - - var util = __webpack_require__(112), - Index = __webpack_require__(10), - - number = util.number, - string = util.string, - array = util.array, - object = util.object, - - isArray = Array.isArray, - validateIndex = array.validateIndex; - - /** - * @constructor Matrix - * - * A Matrix is a wrapper around an Array. A matrix can hold a multi dimensional - * array. A matrix can be constructed as: - * var matrix = new Matrix(data) - * - * Matrix contains the functions to resize, get and set values, get the size, - * clone the matrix and to convert the matrix to a vector, array, or scalar. - * Furthermore, one can iterate over the matrix using map and forEach. - * The internal Array of the Matrix can be accessed using the function valueOf. - * - * Example usage: - * var matrix = new Matrix([[1, 2], [3, 4]); - * matix.size(); // [2, 2] - * matrix.resize([3, 2], 5); - * matrix.valueOf(); // [[1, 2], [3, 4], [5, 5]] - * matrix.subset([1,2]) // 3 (indexes are zero-based) - * - * @param {Array | Matrix} [data] A multi dimensional array - */ - function Matrix(data) { - if (!(this instanceof Matrix)) { - throw new SyntaxError('Constructor must be called with the new operator'); - } - - if (data instanceof Matrix) { - // clone data from a Matrix - this._data = data.clone()._data; - } - else if (isArray(data)) { - // use array - // replace nested Matrices with Arrays - this._data = preprocess(data); - } - else if (data != null) { - // unsupported type - throw new TypeError('Unsupported type of data (' + util.types.type(data) + ')'); - } - else { - // nothing provided - this._data = []; - } - - // verify the size of the array - this._size = array.size(this._data); - } - - /** - * Test whether an object is a Matrix - * @param {*} object - * @return {Boolean} isMatrix - */ - Matrix.isMatrix = function isMatrix(object) { - return (object instanceof Matrix); - }; - - /** - * Get a subset of the matrix, or replace a subset of the matrix. - * - * Usage: - * var subset = matrix.subset(index) // retrieve subset - * var value = matrix.subset(index, replacement) // replace subset - * - * @param {Index} index - * @param {Array | Matrix | *} [replacement] - * @param {*} [defaultValue] Default value, filled in on new entries when - * the matrix is resized. If not provided, - * new matrix elements will be left undefined. - */ - Matrix.prototype.subset = function subset(index, replacement, defaultValue) { - switch (arguments.length) { - case 1: - return _get(this, index); - - // intentional fall through - case 2: - case 3: - return _set(this, index, replacement, defaultValue); - - default: - throw new SyntaxError('Wrong number of arguments'); - } - }; - - /** - * Get a single element from the matrix. - * @param {Number[]} index Zero-based index - * @return {*} value - */ - Matrix.prototype.get = function get(index) { - if (!isArray(index)) { - throw new Error('Array expected'); - } - if (index.length != this._size.length) { - throw new RangeError('Dimension mismatch ' + - '(' + index.length + ' != ' + this._size.length + ')'); - } - - var data = this._data; - for (var i = 0, ii = index.length; i < ii; i++) { - var index_i = index[i]; - validateIndex(index_i, data.length); - data = data[index_i]; - } - - return object.clone(data); - }; - - /** - * Replace a single element in the matrix. - * @param {Number[]} index Zero-based index - * @param {*} value - * @param {*} [defaultValue] Default value, filled in on new entries when - * the matrix is resized. If not provided, - * new matrix elements will be left undefined. - * @return {Matrix} self - */ - Matrix.prototype.set = function set (index, value, defaultValue) { - var i, ii; - - // validate input type and dimensions - if (!isArray(index)) { - throw new Error('Array expected'); - } - if (index.length < this._size.length) { - throw new RangeError('Dimension mismatch ' + - '(' + index.length + ' < ' + this._size.length + ')'); - } - - // enlarge matrix when needed - var size = index.map(function (i) { - return i + 1; - }); - _fit(this, size, defaultValue); - - // traverse over the dimensions - var data = this._data; - for (i = 0, ii = index.length - 1; i < ii; i++) { - var index_i = index[i]; - validateIndex(index_i, data.length); - data = data[index_i]; - } - - // set new value - index_i = index[index.length - 1]; - validateIndex(index_i, data.length); - data[index_i] = value; - - return this; - }; - - /** - * Get a submatrix of this matrix - * @param {Matrix} matrix - * @param {Index} index Zero-based index - * @private - */ - function _get (matrix, index) { - if (!(index instanceof Index)) { - throw new TypeError('Invalid index'); - } - - var isScalar = index.isScalar(); - if (isScalar) { - // return a scalar - return matrix.get(index.min()); - } - else { - // validate dimensions - var size = index.size(); - if (size.length != matrix._size.length) { - throw new RangeError('Dimension mismatch ' + - '(' + size.length + ' != ' + matrix._size.length + ')'); - } - - // retrieve submatrix - var submatrix = new Matrix(_getSubmatrix(matrix._data, index, size.length, 0)); - // TODO: more efficient when creating an empty matrix and setting _data and _size manually - - // squeeze matrix output - while (isArray(submatrix._data) && submatrix._data.length == 1) { - submatrix._data = submatrix._data[0]; - submatrix._size.shift(); - } - - return submatrix; - } - } - - /** - * Recursively get a submatrix of a multi dimensional matrix. - * Index is not checked for correct number of dimensions. - * @param {Array} data - * @param {Index} index - * @param {number} dims Total number of dimensions - * @param {number} dim Current dimension - * @return {Array} submatrix - * @private - */ - function _getSubmatrix (data, index, dims, dim) { - var last = (dim == dims - 1); - var range = index.range(dim); - - if (last) { - return range.map(function (i) { - validateIndex(i, data.length); - return data[i]; - }); - } - else { - return range.map(function (i) { - validateIndex(i, data.length); - var child = data[i]; - return _getSubmatrix(child, index, dims, dim + 1); - }); - } - } - - /** - * Replace a submatrix in this matrix - * Indexes are zero-based. - * @param {Matrix} matrix - * @param {Index} index - * @param {Matrix | Array | *} submatrix - * @param {*} [defaultValue] Default value, filled in on new entries when - * the matrix is resized. If not provided, - * new matrix elements will be left undefined. - * @return {Matrix} matrix - * @private - */ - function _set (matrix, index, submatrix, defaultValue) { - if (!(index instanceof Index)) { - throw new TypeError('Invalid index'); - } - - // get index size and check whether the index contains a single value - var iSize = index.size(), - isScalar = index.isScalar(); - - // calculate the size of the submatrix, and convert it into an Array if needed - var sSize; - if (submatrix instanceof Matrix) { - sSize = submatrix.size(); - submatrix = submatrix.valueOf(); - } - else { - sSize = array.size(submatrix); - } - - if (isScalar) { - // set a scalar - - // check whether submatrix is a scalar - if (sSize.length != 0) { - throw new TypeError('Scalar value expected'); - } - - matrix.set(index.min(), submatrix, defaultValue); - } - else { - // set a submatrix - - // validate dimensions - if (iSize.length < matrix._size.length) { - throw new RangeError('Dimension mismatch ' + - '(' + iSize.length + ' < ' + matrix._size.length + ')'); - } - - // unsqueeze the submatrix when needed - for (var i = 0, ii = iSize.length - sSize.length; i < ii; i++) { - submatrix = [submatrix]; - sSize.unshift(1); - } - - // check whether the size of the submatrix matches the index size - if (!object.deepEqual(iSize, sSize)) { - throw new RangeError('Dimensions mismatch ' + - '(' + string.format(iSize) + ' != '+ string.format(sSize) + ')'); - } - - // enlarge matrix when needed - var size = index.max().map(function (i) { - return i + 1; - }); - _fit(matrix, size, defaultValue); - - // insert the sub matrix - var dims = iSize.length, - dim = 0; - _setSubmatrix (matrix._data, index, submatrix, dims, dim); - } - - return matrix; - } - - /** - * Replace a submatrix of a multi dimensional matrix. - * @param {Array} data - * @param {Index} index - * @param {Array} submatrix - * @param {number} dims Total number of dimensions - * @param {number} dim - * @private - */ - function _setSubmatrix (data, index, submatrix, dims, dim) { - var last = (dim == dims - 1), - range = index.range(dim); - - if (last) { - range.forEach(function (dataIndex, subIndex) { - validateIndex(dataIndex); - data[dataIndex] = submatrix[subIndex]; - }); - } - else { - range.forEach(function (dataIndex, subIndex) { - validateIndex(dataIndex); - _setSubmatrix(data[dataIndex], index, submatrix[subIndex], dims, dim + 1); - }); - } - } - - /** - * Resize the matrix - * @param {Number[]} size - * @param {*} [defaultValue] Default value, filled in on new entries. - * If not provided, the matrix elements will - * be left undefined. - * @return {Matrix} self The matrix itself is returned - */ - Matrix.prototype.resize = function resize(size, defaultValue) { - this._size = object.clone(size); - this._data = array.resize(this._data, this._size, defaultValue); - - // return the matrix itself - return this; - }; - - /** - * Enlarge the matrix when it is smaller than given size. - * If the matrix is larger or equal sized, nothing is done. - * @param {Matrix} matrix The matrix to be resized - * @param {Number[]} size - * @param {*} [defaultValue] Default value, filled in on new entries. - * If not provided, the matrix elements will - * be left undefined. - * @private - */ - function _fit(matrix, size, defaultValue) { - if (!isArray(size)) { - throw new Error('Array expected'); - } - - var newSize = object.clone(matrix._size), - changed = false; - - // add dimensions when needed - while (newSize.length < size.length) { - newSize.unshift(0); - changed = true; - } - - // enlarge size when needed - for (var i = 0, ii = size.length; i < ii; i++) { - if (size[i] > newSize[i]) { - newSize[i] = size[i]; - changed = true; - } - } - - if (changed) { - // resize only when size is changed - matrix.resize(newSize, defaultValue); - } - } - - /** - * Create a clone of the matrix - * @return {Matrix} clone - */ - Matrix.prototype.clone = function clone() { - var matrix = new Matrix(); - matrix._data = object.clone(this._data); - matrix._size = object.clone(this._size); - return matrix; - }; - - /** - * Retrieve the size of the matrix. - * @returns {Number[]} size - */ - Matrix.prototype.size = function size() { - return this._size; - }; - - /** - * Create a new matrix with the results of the callback function executed on - * each entry of the matrix. - * @param {function} callback The callback function is invoked with three - * parameters: the value of the element, the index - * of the element, and the Matrix being traversed. - * @return {Matrix} matrix - */ - Matrix.prototype.map = function map(callback) { - var me = this; - var matrix = new Matrix(); - var index = []; - var recurse = function (value, dim) { - if (isArray(value)) { - return value.map(function (child, i) { - index[dim] = i; - return recurse(child, dim + 1); - }); - } - else { - return callback(value, index, me); - } - }; - matrix._data = recurse(this._data, 0); - matrix._size = object.clone(this._size); - - return matrix; - }; - - /** - * Execute a callback function on each entry of the matrix. - * @param {function} callback The callback function is invoked with three - * parameters: the value of the element, the index - * of the element, and the Matrix being traversed. - */ - Matrix.prototype.forEach = function forEach(callback) { - var me = this; - var index = []; - var recurse = function (value, dim) { - if (isArray(value)) { - value.forEach(function (child, i) { - index[dim] = i; - recurse(child, dim + 1); - }); - } - else { - callback(value, index, me); - } - }; - recurse(this._data, 0); - }; - - /** - * Create an Array with a copy of the data of the Matrix - * @returns {Array} array - */ - Matrix.prototype.toArray = function toArray() { - return object.clone(this._data); - }; - - /** - * Get the primitive value of the Matrix: a multidimensional array - * @returns {Array} array - */ - Matrix.prototype.valueOf = function valueOf() { - return this._data; - }; - - /** - * Get a string representation of the matrix, with optional formatting options. - * @param {Object | Number | Function} [options] Formatting options. See - * lib/util/number:format for a - * description of the available - * options. - * @returns {String} str - */ - Matrix.prototype.format = function format(options) { - return string.format(this._data, options); - }; - - /** - * Get a string representation of the matrix - * @returns {String} str - */ - Matrix.prototype.toString = function toString() { - return string.format(this._data); - }; - - /** - * Preprocess data, which can be an Array or Matrix with nested Arrays and - * Matrices. Replaces all nested Matrices with Arrays - * @param {Array} data - * @return {Array} data - */ - function preprocess(data) { - for (var i = 0, ii = data.length; i < ii; i++) { - var elem = data[i]; - if (isArray(elem)) { - data[i] = preprocess(elem); - } - else if (elem instanceof Matrix) { - data[i] = preprocess(elem._data); - } - } - - return data; - } - - // exports - module.exports = Matrix; - - // to trick my IDE which doesn't get it - exports.isMatrix = Matrix.isMatrix; - - -/***/ }, -/* 12 */ -/***/ function(module, exports, __webpack_require__) { - - var util = __webpack_require__(112), - - number = util.number, - string = util.string, - isNumber = util.number.isNumber, - isString = util.string.isString; - - /** - * @constructor Unit - * - * A unit can be constructed in the following ways: - * var a = new Unit(value, unit); - * var b = new Unit(null, unit); - * var c = Unit.parse(str); - * - * Example usage: - * var a = new Unit(5, 'cm'); // 50 mm - * var b = Unit.parse('23 kg'); // 23 kg - * var c = math.in(a, new Unit(null, 'm'); // 0.05 m - * - * @param {Number} [value] A value like 5.2 - * @param {String} [unit] A unit like "cm" or "inch" - */ - function Unit(value, unit) { - if (!(this instanceof Unit)) { - throw new Error('Constructor must be called with the new operator'); - } - - if (value != null && !isNumber(value)) { - throw new TypeError('First parameter in Unit constructor must be a number'); - } - if (unit != null && !isString(unit)) { - throw new TypeError('Second parameter in Unit constructor must be a string'); - } - - if (unit != null) { - // find the unit and prefix from the string - var res = _findUnit(unit); - if (!res) { - throw new SyntaxError('Unknown unit "' + unit + '"'); - } - this.unit = res.unit; - this.prefix = res.prefix; - } - else { - this.unit = UNIT_NONE; - this.prefix = PREFIX_NONE; // link to a list with supported prefixes - } - - if (value != null) { - this.value = this._normalize(value); - this.fixPrefix = false; // is set true by the methods Unit.in and math.in - } - else { - this.value = null; - this.fixPrefix = true; - } - } - - // private variables and functions for the Unit parser - var text, index, c; - - function skipWhitespace() { - while (c == ' ' || c == '\t') { - next(); - } - } - - function isDigitDot (c) { - return ((c >= '0' && c <= '9') || c == '.'); - } - - function isDigit (c) { - return ((c >= '0' && c <= '9')); - } - - function next() { - index++; - c = text.charAt(index); - } - - function revert(oldIndex) { - index = oldIndex; - c = text.charAt(index); - } - - function parseNumber () { - var number = ''; - var oldIndex; - oldIndex = index; - - if (c == '+') { - next(); - } - else if (c == '-') { - number += c; - next(); - } - - if (!isDigitDot(c)) { - // a + or - must be followed by a digit - revert(oldIndex); - return null; - } - - // get number, can have a single dot - if (c == '.') { - number += c; - next(); - if (!isDigit(c)) { - // this is no legal number, it is just a dot - revert(oldIndex); - return null; - } - } - else { - while (isDigit(c)) { - number += c; - next(); - } - if (c == '.') { - number += c; - next(); - } - } - while (isDigit(c)) { - number += c; - next(); - } - - // check for exponential notation like "2.3e-4" or "1.23e50" - if (c == 'E' || c == 'e') { - number += c; - next(); - - if (c == '+' || c == '-') { - number += c; - next(); - } - - // Scientific notation MUST be followed by an exponent - if (!isDigit(c)) { - // this is no legal number, exponent is missing. - revert(oldIndex); - return null; - } - - while (isDigit(c)) { - number += c; - next(); - } - } - - return number; - } - - function parseUnit() { - var unit = ''; - - skipWhitespace(); - while (c && c != ' ' && c != '\t') { - unit += c; - next(); - } - - return unit || null; - } - - /** - * Parse a string into a unit. Returns null if the provided string does not - * contain a valid unit. - * @param {String} str A string like "5.2 inch", "4e2 kg" - * @return {Unit | null} unit - */ - Unit.parse = function parse(str) { - text = str; - index = -1; - c = ''; - - if (!isString(text)) { - return null; - } - - next(); - skipWhitespace(); - var value = parseNumber(); - var unit; - if (value) { - unit = parseUnit(); - - next(); - skipWhitespace(); - if (c) { - // garbage at the end. not good. - return null; - } - - if (value && unit) { - return new Unit(Number(value), unit); - } - } - else { - unit = parseUnit(); - - next(); - skipWhitespace(); - if (c) { - // garbage at the end. not good. - return null; - } - - return new Unit(null, unit) - } - - return null; - }; - - /** - * Test whether value is of type Unit - * @param {*} value - * @return {Boolean} isUnit - */ - Unit.isUnit = function isUnit(value) { - return (value instanceof Unit); - }; - - /** - * create a copy of this unit - * @return {Unit} clone - */ - Unit.prototype.clone = function () { - var clone = new Unit(); - - for (var p in this) { - if (this.hasOwnProperty(p)) { - clone[p] = this[p]; - } - } - - return clone; - }; - - /** - * Normalize a value, based on its currently set unit - * @param {Number} value - * @return {Number} normalized value - * @private - */ - Unit.prototype._normalize = function(value) { - return (value + this.unit.offset) * - this.unit.value * this.prefix.value; - }; - - /** - * Unnormalize a value, based on its currently set unit - * @param {Number} value - * @param {Number} [prefixValue] Optional prefix value to be used - * @return {Number} unnormalized value - * @private - */ - Unit.prototype._unnormalize = function (value, prefixValue) { - if (prefixValue == undefined) { - return value / this.unit.value / this.prefix.value - - this.unit.offset; - } - else { - return value / this.unit.value / prefixValue - - this.unit.offset; - } - }; - - /** - * Find a unit from a string - * @param {String} str A string like 'cm' or 'inch' - * @returns {Object | null} result When found, an object with fields unit and - * prefix is returned. Else, null is returned. - * @private - */ - function _findUnit(str) { - for (var name in UNITS) { - if (UNITS.hasOwnProperty(name)) { - if (string.endsWith(str, name) ) { - var unit = UNITS[name]; - var prefixLen = (str.length - name.length); - var prefixName = str.substring(0, prefixLen); - var prefix = unit.prefixes[prefixName]; - if (prefix !== undefined) { - // store unit, prefix, and value - return { - unit: unit, - prefix: prefix - }; - } - } - } - } - - return null; - } - - /** - * Test if the given expression is a unit. - * The unit can have a prefix but cannot have a value. - * @param {String} unit A plain unit without value. Can have prefix, like "cm" - * @return {Boolean} true if the given string is a unit - */ - Unit.isPlainUnit = function (unit) { - return (_findUnit(unit) != null); - }; - - /** - * check if this unit has given base unit - * @param {BASE_UNITS | undefined} base - */ - Unit.prototype.hasBase = function(base) { - if (this.unit.base === undefined) { - return (base === undefined); - } - return (this.unit.base === base); - }; - - /** - * Check if this unit has a base equal to another base - * @param {Unit} other - * @return {Boolean} true if equal base - */ - Unit.prototype.equalBase = function(other) { - return (this.unit.base === other.unit.base); - }; - - /** - * Check if this unit equals another unit - * @param {Unit} other - * @return {Boolean} true if both units are equal - */ - Unit.prototype.equals = function(other) { - return (this.equalBase(other) && this.value == other.value); - }; - - /** - * Create a clone of this unit with a representation - * @param {String | Unit} plainUnit A plain unit, without value. Can have prefix, like "cm" - * @returns {Unit} unit having fixed, specified unit - */ - Unit.prototype.to = function (plainUnit) { - var other; - if (isString(plainUnit)) { - other = new Unit(null, plainUnit); - - if (!this.equalBase(other)) { - throw new Error('Units do not match'); - } - - other.value = this.value; - return other; - } - else if (plainUnit instanceof Unit) { - if (!this.equalBase(plainUnit)) { - throw new Error('Units do not match'); - } - if (plainUnit.value != null) { - throw new Error('Cannot convert to a unit with a value'); - } - if (plainUnit.unit == null) { - throw new Error('Unit expected on the right hand side of function in'); - } - - other = plainUnit.clone(); - other.value = this.value; - other.fixPrefix = true; - return other; - } - else { - throw new Error('String or Unit expected as parameter'); - } - }; - - /** - * Return the value of the unit when represented with given plain unit - * @param {String | Unit} plainUnit For example 'cm' or 'inch' - * @return {Number} value - */ - Unit.prototype.toNumber = function (plainUnit) { - var other = this.to(plainUnit); - var prefix = this.fixPrefix ? other._bestPrefix() : other.prefix; - return other._unnormalize(other.value, prefix.value); - }; - - - /** - * Get a string representation of the unit. - * @return {String} - */ - Unit.prototype.toString = function toString() { - return this.format(); - }; - - /** - * Get a string representation of the Unit, with optional formatting options. - * @param {Object | Number | Function} [options] Formatting options. See - * lib/util/number:format for a - * description of the available - * options. - * @return {String} - */ - Unit.prototype.format = function format(options) { - var value, - str; - - if (!this.fixPrefix) { - var bestPrefix = this._bestPrefix(); - value = this._unnormalize(this.value, bestPrefix.value); - str = (this.value != null) ? number.format(value, options) + ' ' : ''; - str += bestPrefix.name + this.unit.name; - } - else { - value = this._unnormalize(this.value); - str = (this.value != null) ? number.format(value, options) + ' ' : ''; - str += this.prefix.name + this.unit.name; - } - return str; - }; - - /** - * Calculate the best prefix using current value. - * @returns {Object} prefix - * @private - */ - Unit.prototype._bestPrefix = function () { - // find the best prefix value (resulting in the value of which - // the absolute value of the log10 is closest to zero, - // though with a little offset of 1.2 for nicer values: you get a - // sequence 1mm 100mm 500mm 0.6m 1m 10m 100m 500m 0.6km 1km ... - var absValue = Math.abs(this.value / this.unit.value); - var bestPrefix = PREFIX_NONE; - var bestDiff = Math.abs( - Math.log(absValue / bestPrefix.value) / Math.LN10 - 1.2); - - var prefixes = this.unit.prefixes; - for (var p in prefixes) { - if (prefixes.hasOwnProperty(p)) { - var prefix = prefixes[p]; - if (prefix.scientific) { - var diff = Math.abs( - Math.log(absValue / prefix.value) / Math.LN10 - 1.2); - - if (diff < bestDiff) { - bestPrefix = prefix; - bestDiff = diff; - } - } - } - } - - return bestPrefix; - }; - - var PREFIXES = { - 'NONE': { - '': {'name': '', 'value': 1, 'scientific': true} - }, - 'SHORT': { - '': {'name': '', 'value': 1, 'scientific': true}, - - 'da': {'name': 'da', 'value': 1e1, 'scientific': false}, - 'h': {'name': 'h', 'value': 1e2, 'scientific': false}, - 'k': {'name': 'k', 'value': 1e3, 'scientific': true}, - 'M': {'name': 'M', 'value': 1e6, 'scientific': true}, - 'G': {'name': 'G', 'value': 1e9, 'scientific': true}, - 'T': {'name': 'T', 'value': 1e12, 'scientific': true}, - 'P': {'name': 'P', 'value': 1e15, 'scientific': true}, - 'E': {'name': 'E', 'value': 1e18, 'scientific': true}, - 'Z': {'name': 'Z', 'value': 1e21, 'scientific': true}, - 'Y': {'name': 'Y', 'value': 1e24, 'scientific': true}, - - 'd': {'name': 'd', 'value': 1e-1, 'scientific': false}, - 'c': {'name': 'c', 'value': 1e-2, 'scientific': false}, - 'm': {'name': 'm', 'value': 1e-3, 'scientific': true}, - 'u': {'name': 'u', 'value': 1e-6, 'scientific': true}, - 'n': {'name': 'n', 'value': 1e-9, 'scientific': true}, - 'p': {'name': 'p', 'value': 1e-12, 'scientific': true}, - 'f': {'name': 'f', 'value': 1e-15, 'scientific': true}, - 'a': {'name': 'a', 'value': 1e-18, 'scientific': true}, - 'z': {'name': 'z', 'value': 1e-21, 'scientific': true}, - 'y': {'name': 'y', 'value': 1e-24, 'scientific': true} - }, - 'LONG': { - '': {'name': '', 'value': 1, 'scientific': true}, - - 'deca': {'name': 'deca', 'value': 1e1, 'scientific': false}, - 'hecto': {'name': 'hecto', 'value': 1e2, 'scientific': false}, - 'kilo': {'name': 'kilo', 'value': 1e3, 'scientific': true}, - 'mega': {'name': 'mega', 'value': 1e6, 'scientific': true}, - 'giga': {'name': 'giga', 'value': 1e9, 'scientific': true}, - 'tera': {'name': 'tera', 'value': 1e12, 'scientific': true}, - 'peta': {'name': 'peta', 'value': 1e15, 'scientific': true}, - 'exa': {'name': 'exa', 'value': 1e18, 'scientific': true}, - 'zetta': {'name': 'zetta', 'value': 1e21, 'scientific': true}, - 'yotta': {'name': 'yotta', 'value': 1e24, 'scientific': true}, - - 'deci': {'name': 'deci', 'value': 1e-1, 'scientific': false}, - 'centi': {'name': 'centi', 'value': 1e-2, 'scientific': false}, - 'milli': {'name': 'milli', 'value': 1e-3, 'scientific': true}, - 'micro': {'name': 'micro', 'value': 1e-6, 'scientific': true}, - 'nano': {'name': 'nano', 'value': 1e-9, 'scientific': true}, - 'pico': {'name': 'pico', 'value': 1e-12, 'scientific': true}, - 'femto': {'name': 'femto', 'value': 1e-15, 'scientific': true}, - 'atto': {'name': 'atto', 'value': 1e-18, 'scientific': true}, - 'zepto': {'name': 'zepto', 'value': 1e-21, 'scientific': true}, - 'yocto': {'name': 'yocto', 'value': 1e-24, 'scientific': true} - }, - 'SQUARED': { - '': {'name': '', 'value': 1, 'scientific': true}, - - 'da': {'name': 'da', 'value': 1e2, 'scientific': false}, - 'h': {'name': 'h', 'value': 1e4, 'scientific': false}, - 'k': {'name': 'k', 'value': 1e6, 'scientific': true}, - 'M': {'name': 'M', 'value': 1e12, 'scientific': true}, - 'G': {'name': 'G', 'value': 1e18, 'scientific': true}, - 'T': {'name': 'T', 'value': 1e24, 'scientific': true}, - 'P': {'name': 'P', 'value': 1e30, 'scientific': true}, - 'E': {'name': 'E', 'value': 1e36, 'scientific': true}, - 'Z': {'name': 'Z', 'value': 1e42, 'scientific': true}, - 'Y': {'name': 'Y', 'value': 1e48, 'scientific': true}, - - 'd': {'name': 'd', 'value': 1e-2, 'scientific': false}, - 'c': {'name': 'c', 'value': 1e-4, 'scientific': false}, - 'm': {'name': 'm', 'value': 1e-6, 'scientific': true}, - 'u': {'name': 'u', 'value': 1e-12, 'scientific': true}, - 'n': {'name': 'n', 'value': 1e-18, 'scientific': true}, - 'p': {'name': 'p', 'value': 1e-24, 'scientific': true}, - 'f': {'name': 'f', 'value': 1e-30, 'scientific': true}, - 'a': {'name': 'a', 'value': 1e-36, 'scientific': true}, - 'z': {'name': 'z', 'value': 1e-42, 'scientific': true}, - 'y': {'name': 'y', 'value': 1e-42, 'scientific': true} - }, - 'CUBIC': { - '': {'name': '', 'value': 1, 'scientific': true}, - - 'da': {'name': 'da', 'value': 1e3, 'scientific': false}, - 'h': {'name': 'h', 'value': 1e6, 'scientific': false}, - 'k': {'name': 'k', 'value': 1e9, 'scientific': true}, - 'M': {'name': 'M', 'value': 1e18, 'scientific': true}, - 'G': {'name': 'G', 'value': 1e27, 'scientific': true}, - 'T': {'name': 'T', 'value': 1e36, 'scientific': true}, - 'P': {'name': 'P', 'value': 1e45, 'scientific': true}, - 'E': {'name': 'E', 'value': 1e54, 'scientific': true}, - 'Z': {'name': 'Z', 'value': 1e63, 'scientific': true}, - 'Y': {'name': 'Y', 'value': 1e72, 'scientific': true}, - - 'd': {'name': 'd', 'value': 1e-3, 'scientific': false}, - 'c': {'name': 'c', 'value': 1e-6, 'scientific': false}, - 'm': {'name': 'm', 'value': 1e-9, 'scientific': true}, - 'u': {'name': 'u', 'value': 1e-18, 'scientific': true}, - 'n': {'name': 'n', 'value': 1e-27, 'scientific': true}, - 'p': {'name': 'p', 'value': 1e-36, 'scientific': true}, - 'f': {'name': 'f', 'value': 1e-45, 'scientific': true}, - 'a': {'name': 'a', 'value': 1e-54, 'scientific': true}, - 'z': {'name': 'z', 'value': 1e-63, 'scientific': true}, - 'y': {'name': 'y', 'value': 1e-72, 'scientific': true} - }, - 'BINARY_SHORT': { - '': {'name': '', 'value': 1, 'scientific': true}, - 'k': {'name': 'k', 'value': 1024, 'scientific': true}, - 'M': {'name': 'M', 'value': Math.pow(1024, 2), 'scientific': true}, - 'G': {'name': 'G', 'value': Math.pow(1024, 3), 'scientific': true}, - 'T': {'name': 'T', 'value': Math.pow(1024, 4), 'scientific': true}, - 'P': {'name': 'P', 'value': Math.pow(1024, 5), 'scientific': true}, - 'E': {'name': 'E', 'value': Math.pow(1024, 6), 'scientific': true}, - 'Z': {'name': 'Z', 'value': Math.pow(1024, 7), 'scientific': true}, - 'Y': {'name': 'Y', 'value': Math.pow(1024, 8), 'scientific': true}, - - 'Ki': {'name': 'Ki', 'value': 1024, 'scientific': true}, - 'Mi': {'name': 'Mi', 'value': Math.pow(1024, 2), 'scientific': true}, - 'Gi': {'name': 'Gi', 'value': Math.pow(1024, 3), 'scientific': true}, - 'Ti': {'name': 'Ti', 'value': Math.pow(1024, 4), 'scientific': true}, - 'Pi': {'name': 'Pi', 'value': Math.pow(1024, 5), 'scientific': true}, - 'Ei': {'name': 'Ei', 'value': Math.pow(1024, 6), 'scientific': true}, - 'Zi': {'name': 'Zi', 'value': Math.pow(1024, 7), 'scientific': true}, - 'Yi': {'name': 'Yi', 'value': Math.pow(1024, 8), 'scientific': true} - }, - 'BINARY_LONG': { - '': {'name': '', 'value': 1, 'scientific': true}, - 'kilo': {'name': 'kilo', 'value': 1024, 'scientific': true}, - 'mega': {'name': 'mega', 'value': Math.pow(1024, 2), 'scientific': true}, - 'giga': {'name': 'giga', 'value': Math.pow(1024, 3), 'scientific': true}, - 'tera': {'name': 'tera', 'value': Math.pow(1024, 4), 'scientific': true}, - 'peta': {'name': 'peta', 'value': Math.pow(1024, 5), 'scientific': true}, - 'exa': {'name': 'exa', 'value': Math.pow(1024, 6), 'scientific': true}, - 'zetta': {'name': 'zetta', 'value': Math.pow(1024, 7), 'scientific': true}, - 'yotta': {'name': 'yotta', 'value': Math.pow(1024, 8), 'scientific': true}, - - 'kibi': {'name': 'kibi', 'value': 1024, 'scientific': true}, - 'mebi': {'name': 'mebi', 'value': Math.pow(1024, 2), 'scientific': true}, - 'gibi': {'name': 'gibi', 'value': Math.pow(1024, 3), 'scientific': true}, - 'tebi': {'name': 'tebi', 'value': Math.pow(1024, 4), 'scientific': true}, - 'pebi': {'name': 'pebi', 'value': Math.pow(1024, 5), 'scientific': true}, - 'exi': {'name': 'exi', 'value': Math.pow(1024, 6), 'scientific': true}, - 'zebi': {'name': 'zebi', 'value': Math.pow(1024, 7), 'scientific': true}, - 'yobi': {'name': 'yobi', 'value': Math.pow(1024, 8), 'scientific': true} - } - }; - - var PREFIX_NONE = {'name': '', 'value': 1, 'scientific': true}; - - var BASE_UNITS = { - 'NONE': {}, - - 'LENGTH': {}, // meter - 'MASS': {}, // kilogram - 'TIME': {}, // second - 'CURRENT': {}, // ampere - 'TEMPERATURE': {}, // kelvin - 'LUMINOUS_INTENSITY': {}, // candela - 'AMOUNT_OF_SUBSTANCE': {}, // mole - - 'FORCE': {}, // Newton - 'SURFACE': {}, // m2 - 'VOLUME': {}, // m3 - 'ANGLE': {}, // rad - 'BIT': {} // bit (digital) - }; - - BASE_UNIT_NONE = {}; - - UNIT_NONE = {'name': '', 'base': BASE_UNIT_NONE, 'value': 1, 'offset': 0}; - - var UNITS = { - // length - meter: {'name': 'meter', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.LONG, 'value': 1, 'offset': 0}, - inch: {'name': 'inch', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.NONE, 'value': 0.0254, 'offset': 0}, - foot: {'name': 'foot', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.NONE, 'value': 0.3048, 'offset': 0}, - yard: {'name': 'yard', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.NONE, 'value': 0.9144, 'offset': 0}, - mile: {'name': 'mile', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.NONE, 'value': 1609.344, 'offset': 0}, - link: {'name': 'link', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.NONE, 'value': 0.201168, 'offset': 0}, - rod: {'name': 'rod', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.NONE, 'value': 5.029210, 'offset': 0}, - chain: {'name': 'chain', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.NONE, 'value': 20.1168, 'offset': 0}, - angstrom: {'name': 'angstrom', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.NONE, 'value': 1e-10, 'offset': 0}, - - m: {'name': 'm', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.SHORT, 'value': 1, 'offset': 0}, - 'in': {'name': 'in', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.NONE, 'value': 0.0254, 'offset': 0}, - ft: {'name': 'ft', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.NONE, 'value': 0.3048, 'offset': 0}, - yd: {'name': 'yd', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.NONE, 'value': 0.9144, 'offset': 0}, - mi: {'name': 'mi', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.NONE, 'value': 1609.344, 'offset': 0}, - li: {'name': 'li', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.NONE, 'value': 0.201168, 'offset': 0}, - rd: {'name': 'rd', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.NONE, 'value': 5.029210, 'offset': 0}, - ch: {'name': 'ch', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.NONE, 'value': 20.1168, 'offset': 0}, - mil: {'name': 'mil', 'base': BASE_UNITS.LENGTH, 'prefixes': PREFIXES.NONE, 'value': 0.0000254, 'offset': 0}, // 1/1000 inch - - // Surface - m2: {'name': 'm2', 'base': BASE_UNITS.SURFACE, 'prefixes': PREFIXES.SQUARED, 'value': 1, 'offset': 0}, - sqin: {'name': 'sqin', 'base': BASE_UNITS.SURFACE, 'prefixes': PREFIXES.NONE, 'value': 0.00064516, 'offset': 0}, // 645.16 mm2 - sqft: {'name': 'sqft', 'base': BASE_UNITS.SURFACE, 'prefixes': PREFIXES.NONE, 'value': 0.09290304, 'offset': 0}, // 0.09290304 m2 - sqyd: {'name': 'sqyd', 'base': BASE_UNITS.SURFACE, 'prefixes': PREFIXES.NONE, 'value': 0.83612736, 'offset': 0}, // 0.83612736 m2 - sqmi: {'name': 'sqmi', 'base': BASE_UNITS.SURFACE, 'prefixes': PREFIXES.NONE, 'value': 2589988.110336, 'offset': 0}, // 2.589988110336 km2 - sqrd: {'name': 'sqrd', 'base': BASE_UNITS.SURFACE, 'prefixes': PREFIXES.NONE, 'value': 25.29295, 'offset': 0}, // 25.29295 m2 - sqch: {'name': 'sqch', 'base': BASE_UNITS.SURFACE, 'prefixes': PREFIXES.NONE, 'value': 404.6873, 'offset': 0}, // 404.6873 m2 - sqmil: {'name': 'sqmil', 'base': BASE_UNITS.SURFACE, 'prefixes': PREFIXES.NONE, 'value': 6.4516e-10, 'offset': 0}, // 6.4516 * 10^-10 m2 - - // Volume - m3: {'name': 'm3', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.CUBIC, 'value': 1, 'offset': 0}, - L: {'name': 'L', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.SHORT, 'value': 0.001, 'offset': 0}, // litre - l: {'name': 'l', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.SHORT, 'value': 0.001, 'offset': 0}, // litre - litre: {'name': 'litre', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.LONG, 'value': 0.001, 'offset': 0}, - cuin: {'name': 'cuin', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 1.6387064e-5, 'offset': 0}, // 1.6387064e-5 m3 - cuft: {'name': 'cuft', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.028316846592, 'offset': 0}, // 28.316 846 592 L - cuyd: {'name': 'cuyd', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.764554857984, 'offset': 0}, // 764.554 857 984 L - teaspoon: {'name': 'teaspoon', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.000005, 'offset': 0}, // 5 mL - tablespoon: {'name': 'tablespoon', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.000015, 'offset': 0}, // 15 mL - //{'name': 'cup', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.000240, 'offset': 0}, // 240 mL // not possible, we have already another cup - - // Liquid volume - minim: {'name': 'minim', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.00000006161152, 'offset': 0}, // 0.06161152 mL - fluiddram: {'name': 'fluiddram', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.0000036966911, 'offset': 0}, // 3.696691 mL - fluidounce: {'name': 'fluidounce', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.00002957353, 'offset': 0}, // 29.57353 mL - gill: {'name': 'gill', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.0001182941, 'offset': 0}, // 118.2941 mL - cc: {'name': 'cc', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 1e-6, 'offset': 0}, // 1e-6 L - cup: {'name': 'cup', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.0002365882, 'offset': 0}, // 236.5882 mL - pint: {'name': 'pint', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.0004731765, 'offset': 0}, // 473.1765 mL - quart: {'name': 'quart', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.0009463529, 'offset': 0}, // 946.3529 mL - gallon: {'name': 'gallon', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.003785412, 'offset': 0}, // 3.785412 L - beerbarrel: {'name': 'beerbarrel', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.1173478, 'offset': 0}, // 117.3478 L - oilbarrel: {'name': 'oilbarrel', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.1589873, 'offset': 0}, // 158.9873 L - hogshead: {'name': 'hogshead', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.2384810, 'offset': 0}, // 238.4810 L - - //{'name': 'min', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.00000006161152, 'offset': 0}, // 0.06161152 mL // min is already in use as minute - fldr: {'name': 'fldr', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.0000036966911, 'offset': 0}, // 3.696691 mL - floz: {'name': 'floz', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.00002957353, 'offset': 0}, // 29.57353 mL - gi: {'name': 'gi', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.0001182941, 'offset': 0}, // 118.2941 mL - cp: {'name': 'cp', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.0002365882, 'offset': 0}, // 236.5882 mL - pt: {'name': 'pt', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.0004731765, 'offset': 0}, // 473.1765 mL - qt: {'name': 'qt', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.0009463529, 'offset': 0}, // 946.3529 mL - gal: {'name': 'gal', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.003785412, 'offset': 0}, // 3.785412 L - bbl: {'name': 'bbl', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.1173478, 'offset': 0}, // 117.3478 L - obl: {'name': 'obl', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.1589873, 'offset': 0}, // 158.9873 L - //{'name': 'hogshead', 'base': BASE_UNITS.VOLUME, 'prefixes': PREFIXES.NONE, 'value': 0.2384810, 'offset': 0}, // 238.4810 L // TODO: hh? - - // Mass - g: {'name': 'g', 'base': BASE_UNITS.MASS, 'prefixes': PREFIXES.SHORT, 'value': 0.001, 'offset': 0}, - gram: {'name': 'gram', 'base': BASE_UNITS.MASS, 'prefixes': PREFIXES.LONG, 'value': 0.001, 'offset': 0}, - - ton: {'name': 'ton', 'base': BASE_UNITS.MASS, 'prefixes': PREFIXES.SHORT, 'value': 907.18474, 'offset': 0}, - tonne: {'name': 'tonne', 'base': BASE_UNITS.MASS, 'prefixes': PREFIXES.SHORT, 'value': 1000, 'offset': 0}, - - grain: {'name': 'grain', 'base': BASE_UNITS.MASS, 'prefixes': PREFIXES.NONE, 'value': 64.79891e-6, 'offset': 0}, - dram: {'name': 'dram', 'base': BASE_UNITS.MASS, 'prefixes': PREFIXES.NONE, 'value': 1.7718451953125e-3, 'offset': 0}, - ounce: {'name': 'ounce', 'base': BASE_UNITS.MASS, 'prefixes': PREFIXES.NONE, 'value': 28.349523125e-3, 'offset': 0}, - poundmass: {'name': 'poundmass', 'base': BASE_UNITS.MASS, 'prefixes': PREFIXES.NONE, 'value': 453.59237e-3, 'offset': 0}, - hundredweight: {'name': 'hundredweight', 'base': BASE_UNITS.MASS, 'prefixes': PREFIXES.NONE, 'value': 45.359237, 'offset': 0}, - stick: {'name': 'stick', 'base': BASE_UNITS.MASS, 'prefixes': PREFIXES.NONE, 'value': 115e-3, 'offset': 0}, - - gr: {'name': 'gr', 'base': BASE_UNITS.MASS, 'prefixes': PREFIXES.NONE, 'value': 64.79891e-6, 'offset': 0}, - dr: {'name': 'dr', 'base': BASE_UNITS.MASS, 'prefixes': PREFIXES.NONE, 'value': 1.7718451953125e-3, 'offset': 0}, - oz: {'name': 'oz', 'base': BASE_UNITS.MASS, 'prefixes': PREFIXES.NONE, 'value': 28.349523125e-3, 'offset': 0}, - lbm: {'name': 'lbm', 'base': BASE_UNITS.MASS, 'prefixes': PREFIXES.NONE, 'value': 453.59237e-3, 'offset': 0}, - cwt: {'name': 'cwt', 'base': BASE_UNITS.MASS, 'prefixes': PREFIXES.NONE, 'value': 45.359237, 'offset': 0}, - - // Time - s: {'name': 's', 'base': BASE_UNITS.TIME, 'prefixes': PREFIXES.SHORT, 'value': 1, 'offset': 0}, - min: {'name': 'min', 'base': BASE_UNITS.TIME, 'prefixes': PREFIXES.NONE, 'value': 60, 'offset': 0}, - h: {'name': 'h', 'base': BASE_UNITS.TIME, 'prefixes': PREFIXES.NONE, 'value': 3600, 'offset': 0}, - second: {'name': 'second', 'base': BASE_UNITS.TIME, 'prefixes': PREFIXES.LONG, 'value': 1, 'offset': 0}, - sec: {'name': 'sec', 'base': BASE_UNITS.TIME, 'prefixes': PREFIXES.LONG, 'value': 1, 'offset': 0}, - minute: {'name': 'minute', 'base': BASE_UNITS.TIME, 'prefixes': PREFIXES.NONE, 'value': 60, 'offset': 0}, - hour: {'name': 'hour', 'base': BASE_UNITS.TIME, 'prefixes': PREFIXES.NONE, 'value': 3600, 'offset': 0}, - day: {'name': 'day', 'base': BASE_UNITS.TIME, 'prefixes': PREFIXES.NONE, 'value': 86400, 'offset': 0}, - - // Angle - rad: {'name': 'rad', 'base': BASE_UNITS.ANGLE, 'prefixes': PREFIXES.NONE, 'value': 1, 'offset': 0}, - // deg = rad / (2*pi) * 360 = rad / 0.017453292519943295769236907684888 - deg: {'name': 'deg', 'base': BASE_UNITS.ANGLE, 'prefixes': PREFIXES.NONE, 'value': 0.017453292519943295769236907684888, 'offset': 0}, - // grad = rad / (2*pi) * 400 = rad / 0.015707963267948966192313216916399 - grad: {'name': 'grad', 'base': BASE_UNITS.ANGLE, 'prefixes': PREFIXES.NONE, 'value': 0.015707963267948966192313216916399, 'offset': 0}, - // cycle = rad / (2*pi) = rad / 6.2831853071795864769252867665793 - cycle: {'name': 'cycle', 'base': BASE_UNITS.ANGLE, 'prefixes': PREFIXES.NONE, 'value': 6.2831853071795864769252867665793, 'offset': 0}, - - // Electric current - A: {'name': 'A', 'base': BASE_UNITS.CURRENT, 'prefixes': PREFIXES.SHORT, 'value': 1, 'offset': 0}, - ampere: {'name': 'ampere', 'base': BASE_UNITS.CURRENT, 'prefixes': PREFIXES.LONG, 'value': 1, 'offset': 0}, - - // Temperature - // K(C) = °C + 273.15 - // K(F) = (°F + 459.67) / 1.8 - // K(R) = °R / 1.8 - K: {'name': 'K', 'base': BASE_UNITS.TEMPERATURE, 'prefixes': PREFIXES.NONE, 'value': 1, 'offset': 0}, - degC: {'name': 'degC', 'base': BASE_UNITS.TEMPERATURE, 'prefixes': PREFIXES.NONE, 'value': 1, 'offset': 273.15}, - degF: {'name': 'degF', 'base': BASE_UNITS.TEMPERATURE, 'prefixes': PREFIXES.NONE, 'value': 1/1.8, 'offset': 459.67}, - degR: {'name': 'degR', 'base': BASE_UNITS.TEMPERATURE, 'prefixes': PREFIXES.NONE, 'value': 1/1.8, 'offset': 0}, - kelvin: {'name': 'kelvin', 'base': BASE_UNITS.TEMPERATURE, 'prefixes': PREFIXES.NONE, 'value': 1, 'offset': 0}, - celsius: {'name': 'celsius', 'base': BASE_UNITS.TEMPERATURE, 'prefixes': PREFIXES.NONE, 'value': 1, 'offset': 273.15}, - fahrenheit: {'name': 'fahrenheit', 'base': BASE_UNITS.TEMPERATURE, 'prefixes': PREFIXES.NONE, 'value': 1/1.8, 'offset': 459.67}, - rankine: {'name': 'rankine', 'base': BASE_UNITS.TEMPERATURE, 'prefixes': PREFIXES.NONE, 'value': 1/1.8, 'offset': 0}, - - // amount of substance - mol: {'name': 'mol', 'base': BASE_UNITS.AMOUNT_OF_SUBSTANCE, 'prefixes': PREFIXES.NONE, 'value': 1, 'offset': 0}, - mole: {'name': 'mole', 'base': BASE_UNITS.AMOUNT_OF_SUBSTANCE, 'prefixes': PREFIXES.NONE, 'value': 1, 'offset': 0}, - - // luminous intensity - cd: {'name': 'cd', 'base': BASE_UNITS.LUMINOUS_INTENSITY, 'prefixes': PREFIXES.NONE, 'value': 1, 'offset': 0}, - candela: {'name': 'candela', 'base': BASE_UNITS.LUMINOUS_INTENSITY, 'prefixes': PREFIXES.NONE, 'value': 1, 'offset': 0}, - // TODO: units STERADIAN - //{'name': 'sr', 'base': BASE_UNITS.STERADIAN, 'prefixes': PREFIXES.NONE, 'value': 1, 'offset': 0}, - //{'name': 'steradian', 'base': BASE_UNITS.STERADIAN, 'prefixes': PREFIXES.NONE, 'value': 1, 'offset': 0}, - - // Force - N: {'name': 'N', 'base': BASE_UNITS.FORCE, 'prefixes': PREFIXES.SHORT, 'value': 1, 'offset': 0}, - newton: {'name': 'newton', 'base': BASE_UNITS.FORCE, 'prefixes': PREFIXES.LONG, 'value': 1, 'offset': 0}, - lbf: {'name': 'lbf', 'base': BASE_UNITS.FORCE, 'prefixes': PREFIXES.NONE, 'value': 4.4482216152605, 'offset': 0}, - poundforce: {'name': 'poundforce', 'base': BASE_UNITS.FORCE, 'prefixes': PREFIXES.NONE, 'value': 4.4482216152605, 'offset': 0}, - - // Binary - b: {'name': 'b', 'base': BASE_UNITS.BIT, 'prefixes': PREFIXES.BINARY_SHORT, 'value': 1, 'offset': 0}, - bits: {'name': 'bits', 'base': BASE_UNITS.BIT, 'prefixes': PREFIXES.BINARY_LONG, 'value': 1, 'offset': 0}, - B: {'name': 'B', 'base': BASE_UNITS.BIT, 'prefixes': PREFIXES.BINARY_SHORT, 'value': 8, 'offset': 0}, - bytes: {'name': 'bytes', 'base': BASE_UNITS.BIT, 'prefixes': PREFIXES.BINARY_LONG, 'value': 8, 'offset': 0} - }; - - // plurals - var PLURALS = { - meters: 'meter', - inches: 'inch', - feet: 'foot', - yards: 'yard', - miles: 'mile', - links: 'link', - rods: 'rod', - chains: 'chain', - angstroms: 'angstrom', - - litres: 'litre', - teaspoons: 'teaspoon', - tablespoons: 'tablespoon', - minims: 'minim', - fluiddrams: 'fluiddram', - fluidounces: 'fluidounce', - gills: 'gill', - cups: 'cup', - pints: 'pint', - quarts: 'quart', - gallons: 'gallon', - beerbarrels: 'beerbarrel', - oilbarrels: 'oilbarrel', - hogsheads: 'hogshead', - - grams: 'gram', - tons: 'ton', - tonnes: 'tonne', - grains: 'grain', - drams: 'dram', - ounces: 'ounce', - poundmasses: 'poundmass', - hundredweights: 'hundredweight', - sticks: 'stick', - - seconds: 'second', - minutes: 'minute', - hours: 'hour', - days: 'day', - - radians: 'rad', - degrees: 'deg', - gradients: 'grad', - cycles: 'cycle', - - amperes: 'ampere', - moles: 'mole' - }; - - for (var name in PLURALS) { - if (PLURALS.hasOwnProperty(name)) { - var unit = UNITS[PLURALS[name]]; - var plural = Object.create(unit); - plural.name = name; - UNITS[name] = plural; - } - } - - // aliases - UNITS.lt = UNITS.l; - UNITS.liter = UNITS.litre; - UNITS.liters = UNITS.litres; - UNITS.lb = UNITS.lbm; - - - Unit.PREFIXES = PREFIXES; - Unit.BASE_UNITS = BASE_UNITS; - Unit.UNITS = UNITS; - - // end of unit aliases - - - // exports - module.exports = Unit; - - // to trick my IDE which doesn't get it - exports.isUnit = Unit.isUnit; - exports.isPlainUnit = Unit.isPlainUnit; - exports.parse = Unit.parse; - - -/***/ }, -/* 13 */ -/***/ function(module, exports, __webpack_require__) { - - var util = __webpack_require__(112), - object = util.object, - string = util.string; - - /** - * Documentation object - * @param {Object} math The math.js namespace - * @param {Object} doc Object containing properties: - * {String} name - * {String} category - * {String[]} syntax - * {String[]} examples - * {String[]} seealso - * @constructor - */ - function Help (math, doc) { - if (!(this instanceof Help)) { - throw new SyntaxError('Constructor must be called with the new operator'); - } - - // TODO: throw an error when math or doc is not provided - - this.math = math; - this.doc = doc; - } - - /** - * Test whether a value is an instance of Help - * @param {*} value - * @return {Boolean} isHelp - */ - Help.isHelp = function isHelp (value) { - return (value instanceof Help); - }; - - /** - * Generate readable description from a Help object - * @return {String} readableDoc - * @private - */ - Help.prototype.toString = function () { - var doc = this.doc || {}; - var desc = '\n'; - - if (doc.name) { - desc += 'Name: ' + doc.name + '\n\n'; - } - if (doc.category) { - desc += 'Category: ' + doc.category + '\n\n'; - } - if (doc.description) { - desc += 'Description:\n ' + doc.description + '\n\n'; - } - if (doc.syntax) { - desc += 'Syntax:\n ' + doc.syntax.join('\n ') + '\n\n'; - } - if (doc.examples) { - var parser = this.math.parser(); - desc += 'Examples:\n'; - for (var i = 0; i < doc.examples.length; i++) { - var expr = doc.examples[i]; - var res; - try { - res = parser.eval(expr); - } - catch (e) { - res = e; - } - desc += ' ' + expr + '\n'; - if (res && !(res instanceof Help)) { - desc += ' ' + string.format(res) + '\n'; - } - } - desc += '\n'; - } - if (doc.seealso) { - desc += 'See also: ' + doc.seealso.join(', ') + '\n'; - } - - return desc; - }; - - // TODO: implement a toHTML function in Help - - /** - * Export the help object to JSON - */ - Help.prototype.toJSON = function () { - return object.clone(this.doc); - }; - - // exports - module.exports = Help; - - // to trick my IDE which doesn't get it - exports.isHelp = Help.isHelp; - - /***/ }, /* 14 */ /***/ function(module, exports, __webpack_require__) { - // utility methods for arrays and matrices - - var util = __webpack_require__(112), - - Matrix = __webpack_require__(11), - - isArray = util.array.isArray, - isString = util.string.isString; - - /** - * Convert function arguments to an array. Arguments can have the following - * signature: - * fn() - * fn(n) - * fn(m, n, p, ...) - * fn([m, n, p, ...]) - * @param {...Number | Array | Matrix} args - * @returns {Array} array - */ - exports.argsToArray = function argsToArray(args) { - var array; - if (args.length == 0) { - // fn() - array = []; - } - else if (args.length == 1) { - // fn(n) - // fn([m, n, p, ...]) - array = args[0]; - if (array instanceof Matrix) { - array = array.valueOf(); - } - if (!isArray(array)) { - array = [array]; - } - } - else { - // fn(m, n, p, ...) - array = Array.prototype.slice.apply(args); - } - return array; - }; - - - /** - * Test whether a value is a collection: an Array or Matrix - * @param {*} x - * @returns {boolean} isCollection - */ - exports.isCollection = function isCollection (x) { - return (isArray(x) || (x instanceof Matrix)); - }; - - /** - * Execute the callback function element wise for each element in array and any - * nested array - * Returns an array with the results - * @param {Array | Matrix} array - * @param {function} callback The callback is called with two parameters: - * value1 and value2, which contain the current - * element of both arrays. - * @return {Array | Matrix} res - */ - exports.deepMap = function deepMap(array, callback) { - if (array && (typeof array.map === 'function')) { - return array.map(function (x) { - return deepMap(x, callback); - }); - } - else { - return callback(array); - } - }; - - /** - * Execute the callback function element wise for each entry in two given arrays, - * and for any nested array. Objects can also be scalar objects. - * Returns an array with the results. - * @param {Array | Matrix | Object} array1 - * @param {Array | Matrix | Object} array2 - * @param {function} callback The callback is called with two parameters: - * value1 and value2, which contain the current - * element of both arrays. - * @return {Array | Matrix} res - */ - exports.deepMap2 = function deepMap2(array1, array2, callback) { - var res, len, i; - - if (isArray(array1)) { - if (isArray(array2)) { - // callback(array, array) - if (array1.length != array2.length) { - throw new RangeError('Dimension mismatch ' + - '(' + array1.length + ' != ' + array2.length + ')'); - } - - res = []; - len = array1.length; - for (i = 0; i < len; i++) { - res[i] = deepMap2(array1[i], array2[i], callback); - } - } - else if (array2 instanceof Matrix) { - // callback(array, matrix) - res = deepMap2(array1, array2.valueOf(), callback); - return new Matrix(res); - } - else { - // callback(array, object) - res = []; - len = array1.length; - for (i = 0; i < len; i++) { - res[i] = deepMap2(array1[i], array2, callback); - } - } - } - else if (array1 instanceof Matrix) { - if (array2 instanceof Matrix) { - // callback(matrix, matrix) - res = deepMap2(array1.valueOf(), array2.valueOf(), callback); - return new Matrix(res); - } - else { - // callback(matrix, array) - // callback(matrix, object) - res = deepMap2(array1.valueOf(), array2, callback); - return new Matrix(res); - } - } - else { - if (isArray(array2)) { - // callback(object, array) - res = []; - len = array2.length; - for (i = 0; i < len; i++) { - res[i] = deepMap2(array1, array2[i], callback); - } - } - else if (array2 instanceof Matrix) { - // callback(object, matrix) - res = deepMap2(array1, array2.valueOf(), callback); - return new Matrix(res); - } - else { - // callback(object, object) - res = callback(array1, array2); - } - } - - return res; - }; - - /** - * Reduce a given matrix or array to a new matrix or - * array with one less dimension, applying the given - * callback in the selected dimension. - * @param {Array | Matrix} mat - * @param {Number} dim - * @param {function} callback - * @return {Array | Matrix} res - */ - exports.reduce = function reduce (mat, dim, callback) { - if (mat instanceof Matrix) { - return new Matrix(_reduce(mat.valueOf(), dim, callback)); - }else { - return _reduce(mat, dim, callback); - } - }; - - /** - * Recursively reduce a matrix - * @param {Array} mat - * @param {Number} dim - * @param {Function} callback - * @returns {Array} ret - * @private - */ - function _reduce(mat, dim, callback){ - var i, ret, val, tran; - - if(dim<=0){ - if( !isArray(mat[0]) ){ - val = mat[0]; - for(i=1; i does not support a parameter of type '; - * @param {String} name Function name - * @param {*} [value1] - * @param {*...} [value_n] - * @extends TypeError - */ - // TODO: rename UnsupportedTypeError to TypeError? - error.UnsupportedTypeError = function UnsupportedTypeError(name, value1, value_n) { - if (!(this instanceof UnsupportedTypeError)) { - throw new SyntaxError('Constructor must be called with the new operator'); - } + // functions - complex + exports.arg = __webpack_require__(184); + exports.conj = __webpack_require__(185); + exports.re = __webpack_require__(186); + exports.im = __webpack_require__(187); - switch (arguments.length) { - case 0: - this.message = 'Unsupported type of argument'; - break; + // functions - construction + exports.bignumber = __webpack_require__(188); + exports['boolean'] = __webpack_require__(189); + exports.complex = __webpack_require__(190); + exports.index = __webpack_require__(191); + exports.matrix = __webpack_require__(192); + exports.number = __webpack_require__(193); + exports.string = __webpack_require__(194); + exports.unit = __webpack_require__(195); - case 1: - this.message = 'Unsupported type of argument in function ' + name; - break; + // functions - epxression + exports['eval'] = __webpack_require__(196); + exports.help = __webpack_require__(197); - case 2: - var type1 = math['typeof'](value1); - this.message = 'Function ' + name + '(' + type1 + ') not supported'; - break; + // functions - matrix + exports['concat'] = __webpack_require__(198); + exports.det = __webpack_require__(199); + exports.diag = __webpack_require__(200); + exports.eye = __webpack_require__(201); + exports.inv = __webpack_require__(202); + exports.ones = __webpack_require__(203); + exports.range = __webpack_require__(204); + exports.resize = __webpack_require__(205); + exports.size = __webpack_require__(206); + exports.squeeze = __webpack_require__(207); + exports.subset = __webpack_require__(208); + exports.transpose = __webpack_require__(209); + exports.zeros = __webpack_require__(210); - default: // more than two arguments - var values = Array.prototype.splice.call(arguments, 1); - var types = values.map(function (value) { - return math['typeof'](value); - }); - this.message = 'Function ' + name + '(' + types.join(', ') + ') not supported'; - break; - } + // functions - probability + exports.combinations = __webpack_require__(211); + exports.distribution = __webpack_require__(212); + exports.factorial = __webpack_require__(213); + exports.permutations = __webpack_require__(214); + exports.pickRandom = __webpack_require__(215); + exports.random = __webpack_require__(216); + exports.randomInt = __webpack_require__(217); - this.stack = (new Error()).stack; - }; + // functions - statistics + exports.max = __webpack_require__(218); + exports.mean = __webpack_require__(219); + exports.median = __webpack_require__(220); + exports.min = __webpack_require__(221); + exports.prod = __webpack_require__(222); + exports.std = __webpack_require__(223); + exports.sum = __webpack_require__(224); + exports['var'] = __webpack_require__(225); - error.UnsupportedTypeError.prototype = new TypeError(); - error.UnsupportedTypeError.prototype.constructor = TypeError; - error.UnsupportedTypeError.prototype.name = 'UnsupportedTypeError'; + // functions - trigonometry + exports.acos = __webpack_require__(226); + exports.asin = __webpack_require__(227); + exports.atan = __webpack_require__(228); + exports.atan2 = __webpack_require__(229); + exports.cos = __webpack_require__(230); + exports.cot = __webpack_require__(231); + exports.csc = __webpack_require__(232); + exports.sec = __webpack_require__(233); + exports.sin = __webpack_require__(234); + exports.tan = __webpack_require__(235); - /** - * Create a syntax error with the message: - * 'Wrong number of arguments in function ( provided, - expected)' - * @param {String} name Function name - * @param {Number} count Actual argument count - * @param {Number} min Minimum required argument count - * @param {Number} [max] Maximum required argument count - * @extends SyntaxError - */ - error.ArgumentsError = function ArgumentsError(name, count, min, max) { - if (!(this instanceof ArgumentsError)) { - throw new SyntaxError('Constructor must be called with the new operator'); - } + // functions - units + exports.to = __webpack_require__(236); - this.message = 'Wrong number of arguments in function ' + name + - ' (' + count + ' provided, ' + - min + ((max != undefined) ? ('-' + max) : '') + ' expected)'; + // functions - utils + exports.clone = __webpack_require__(237); + exports.map = __webpack_require__(238); + exports.forEach = __webpack_require__(239); + exports.format = __webpack_require__(240); + // exports.print = require('./function/utils/print'); // TODO: add documentation for print as soon as the parser supports objects. + exports.ifElse = __webpack_require__(241); + exports['import'] = __webpack_require__(242); + exports['typeof'] = __webpack_require__(243); - this.stack = (new Error()).stack; - }; - - error.ArgumentsError.prototype = new Error(); - error.ArgumentsError.prototype.constructor = Error; - error.ArgumentsError.prototype.name = 'ArgumentsError'; - - // TODO: implement a InvalidValueError? - - }; /***/ }, /* 16 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var string = __webpack_require__(127); + var string = __webpack_require__(132); /** * @constructor Selector @@ -4925,11 +4966,11 @@ return /******/ (function(modules) { // webpackBootstrap /* 17 */ /***/ function(module, exports, __webpack_require__) { - module.exports = function (math, settings) { - var util = __webpack_require__(112), - _parse = __webpack_require__(4), + module.exports = function (math, config) { + var util = __webpack_require__(117), + _parse = __webpack_require__(12), - collection = __webpack_require__(14), + collection = __webpack_require__(11), isString = util.string.isString, isCollection = collection.isCollection; @@ -4990,10 +5031,10 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), - _parse = __webpack_require__(4), + var util = __webpack_require__(117), + _parse = __webpack_require__(12), - collection = __webpack_require__(14), + collection = __webpack_require__(11), isString = util.string.isString, isCollection = collection.isCollection; @@ -5057,7 +5098,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var Help = __webpack_require__(13); + var Help = __webpack_require__(10); /** * Retrieve help on a function or data type. @@ -5113,8 +5154,8 @@ return /******/ (function(modules) { // webpackBootstrap /* 20 */ /***/ function(module, exports, __webpack_require__) { - module.exports = function (math, settings) { - var _parse = __webpack_require__(4); + module.exports = function (math, config) { + var _parse = __webpack_require__(12); /** * Parse an expression. @@ -5159,12 +5200,12 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - Matrix = __webpack_require__(11), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + Matrix = __webpack_require__(8), + collection = __webpack_require__(11), isNumber = util.number.isNumber, isBoolean = util['boolean'].isBoolean, @@ -5206,7 +5247,7 @@ return /******/ (function(modules) { // webpackBootstrap return Math.abs(x); } - throw new math.error.UnsupportedTypeError('abs', x); + throw new math.error.UnsupportedTypeError('abs', math['typeof'](x)); }; }; @@ -5216,18 +5257,16 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - Matrix = __webpack_require__(11), - Unit = __webpack_require__(12), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + Matrix = __webpack_require__(8), + Unit = __webpack_require__(9), + collection = __webpack_require__(11), isBoolean = util['boolean'].isBoolean, isNumber = util.number.isNumber, - toNumber = util.number.toNumber, - toBigNumber = util.number.toBigNumber, isString = util.string.isString, isComplex = Complex.isComplex, isUnit = Unit.isUnit, @@ -5305,7 +5344,7 @@ return /******/ (function(modules) { // webpackBootstrap if (x instanceof BigNumber) { // try to convert to big number if (isNumber(y)) { - y = toBigNumber(y); + y = BigNumber.convert(y); } else if (isBoolean(y)) { y = new BigNumber(y ? 1 : 0); @@ -5316,12 +5355,12 @@ return /******/ (function(modules) { // webpackBootstrap } // downgrade to Number - return add(toNumber(x), y); + return add(x.toNumber(), y); } if (y instanceof BigNumber) { // try to convert to big number if (isNumber(x)) { - x = toBigNumber(x); + x = BigNumber.convert(x); } else if (isBoolean(x)) { x = new BigNumber(x ? 1 : 0); @@ -5332,7 +5371,7 @@ return /******/ (function(modules) { // webpackBootstrap } // downgrade to Number - return add(x, toNumber(y)); + return add(x, y.toNumber()); } if (isString(x) || isString(y)) { @@ -5350,7 +5389,7 @@ return /******/ (function(modules) { // webpackBootstrap return add(x, +y); } - throw new math.error.UnsupportedTypeError('add', x, y); + throw new math.error.UnsupportedTypeError('add', math['typeof'](x), math['typeof'](y)); }; }; @@ -5360,11 +5399,11 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + collection = __webpack_require__(11), isNumber = util.number.isNumber, isBoolean = util['boolean'].isBoolean, @@ -5409,7 +5448,7 @@ return /******/ (function(modules) { // webpackBootstrap return Math.ceil(x); } - throw new math.error.UnsupportedTypeError('ceil', x); + throw new math.error.UnsupportedTypeError('ceil', math['typeof'](x)); }; }; @@ -5418,17 +5457,16 @@ return /******/ (function(modules) { // webpackBootstrap /* 24 */ /***/ function(module, exports, __webpack_require__) { - module.exports = function (math) { - var util = __webpack_require__(112), + module.exports = function (math, config) { + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - Unit = __webpack_require__(12), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + Unit = __webpack_require__(9), + collection = __webpack_require__(11), isNumber = util.number.isNumber, - toNumber = util.number.toNumber, - toBigNumber = util.number.toBigNumber, + nearlyEqual = util.number.nearlyEqual, isBoolean = util['boolean'].isBoolean, isString = util.string.isString, isComplex = Complex.isComplex, @@ -5441,6 +5479,10 @@ return /******/ (function(modules) { // webpackBootstrap * * compare(x, y) * + * x and y are considered equal when the relative difference between x and y + * is smaller than the configured epsilon. The function cannot be used to + * compare values smaller than approximately 2.22e-16. + * * @param {Number | BigNumber | Boolean | Unit | String | Array | Matrix} x * @param {Number | BigNumber | Boolean | Unit | String | Array | Matrix} y * @return {Number | BigNumber | Array | Matrix} res @@ -5451,13 +5493,13 @@ return /******/ (function(modules) { // webpackBootstrap } if (isNumber(x) && isNumber(y)) { - return (x > y) ? 1 : ((x < y) ? -1 : 0); + return nearlyEqual(x, y, config.epsilon) ? 0 : (x > y ? 1 : -1); } if (x instanceof BigNumber) { // try to convert to big number if (isNumber(y)) { - y = toBigNumber(y); + y = BigNumber.convert(y); } else if (isBoolean(y)) { y = new BigNumber(y ? 1 : 0); @@ -5468,12 +5510,12 @@ return /******/ (function(modules) { // webpackBootstrap } // downgrade to Number - return compare(toNumber(x), y); + return compare(x.toNumber(), y); } if (y instanceof BigNumber) { // try to convert to big number if (isNumber(x)) { - x = toBigNumber(x); + x = BigNumber.convert(x); } else if (isBoolean(x)) { x = new BigNumber(x ? 1 : 0); @@ -5484,7 +5526,7 @@ return /******/ (function(modules) { // webpackBootstrap } // downgrade to Number - return compare(x, toNumber(y)); + return compare(x, y.toNumber()); } if ((isUnit(x)) && (isUnit(y))) { @@ -5494,14 +5536,16 @@ return /******/ (function(modules) { // webpackBootstrap return (x.value > y.value) ? 1 : ((x.value < y.value) ? -1 : 0); } - if (isString(x) || isString(y)) { - return (x > y) ? 1 : ((x < y) ? -1 : 0); - } - if (isCollection(x) || isCollection(y)) { return collection.deepMap2(x, y, compare); } + // Note: test strings after testing collections, + // else we can't compare a string with a matrix + if (isString(x) || isString(y)) { + return (x > y) ? 1 : ((x < y) ? -1 : 0); + } + if (isBoolean(x)) { return compare(+x, y); } @@ -5513,7 +5557,7 @@ return /******/ (function(modules) { // webpackBootstrap throw new TypeError('No ordering relation is defined for complex numbers'); } - throw new math.error.UnsupportedTypeError('compare', x, y); + throw new math.error.UnsupportedTypeError('compare', math['typeof'](x), math['typeof'](y)); }; }; @@ -5523,11 +5567,11 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + collection = __webpack_require__(11), isNumber = util.number.isNumber, isBoolean = util['boolean'].isBoolean, @@ -5570,7 +5614,7 @@ return /******/ (function(modules) { // webpackBootstrap return cube(+x); } - throw new math.error.UnsupportedTypeError('cube', x); + throw new math.error.UnsupportedTypeError('cube', math['typeof'](x)); }; }; @@ -5580,17 +5624,15 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports, __webpack_require__) { module.exports = function(math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - Matrix = __webpack_require__(11), - Unit = __webpack_require__(12), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + Matrix = __webpack_require__(8), + Unit = __webpack_require__(9), + collection = __webpack_require__(11), isNumber = util.number.isNumber, - toNumber = util.number.toNumber, - toBigNumber = util.number.toBigNumber, isBoolean = util['boolean'].isBoolean, isComplex = Complex.isComplex, isUnit = Unit.isUnit, @@ -5636,7 +5678,7 @@ return /******/ (function(modules) { // webpackBootstrap if (x instanceof BigNumber) { // try to convert to big number if (isNumber(y)) { - y = toBigNumber(y); + y = BigNumber.convert(y); } else if (isBoolean(y)) { y = new BigNumber(y ? 1 : 0); @@ -5647,12 +5689,12 @@ return /******/ (function(modules) { // webpackBootstrap } // downgrade to Number - return divide(toNumber(x), y); + return divide(x.toNumber(), y); } if (y instanceof BigNumber) { // try to convert to big number if (isNumber(x)) { - x = toBigNumber(x); + x = BigNumber.convert(x); } else if (isBoolean(x)) { x = new BigNumber(x ? 1 : 0); @@ -5663,7 +5705,7 @@ return /******/ (function(modules) { // webpackBootstrap } // downgrade to Number - return divide(x, toNumber(y)); + return divide(x, y.toNumber()); } if (isUnit(x)) { @@ -5700,7 +5742,7 @@ return /******/ (function(modules) { // webpackBootstrap return divide(x, +y); } - throw new math.error.UnsupportedTypeError('divide', x, y); + throw new math.error.UnsupportedTypeError('divide', math['typeof'](x), math['typeof'](y)); }; /** @@ -5734,7 +5776,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var collection = __webpack_require__(14); + var collection = __webpack_require__(11); /** * Divide two values element wise. @@ -5761,7 +5803,8 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var collection = __webpack_require__(14); + var util = __webpack_require__(117), + collection = __webpack_require__(11); /** * Multiply two values element wise. @@ -5788,7 +5831,8 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var collection = __webpack_require__(14); + var util = __webpack_require__(117), + collection = __webpack_require__(11); /** * Calculates the power of x to y element wise @@ -5814,17 +5858,16 @@ return /******/ (function(modules) { // webpackBootstrap /* 30 */ /***/ function(module, exports, __webpack_require__) { - module.exports = function (math) { - var util = __webpack_require__(112), + module.exports = function (math, config) { + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - Unit = __webpack_require__(12), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + Unit = __webpack_require__(9), + collection = __webpack_require__(11), isNumber = util.number.isNumber, - toNumber = util.number.toNumber, - toBigNumber = util.number.toBigNumber, + nearlyEqual = util.number.nearlyEqual, isBoolean = util['boolean'].isBoolean, isString = util.string.isString, isComplex = Complex.isComplex, @@ -5840,6 +5883,10 @@ return /******/ (function(modules) { // webpackBootstrap * For matrices, the function is evaluated element wise. * In case of complex numbers, x.re must equal y.re, and x.im must equal y.im. * + * The function checks whether the relative difference between x and y is + * smaller than the configured epsilon. The function cannot be used to + * compare values smaller than approximately 2.22e-16. + * * @param {Number | BigNumber | Boolean | Complex | Unit | String | Array | Matrix} x * @param {Number | BigNumber | Boolean | Complex | Unit | String | Array | Matrix} y * @return {Boolean | Array | Matrix} res @@ -5851,26 +5898,26 @@ return /******/ (function(modules) { // webpackBootstrap if (isNumber(x)) { if (isNumber(y)) { - return x == y; + return nearlyEqual(x, y, config.epsilon); } else if (isComplex(y)) { - return (x == y.re) && (y.im == 0); + return nearlyEqual(x, y.re, config.epsilon) && nearlyEqual(y.im, 0, config.epsilon); } } if (isComplex(x)) { if (isNumber(y)) { - return (x.re == y) && (x.im == 0); + return nearlyEqual(x.re, y, config.epsilon) && nearlyEqual(x.im, 0, config.epsilon); } else if (isComplex(y)) { - return (x.re == y.re) && (x.im == y.im); + return nearlyEqual(x.re, y.re, config.epsilon) && nearlyEqual(x.im, y.im, config.epsilon); } } if (x instanceof BigNumber) { // try to convert to big number if (isNumber(y)) { - y = toBigNumber(y); + y = BigNumber.convert(y); } else if (isBoolean(y)) { y = new BigNumber(y ? 1 : 0); @@ -5881,12 +5928,12 @@ return /******/ (function(modules) { // webpackBootstrap } // downgrade to Number - return equal(toNumber(x), y); + return equal(x.toNumber(), y); } if (y instanceof BigNumber) { // try to convert to big number if (isNumber(x)) { - x = toBigNumber(x); + x = BigNumber.convert(x); } else if (isBoolean(x)) { x = new BigNumber(x ? 1 : 0); @@ -5897,7 +5944,7 @@ return /******/ (function(modules) { // webpackBootstrap } // downgrade to Number - return equal(x, toNumber(y)); + return equal(x, y.toNumber()); } if ((isUnit(x)) && (isUnit(y))) { @@ -5907,14 +5954,16 @@ return /******/ (function(modules) { // webpackBootstrap return x.value == y.value; } - if (isString(x) || isString(y)) { - return x == y; - } - if (isCollection(x) || isCollection(y)) { return collection.deepMap2(x, y, equal); } + // Note: test strings after testing collections, + // else we can't compare a string with a matrix + if (isString(x) || isString(y)) { + return x == y; + } + if (isBoolean(x)) { return equal(+x, y); } @@ -5922,7 +5971,7 @@ return /******/ (function(modules) { // webpackBootstrap return equal(x, +y); } - throw new math.error.UnsupportedTypeError('equal', x, y); + throw new math.error.UnsupportedTypeError('equal', math['typeof'](x), math['typeof'](y)); }; }; @@ -5932,12 +5981,12 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - Matrix = __webpack_require__(11), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + Matrix = __webpack_require__(8), + collection = __webpack_require__(11), isNumber = util.number.isNumber, isBoolean = util['boolean'].isBoolean, @@ -5951,8 +6000,8 @@ return /******/ (function(modules) { // webpackBootstrap * * For matrices, the function is evaluated element wise. * - * @param {Number | Boolean | Complex | Array | Matrix} x - * @return {Number | Complex | Array | Matrix} res + * @param {Number | BigNumber | Boolean | Complex | Array | Matrix} x + * @return {Number | BigNumber | Complex | Array | Matrix} res */ math.exp = function exp (x) { if (arguments.length != 1) { @@ -5972,9 +6021,7 @@ return /******/ (function(modules) { // webpackBootstrap } if (x instanceof BigNumber) { - // TODO: implement BigNumber support - // downgrade to Number - return exp(util.number.toNumber(x)); + return x.exp(); } if (isCollection(x)) { @@ -5985,7 +6032,7 @@ return /******/ (function(modules) { // webpackBootstrap return Math.exp(x); } - throw new math.error.UnsupportedTypeError('exp', x); + throw new math.error.UnsupportedTypeError('exp', math['typeof'](x)); }; }; @@ -5995,11 +6042,11 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + collection = __webpack_require__(11), isNumber = util.number.isNumber, isBoolean = util['boolean'].isBoolean, @@ -6044,7 +6091,7 @@ return /******/ (function(modules) { // webpackBootstrap return fix(+x); } - throw new math.error.UnsupportedTypeError('fix', x); + throw new math.error.UnsupportedTypeError('fix', math['typeof'](x)); }; }; @@ -6054,11 +6101,11 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + collection = __webpack_require__(11), isNumber = util.number.isNumber, isBoolean = util['boolean'].isBoolean, @@ -6103,7 +6150,7 @@ return /******/ (function(modules) { // webpackBootstrap return floor(+x); } - throw new math.error.UnsupportedTypeError('floor', x); + throw new math.error.UnsupportedTypeError('floor', math['typeof'](x)); }; }; @@ -6113,13 +6160,12 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + collection = __webpack_require__(11), isNumber = util.number.isNumber, - toNumber = util.number.toNumber, isBoolean = util['boolean'].isBoolean, isInteger = util.number.isInteger, isCollection = collection.isCollection; @@ -6165,10 +6211,10 @@ return /******/ (function(modules) { // webpackBootstrap // downgrade bignumbers to numbers if (a instanceof BigNumber) { - return gcd(toNumber(a), b); + return gcd(a.toNumber(), b); } if (b instanceof BigNumber) { - return gcd(a, toNumber(b)); + return gcd(a, b.toNumber()); } if (isBoolean(a)) { @@ -6178,7 +6224,7 @@ return /******/ (function(modules) { // webpackBootstrap return gcd(a, +b); } - throw new math.error.UnsupportedTypeError('gcd', a, b); + throw new math.error.UnsupportedTypeError('gcd', math['typeof'](a), math['typeof'](b)); } if (arguments.length > 2) { @@ -6199,17 +6245,16 @@ return /******/ (function(modules) { // webpackBootstrap /* 35 */ /***/ function(module, exports, __webpack_require__) { - module.exports = function (math) { - var util = __webpack_require__(112), + module.exports = function (math, config) { + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - Unit = __webpack_require__(12), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + Unit = __webpack_require__(9), + collection = __webpack_require__(11), isNumber = util.number.isNumber, - toNumber = util.number.toNumber, - toBigNumber = util.number.toBigNumber, + nearlyEqual = util.number.nearlyEqual, isBoolean = util['boolean'].isBoolean, isString = util.string.isString, isComplex = Complex.isComplex, @@ -6224,6 +6269,10 @@ return /******/ (function(modules) { // webpackBootstrap * * For matrices, the function is evaluated element wise. * + * The function returns true when x is larger than y and the relative + * difference between x and y is larger than the configured epsilon. The + * function cannot be used to compare values smaller than approximately 2.22e-16. + * * @param {Number | BigNumber | Boolean | Unit | String | Array | Matrix} x * @param {Number | BigNumber | Boolean | Unit | String | Array | Matrix} y * @return {Boolean | Array | Matrix} res @@ -6234,13 +6283,13 @@ return /******/ (function(modules) { // webpackBootstrap } if (isNumber(x) && isNumber(y)) { - return x > y; + return !nearlyEqual(x, y, config.epsilon) && x > y; } if (x instanceof BigNumber) { // try to convert to big number if (isNumber(y)) { - y = toBigNumber(y); + y = BigNumber.convert(y); } else if (isBoolean(y)) { y = new BigNumber(y ? 1 : 0); @@ -6251,12 +6300,12 @@ return /******/ (function(modules) { // webpackBootstrap } // downgrade to Number - return larger(toNumber(x), y); + return larger(x.toNumber(), y); } if (y instanceof BigNumber) { // try to convert to big number if (isNumber(x)) { - x = toBigNumber(x); + x = BigNumber.convert(x); } else if (isBoolean(x)) { x = new BigNumber(x ? 1 : 0); @@ -6267,7 +6316,7 @@ return /******/ (function(modules) { // webpackBootstrap } // downgrade to Number - return larger(x, toNumber(y)); + return larger(x, y.toNumber()); } if ((isUnit(x)) && (isUnit(y))) { @@ -6277,14 +6326,16 @@ return /******/ (function(modules) { // webpackBootstrap return x.value > y.value; } - if (isString(x) || isString(y)) { - return x > y; - } - if (isCollection(x) || isCollection(y)) { return collection.deepMap2(x, y, larger); } + // Note: test strings after testing collections, + // else we can't compare a string with a matrix + if (isString(x) || isString(y)) { + return x > y; + } + if (isBoolean(x)) { return larger(+x, y); } @@ -6296,7 +6347,7 @@ return /******/ (function(modules) { // webpackBootstrap throw new TypeError('No ordering relation is defined for complex numbers'); } - throw new math.error.UnsupportedTypeError('larger', x, y); + throw new math.error.UnsupportedTypeError('larger', math['typeof'](x), math['typeof'](y)); }; }; @@ -6305,17 +6356,16 @@ return /******/ (function(modules) { // webpackBootstrap /* 36 */ /***/ function(module, exports, __webpack_require__) { - module.exports = function (math) { - var util = __webpack_require__(112), + module.exports = function (math, config) { + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - Unit = __webpack_require__(12), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + Unit = __webpack_require__(9), + collection = __webpack_require__(11), isNumber = util.number.isNumber, - toNumber = util.number.toNumber, - toBigNumber = util.number.toBigNumber, + nearlyEqual = util.number.nearlyEqual, isBoolean = util['boolean'].isBoolean, isString = util.string.isString, isComplex = Complex.isComplex, @@ -6330,6 +6380,10 @@ return /******/ (function(modules) { // webpackBootstrap * * For matrices, the function is evaluated element wise. * + * The function returns true when x is larger than y or the relative + * difference between x and y is smaller than the configured epsilon. The + * function cannot be used to compare values smaller than approximately 2.22e-16. + * * @param {Number | BigNumber | Boolean | Unit | String | Array | Matrix} x * @param {Number | BigNumber | Boolean | Unit | String | Array | Matrix} y * @return {Boolean | Array | Matrix} res @@ -6340,13 +6394,13 @@ return /******/ (function(modules) { // webpackBootstrap } if (isNumber(x) && isNumber(y)) { - return x >= y; + return nearlyEqual(x, y, config.epsilon) || x > y; } if (x instanceof BigNumber) { // try to convert to big number if (isNumber(y)) { - y = toBigNumber(y); + y = BigNumber.convert(y); } else if (isBoolean(y)) { y = new BigNumber(y ? 1 : 0); @@ -6357,12 +6411,12 @@ return /******/ (function(modules) { // webpackBootstrap } // downgrade to Number - return largereq(toNumber(x), y); + return largereq(x.toNumber(), y); } if (y instanceof BigNumber) { // try to convert to big number if (isNumber(x)) { - x = toBigNumber(x); + x = BigNumber.convert(x); } else if (isBoolean(x)) { x = new BigNumber(x ? 1 : 0); @@ -6373,7 +6427,7 @@ return /******/ (function(modules) { // webpackBootstrap } // downgrade to Number - return largereq(x, toNumber(y)); + return largereq(x, y.toNumber()); } if ((isUnit(x)) && (isUnit(y))) { @@ -6383,14 +6437,16 @@ return /******/ (function(modules) { // webpackBootstrap return x.value >= y.value; } - if (isString(x) || isString(y)) { - return x >= y; - } - if (isCollection(x) || isCollection(y)) { return collection.deepMap2(x, y, largereq); } + // Note: test strings after testing collections, + // else we can't compare a string with a matrix + if (isString(x) || isString(y)) { + return x >= y; + } + if (isBoolean(x)) { return largereq(+x, y); } @@ -6402,7 +6458,7 @@ return /******/ (function(modules) { // webpackBootstrap throw new TypeError('No ordering relation is defined for complex numbers'); } - throw new math.error.UnsupportedTypeError('largereq', x, y); + throw new math.error.UnsupportedTypeError('largereq', math['typeof'](x), math['typeof'](y)); }; }; @@ -6412,13 +6468,12 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + collection = __webpack_require__(11), isNumber = util.number.isNumber, - toNumber = util.number.toNumber, isBoolean = util['boolean'].isBoolean, isInteger = util.number.isInteger, isCollection = collection.isCollection; @@ -6480,13 +6535,13 @@ return /******/ (function(modules) { // webpackBootstrap // downgrade bignumbers to numbers if (a instanceof BigNumber) { - return lcm(toNumber(a), b); + return lcm(a.toNumber(), b); } if (b instanceof BigNumber) { - return lcm(a, toNumber(b)); + return lcm(a, b.toNumber()); } - throw new math.error.UnsupportedTypeError('lcm', a, b); + throw new math.error.UnsupportedTypeError('lcm', math['typeof'](a), math['typeof'](b)); } if (arguments.length > 2) { @@ -6508,11 +6563,11 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + collection = __webpack_require__(11), isNumber = util.number.isNumber, isBoolean = util['boolean'].isBoolean, @@ -6528,9 +6583,9 @@ return /******/ (function(modules) { // webpackBootstrap * base is optional. If not provided, the natural logarithm of x is calculated. * For matrices, the function is evaluated element wise. * - * @param {Number | Boolean | Complex | Array | Matrix} x - * @param {Number | Boolean | Complex} [base] - * @return {Number | Complex | Array | Matrix} res + * @param {Number | BigNumber | Boolean | Complex | Array | Matrix} x + * @param {Number | BigNumber | Boolean | Complex} [base] + * @return {Number | BigNumber | Complex | Array | Matrix} res */ math.log = function log(x, base) { if (arguments.length == 1) { @@ -6553,9 +6608,7 @@ return /******/ (function(modules) { // webpackBootstrap } if (x instanceof BigNumber) { - // TODO: implement BigNumber support - // downgrade to Number - return log(util.number.toNumber(x)); + return x.ln(); } if (isCollection(x)) { @@ -6566,7 +6619,7 @@ return /******/ (function(modules) { // webpackBootstrap return log(+x); } - throw new math.error.UnsupportedTypeError('log', x); + throw new math.error.UnsupportedTypeError('log', math['typeof'](x)); } else if (arguments.length == 2) { // calculate logarithm for a specified base, log(x, base) @@ -6584,11 +6637,11 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + collection = __webpack_require__(11), isNumber = util.number.isNumber, isBoolean = util['boolean'].isBoolean, @@ -6602,8 +6655,8 @@ return /******/ (function(modules) { // webpackBootstrap * * For matrices, the function is evaluated element wise. * - * @param {Number | Boolean | Complex | Array | Matrix} x - * @return {Number | Complex | Array | Matrix} res + * @param {Number | BigNumber | Boolean | Complex | Array | Matrix} x + * @return {Number | BigNumber | Complex | Array | Matrix} res */ math.log10 = function log10(x) { if (arguments.length != 1) { @@ -6621,9 +6674,7 @@ return /******/ (function(modules) { // webpackBootstrap } if (x instanceof BigNumber) { - // TODO: implement BigNumber support - // downgrade to Number - return log10(util.number.toNumber(x)); + return x.log(); } if (isComplex(x)) { @@ -6641,7 +6692,7 @@ return /******/ (function(modules) { // webpackBootstrap return log10(+x); } - throw new math.error.UnsupportedTypeError('log10', x); + throw new math.error.UnsupportedTypeError('log10', math['typeof'](x)); }; }; @@ -6651,14 +6702,12 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + collection = __webpack_require__(11), isNumber = util.number.isNumber, - toNumber = util.number.toNumber, - toBigNumber = util.number.toBigNumber, isBoolean = util['boolean'].isBoolean, isCollection = collection.isCollection; @@ -6691,34 +6740,34 @@ return /******/ (function(modules) { // webpackBootstrap if (x instanceof BigNumber) { // try to convert to big number if (isNumber(y)) { - y = toBigNumber(y); + y = BigNumber.convert(y); } else if (isBoolean(y)) { y = new BigNumber(y ? 1 : 0); } if (y instanceof BigNumber) { - return x.mod(y); + return y.isZero() ? x : x.mod(y); } - // downgrade to Number - return mod(toNumber(x), y); + // downgrade x to Number + return mod(x.toNumber(), y); } if (y instanceof BigNumber) { // try to convert to big number if (isNumber(x)) { - x = toBigNumber(x); + x = BigNumber.convert(x); } else if (isBoolean(x)) { x = new BigNumber(x ? 1 : 0); } if (x instanceof BigNumber) { - return x.mod(y) + return y.isZero() ? x : x.mod(y); } - // downgrade to Number - return mod(x, toNumber(y)); + // downgrade y to Number + return mod(x, y.toNumber()); } // TODO: implement mod for complex values @@ -6734,7 +6783,7 @@ return /******/ (function(modules) { // webpackBootstrap return mod(x, +y); } - throw new math.error.UnsupportedTypeError('mod', x, y); + throw new math.error.UnsupportedTypeError('mod', math['typeof'](x), math['typeof'](y)); }; /** @@ -6772,18 +6821,16 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports, __webpack_require__) { module.exports = function(math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - Matrix = __webpack_require__(11), - Unit = __webpack_require__(12), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + Matrix = __webpack_require__(8), + Unit = __webpack_require__(9), + collection = __webpack_require__(11), array = util.array, isNumber = util.number.isNumber, - toNumber = util.number.toNumber, - toBigNumber = util.number.toBigNumber, isBoolean = util['boolean'].isBoolean, isComplex = Complex.isComplex, isArray = Array.isArray, @@ -6800,6 +6847,8 @@ return /******/ (function(modules) { // webpackBootstrap * @return {Number | BigNumber | Complex | Unit | Array | Matrix} res */ math.multiply = function multiply(x, y) { + var res; + if (arguments.length != 2) { throw new math.error.ArgumentsError('multiply', arguments.length, 2); } @@ -6834,7 +6883,7 @@ return /******/ (function(modules) { // webpackBootstrap if (x instanceof BigNumber) { // try to convert to big number if (isNumber(y)) { - y = toBigNumber(y); + y = BigNumber.convert(y); } else if (isBoolean(y)) { y = new BigNumber(y ? 1 : 0); @@ -6845,12 +6894,12 @@ return /******/ (function(modules) { // webpackBootstrap } // downgrade to Number - return multiply(toNumber(x), y); + return multiply(x.toNumber(), y); } if (y instanceof BigNumber) { // try to convert to big number if (isNumber(x)) { - x = toBigNumber(x); + x = BigNumber.convert(x); } else if (isBoolean(x)) { x = new BigNumber(x ? 1 : 0); @@ -6861,7 +6910,7 @@ return /******/ (function(modules) { // webpackBootstrap } // downgrade to Number - return multiply(x, toNumber(y)); + return multiply(x, y.toNumber()); } if (isUnit(x)) { @@ -6882,7 +6931,7 @@ return /******/ (function(modules) { // webpackBootstrap if (sizeY.length == 1) { // vector * vector if (sizeX[0] != sizeY[0]) { - throw new RangeError('Dimensions mismatch in multiplication. ' + + throw new RangeError('Dimension mismatch in multiplication. ' + 'Length of A must match length of B ' + '(A is ' + sizeX[0] + ', B is ' + sizeY[0] + @@ -6894,7 +6943,7 @@ return /******/ (function(modules) { // webpackBootstrap else if (sizeY.length == 2) { // vector * matrix if (sizeX[0] != sizeY[0]) { - throw new RangeError('Dimensions mismatch in multiplication. ' + + throw new RangeError('Dimension mismatch in multiplication. ' + 'Length of A must match rows of B ' + '(A is ' + sizeX[0] + ', B is ' + sizeY[0] + 'x' + sizeY[1] + ', ' + @@ -6912,7 +6961,7 @@ return /******/ (function(modules) { // webpackBootstrap if (sizeY.length == 1) { // matrix * vector if (sizeX[1] != sizeY[0]) { - throw new RangeError('Dimensions mismatch in multiplication. ' + + throw new RangeError('Dimension mismatch in multiplication. ' + 'Columns of A must match length of B ' + '(A is ' + sizeX[0] + 'x' + sizeX[0] + ', B is ' + sizeY[0] + ', ' + @@ -6924,7 +6973,7 @@ return /******/ (function(modules) { // webpackBootstrap else if (sizeY.length == 2) { // matrix * matrix if (sizeX[1] != sizeY[0]) { - throw new RangeError('Dimensions mismatch in multiplication. ' + + throw new RangeError('Dimension mismatch in multiplication. ' + 'Columns of A must match rows of B ' + '(A is ' + sizeX[0] + 'x' + sizeX[1] + ', B is ' + sizeY[0] + 'x' + sizeY[1] + ', ' + @@ -6981,7 +7030,7 @@ return /******/ (function(modules) { // webpackBootstrap return multiply(x, +y); } - throw new math.error.UnsupportedTypeError('multiply', x, y); + throw new math.error.UnsupportedTypeError('multiply', math['typeof'](x), math['typeof'](y)); }; /** @@ -7176,17 +7225,174 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - Matrix = __webpack_require__(11), - collection = __webpack_require__(14), + array = __webpack_require__(147), + + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + Matrix = __webpack_require__(8), + collection = __webpack_require__(11), + + isNumber = util.number.isNumber, + isBoolean = util['boolean'].isBoolean, + isComplex = Complex.isComplex, + isCollection = collection.isCollection; + + /** + * Calculate the norm of a number, vector or matrix. + * + * norm(x) + * norm(x, p) + * + * p is optional. If not provided, defaults to 2 (The Frobenius norm or 'fro')). + * + * @param {Number | BigNumber | Complex | Boolean | Array | Matrix} x + * @param {Number | Infinity | -Infinity, 'inf', '-inf', 'fro'} [p] + * @return {Number} the p-norm + */ + math.norm = function norm(x, p) { + if (arguments.length < 1 || arguments.length > 2) { + throw new math.error.ArgumentsError('abs', arguments.length, 1, 2); + } + + if (isNumber(x)) { + // norm(x) = abs(x) + return Math.abs(x); + } + + if (isComplex(x)) { + // ignore p, complex numbers + return Math.sqrt(x.re * x.re + x.im * x.im); + } + + if (x instanceof BigNumber) { + // norm(x) = abs(x) + return x.abs(); + } + + if (isBoolean(x)) { + // norm(x) = abs(x) + return Math.abs(x); + } + + if (isArray(x)) { + // size + var sizeX = array.size(x); + // p + p = p || 2; + // check it is a Vector + if (sizeX.length == 1) { + // check p + if (p === Number.POSITIVE_INFINITY || p === 'inf') { + // norm(x, Infinity) = max(abs(x)) + var n; + math.forEach(x, function (value) { + var v = math.abs(value); + if (!n || math.larger(v, n)) + n = v; + }); + return n; + } + if (p === Number.NEGATIVE_INFINITY || p === '-inf') { + // norm(x, -Infinity) = min(abs(x)) + var n; + math.forEach(x, function (value) { + var v = math.abs(value); + if (!n || math.smaller(v, n)) + n = v; + }); + return n; + } + if (p === 'fro') + return norm(x); + if (isNumber(p) && !isNaN(p)) { + // check p != 0 + if (!math.equal(p, 0)) { + // norm(x, p) = sum(abs(xi) ^ p) ^ 1/p + var n = 0; + math.forEach(x, function (value) { + n = math.add(math.pow(math.abs(value), p), n); + }); + return math.pow(n, 1 / p); + } + return Number.POSITIVE_INFINITY; + } + // invalid parameter value + throw new Error('Unsupported parameter value'); + } + else if (sizeX.length == 2) { + // check p + if (p == 1) { + // norm(x) = the largest column sum + var c = []; + // loop rows + for (var i = 0; i < x.length; i++) { + var r = x[i]; + // loop columns + for (var j = 0; j < r.length; j++) { + c[j] = math.add(c[j] || 0, math.abs(r[j])); + } + } + return math.max(c); + } + if (p == Number.POSITIVE_INFINITY || p === 'inf') { + // norm(x) = the largest row sum + var n = 0; + // loop rows + for (var i = 0; i < x.length; i++) { + var rs = 0; + var r = x[i]; + // loop columns + for (var j = 0; j < r.length; j++) { + rs = math.add(rs, math.abs(r[j])); + } + if (math.larger(rs, n)) + n = rs; + } + return n; + } + if (p === 'fro') { + // norm(x) = sqrt(sum(diag(x'x))) + var d = math.diag(math.multiply(math.transpose(x), x)); + var s = 0; + math.forEach(d, function (value) { + s = math.add(value, s); + }); + return math.sqrt(s); + } + if (p == 2) { + // not implemented + throw new Error('Unsupported parameter value, missing implementation of matrix singular value decomposition'); + } + // invalid parameter value + throw new Error('Unsupported parameter value'); + } + } + + if (x instanceof Matrix) { + return norm(x.valueOf(), p); + } + + throw new math.error.UnsupportedTypeError('norm', x); + }; + }; + + +/***/ }, +/* 43 */ +/***/ function(module, exports, __webpack_require__) { + + module.exports = function (math) { + var util = __webpack_require__(117), + + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + Matrix = __webpack_require__(8), + collection = __webpack_require__(11), array = util.array, isNumber = util.number.isNumber, - toNumber = util.number.toNumber, - toBigNumber = util.number.toBigNumber, isBoolean = util['boolean'].isBoolean, isArray = Array.isArray, isInteger = util.number.isInteger, @@ -7231,12 +7437,10 @@ return /******/ (function(modules) { // webpackBootstrap } } - // TODO: pow for complex numbers and bignumbers - if (x instanceof BigNumber) { // try to convert to big number if (isNumber(y)) { - y = toBigNumber(y); + y = BigNumber.convert(y); } else if (isBoolean(y)) { y = new BigNumber(y ? 1 : 0); @@ -7247,12 +7451,12 @@ return /******/ (function(modules) { // webpackBootstrap } // downgrade to Number - return pow(toNumber(x), y); + return pow(x.toNumber(), y); } if (y instanceof BigNumber) { // try to convert to big number if (isNumber(x)) { - x = toBigNumber(x); + x = BigNumber.convert(x); } else if (isBoolean(x)) { x = new BigNumber(x ? 1 : 0); @@ -7263,7 +7467,7 @@ return /******/ (function(modules) { // webpackBootstrap } // downgrade to Number - return pow(x, toNumber(y)); + return pow(x, y.toNumber()); } @@ -7306,7 +7510,7 @@ return /******/ (function(modules) { // webpackBootstrap return pow(x, +y); } - throw new math.error.UnsupportedTypeError('pow', x, y); + throw new math.error.UnsupportedTypeError('pow', math['typeof'](x), math['typeof'](y)); }; /** @@ -7327,15 +7531,15 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 43 */ +/* 44 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + collection = __webpack_require__(11), isNumber = util.number.isNumber, isInteger = util.number.isInteger, @@ -7375,7 +7579,7 @@ return /******/ (function(modules) { // webpackBootstrap } if (x instanceof BigNumber) { - return x.round(); + return x.toDecimalPlaces(0); } if (isCollection(x)) { @@ -7386,7 +7590,7 @@ return /******/ (function(modules) { // webpackBootstrap return Math.round(x); } - throw new math.error.UnsupportedTypeError('round', x); + throw new math.error.UnsupportedTypeError('round', math['typeof'](x)); } else { // round (x, n) @@ -7417,7 +7621,7 @@ return /******/ (function(modules) { // webpackBootstrap } if (x instanceof BigNumber) { - return x.round(n); + return x.toDecimalPlaces(n); } if (isCollection(x) || isCollection(n)) { @@ -7428,7 +7632,7 @@ return /******/ (function(modules) { // webpackBootstrap return round(+x, n); } - throw new math.error.UnsupportedTypeError('round', x, n); + throw new math.error.UnsupportedTypeError('round', math['typeof'](x), math['typeof'](n)); } }; @@ -7447,15 +7651,15 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 44 */ +/* 45 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + collection = __webpack_require__(11), number = util.number, isNumber = util.number.isNumber, @@ -7500,26 +7704,25 @@ return /******/ (function(modules) { // webpackBootstrap return number.sign(x); } - throw new math.error.UnsupportedTypeError('sign', x); + throw new math.error.UnsupportedTypeError('sign', math['typeof'](x)); }; }; /***/ }, -/* 45 */ +/* 46 */ /***/ function(module, exports, __webpack_require__) { - module.exports = function (math) { - var util = __webpack_require__(112), + module.exports = function (math, config) { + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - Unit = __webpack_require__(12), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + Unit = __webpack_require__(9), + collection = __webpack_require__(11), isNumber = util.number.isNumber, - toNumber = util.number.toNumber, - toBigNumber = util.number.toBigNumber, + nearlyEqual = util.number.nearlyEqual, isBoolean = util['boolean'].isBoolean, isString = util.string.isString, isComplex = Complex.isComplex, @@ -7534,6 +7737,10 @@ return /******/ (function(modules) { // webpackBootstrap * * For matrices, the function is evaluated element wise. * + * The function returns true when x is smaller than y and the relative + * difference between x and y is larger than the configured epsilon. The + * function cannot be used to compare values smaller than approximately 2.22e-16. + * * @param {Number | BigNumber | Boolean | Unit | String | Array | Matrix} x * @param {Number | BigNumber | Boolean | Unit | String | Array | Matrix} y * @return {Boolean | Array | Matrix} res @@ -7544,13 +7751,13 @@ return /******/ (function(modules) { // webpackBootstrap } if (isNumber(x) && isNumber(y)) { - return x < y; + return !nearlyEqual(x, y, config.epsilon) && x < y; } if (x instanceof BigNumber) { // try to convert to big number if (isNumber(y)) { - y = toBigNumber(y); + y = BigNumber.convert(y); } else if (isBoolean(y)) { y = new BigNumber(y ? 1 : 0); @@ -7561,12 +7768,12 @@ return /******/ (function(modules) { // webpackBootstrap } // downgrade to Number - return smaller(toNumber(x), y); + return smaller(x.toNumber(), y); } if (y instanceof BigNumber) { // try to convert to big number if (isNumber(x)) { - x = toBigNumber(x); + x = BigNumber.convert(x); } else if (isBoolean(x)) { x = new BigNumber(x ? 1 : 0); @@ -7577,7 +7784,7 @@ return /******/ (function(modules) { // webpackBootstrap } // downgrade to Number - return smaller(x, toNumber(y)); + return smaller(x, y.toNumber()); } if ((isUnit(x)) && (isUnit(y))) { @@ -7587,14 +7794,16 @@ return /******/ (function(modules) { // webpackBootstrap return x.value < y.value; } - if (isString(x) || isString(y)) { - return x < y; - } - if (isCollection(x) || isCollection(y)) { return collection.deepMap2(x, y, smaller); } + // Note: test strings after testing collections, + // else we can't compare a string with a matrix + if (isString(x) || isString(y)) { + return x < y; + } + if (isBoolean(x)) { return smaller(+x, y); } @@ -7606,26 +7815,25 @@ return /******/ (function(modules) { // webpackBootstrap throw new TypeError('No ordering relation is defined for complex numbers'); } - throw new math.error.UnsupportedTypeError('smaller', x, y); + throw new math.error.UnsupportedTypeError('smaller', math['typeof'](x), math['typeof'](y)); }; }; /***/ }, -/* 46 */ +/* 47 */ /***/ function(module, exports, __webpack_require__) { - module.exports = function (math) { - var util = __webpack_require__(112), + module.exports = function (math, config) { + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - Unit = __webpack_require__(12), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + Unit = __webpack_require__(9), + collection = __webpack_require__(11), isNumber = util.number.isNumber, - toNumber = util.number.toNumber, - toBigNumber = util.number.toBigNumber, + nearlyEqual = util.number.nearlyEqual, isBoolean = util['boolean'].isBoolean, isString = util.string.isString, isComplex = Complex.isComplex, @@ -7633,13 +7841,17 @@ return /******/ (function(modules) { // webpackBootstrap isCollection = collection.isCollection; /** - * Check if value a is smaller or equal to b + * Check if value x is smaller or equal to y * - * a <= b - * smallereq(a, b) + * x <= y + * smallereq(x, y) * * For matrices, the function is evaluated element wise. * + * The function returns true when x is smaller than y or the relative + * difference between x and y is smaller than the configured epsilon. The + * function cannot be used to compare values smaller than approximately 2.22e-16. + * * @param {Number | BigNumber | Boolean | Complex | Unit | String | Array | Matrix} x * @param {Number | BigNumber | Boolean | Complex | Unit | String | Array | Matrix} y * @return {Boolean | Array | Matrix} res @@ -7650,13 +7862,13 @@ return /******/ (function(modules) { // webpackBootstrap } if (isNumber(x) && isNumber(y)) { - return x <= y; + return nearlyEqual(x, y, config.epsilon) || x < y; } if (x instanceof BigNumber) { // try to convert to big number if (isNumber(y)) { - y = toBigNumber(y); + y = BigNumber.convert(y); } else if (isBoolean(y)) { y = new BigNumber(y ? 1 : 0); @@ -7667,12 +7879,12 @@ return /******/ (function(modules) { // webpackBootstrap } // downgrade to Number - return smallereq(toNumber(x), y); + return smallereq(x.toNumber(), y); } if (y instanceof BigNumber) { // try to convert to big number if (isNumber(x)) { - x = toBigNumber(x); + x = BigNumber.convert(x); } else if (isBoolean(x)) { x = new BigNumber(x ? 1 : 0); @@ -7683,7 +7895,7 @@ return /******/ (function(modules) { // webpackBootstrap } // downgrade to Number - return smallereq(x, toNumber(y)); + return smallereq(x, y.toNumber()); } if ((isUnit(x)) && (isUnit(y))) { @@ -7693,14 +7905,16 @@ return /******/ (function(modules) { // webpackBootstrap return x.value <= y.value; } - if (isString(x) || isString(y)) { - return x <= y; - } - if (isCollection(x) || isCollection(y)) { return collection.deepMap2(x, y, smallereq); } + // Note: test strings after testing collections, + // else we can't compare a string with a matrix + if (isString(x) || isString(y)) { + return x <= y; + } + if (isBoolean(x)) { return smallereq(+x, y); } @@ -7712,21 +7926,21 @@ return /******/ (function(modules) { // webpackBootstrap throw new TypeError('No ordering relation is defined for complex numbers'); } - throw new math.error.UnsupportedTypeError('smallereq', x, y); + throw new math.error.UnsupportedTypeError('smallereq', math['typeof'](x), math['typeof'](y)); }; }; /***/ }, -/* 47 */ +/* 48 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + collection = __webpack_require__(11), isNumber = util.number.isNumber, isBoolean = util['boolean'].isBoolean, @@ -7785,21 +7999,21 @@ return /******/ (function(modules) { // webpackBootstrap return sqrt(+x); } - throw new math.error.UnsupportedTypeError('sqrt', x); + throw new math.error.UnsupportedTypeError('sqrt', math['typeof'](x)); }; }; /***/ }, -/* 48 */ +/* 49 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + collection = __webpack_require__(11), isNumber = util.number.isNumber, isBoolean = util['boolean'].isBoolean, @@ -7842,26 +8056,24 @@ return /******/ (function(modules) { // webpackBootstrap return x * x; } - throw new math.error.UnsupportedTypeError('square', x); + throw new math.error.UnsupportedTypeError('square', math['typeof'](x)); }; }; /***/ }, -/* 49 */ +/* 50 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - Matrix = __webpack_require__(11), - Unit = __webpack_require__(12), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + Matrix = __webpack_require__(8), + Unit = __webpack_require__(9), + collection = __webpack_require__(11), - toNumber = util.number.toNumber, - toBigNumber = util.number.toBigNumber, isBoolean = util['boolean'].isBoolean, isNumber = util.number.isNumber, isComplex = Complex.isComplex, @@ -7918,7 +8130,7 @@ return /******/ (function(modules) { // webpackBootstrap if (x instanceof BigNumber) { // try to convert to big number if (isNumber(y)) { - y = toBigNumber(y); + y = BigNumber.convert(y); } else if (isBoolean(y)) { y = new BigNumber(y ? 1 : 0); @@ -7929,12 +8141,12 @@ return /******/ (function(modules) { // webpackBootstrap } // downgrade to Number - return subtract(toNumber(x), y); + return subtract(x.toNumber(), y); } if (y instanceof BigNumber) { // try to convert to big number if (isNumber(x)) { - x = toBigNumber(x); + x = BigNumber.convert(x); } else if (isBoolean(x)) { x = new BigNumber(x ? 1 : 0); @@ -7945,7 +8157,7 @@ return /******/ (function(modules) { // webpackBootstrap } // downgrade to Number - return subtract(x, toNumber(y)); + return subtract(x, y.toNumber()); } if (isUnit(x)) { @@ -7981,22 +8193,22 @@ return /******/ (function(modules) { // webpackBootstrap return subtract(x, +y); } - throw new math.error.UnsupportedTypeError('subtract', x, y); + throw new math.error.UnsupportedTypeError('subtract', math['typeof'](x), math['typeof'](y)); }; }; /***/ }, -/* 50 */ +/* 51 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - Unit = __webpack_require__(12), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + Unit = __webpack_require__(9), + collection = __webpack_require__(11), isNumber = util.number.isNumber, isBoolean = util['boolean'].isBoolean, @@ -8049,26 +8261,25 @@ return /******/ (function(modules) { // webpackBootstrap return -x; } - throw new math.error.UnsupportedTypeError('unary', x); + throw new math.error.UnsupportedTypeError('unary', math['typeof'](x)); }; }; /***/ }, -/* 51 */ +/* 52 */ /***/ function(module, exports, __webpack_require__) { - module.exports = function (math) { - var util = __webpack_require__(112), + module.exports = function (math, config) { + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - Unit = __webpack_require__(12), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + Unit = __webpack_require__(9), + collection = __webpack_require__(11), isNumber = util.number.isNumber, - toNumber = util.number.toNumber, - toBigNumber = util.number.toBigNumber, + nearlyEqual = util.number.nearlyEqual, isBoolean = util['boolean'].isBoolean, isString = util.string.isString, isComplex = Complex.isComplex, @@ -8078,6 +8289,11 @@ return /******/ (function(modules) { // webpackBootstrap /** * Check if value x unequals y, x != y * In case of complex numbers, x.re must unequal y.re, or x.im must unequal y.im + * + * The function checks whether the relative difference between x and y is + * larger than the configured epsilon. The function cannot be used to compare + * values smaller than approximately 2.22e-16. + * * @param {Number | BigNumber | Boolean | Complex | Unit | String | Array | Matrix} x * @param {Number | BigNumber | Boolean | Complex | Unit | String | Array | Matrix} y * @return {Boolean | Array | Matrix} res @@ -8089,26 +8305,26 @@ return /******/ (function(modules) { // webpackBootstrap if (isNumber(x)) { if (isNumber(y)) { - return x != y; + return !nearlyEqual(x, y, config.epsilon); } else if (isComplex(y)) { - return (x != y.re) || (y.im != 0); + return !nearlyEqual(x, y.re, config.epsilon) || !nearlyEqual(y.im, 0, config.epsilon); } } if (isComplex(x)) { if (isNumber(y)) { - return (x.re != y) || (x.im != 0); + return !nearlyEqual(x.re, y, config.epsilon) || !nearlyEqual(x.im, 0, config.epsilon); } else if (isComplex(y)) { - return (x.re != y.re) || (x.im != y.im); + return !nearlyEqual(x.re, y.re, config.epsilon) || !nearlyEqual(x.im, y.im, config.epsilon); } } if (x instanceof BigNumber) { // try to convert to big number if (isNumber(y)) { - y = toBigNumber(y); + y = BigNumber.convert(y); } else if (isBoolean(y)) { y = new BigNumber(y ? 1 : 0); @@ -8119,12 +8335,12 @@ return /******/ (function(modules) { // webpackBootstrap } // downgrade to Number - return unequal(toNumber(x), y); + return unequal(x.toNumber(), y); } if (y instanceof BigNumber) { // try to convert to big number if (isNumber(x)) { - x = toBigNumber(x); + x = BigNumber.convert(x); } else if (isBoolean(x)) { x = new BigNumber(x ? 1 : 0); @@ -8135,7 +8351,7 @@ return /******/ (function(modules) { // webpackBootstrap } // downgrade to Number - return unequal(x, toNumber(y)); + return unequal(x, y.toNumber()); } if ((isUnit(x)) && (isUnit(y))) { @@ -8145,14 +8361,16 @@ return /******/ (function(modules) { // webpackBootstrap return x.value != y.value; } - if (isString(x) || isString(y)) { - return x != y; - } - if (isCollection(x) || isCollection(y)) { return collection.deepMap2(x, y, unequal); } + // Note: test strings after testing collections, + // else we can't compare a string with a matrix + if (isString(x) || isString(y)) { + return x != y; + } + if (isBoolean(x)) { return unequal(+x, y); } @@ -8160,21 +8378,20 @@ return /******/ (function(modules) { // webpackBootstrap return unequal(x, +y); } - throw new math.error.UnsupportedTypeError('unequal', x, y); + throw new math.error.UnsupportedTypeError('unequal', math['typeof'](x), math['typeof'](y)); }; }; /***/ }, -/* 52 */ +/* 53 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), + BigNumber = math.type.BigNumber, - toNumber = util.number.toNumber, isNumber = util.number.isNumber, isBoolean = util['boolean'].isBoolean, isInteger = util.number.isInteger; @@ -8206,10 +8423,10 @@ return /******/ (function(modules) { // webpackBootstrap // downgrade bignumbers to numbers if (a instanceof BigNumber) { - return xgcd(toNumber(a), b); + return xgcd(a.toNumber(), b); } if (b instanceof BigNumber) { - return xgcd(a, toNumber(b)); + return xgcd(a, b.toNumber()); } if (isBoolean(a)) { @@ -8219,7 +8436,7 @@ return /******/ (function(modules) { // webpackBootstrap return xgcd(a, +b); } - throw new math.error.UnsupportedTypeError('xgcd', a, b); + throw new math.error.UnsupportedTypeError('xgcd', math['typeof'](a), math['typeof'](b)); } // zero or one argument @@ -8268,15 +8485,15 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 53 */ +/* 54 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + collection = __webpack_require__(11), isNumber = util.number.isNumber, isBoolean = util['boolean'].isBoolean, @@ -8318,24 +8535,24 @@ return /******/ (function(modules) { // webpackBootstrap if (x instanceof BigNumber) { // downgrade to Number // TODO: implement BigNumber support - return arg(util.number.toNumber(x)); + return arg(x.toNumber()); } - throw new math.error.UnsupportedTypeError('arg', x); + throw new math.error.UnsupportedTypeError('arg', math['typeof'](x)); }; }; /***/ }, -/* 54 */ +/* 55 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + collection = __webpack_require__(11), object = util.object, isNumber = util.number.isNumber, @@ -8386,15 +8603,15 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 55 */ +/* 56 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + collection = __webpack_require__(11), object = util.object, isNumber = util.number.isNumber, @@ -8444,15 +8661,15 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 56 */ +/* 57 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + collection = __webpack_require__(11), isNumber = util.number.isNumber, isBoolean = util['boolean'].isBoolean, @@ -8501,31 +8718,21 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 57 */ +/* 58 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - collection = __webpack_require__(14), + // take the BigNumber instance the provided math.js instance + BigNumber = math.type.BigNumber, + collection = __webpack_require__(11), isCollection = collection.isCollection, isNumber = util.number.isNumber, isString = util.string.isString, isBoolean = util['boolean'].isBoolean; - // extend BigNumber with a function clone - if (typeof BigNumber.prototype.clone !== 'function') { - /** - * Clone a bignumber - * @return {BigNumber} clone - */ - BigNumber.prototype.clone = function clone () { - return new BigNumber(this); - }; - } - /** * Create a big number, which can store numbers with higher precision than * a JavaScript Number. @@ -8555,20 +8762,20 @@ return /******/ (function(modules) { // webpackBootstrap return new BigNumber(0); } - throw new math.error.UnsupportedTypeError('bignumber', value); + throw new math.error.UnsupportedTypeError('bignumber', math['typeof'](value)); }; }; /***/ }, -/* 58 */ +/* 59 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + collection = __webpack_require__(11), isCollection = collection.isCollection, isNumber = util.number.isNumber, @@ -8635,19 +8842,18 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 59 */ +/* 60 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + collection = __webpack_require__(11), isCollection = collection.isCollection, isNumber = util.number.isNumber, - toNumber = util.number.toNumber, isString = util.string.isString, isComplex = Complex.isComplex; @@ -8666,6 +8872,10 @@ return /******/ (function(modules) { // webpackBootstrap * complex(array : Array) converts the elements of the array * or matrix element wise into a * complex value. + * complex({re: number, im: number}) creates a complex value with provided + * values for real an imaginary part. + * complex({r: number, phi: number}) creates a complex value with provided + * polar coordinates * * Example usage: * var a = math.complex(3, -4); // 3 - 4i @@ -8694,7 +8904,7 @@ return /******/ (function(modules) { // webpackBootstrap if (arg instanceof BigNumber) { // convert to Number - return new Complex(toNumber(arg), 0); + return new Complex(arg.toNumber(), 0); } if (isComplex(arg)) { @@ -8716,7 +8926,15 @@ return /******/ (function(modules) { // webpackBootstrap return collection.deepMap(arg, complex); } - throw new TypeError('Two numbers or a single string expected in function complex'); + if (typeof arg === 'object') { + if('re' in arg && 'im' in arg) { + return new Complex(arg.re, arg.im); + } else if ('r' in arg && 'phi' in arg) { + return Complex.fromPolar(arg.r, arg.phi); + } + } + + throw new TypeError('Two numbers, single string or an fitting object expected in function complex'); case 2: // re and im provided @@ -8725,12 +8943,12 @@ return /******/ (function(modules) { // webpackBootstrap // convert re to number if (re instanceof BigNumber) { - re = toNumber(re); + re = re.toNumber(); } // convert im to number if (im instanceof BigNumber) { - im = toNumber(im); + im = im.toNumber(); } if (isNumber(re) && isNumber(im)) { @@ -8748,16 +8966,14 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 60 */ +/* 61 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Index = __webpack_require__(10), - - toNumber = util.number.toNumber; + BigNumber = math.type.BigNumber, + Index = __webpack_require__(7); /** * Create an index. An Index can store ranges having start, step, and end @@ -8783,11 +8999,11 @@ return /******/ (function(modules) { // webpackBootstrap // downgrade BigNumber to Number var args = Array.prototype.slice.apply(arguments).map(function (arg) { if (arg instanceof BigNumber) { - return toNumber(arg); + return arg.toNumber(); } else if (Array.isArray(arg)) { return arg.map(function (elem) { - return (elem instanceof BigNumber) ? toNumber (elem) : elem; + return (elem instanceof BigNumber) ? elem.toNumber() : elem; }); } else { @@ -8802,11 +9018,12 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 61 */ +/* 62 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var Matrix = __webpack_require__(11); + var util = __webpack_require__(117), + Matrix = __webpack_require__(8); /** * Create a matrix. The function creates a new math.type.Matrix object. @@ -8836,17 +9053,16 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 62 */ +/* 63 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + collection = __webpack_require__(11), isCollection = collection.isCollection, - toNumber = util.number.toNumber, isNumber = util.number.isNumber, isBoolean = util['boolean'].isBoolean, isString = util.string.isString; @@ -8868,7 +9084,7 @@ return /******/ (function(modules) { // webpackBootstrap } if (value instanceof BigNumber) { - return toNumber(value); + return value.toNumber(); } if (isString(value)) { @@ -8890,7 +9106,7 @@ return /******/ (function(modules) { // webpackBootstrap return value; } - throw new math.error.UnsupportedTypeError('number', value); + throw new math.error.UnsupportedTypeError('number', math['typeof'](value)); default: throw new math.error.ArgumentsError('number', arguments.length, 0, 1); @@ -8900,11 +9116,11 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 63 */ +/* 64 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var Parser = __webpack_require__(5); + var Parser = __webpack_require__(13); /** * Create a parser. The function creates a new math.expression.Parser object. @@ -8949,7 +9165,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 64 */ +/* 65 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { @@ -8995,13 +9211,13 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 65 */ +/* 66 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - collection = __webpack_require__(14), + collection = __webpack_require__(11), number = util.number, isNumber = util.number.isNumber, @@ -9041,18 +9257,17 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 66 */ +/* 67 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Unit = __webpack_require__(12), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Unit = __webpack_require__(9), + collection = __webpack_require__(11), isCollection = collection.isCollection, - toNumber = util.number.toNumber, isString = util.string.isString; /** @@ -9084,7 +9299,7 @@ return /******/ (function(modules) { // webpackBootstrap } if (isString(arg)) { - if (Unit.isPlainUnit(arg)) { + if (Unit.isValuelessUnit(arg)) { return new Unit(null, arg); // a pure unit } @@ -9107,7 +9322,7 @@ return /******/ (function(modules) { // webpackBootstrap if (arguments[0] instanceof BigNumber) { // convert value to number - return new Unit(toNumber(arguments[0]), arguments[1]); + return new Unit(arguments[0].toNumber(), arguments[1]); } else { return new Unit(arguments[0], arguments[1]); @@ -9121,14 +9336,14 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 67 */ +/* 68 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - Matrix = __webpack_require__(11), - collection = __webpack_require__(14), + Matrix = __webpack_require__(8), + collection = __webpack_require__(11), object = util.object, array = util.array, @@ -9175,8 +9390,7 @@ return /******/ (function(modules) { // webpackBootstrap } if (i > 0 && dim > prevDim) { - throw new RangeError('Dimension out of range ' + - '(' + dim + ' > ' + prevDim + ')'); + throw new math.error.DimensionError(dim, prevDim, '>'); } } else if (isCollection(arg)) { @@ -9189,12 +9403,11 @@ return /******/ (function(modules) { // webpackBootstrap // verify whether each of the matrices has the same number of dimensions if (i > 0 && dim != prevDim) { - throw new RangeError('Dimension mismatch ' + - '(' + prevDim + ' != ' + dim + ')'); + throw new math.error.DimensionError(dim, prevDim); } } else { - throw new math.error.UnsupportedTypeError('concat', arg); + throw new math.error.UnsupportedTypeError('concat', math['typeof'](arg)); } } @@ -9224,7 +9437,7 @@ return /******/ (function(modules) { // webpackBootstrap if (dim < concatDim) { // recurse into next dimension if (a.length != b.length) { - throw new Error('Dimensions mismatch (' + a.length + ' != ' + b.length + ')'); + throw new math.error.DimensionError(a.length, b.length); } var c = []; @@ -9242,13 +9455,13 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 68 */ +/* 69 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - Matrix = __webpack_require__(11), + Matrix = __webpack_require__(8), object = util.object, string = util.string; @@ -9337,64 +9550,47 @@ return /******/ (function(modules) { // webpackBootstrap } else { // this is an n x n matrix - // TODO: support for bignumbers, complex numbers, etc - var a; - var d = 1; - var lead = 0; - for (var r = 0; r < rows; r++) { - if (lead >= cols) { - break; + function compute_mu(matrix) { + var i, j; + + // Compute the matrix with zero lower triangle, same upper triangle, + // and diagonals given by the negated sum of the below diagonal + // elements. + var mu = new Array(matrix.length); + var sum = 0; + for (i = 1; i < matrix.length; i++) { + sum = math.add(sum, matrix[i][i]); } - var i = r; - // Find the pivot element. - while (matrix[i][lead] == 0) { - i++; - if (i == rows) { - i = r; - lead++; - if (lead == cols) { - // We found the last pivot. - if (object.deepEqual(matrix, math.eye(rows).valueOf())) { - return math.round(d, 6); // FIXME: should d be rounded to 6 here? - } else { - return 0; - } - } + + for (i = 0; i < matrix.length; i++) { + mu[i] = new Array(matrix.length); + mu[i][i] = math.unary(sum); + + for (j = 0; j < i; j++) { + mu[i][j] = 0; + } + + for (j = i + 1; j < matrix.length; j++) { + mu[i][j] = matrix[i][j]; + } + + if (i+1 < matrix.length) { + sum = math.subtract(sum, matrix[i + 1][i + 1]); } } - if (i != r) { - // Swap rows i and r, which negates the determinant. - for (a = 0; a < cols; a++) { - var temp = matrix[i][a]; - matrix[i][a] = matrix[r][a]; - matrix[r][a] = temp; - } - d *= -1; - } - // Scale row r and the determinant simultaneously. - var div = matrix[r][lead]; - for (a = 0; a < cols; a++) { - matrix[r][a] = matrix[r][a] / div; - } - d *= div; - // Back-substitute upwards. - for (var j = 0; j < rows; j++) { - if (j != r) { - // Taking linear combinations does not change the det. - var c = matrix[j][lead]; - for (a = 0; a < cols; a++) { - matrix[j][a] = matrix[j][a] - matrix[r][a] * c; - } - } - } - lead++; // Now looking for a pivot further right. + + return mu; } - // If reduction did not result in the identity, the matrix is singular. - if (object.deepEqual(matrix, math.eye(rows).valueOf())) { - return math.round(d, 6); // FIXME: should d be rounded to 6 here? + var fa = matrix; + for (var i = 0; i < rows - 1; i++) { + fa = math.multiply(compute_mu(fa), matrix); + } + + if (rows % 2 == 0) { + return math.unary(fa[0][0]); } else { - return 0; + return fa[0][0]; } } } @@ -9402,13 +9598,14 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 69 */ +/* 70 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - Matrix = __webpack_require__(11), + BigNumber = math.type.BigNumber, + Matrix = __webpack_require__(8), object = util.object, isArray = util.array.isArray, @@ -9426,7 +9623,7 @@ return /******/ (function(modules) { // webpackBootstrap * TODO: more documentation on diag * * @param {Matrix | Array} x - * @param {Number} [k] + * @param {Number | BigNumber} [k] * @return {Matrix | Array} matrix */ math.diag = function diag (x, k) { @@ -9437,6 +9634,9 @@ return /******/ (function(modules) { // webpackBootstrap } if (k) { + // convert BigNumber to a number + if (k instanceof BigNumber) k = k.toNumber(); + if (!isNumber(k) || !isInteger(k)) { throw new TypeError ('Second parameter in function diag must be an integer'); } @@ -9461,15 +9661,13 @@ return /******/ (function(modules) { // webpackBootstrap throw new TypeError ('First parameter in function diag must be a Matrix or Array'); } - // TODO: bignumber support for diag - var s = x.size(); switch (s.length) { case 1: // x is a vector. create diagonal matrix vector = x.valueOf(); var matrix = new Matrix(); - var defaultValue = 0; + var defaultValue = (vector[0] instanceof BigNumber) ? new BigNumber(0) : 0; matrix.resize([vector.length + kSub, vector.length + kSuper], defaultValue); data = matrix.valueOf(); iMax = vector.length; @@ -9496,17 +9694,16 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 70 */ +/* 71 */ /***/ function(module, exports, __webpack_require__) { - module.exports = function (math, settings) { - var util = __webpack_require__(112), + module.exports = function (math, config) { + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Matrix = __webpack_require__(11), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Matrix = __webpack_require__(8), + collection = __webpack_require__(11), - toNumber = util.number.toNumber, isNumber = util.number.isNumber, isInteger = util.number.isInteger, isArray = Array.isArray; @@ -9526,7 +9723,7 @@ return /******/ (function(modules) { // webpackBootstrap math.eye = function eye (size) { var args = collection.argsToArray(arguments), asMatrix = (size instanceof Matrix) ? true : - (isArray(size) ? false : (settings.matrix === 'matrix')); + (isArray(size) ? false : (config.matrix === 'matrix')); if (args.length == 0) { @@ -9542,16 +9739,11 @@ return /******/ (function(modules) { // webpackBootstrap throw new math.error.ArgumentsError('eye', args.length, 0, 2); } - var asBigNumber = args[0] instanceof BigNumber, - rows = args[0], + var rows = args[0], cols = args[1]; - if (rows instanceof BigNumber) { - rows = toNumber(rows); - } - if (cols instanceof BigNumber) { - cols = toNumber(cols); - } + if (rows instanceof BigNumber) rows = rows.toNumber(); + if (cols instanceof BigNumber) cols = cols.toNumber(); if (!isNumber(rows) || !isInteger(rows) || rows < 1) { throw new Error('Parameters in function eye must be positive integers'); @@ -9560,11 +9752,22 @@ return /******/ (function(modules) { // webpackBootstrap throw new Error('Parameters in function eye must be positive integers'); } + // convert arguments from bignumber to numbers if needed + var asBigNumber = false; + args = args.map(function (value) { + if (value instanceof BigNumber) { + asBigNumber = true; + return value.toNumber(); + } else { + return value; + } + }); + // create the matrix var matrix = new Matrix(); var one = asBigNumber ? new BigNumber(1) : 1; var defaultValue = asBigNumber ? new BigNumber(0) : 0; - matrix.resize(args.map(toNumber), defaultValue); + matrix.resize(args, defaultValue); // fill in ones on the diagonal var minimum = math.min(args); @@ -9579,14 +9782,15 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 71 */ +/* 72 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var string = __webpack_require__(127), + var util = __webpack_require__(117), + string = util.string, - Matrix = __webpack_require__(11), - collection = __webpack_require__(14); + Matrix = __webpack_require__(8), + collection = __webpack_require__(11); /** * Calculate the inverse of a matrix @@ -9766,19 +9970,18 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 72 */ +/* 73 */ /***/ function(module, exports, __webpack_require__) { - module.exports = function (math, settings) { - var util = __webpack_require__(112), + module.exports = function (math, config) { + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Matrix = __webpack_require__(11), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Matrix = __webpack_require__(8), + collection = __webpack_require__(11), array = util.array, - toNumber = util.number.toNumber, isArray = Array.isArray; /** @@ -9795,7 +9998,7 @@ return /******/ (function(modules) { // webpackBootstrap math.ones = function ones (size) { var args = collection.argsToArray(arguments); var asMatrix = (size instanceof Matrix) ? true : - (isArray(size) ? false : (settings.matrix === 'matrix')); + (isArray(size) ? false : (config.matrix === 'matrix')); if (args.length == 0) { // output an empty matrix @@ -9803,9 +10006,22 @@ return /******/ (function(modules) { // webpackBootstrap } else { // output an array or matrix + + // convert arguments from bignumber to numbers if needed + var asBigNumber = false; + args = args.map(function (value) { + if (value instanceof BigNumber) { + asBigNumber = true; + return value.toNumber(); + } else { + return value; + } + }); + + // resize the matrix var res = []; - var defaultValue = (args[0] instanceof BigNumber) ? new BigNumber(1) : 1; - res = array.resize(res, args.map(toNumber), defaultValue); + var defaultValue = asBigNumber ? new BigNumber(1) : 1; + res = array.resize(res, args, defaultValue); return asMatrix ? new Matrix(res) : res; } @@ -9814,21 +10030,19 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 73 */ +/* 74 */ /***/ function(module, exports, __webpack_require__) { - module.exports = function (math, settings) { - var util = __webpack_require__(112), + module.exports = function (math, config) { + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Matrix = __webpack_require__(11), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Matrix = __webpack_require__(8), + collection = __webpack_require__(11), isBoolean = util['boolean'].isBoolean, isString = util.string.isString, - isNumber = util.number.isNumber, - toNumber = util.number.toNumber, - toBigNumber = util.number.toBigNumber; + isNumber = util.number.isNumber; /** * Create an array from a range. @@ -9890,8 +10104,7 @@ return /******/ (function(modules) { // webpackBootstrap step = r.step; } else { - throw new TypeError( - 'Two or three numbers or a single string expected in function range'); + throw new TypeError('Two or three numbers or a single string expected in function range'); } break; @@ -9934,23 +10147,17 @@ return /******/ (function(modules) { // webpackBootstrap var asBigNumber = true; // convert start, end, step to BigNumber - if (!(start instanceof BigNumber)) { - start = toBigNumber(start); - } - if (!(end instanceof BigNumber)) { - end = toBigNumber(end); - } - if (!(step instanceof BigNumber)) { - step = toBigNumber(step); - } + if (!(start instanceof BigNumber)) start = BigNumber.convert(start); + if (!(end instanceof BigNumber)) end = BigNumber.convert(end); + if (!(step instanceof BigNumber)) step = BigNumber.convert(step); if (!(start instanceof BigNumber) || !(end instanceof BigNumber) || !(step instanceof BigNumber)) { // not all values can be converted to big number :( // fall back to numbers asBigNumber = false; - start = toNumber(start); - end = toNumber(end); - step = toNumber(step); + if (start instanceof BigNumber) start = start.toNumber(); + if (end instanceof BigNumber) end = end.toNumber(); + if (step instanceof BigNumber) step = step.toNumber(); } } @@ -9961,7 +10168,7 @@ return /******/ (function(modules) { // webpackBootstrap var array = fn(start, end, step); // return as array or matrix - return (settings.matrix === 'array') ? array : new Matrix(array); + return (config.matrix === 'array') ? array : new Matrix(array); }; /** @@ -10087,7 +10294,7 @@ return /******/ (function(modules) { // webpackBootstrap var args = str.split(':'), nums = null; - if (settings.number === 'bignumber') { + if (config.number === 'bignumber') { // bignumber try { nums = args.map(function (arg) { @@ -10137,20 +10344,19 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 74 */ +/* 75 */ /***/ function(module, exports, __webpack_require__) { - module.exports = function (math, settings) { - var util = __webpack_require__(112), + module.exports = function (math, config) { + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Matrix = __webpack_require__(11), + BigNumber = math.type.BigNumber, + Matrix = __webpack_require__(8), array = util.array, clone = util.object.clone, string = util.string, isString = util.string.isString, - toNumber = util.number.toNumber, isNumber = util.number.isNumber, isInteger = util.number.isInteger, isArray = array.isArray; @@ -10173,7 +10379,7 @@ return /******/ (function(modules) { // webpackBootstrap throw new math.error.ArgumentsError('resize', arguments.length, 2, 3); } - var asMatrix = (x instanceof Matrix) ? true : isArray(x) ? false : (settings.matrix !== 'array'); + var asMatrix = (x instanceof Matrix) ? true : isArray(x) ? false : (config.matrix !== 'array'); if (x instanceof Matrix) { x = x.valueOf(); // get Array @@ -10184,7 +10390,9 @@ return /******/ (function(modules) { // webpackBootstrap if (size.length && size[0] instanceof BigNumber) { // convert bignumbers to numbers - size = size.map(toNumber); + size = size.map(function (value) { + return (value instanceof BigNumber) ? value.toNumber() : value; + }); } if (isString(x)) { @@ -10230,7 +10438,7 @@ return /******/ (function(modules) { // webpackBootstrap } if (size.length !== 1) { - throw new Error('Dimension mismatch: (' + size.length + ' != 1)'); + throw new math.error.DimensionError(size.length, 1); } var len = size[0]; if (!isNumber(len) || !isInteger(len)) { @@ -10256,16 +10464,16 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 75 */ +/* 76 */ /***/ function(module, exports, __webpack_require__) { - module.exports = function (math, settings) { - var util = __webpack_require__(112), + module.exports = function (math, config) { + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - Unit = __webpack_require__(12), - Matrix = __webpack_require__(11), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + Unit = __webpack_require__(9), + Matrix = __webpack_require__(8), array = util.array, isNumber = util.number.isNumber, @@ -10287,7 +10495,7 @@ return /******/ (function(modules) { // webpackBootstrap throw new math.error.ArgumentsError('size', arguments.length, 1); } - var asArray = (settings.matrix === 'array'); + var asArray = (config.matrix === 'array'); if (isNumber(x) || isComplex(x) || isUnit(x) || isBoolean(x) || x == null || x instanceof BigNumber) { @@ -10306,19 +10514,19 @@ return /******/ (function(modules) { // webpackBootstrap return new Matrix(x.size()); } - throw new math.error.UnsupportedTypeError('size', x); + throw new math.error.UnsupportedTypeError('size', math['typeof'](x)); }; }; /***/ }, -/* 76 */ +/* 77 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - Matrix = __webpack_require__(11), + Matrix = __webpack_require__(8), object = util.object, array = util.array, @@ -10353,14 +10561,14 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 77 */ +/* 78 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - Matrix = __webpack_require__(11), - Index = __webpack_require__(10), + Matrix = __webpack_require__(8), + Index = __webpack_require__(7), array = util.array, isString = util.string.isString, @@ -10425,7 +10633,7 @@ return /******/ (function(modules) { // webpackBootstrap return _getSubstring(value, index); } else { - throw new math.error.UnsupportedTypeError('subset', value); + throw new math.error.UnsupportedTypeError('subset', math['typeof'](value)); } } @@ -10442,7 +10650,7 @@ return /******/ (function(modules) { // webpackBootstrap throw new TypeError('Index expected'); } if (index.size().length != 1) { - throw new RangeError('Dimension mismatch (' + index.size().length + ' != 1)'); + throw new math.error.DimensionError(index.size().length, 1); } var range = index.range(0); @@ -10484,7 +10692,7 @@ return /******/ (function(modules) { // webpackBootstrap return _setSubstring(value, index, replacement, defaultValue); } else { - throw new math.error.UnsupportedTypeError('subset', value); + throw new math.error.UnsupportedTypeError('subset', math['typeof'](value)); } } @@ -10504,7 +10712,7 @@ return /******/ (function(modules) { // webpackBootstrap throw new TypeError('Index expected'); } if (index.size().length != 1) { - throw new RangeError('Dimension mismatch (' + index.size().length + ' != 1)'); + throw new math.error.DimensionError(index.size().length, 1); } if (defaultValue !== undefined) { if (!isString(defaultValue) || defaultValue.length !== 1) { @@ -10519,8 +10727,7 @@ return /******/ (function(modules) { // webpackBootstrap var len = range.size()[0]; if (len != replacement.length) { - throw new RangeError('Dimension mismatch ' + - '(' + range.size()[0] + ' != ' + replacement.length + ')'); + throw new math.error.DimensionError(range.size()[0], replacement.length); } // copy the string into an array with characters @@ -10550,14 +10757,14 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 78 */ +/* 79 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - Matrix = __webpack_require__(11), - collection = __webpack_require__(14), + Matrix = __webpack_require__(8), + collection = __webpack_require__(11), object = util.object, string = util.string; @@ -10620,18 +10827,17 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 79 */ +/* 80 */ /***/ function(module, exports, __webpack_require__) { - module.exports = function (math, settings) { - var util = __webpack_require__(112), + module.exports = function (math, config) { + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Matrix = __webpack_require__(11), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Matrix = __webpack_require__(8), + collection = __webpack_require__(11), array = util.array, - toNumber = util.number.toNumber, isArray = Array.isArray; /** @@ -10648,7 +10854,7 @@ return /******/ (function(modules) { // webpackBootstrap math.zeros = function zeros (size) { var args = collection.argsToArray(arguments); var asMatrix = (size instanceof Matrix) ? true : - (isArray(size) ? false : (settings.matrix === 'matrix')); + (isArray(size) ? false : (config.matrix === 'matrix')); if (args.length == 0) { // output an empty matrix @@ -10656,9 +10862,22 @@ return /******/ (function(modules) { // webpackBootstrap } else { // output an array or matrix + + // convert arguments from bignumber to numbers if needed + var asBigNumber = false; + args = args.map(function (value) { + if (value instanceof BigNumber) { + asBigNumber = true; + return value.toNumber(); + } else { + return value; + } + }); + + // resize the matrix var res = []; - var defaultValue = (args[0] instanceof BigNumber) ? new BigNumber(0) : 0; - res = array.resize(res, args.map(toNumber), defaultValue); + var defaultValue = asBigNumber ? new BigNumber(0) : 0; + res = array.resize(res, args, defaultValue); return asMatrix ? new Matrix(res) : res; } @@ -10667,14 +10886,14 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 80 */ +/* 81 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + collection = __webpack_require__(11), isNumber = util.number.isNumber, isBoolean = util['boolean'].isBoolean, @@ -10748,7 +10967,7 @@ return /******/ (function(modules) { // webpackBootstrap return collection.deepMap(n, factorial); } - throw new math.error.UnsupportedTypeError('factorial', n); + throw new math.error.UnsupportedTypeError('factorial', math['typeof'](n)); }; /** @@ -10757,18 +10976,18 @@ return /******/ (function(modules) { // webpackBootstrap * @returns {boolean} isPositiveInteger */ var isPositiveInteger = function(n) { - return n.round().equals(n) && n.gte(0); + return n.isInteger() && n.gte(0); }; }; /***/ }, -/* 81 */ +/* 82 */ /***/ function(module, exports, __webpack_require__) { - module.exports = function (math, settings) { - var Matrix = __webpack_require__(11), - collection = __webpack_require__(14); + module.exports = function (math, config) { + var Matrix = __webpack_require__(8), + collection = __webpack_require__(11); // TODO: implement BigNumber support for random @@ -10859,7 +11078,7 @@ return /******/ (function(modules) { // webpackBootstrap if (min === undefined) min = 0; if (size !== undefined) { var res = _randomDataForMatrix(size, min, max, _random); - return (settings.matrix === 'array') ? res : new Matrix(res); + return (config.matrix === 'array') ? res : new Matrix(res); } else return _random(min, max); }, @@ -10889,7 +11108,7 @@ return /******/ (function(modules) { // webpackBootstrap if (min === undefined) min = 0; if (size !== undefined) { var res = _randomDataForMatrix(size, min, max, _randomInt); - return (settings.matrix === 'array') ? res : new Matrix(res); + return (config.matrix === 'array') ? res : new Matrix(res); } else return _randomInt(min, max); }, @@ -10899,7 +11118,7 @@ return /******/ (function(modules) { // webpackBootstrap throw new math.error.ArgumentsError('pickRandom', arguments.length, 1); } if (!Array.isArray(possibles)) { - throw new math.error.UnsupportedTypeError('pickRandom', possibles); + throw new math.error.UnsupportedTypeError('pickRandom', math['typeof'](possibles)); } // TODO: add support for matrices @@ -10948,17 +11167,16 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 82 */ +/* 83 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), + BigNumber = math.type.BigNumber, isNumber = util.number.isNumber, - isInteger = util.number.isInteger, - toBigNumber = util.number.toBigNumber; + isInteger = util.number.isInteger; /** * Compute the number of permutations of n items taken k at a time @@ -11017,7 +11235,7 @@ return /******/ (function(modules) { // webpackBootstrap // make sure k is a BigNumber as well // not all numbers can be converted to BigNumber - k = toBigNumber(k); + k = BigNumber.convert(k); if (!(k instanceof BigNumber) || !isPositiveInteger(n) || !isPositiveInteger(k)) { throw new TypeError('Positive integer value expected in function permutations'); @@ -11033,7 +11251,7 @@ return /******/ (function(modules) { // webpackBootstrap return result; } - throw new math.error.UnsupportedTypeError('permutations', n); + throw new math.error.UnsupportedTypeError('permutations', math['typeof'](n)); }; /** @@ -11042,24 +11260,23 @@ return /******/ (function(modules) { // webpackBootstrap * @returns {boolean} isPositiveInteger */ var isPositiveInteger = function(n) { - return n.round().equals(n) && n.gte(0); + return n.isInteger() && n.gte(0); }; }; /***/ }, -/* 83 */ +/* 84 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + collection = __webpack_require__(11), isNumber = util.number.isNumber, - isInteger = util.number.isInteger, - toBigNumber = util.number.toBigNumber; + isInteger = util.number.isInteger; /** * Compute the number of combinations of n items taken k at a time @@ -11100,7 +11317,7 @@ return /******/ (function(modules) { // webpackBootstrap if (n instanceof BigNumber) { // make sure k is a BigNumber as well // not all numbers can be converted to BigNumber - k = toBigNumber(k); + k = BigNumber.convert(k); if (!(k instanceof BigNumber) || !isPositiveInteger(n) || !isPositiveInteger(k)) { throw new TypeError('Positive integer value expected in function combinations'); @@ -11118,7 +11335,7 @@ return /******/ (function(modules) { // webpackBootstrap return result; } - throw new math.error.UnsupportedTypeError('combinations', n); + throw new math.error.UnsupportedTypeError('combinations', math['typeof'](n)); }; /** @@ -11127,18 +11344,18 @@ return /******/ (function(modules) { // webpackBootstrap * @returns {boolean} isPositiveInteger */ var isPositiveInteger = function(n) { - return n.round().equals(n) && n.gte(0); + return n.isInteger() && n.gte(0); }; }; /***/ }, -/* 84 */ +/* 85 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var Matrix = __webpack_require__(11), - collection = __webpack_require__(14), + var Matrix = __webpack_require__(8), + collection = __webpack_require__(11), isCollection = collection.isCollection; @@ -11208,12 +11425,12 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 85 */ +/* 86 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var Matrix = __webpack_require__(11), - collection = __webpack_require__(14), + var Matrix = __webpack_require__(8), + collection = __webpack_require__(11), isCollection = collection.isCollection; @@ -11283,16 +11500,16 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 86 */ +/* 87 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var Matrix = __webpack_require__(11), - collection = __webpack_require__(14), + var Matrix = __webpack_require__(8), + collection = __webpack_require__(11), isCollection = collection.isCollection, - size = __webpack_require__(142).size; + size = __webpack_require__(147).size; /** * Compute the mean value of a list of values @@ -11370,19 +11587,19 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 87 */ +/* 88 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var Matrix = __webpack_require__(11), - Unit = __webpack_require__(12), - BigNumber = __webpack_require__(111), - collection = __webpack_require__(14), + var Matrix = __webpack_require__(8), + Unit = __webpack_require__(9), + BigNumber = math.type.BigNumber, + collection = __webpack_require__(11), - isNumber = __webpack_require__(143).isNumber, + isNumber = __webpack_require__(148).isNumber, isCollection = collection.isCollection, - flatten = __webpack_require__(142).flatten; + flatten = __webpack_require__(147).flatten; /** * Compute the median of a list of values. The values are sorted and the @@ -11448,10 +11665,10 @@ return /******/ (function(modules) { // webpackBootstrap var right = flat[num / 2]; if (!isNumber(left) && !(left instanceof BigNumber) && !(left instanceof Unit)) { - throw new math.error.UnsupportedTypeError('median', left); + throw new math.error.UnsupportedTypeError('median', math['typeof'](left)); } if (!isNumber(right) && !(right instanceof BigNumber) && !(right instanceof Unit)) { - throw new math.error.UnsupportedTypeError('median', right); + throw new math.error.UnsupportedTypeError('median', math['typeof'](right)); } return math.divide(math.add(left, right), 2); @@ -11461,7 +11678,7 @@ return /******/ (function(modules) { // webpackBootstrap var middle = flat[(num - 1) / 2]; if (!isNumber(middle) && !(middle instanceof BigNumber) && !(middle instanceof Unit)) { - throw new math.error.UnsupportedTypeError('median', middle); + throw new math.error.UnsupportedTypeError('median', math['typeof'](middle)); } return middle; @@ -11471,12 +11688,12 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 88 */ +/* 89 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var Matrix = __webpack_require__(11), - collection = __webpack_require__(14), + var Matrix = __webpack_require__(8), + collection = __webpack_require__(11), isCollection = collection.isCollection; @@ -11540,7 +11757,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 89 */ +/* 90 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { @@ -11576,12 +11793,12 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 90 */ +/* 91 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var Matrix = __webpack_require__(11), - collection = __webpack_require__(14), + var Matrix = __webpack_require__(8), + collection = __webpack_require__(11), isCollection = collection.isCollection; @@ -11645,16 +11862,16 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 91 */ +/* 92 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var Matrix = __webpack_require__(11), - BigNumber = __webpack_require__(111), - collection = __webpack_require__(14), + var Matrix = __webpack_require__(8), + BigNumber = math.type.BigNumber, + collection = __webpack_require__(11), isCollection = collection.isCollection, - isString = __webpack_require__(127).isString, + isString = __webpack_require__(132).isString, DEFAULT_NORMALIZATION = 'unbiased'; @@ -11764,15 +11981,15 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 92 */ +/* 93 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + collection = __webpack_require__(11), isNumber = util.number.isNumber, isBoolean = util['boolean'].isBoolean, @@ -11836,24 +12053,24 @@ return /******/ (function(modules) { // webpackBootstrap if (x instanceof BigNumber) { // TODO: implement BigNumber support // downgrade to Number - return acos(util.number.toNumber(x)); + return acos(x.toNumber()); } - throw new math.error.UnsupportedTypeError('acos', x); + throw new math.error.UnsupportedTypeError('acos', math['typeof'](x)); }; }; /***/ }, -/* 93 */ +/* 94 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + collection = __webpack_require__(11), isNumber = util.number.isNumber, isBoolean = util['boolean'].isBoolean, @@ -11915,24 +12132,24 @@ return /******/ (function(modules) { // webpackBootstrap if (x instanceof BigNumber) { // TODO: implement BigNumber support // downgrade to Number - return asin(util.number.toNumber(x)); + return asin(x.toNumber()); } - throw new math.error.UnsupportedTypeError('asin', x); + throw new math.error.UnsupportedTypeError('asin', math['typeof'](x)); }; }; /***/ }, -/* 94 */ +/* 95 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + collection = __webpack_require__(11), isNumber = util.number.isNumber, isBoolean = util['boolean'].isBoolean, @@ -11989,26 +12206,25 @@ return /******/ (function(modules) { // webpackBootstrap if (x instanceof BigNumber) { // TODO: implement BigNumber support // downgrade to Number - return atan(util.number.toNumber(x)); + return atan(x.toNumber()); } - throw new math.error.UnsupportedTypeError('atan', x); + throw new math.error.UnsupportedTypeError('atan', math['typeof'](x)); }; }; /***/ }, -/* 95 */ +/* 96 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + collection = __webpack_require__(11), - toNumber = util.number.toNumber, isNumber = util.number.isNumber, isBoolean = util['boolean'].isBoolean, isComplex = Complex.isComplex, @@ -12053,28 +12269,28 @@ return /******/ (function(modules) { // webpackBootstrap // TODO: implement bignumber support if (y instanceof BigNumber) { - return atan2(toNumber(y), x); + return atan2(y.toNumber(), x); } if (x instanceof BigNumber) { - return atan2(y, toNumber(x)); + return atan2(y, x.toNumber()); } - throw new math.error.UnsupportedTypeError('atan2', y, x); + throw new math.error.UnsupportedTypeError('atan2', math['typeof'](y), math['typeof'](x)); }; }; /***/ }, -/* 96 */ +/* 97 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - Unit = __webpack_require__(12), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + Unit = __webpack_require__(9), + collection = __webpack_require__(11), isNumber = util.number.isNumber, isBoolean = util['boolean'].isBoolean, @@ -12129,25 +12345,25 @@ return /******/ (function(modules) { // webpackBootstrap if (x instanceof BigNumber) { // TODO: implement BigNumber support // downgrade to Number - return cos(util.number.toNumber(x)); + return cos(x.toNumber()); } - throw new math.error.UnsupportedTypeError('cos', x); + throw new math.error.UnsupportedTypeError('cos', math['typeof'](x)); }; }; /***/ }, -/* 97 */ +/* 98 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - Unit = __webpack_require__(12), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + Unit = __webpack_require__(9), + collection = __webpack_require__(11), isNumber = util.number.isNumber, isBoolean = util['boolean'].isBoolean, @@ -12202,25 +12418,25 @@ return /******/ (function(modules) { // webpackBootstrap if (x instanceof BigNumber) { // TODO: implement BigNumber support // downgrade to Number - return cot(util.number.toNumber(x)); + return cot(x.toNumber()); } - throw new math.error.UnsupportedTypeError('cot', x); + throw new math.error.UnsupportedTypeError('cot', math['typeof'](x)); }; }; /***/ }, -/* 98 */ +/* 99 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - Unit = __webpack_require__(12), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + Unit = __webpack_require__(9), + collection = __webpack_require__(11), isNumber = util.number.isNumber, isBoolean = util['boolean'].isBoolean, @@ -12276,25 +12492,25 @@ return /******/ (function(modules) { // webpackBootstrap if (x instanceof BigNumber) { // TODO: implement BigNumber support // downgrade to Number - return csc(util.number.toNumber(x)); + return csc(x.toNumber()); } - throw new math.error.UnsupportedTypeError('csc', x); + throw new math.error.UnsupportedTypeError('csc', math['typeof'](x)); }; }; /***/ }, -/* 99 */ +/* 100 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - Unit = __webpack_require__(12), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + Unit = __webpack_require__(9), + collection = __webpack_require__(11), isNumber = util.number.isNumber, isBoolean = util['boolean'].isBoolean, @@ -12350,25 +12566,25 @@ return /******/ (function(modules) { // webpackBootstrap if (x instanceof BigNumber) { // TODO: implement BigNumber support // downgrade to Number - return sec(util.number.toNumber(x)); + return sec(x.toNumber()); } - throw new math.error.UnsupportedTypeError('sec', x); + throw new math.error.UnsupportedTypeError('sec', math['typeof'](x)); }; }; /***/ }, -/* 100 */ +/* 101 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - Unit = __webpack_require__(12), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + Unit = __webpack_require__(9), + collection = __webpack_require__(11), isNumber = util.number.isNumber, isBoolean = util['boolean'].isBoolean, @@ -12422,25 +12638,25 @@ return /******/ (function(modules) { // webpackBootstrap if (x instanceof BigNumber) { // TODO: implement BigNumber support // downgrade to Number - return sin(util.number.toNumber(x)); + return sin(x.toNumber()); } - throw new math.error.UnsupportedTypeError('sin', x); + throw new math.error.UnsupportedTypeError('sin', math['typeof'](x)); }; }; /***/ }, -/* 101 */ +/* 102 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - Unit = __webpack_require__(12), - collection = __webpack_require__(14), + BigNumber = math.type.BigNumber, + Complex = __webpack_require__(5), + Unit = __webpack_require__(9), + collection = __webpack_require__(11), isNumber = util.number.isNumber, isBoolean = util['boolean'].isBoolean, @@ -12498,23 +12714,23 @@ return /******/ (function(modules) { // webpackBootstrap if (x instanceof BigNumber) { // TODO: implement BigNumber support // downgrade to Number - return tan(util.number.toNumber(x)); + return tan(x.toNumber()); } - throw new math.error.UnsupportedTypeError('tan', x); + throw new math.error.UnsupportedTypeError('tan', math['typeof'](x)); }; }; /***/ }, -/* 102 */ +/* 103 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - Unit = __webpack_require__(12), - collection = __webpack_require__(14), + Unit = __webpack_require__(9), + collection = __webpack_require__(11), isString = util.string.isString, isUnit = Unit.isUnit, @@ -12549,17 +12765,18 @@ return /******/ (function(modules) { // webpackBootstrap return collection.deepMap2(x, unit, to); } - throw new math.error.UnsupportedTypeError('to', x, unit); + throw new math.error.UnsupportedTypeError('to', math['typeof'](x), math['typeof'](unit)); }; }; /***/ }, -/* 103 */ +/* 104 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var object = __webpack_require__(3); + var util = __webpack_require__(117), + object = util.object; /** * Clone an object @@ -12580,11 +12797,12 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 104 */ +/* 105 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var string = __webpack_require__(127); + var util = __webpack_require__(117), + string = util.string; /** * Format a value of any type into a string. @@ -12661,38 +12879,140 @@ return /******/ (function(modules) { // webpackBootstrap }; -/***/ }, -/* 105 */ -/***/ function(module, exports, __webpack_require__) { - - module.exports = function (math) { - - /** - * Executes a ternary operation - * @param {*} conditionalExpr The conditional expression - * @param {*} trueExpr The true expression - * @param {*} falseExpr The false expression - * @return {*} The evaluated return expression - */ - math.ifElse = function ifElse(conditionalExpr, trueExpr, falseExpr) { - if (arguments.length != 3) { - throw new math.error.ArgumentsError('ifElse', arguments.length, 3); - } - - return conditionalExpr ? trueExpr : falseExpr; - }; - }; - - /***/ }, /* 106 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var util = __webpack_require__(112), + var util = __webpack_require__(117), - Complex = __webpack_require__(8), - Unit = __webpack_require__(12), + BigNumber = math.type.BigNumber, + Matrix = __webpack_require__(8), + Complex = __webpack_require__(5), + Unit = __webpack_require__(9), + collection = __webpack_require__(11), + + deepEqual = util.object.deepEqual, + isNumber = util.number.isNumber, + isString = util.string.isString, + isBoolean = util['boolean'].isBoolean, + isComplex = Complex.isComplex, + isUnit = Unit.isUnit, + isCollection = collection.isCollection; + + /** + * Execute a conditional expression. + * + * In case of a matrix or array, the test is done element wise, the + * true and false part can be either a matrix/array with the same size + * of the condition, or a scalar value. + * + * @param {Number | Boolean | String | Complex | BigNumber | Unit | Matrix | Array} condition + * The conditional expression + * @param {*} trueExpr The true expression + * @param {*} falseExpr The false expression + * @return {*} The evaluated return expression + */ + math.ifElse = function ifElse(condition, trueExpr, falseExpr) { + if (arguments.length != 3) { + throw new math.error.ArgumentsError('ifElse', arguments.length, 3); + } + + if (isNumber(condition) || isBoolean(condition)) { + return condition ? trueExpr : falseExpr; + } + + if (condition instanceof BigNumber) { + return condition.isZero() ? falseExpr : trueExpr; + } + + if (isString(condition)) { + return condition ? trueExpr : falseExpr; + } + + if (isComplex(condition)) { + return (condition.re || condition.im) ? trueExpr : falseExpr; + } + + if (isUnit(condition)) { + return condition.value ? trueExpr : falseExpr; + } + + if (condition === null || condition === undefined) { + return falseExpr; + } + + if (isCollection(condition)) { + return _ifElseCollection(condition, trueExpr, falseExpr); + } + + throw new math.error.UnsupportedTypeError('ifElse', math['typeof'](condition)); + }; + + /** + * Execute the if-else condition element wise + * @param {Matrix | Array} condition + * @param {*} trueExpr + * @param {*} falseExpr + * @returns {*} + * @private + */ + function _ifElseCollection(condition, trueExpr, falseExpr) { + var asMatrix = (condition instanceof Matrix) || + (trueExpr instanceof Matrix) || + (falseExpr instanceof Matrix); + + // change an array into a matrix + if (!(condition instanceof Matrix)) condition = new Matrix(condition); + + // change the true expression into a matrix and check whether the size + // matches with the condition matrix + if (isCollection(trueExpr)) { + if (!(trueExpr instanceof Matrix)) trueExpr = new Matrix(trueExpr); + + if (!deepEqual(condition.size(), trueExpr.size())) { + throw new RangeError('Dimension mismatch ([' + + condition.size().join(', ') + '] != [' + + trueExpr.size().join(', ') + + '])'); + throw new math.error.DimensionError(condition.size(), trueExpr.size()); + } + } + + // change the false expression into a matrix and check whether the size + // matches with the condition matrix + if (isCollection(falseExpr)) { + if (!(falseExpr instanceof Matrix)) falseExpr = new Matrix(falseExpr); + + if (!deepEqual(condition.size(), falseExpr.size())) { + throw new math.error.DimensionError(condition.size(), falseExpr.size()); + } + } + + // do the actual conditional test element wise + var trueIsMatrix = trueExpr instanceof Matrix, + falseIsMatrix = falseExpr instanceof Matrix; + var result = condition.map(function (value, index) { + return math.ifElse(value, + trueIsMatrix ? trueExpr.get(index) : trueExpr, + falseIsMatrix ? falseExpr.get(index) : falseExpr + ); + }); + + return asMatrix ? result : result.valueOf(); + } + }; + + +/***/ }, +/* 107 */ +/***/ function(module, exports, __webpack_require__) { + + module.exports = function (math) { + var util = __webpack_require__(117), + + Complex = __webpack_require__(5), + Unit = __webpack_require__(9), isNumber = util.number.isNumber, isString = util.string.isString, @@ -12737,7 +13057,7 @@ return /******/ (function(modules) { // webpackBootstrap // istanbul ignore else (we cannot unit test the else case in a node.js environment) if (true) { // load the file using require - var _module = __webpack_require__(144)(object); + var _module = __webpack_require__(149)(object); math_import(_module); } else { @@ -12809,11 +13129,11 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 107 */ +/* 108 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var isMatrix = __webpack_require__(11).isMatrix; + var isMatrix = __webpack_require__(8).isMatrix; /** * Create a new matrix or array with the results of the callback function executed on @@ -12834,7 +13154,7 @@ return /******/ (function(modules) { // webpackBootstrap } else if (isMatrix(x)) { return x.map(callback); } else { - throw new math.error.UnsupportedTypeError('map', x); + throw new math.error.UnsupportedTypeError('map', math['typeof'](x)); } }; @@ -12858,13 +13178,13 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 108 */ +/* 109 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var string = __webpack_require__(127), + var util = __webpack_require__(117), - isString = string.isString; + isString = util.string.isString; /** * Interpolate values into a string template. @@ -12932,19 +13252,18 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 109 */ +/* 110 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var types = __webpack_require__(126), + var types = __webpack_require__(150), - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - Matrix = __webpack_require__(11), - Unit = __webpack_require__(12), - Index = __webpack_require__(10), - Range = __webpack_require__(9), - Help = __webpack_require__(13); + Complex = __webpack_require__(5), + Matrix = __webpack_require__(8), + Unit = __webpack_require__(9), + Index = __webpack_require__(7), + Range = __webpack_require__(6), + Help = __webpack_require__(10); /** * Determines the type of a variable. @@ -12967,13 +13286,14 @@ return /******/ (function(modules) { // webpackBootstrap // math.js types if (type === 'object') { if (x instanceof Complex) return 'complex'; - if (x instanceof BigNumber) return 'bignumber'; if (x instanceof Matrix) return 'matrix'; if (x instanceof Unit) return 'unit'; if (x instanceof Index) return 'index'; if (x instanceof Range) return 'range'; if (x instanceof Help) return 'help'; + // the following types are different instances per math.js instance + if (x instanceof math.type.BigNumber) return 'bignumber'; if (x instanceof math.chaining.Selector) return 'selector'; } @@ -12983,11 +13303,11 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 110 */ +/* 111 */ /***/ function(module, exports, __webpack_require__) { module.exports = function (math) { - var isMatrix = __webpack_require__(11).isMatrix; + var isMatrix = __webpack_require__(8).isMatrix; /** * Execute a callback method on each entry of the matrix or the array. @@ -13006,7 +13326,7 @@ return /******/ (function(modules) { // webpackBootstrap } else if (isMatrix(x)) { return x.forEach(callback); } else { - throw new math.error.UnsupportedTypeError('forEach', x); + throw new math.error.UnsupportedTypeError('forEach', math['typeof'](x)); } }; @@ -13028,2042 +13348,3823 @@ return /******/ (function(modules) { // webpackBootstrap }; -/***/ }, -/* 111 */ -/***/ function(module, exports, __webpack_require__) { - - var __WEBPACK_AMD_DEFINE_RESULT__;/* bignumber.js v1.3.0 https://github.com/MikeMcl/bignumber.js/LICENCE */ - - /*jslint ass: true, bitwise: true, eqeq: true, plusplus: true, sub: true, white: true, maxerr: 500 */ - /*global module, define */ - - ;(function ( global ) { - 'use strict'; - - /* - bignumber.js v1.3.0 - A JavaScript library for arbitrary-precision arithmetic. - https://github.com/MikeMcl/bignumber.js - Copyright (c) 2012 Michael Mclaughlin - MIT Expat Licence - */ - - /*********************************** DEFAULTS ************************************/ - - /* - * The default values below must be integers within the stated ranges (inclusive). - * Most of these values can be changed during run-time using BigNumber.config(). - */ - - /* - * The limit on the value of DECIMAL_PLACES, TO_EXP_NEG, TO_EXP_POS, MIN_EXP, - * MAX_EXP, and the argument to toFixed, toPrecision and toExponential, beyond - * which an exception is thrown (if ERRORS is true). - */ - var MAX = 1E9, // 0 to 1e+9 - - // Limit of magnitude of exponent argument to toPower. - MAX_POWER = 1E6, // 1 to 1e+6 - - // The maximum number of decimal places for operations involving division. - DECIMAL_PLACES = 20, // 0 to MAX - - /* - * The rounding mode used when rounding to the above decimal places, and when - * using toFixed, toPrecision and toExponential, and round (default value). - * UP 0 Away from zero. - * DOWN 1 Towards zero. - * CEIL 2 Towards +Infinity. - * FLOOR 3 Towards -Infinity. - * HALF_UP 4 Towards nearest neighbour. If equidistant, up. - * HALF_DOWN 5 Towards nearest neighbour. If equidistant, down. - * HALF_EVEN 6 Towards nearest neighbour. If equidistant, towards even neighbour. - * HALF_CEIL 7 Towards nearest neighbour. If equidistant, towards +Infinity. - * HALF_FLOOR 8 Towards nearest neighbour. If equidistant, towards -Infinity. - */ - ROUNDING_MODE = 4, // 0 to 8 - - // EXPONENTIAL_AT : [TO_EXP_NEG , TO_EXP_POS] - - // The exponent value at and beneath which toString returns exponential notation. - // Number type: -7 - TO_EXP_NEG = -7, // 0 to -MAX - - // The exponent value at and above which toString returns exponential notation. - // Number type: 21 - TO_EXP_POS = 21, // 0 to MAX - - // RANGE : [MIN_EXP, MAX_EXP] - - // The minimum exponent value, beneath which underflow to zero occurs. - // Number type: -324 (5e-324) - MIN_EXP = -MAX, // -1 to -MAX - - // The maximum exponent value, above which overflow to Infinity occurs. - // Number type: 308 (1.7976931348623157e+308) - MAX_EXP = MAX, // 1 to MAX - - // Whether BigNumber Errors are ever thrown. - // CHANGE parseInt to parseFloat if changing ERRORS to false. - ERRORS = true, // true or false - parse = parseInt, // parseInt or parseFloat - - /***********************************************************************************/ - - P = BigNumber.prototype, - DIGITS = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_', - outOfRange, - id = 0, - isValid = /^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i, - trim = String.prototype.trim || function () {return this.replace(/^\s+|\s+$/g, '')}, - ONE = BigNumber(1); - - - // CONSTRUCTOR - - - /* - * The exported function. - * Create and return a new instance of a BigNumber object. - * - * n {number|string|BigNumber} A numeric value. - * [b] {number} The base of n. Integer, 2 to 64 inclusive. - */ - function BigNumber( n, b ) { - var e, i, isNum, digits, valid, orig, - x = this; - - // Enable constructor usage without new. - if ( !(x instanceof BigNumber) ) { - return new BigNumber( n, b ) - } - - // Duplicate. - if ( n instanceof BigNumber ) { - id = 0; - - // e is undefined. - if ( b !== e ) { - n += '' - } else { - x['s'] = n['s']; - x['e'] = n['e']; - x['c'] = ( n = n['c'] ) ? n.slice() : n; - return; - } - } - - // If number, check if minus zero. - if ( typeof n != 'string' ) { - n = ( isNum = typeof n == 'number' || - Object.prototype.toString.call(n) == '[object Number]' ) && - n === 0 && 1 / n < 0 ? '-0' : n + ''; - } - - orig = n; - - if ( b === e && isValid.test(n) ) { - - // Determine sign. - x['s'] = n.charAt(0) == '-' ? ( n = n.slice(1), -1 ) : 1; - - // Either n is not a valid BigNumber or a base has been specified. - } else { - - // Enable exponential notation to be used with base 10 argument. - // Ensure return value is rounded to DECIMAL_PLACES as with other bases. - if ( b == 10 ) { - - return setMode( n, DECIMAL_PLACES, ROUNDING_MODE ); - } - - n = trim.call(n).replace( /^\+(?!-)/, '' ); - - x['s'] = n.charAt(0) == '-' ? ( n = n.replace( /^-(?!-)/, '' ), -1 ) : 1; - - if ( b != null ) { - - if ( ( b == (b | 0) || !ERRORS ) && - !( outOfRange = !( b >= 2 && b < 65 ) ) ) { - - digits = '[' + DIGITS.slice( 0, b = b | 0 ) + ']+'; - - // Before non-decimal number validity test and base conversion - // remove the `.` from e.g. '1.', and replace e.g. '.1' with '0.1'. - n = n.replace( /\.$/, '' ).replace( /^\./, '0.' ); - - // Any number in exponential form will fail due to the e+/-. - if ( valid = new RegExp( - '^' + digits + '(?:\\.' + digits + ')?$', b < 37 ? 'i' : '' ).test(n) ) { - - if ( isNum ) { - - if ( n.replace( /^0\.0*|\./, '' ).length > 15 ) { - - // 'new BigNumber() number type has more than 15 significant digits: {n}' - ifExceptionsThrow( orig, 0 ); - } - - // Prevent later check for length on converted number. - isNum = !isNum; - } - n = convert( n, 10, b, x['s'] ); - - } else if ( n != 'Infinity' && n != 'NaN' ) { - - // 'new BigNumber() not a base {b} number: {n}' - ifExceptionsThrow( orig, 1, b ); - n = 'NaN'; - } - } else { - - // 'new BigNumber() base not an integer: {b}' - // 'new BigNumber() base out of range: {b}' - ifExceptionsThrow( b, 2 ); - - // Ignore base. - valid = isValid.test(n); - } - } else { - valid = isValid.test(n); - } - - if ( !valid ) { - - // Infinity/NaN - x['c'] = x['e'] = null; - - // NaN - if ( n != 'Infinity' ) { - - // No exception on NaN. - if ( n != 'NaN' ) { - - // 'new BigNumber() not a number: {n}' - ifExceptionsThrow( orig, 3 ); - } - x['s'] = null; - } - id = 0; - - return; - } - } - - // Decimal point? - if ( ( e = n.indexOf('.') ) > -1 ) { - n = n.replace( '.', '' ); - } - - // Exponential form? - if ( ( i = n.search( /e/i ) ) > 0 ) { - - // Determine exponent. - if ( e < 0 ) { - e = i; - } - e += +n.slice( i + 1 ); - n = n.substring( 0, i ); - - } else if ( e < 0 ) { - - // Integer. - e = n.length; - } - - // Determine leading zeros. - for ( i = 0; n.charAt(i) == '0'; i++ ) { - } - - b = n.length; - - // Disallow numbers with over 15 significant digits if number type. - if ( isNum && b > 15 && n.slice(i).length > 15 ) { - - // 'new BigNumber() number type has more than 15 significant digits: {n}' - ifExceptionsThrow( orig, 0 ); - } - id = 0; - - // Overflow? - if ( ( e -= i + 1 ) > MAX_EXP ) { - - // Infinity. - x['c'] = x['e'] = null; - - // Zero or underflow? - } else if ( i == b || e < MIN_EXP ) { - - // Zero. - x['c'] = [ x['e'] = 0 ]; - } else { - - // Determine trailing zeros. - for ( ; n.charAt(--b) == '0'; ) { - } - - x['e'] = e; - x['c'] = []; - - // Convert string to array of digits (without leading and trailing zeros). - for ( e = 0; i <= b; x['c'][e++] = +n.charAt(i++) ) { - } - } - } - - - // CONSTRUCTOR PROPERTIES/METHODS - - - BigNumber['ROUND_UP'] = 0; - BigNumber['ROUND_DOWN'] = 1; - BigNumber['ROUND_CEIL'] = 2; - BigNumber['ROUND_FLOOR'] = 3; - BigNumber['ROUND_HALF_UP'] = 4; - BigNumber['ROUND_HALF_DOWN'] = 5; - BigNumber['ROUND_HALF_EVEN'] = 6; - BigNumber['ROUND_HALF_CEIL'] = 7; - BigNumber['ROUND_HALF_FLOOR'] = 8; - - - /* - * Configure infrequently-changing library-wide settings. - * - * Accept an object or an argument list, with one or many of the following - * properties or parameters respectively: - * [ DECIMAL_PLACES [, ROUNDING_MODE [, EXPONENTIAL_AT [, RANGE [, ERRORS ]]]]] - * - * E.g. - * BigNumber.config(20, 4) is equivalent to - * BigNumber.config({ DECIMAL_PLACES : 20, ROUNDING_MODE : 4 }) - * Ignore properties/parameters set to null or undefined. - * - * Return an object with the properties current values. - */ - BigNumber['config'] = function () { - var v, p, - i = 0, - r = {}, - a = arguments, - o = a[0], - c = 'config', - inRange = function ( n, lo, hi ) { - return !( ( outOfRange = n < lo || n > hi ) || - parse(n) != n && n !== 0 ); - }, - has = o && typeof o == 'object' - ? function () {if ( o.hasOwnProperty(p) ) return ( v = o[p] ) != null} - : function () {if ( a.length > i ) return ( v = a[i++] ) != null}; - - // [DECIMAL_PLACES] {number} Integer, 0 to MAX inclusive. - if ( has( p = 'DECIMAL_PLACES' ) ) { - - if ( inRange( v, 0, MAX ) ) { - DECIMAL_PLACES = v | 0; - } else { - - // 'config() DECIMAL_PLACES not an integer: {v}' - // 'config() DECIMAL_PLACES out of range: {v}' - ifExceptionsThrow( v, p, c ); - } - } - r[p] = DECIMAL_PLACES; - - // [ROUNDING_MODE] {number} Integer, 0 to 8 inclusive. - if ( has( p = 'ROUNDING_MODE' ) ) { - - if ( inRange( v, 0, 8 ) ) { - ROUNDING_MODE = v | 0; - } else { - - // 'config() ROUNDING_MODE not an integer: {v}' - // 'config() ROUNDING_MODE out of range: {v}' - ifExceptionsThrow( v, p, c ); - } - } - r[p] = ROUNDING_MODE; - - /* - * [EXPONENTIAL_AT] {number|number[]} Integer, -MAX to MAX inclusive or - * [ integer -MAX to 0 inclusive, 0 to MAX inclusive ]. - */ - if ( has( p = 'EXPONENTIAL_AT' ) ) { - - if ( inRange( v, -MAX, MAX ) ) { - TO_EXP_NEG = -( TO_EXP_POS = ~~( v < 0 ? -v : +v ) ); - } else if ( !outOfRange && v && inRange( v[0], -MAX, 0 ) && - inRange( v[1], 0, MAX ) ) { - TO_EXP_NEG = ~~v[0]; - TO_EXP_POS = ~~v[1]; - } else { - - // 'config() EXPONENTIAL_AT not an integer or not [integer, integer]: {v}' - // 'config() EXPONENTIAL_AT out of range or not [negative, positive: {v}' - ifExceptionsThrow( v, p, c, 1 ); - } - } - r[p] = [ TO_EXP_NEG, TO_EXP_POS ]; - - /* - * [RANGE][ {number|number[]} Non-zero integer, -MAX to MAX inclusive or - * [ integer -MAX to -1 inclusive, integer 1 to MAX inclusive ]. - */ - if ( has( p = 'RANGE' ) ) { - - if ( inRange( v, -MAX, MAX ) && ~~v ) { - MIN_EXP = -( MAX_EXP = ~~( v < 0 ? -v : +v ) ); - } else if ( !outOfRange && v && inRange( v[0], -MAX, -1 ) && - inRange( v[1], 1, MAX ) ) { - MIN_EXP = ~~v[0], MAX_EXP = ~~v[1]; - } else { - - // 'config() RANGE not a non-zero integer or not [integer, integer]: {v}' - // 'config() RANGE out of range or not [negative, positive: {v}' - ifExceptionsThrow( v, p, c, 1, 1 ); - } - } - r[p] = [ MIN_EXP, MAX_EXP ]; - - // [ERRORS] {boolean|number} true, false, 1 or 0. - if ( has( p = 'ERRORS' ) ) { - - if ( v === !!v || v === 1 || v === 0 ) { - parse = ( outOfRange = id = 0, ERRORS = !!v ) - ? parseInt - : parseFloat; - } else { - - // 'config() ERRORS not a boolean or binary digit: {v}' - ifExceptionsThrow( v, p, c, 0, 0, 1 ); - } - } - r[p] = ERRORS; - - return r; - }; - - - // PRIVATE FUNCTIONS - - - // Assemble error messages. Throw BigNumber Errors. - function ifExceptionsThrow( arg, i, j, isArray, isRange, isErrors) { - - if ( ERRORS ) { - var error, - method = ['new BigNumber', 'cmp', 'div', 'eq', 'gt', 'gte', 'lt', - 'lte', 'minus', 'mod', 'plus', 'times', 'toFr' - ][ id ? id < 0 ? -id : id : 1 / id < 0 ? 1 : 0 ] + '()', - message = outOfRange ? ' out of range' : ' not a' + - ( isRange ? ' non-zero' : 'n' ) + ' integer'; - - message = ( [ - method + ' number type has more than 15 significant digits', - method + ' not a base ' + j + ' number', - method + ' base' + message, - method + ' not a number' ][i] || - j + '() ' + i + ( isErrors - ? ' not a boolean or binary digit' - : message + ( isArray - ? ' or not [' + ( outOfRange - ? ' negative, positive' - : ' integer, integer' ) + ' ]' - : '' ) ) ) + ': ' + arg; - - outOfRange = id = 0; - error = new Error(message); - error['name'] = 'BigNumber Error'; - - throw error; - } - } - - - /* - * Convert a numeric string of baseIn to a numeric string of baseOut. - */ - function convert( nStr, baseOut, baseIn, sign ) { - var e, dvs, dvd, nArr, fracArr, fracBN; - - // Convert string of base bIn to an array of numbers of baseOut. - // Eg. strToArr('255', 10) where baseOut is 16, returns [15, 15]. - // Eg. strToArr('ff', 16) where baseOut is 10, returns [2, 5, 5]. - function strToArr( str, bIn ) { - var j, - i = 0, - strL = str.length, - arrL, - arr = [0]; - - for ( bIn = bIn || baseIn; i < strL; i++ ) { - - for ( arrL = arr.length, j = 0; j < arrL; arr[j] *= bIn, j++ ) { - } - - for ( arr[0] += DIGITS.indexOf( str.charAt(i) ), j = 0; - j < arr.length; - j++ ) { - - if ( arr[j] > baseOut - 1 ) { - - if ( arr[j + 1] == null ) { - arr[j + 1] = 0; - } - arr[j + 1] += arr[j] / baseOut ^ 0; - arr[j] %= baseOut; - } - } - } - - return arr.reverse(); - } - - // Convert array to string. - // E.g. arrToStr( [9, 10, 11] ) becomes '9ab' (in bases above 11). - function arrToStr( arr ) { - var i = 0, - arrL = arr.length, - str = ''; - - for ( ; i < arrL; str += DIGITS.charAt( arr[i++] ) ) { - } - - return str; - } - - if ( baseIn < 37 ) { - nStr = nStr.toLowerCase(); - } - - /* - * If non-integer convert integer part and fraction part separately. - * Convert the fraction part as if it is an integer than use division to - * reduce it down again to a value less than one. - */ - if ( ( e = nStr.indexOf( '.' ) ) > -1 ) { - - /* - * Calculate the power to which to raise the base to get the number - * to divide the fraction part by after it has been converted as an - * integer to the required base. - */ - e = nStr.length - e - 1; - - // Use toFixed to avoid possible exponential notation. - dvs = strToArr( new BigNumber(baseIn)['pow'](e)['toF'](), 10 ); - - nArr = nStr.split('.'); - - // Convert the base of the fraction part (as integer). - dvd = strToArr( nArr[1] ); - - // Convert the base of the integer part. - nArr = strToArr( nArr[0] ); - - // Result will be a BigNumber with a value less than 1. - fracBN = divide( dvd, dvs, dvd.length - dvs.length, sign, baseOut, - // Is least significant digit of integer part an odd number? - nArr[nArr.length - 1] & 1 ); - - fracArr = fracBN['c']; - - // e can be <= 0 ( if e == 0, fracArr is [0] or [1] ). - if ( e = fracBN['e'] ) { - - // Append zeros according to the exponent of the result. - for ( ; ++e; fracArr.unshift(0) ) { - } - - // Append the fraction part to the converted integer part. - nStr = arrToStr(nArr) + '.' + arrToStr(fracArr); - - // fracArr is [1]. - // Fraction digits rounded up, so increment last digit of integer part. - } else if ( fracArr[0] ) { - - if ( nArr[ e = nArr.length - 1 ] < baseOut - 1 ) { - ++nArr[e]; - nStr = arrToStr(nArr); - } else { - nStr = new BigNumber( arrToStr(nArr), - baseOut )['plus'](ONE)['toS'](baseOut); - } - - // fracArr is [0]. No fraction digits. - } else { - nStr = arrToStr(nArr); - } - } else { - - // Simple integer. Convert base. - nStr = arrToStr( strToArr(nStr) ); - } - - return nStr; - } - - - // Perform division in the specified base. Called by div and convert. - function divide( dvd, dvs, exp, s, base, isOdd ) { - var dvsL, dvsT, next, cmp, remI, - dvsZ = dvs.slice(), - dvdI = dvsL = dvs.length, - dvdL = dvd.length, - rem = dvd.slice( 0, dvsL ), - remL = rem.length, - quo = new BigNumber(ONE), - qc = quo['c'] = [], - qi = 0, - dig = DECIMAL_PLACES + ( quo['e'] = exp ) + 1; - - quo['s'] = s; - s = dig < 0 ? 0 : dig; - - // Add zeros to make remainder as long as divisor. - for ( ; remL++ < dvsL; rem.push(0) ) { - } - - // Create version of divisor with leading zero. - dvsZ.unshift(0); - - do { - - // 'next' is how many times the divisor goes into the current remainder. - for ( next = 0; next < base; next++ ) { - - // Compare divisor and remainder. - if ( dvsL != ( remL = rem.length ) ) { - cmp = dvsL > remL ? 1 : -1; - } else { - for ( remI = -1, cmp = 0; ++remI < dvsL; ) { - - if ( dvs[remI] != rem[remI] ) { - cmp = dvs[remI] > rem[remI] ? 1 : -1; - break; - } - } - } - - // Subtract divisor from remainder (if divisor < remainder). - if ( cmp < 0 ) { - - // Remainder cannot be more than one digit longer than divisor. - // Equalise lengths using divisor with extra leading zero? - for ( dvsT = remL == dvsL ? dvs : dvsZ; remL; ) { - - if ( rem[--remL] < dvsT[remL] ) { - - for ( remI = remL; - remI && !rem[--remI]; - rem[remI] = base - 1 ) { - } - --rem[remI]; - rem[remL] += base; - } - rem[remL] -= dvsT[remL]; - } - for ( ; !rem[0]; rem.shift() ) { - } - } else { - break; - } - } - - // Add the 'next' digit to the result array. - qc[qi++] = cmp ? next : ++next; - - // Update the remainder. - rem[0] && cmp - ? ( rem[remL] = dvd[dvdI] || 0 ) - : ( rem = [ dvd[dvdI] ] ); - - } while ( ( dvdI++ < dvdL || rem[0] != null ) && s-- ); - - // Leading zero? Do not remove if result is simply zero (qi == 1). - if ( !qc[0] && qi != 1 ) { - - // There can't be more than one zero. - --quo['e']; - qc.shift(); - } - - // Round? - if ( qi > dig ) { - rnd( quo, DECIMAL_PLACES, base, isOdd, rem[0] != null ); - } - - // Overflow? - if ( quo['e'] > MAX_EXP ) { - - // Infinity. - quo['c'] = quo['e'] = null; - - // Underflow? - } else if ( quo['e'] < MIN_EXP ) { - - // Zero. - quo['c'] = [quo['e'] = 0]; - } - - return quo; - } - - - /* - * Return a string representing the value of BigNumber n in normal or - * exponential notation rounded to the specified decimal places or - * significant digits. - * Called by toString, toExponential (exp 1), toFixed, and toPrecision (exp 2). - * d is the index (with the value in normal notation) of the digit that may be - * rounded up. - */ - function format( n, d, exp ) { - - // Initially, i is the number of decimal places required. - var i = d - (n = new BigNumber(n))['e'], - c = n['c']; - - // +-Infinity or NaN? - if ( !c ) { - return n['toS'](); - } - - // Round? - if ( c.length > ++d ) { - rnd( n, i, 10 ); - } - - // Recalculate d if toFixed as n['e'] may have changed if value rounded up. - i = c[0] == 0 ? i + 1 : exp ? d : n['e'] + i + 1; - - // Append zeros? - for ( ; c.length < i; c.push(0) ) { - } - i = n['e']; - - /* - * toPrecision returns exponential notation if the number of significant - * digits specified is less than the number of digits necessary to - * represent the integer part of the value in normal notation. - */ - return exp == 1 || exp == 2 && ( --d < i || i <= TO_EXP_NEG ) - - // Exponential notation. - ? ( n['s'] < 0 && c[0] ? '-' : '' ) + ( c.length > 1 - ? ( c.splice( 1, 0, '.' ), c.join('') ) - : c[0] ) + ( i < 0 ? 'e' : 'e+' ) + i - - // Normal notation. - : n['toS'](); - } - - - // Round if necessary. - // Called by divide, format, setMode and sqrt. - function rnd( x, dp, base, isOdd, r ) { - var xc = x['c'], - isNeg = x['s'] < 0, - half = base / 2, - i = x['e'] + dp + 1, - - // 'next' is the digit after the digit that may be rounded up. - next = xc[i], - - /* - * 'more' is whether there are digits after 'next'. - * E.g. - * 0.005 (e = -3) to be rounded to 0 decimal places (dp = 0) gives i = -2 - * The 'next' digit is zero, and there ARE 'more' digits after it. - * 0.5 (e = -1) dp = 0 gives i = 0 - * The 'next' digit is 5 and there are no 'more' digits after it. - */ - more = r || i < 0 || xc[i + 1] != null; - - r = ROUNDING_MODE < 4 - ? ( next != null || more ) && - ( ROUNDING_MODE == 0 || - ROUNDING_MODE == 2 && !isNeg || - ROUNDING_MODE == 3 && isNeg ) - : next > half || next == half && - ( ROUNDING_MODE == 4 || more || - - /* - * isOdd is used in base conversion and refers to the least significant - * digit of the integer part of the value to be converted. The fraction - * part is rounded by this method separately from the integer part. - */ - ROUNDING_MODE == 6 && ( xc[i - 1] & 1 || !dp && isOdd ) || - ROUNDING_MODE == 7 && !isNeg || - ROUNDING_MODE == 8 && isNeg ); - - if ( i < 1 || !xc[0] ) { - xc.length = 0; - xc.push(0); - - if ( r ) { - - // 1, 0.1, 0.01, 0.001, 0.0001 etc. - xc[0] = 1; - x['e'] = -dp; - } else { - - // Zero. - x['e'] = 0; - } - - return x; - } - - // Remove any digits after the required decimal places. - xc.length = i--; - - // Round up? - if ( r ) { - - // Rounding up may mean the previous digit has to be rounded up and so on. - for ( --base; ++xc[i] > base; ) { - xc[i] = 0; - - if ( !i-- ) { - ++x['e']; - xc.unshift(1); - } - } - } - - // Remove trailing zeros. - for ( i = xc.length; !xc[--i]; xc.pop() ) { - } - - return x; - } - - - // Round after setting the appropriate rounding mode. - // Handles ceil, floor and round. - function setMode( x, dp, rm ) { - var r = ROUNDING_MODE; - - ROUNDING_MODE = rm; - x = new BigNumber(x); - x['c'] && rnd( x, dp, 10 ); - ROUNDING_MODE = r; - - return x; - } - - - // PROTOTYPE/INSTANCE METHODS - - - /* - * Return a new BigNumber whose value is the absolute value of this BigNumber. - */ - P['abs'] = P['absoluteValue'] = function () { - var x = new BigNumber(this); - - if ( x['s'] < 0 ) { - x['s'] = 1; - } - - return x; - }; - - - /* - * Return a new BigNumber whose value is the value of this BigNumber - * rounded to a whole number in the direction of Infinity. - */ - P['ceil'] = function () { - return setMode( this, 0, 2 ); - }; - - - /* - * Return - * 1 if the value of this BigNumber is greater than the value of BigNumber(y, b), - * -1 if the value of this BigNumber is less than the value of BigNumber(y, b), - * 0 if they have the same value, - * or null if the value of either is NaN. - */ - P['comparedTo'] = P['cmp'] = function ( y, b ) { - var a, - x = this, - xc = x['c'], - yc = ( id = -id, y = new BigNumber( y, b ) )['c'], - i = x['s'], - j = y['s'], - k = x['e'], - l = y['e']; - - // Either NaN? - if ( !i || !j ) { - return null; - } - - a = xc && !xc[0], b = yc && !yc[0]; - - // Either zero? - if ( a || b ) { - return a ? b ? 0 : -j : i; - } - - // Signs differ? - if ( i != j ) { - return i; - } - - // Either Infinity? - if ( a = i < 0, b = k == l, !xc || !yc ) { - return b ? 0 : !xc ^ a ? 1 : -1; - } - - // Compare exponents. - if ( !b ) { - return k > l ^ a ? 1 : -1; - } - - // Compare digit by digit. - for ( i = -1, - j = ( k = xc.length ) < ( l = yc.length ) ? k : l; - ++i < j; ) { - - if ( xc[i] != yc[i] ) { - return xc[i] > yc[i] ^ a ? 1 : -1; - } - } - // Compare lengths. - return k == l ? 0 : k > l ^ a ? 1 : -1; - }; - - - /* - * n / 0 = I - * n / N = N - * n / I = 0 - * 0 / n = 0 - * 0 / 0 = N - * 0 / N = N - * 0 / I = 0 - * N / n = N - * N / 0 = N - * N / N = N - * N / I = N - * I / n = I - * I / 0 = I - * I / N = N - * I / I = N - * - * Return a new BigNumber whose value is the value of this BigNumber - * divided by the value of BigNumber(y, b), rounded according to - * DECIMAL_PLACES and ROUNDING_MODE. - */ - P['dividedBy'] = P['div'] = function ( y, b ) { - var xc = this['c'], - xe = this['e'], - xs = this['s'], - yc = ( id = 2, y = new BigNumber( y, b ) )['c'], - ye = y['e'], - ys = y['s'], - s = xs == ys ? 1 : -1; - - // Either NaN/Infinity/0? - return !xe && ( !xc || !xc[0] ) || !ye && ( !yc || !yc[0] ) - - // Either NaN? - ? new BigNumber( !xs || !ys || - - // Both 0 or both Infinity? - ( xc ? yc && xc[0] == yc[0] : !yc ) - - // Return NaN. - ? NaN - - // x is 0 or y is Infinity? - : xc && xc[0] == 0 || !yc - - // Return +-0. - ? s * 0 - - // y is 0. Return +-Infinity. - : s / 0 ) - - : divide( xc, yc, xe - ye, s, 10 ); - }; - - - /* - * Return true if the value of this BigNumber is equal to the value of - * BigNumber(n, b), otherwise returns false. - */ - P['equals'] = P['eq'] = function ( n, b ) { - id = 3; - return this['cmp']( n, b ) === 0; - }; - - - /* - * Return a new BigNumber whose value is the value of this BigNumber - * rounded to a whole number in the direction of -Infinity. - */ - P['floor'] = function () { - return setMode( this, 0, 3 ); - }; - - - /* - * Return true if the value of this BigNumber is greater than the value of - * BigNumber(n, b), otherwise returns false. - */ - P['greaterThan'] = P['gt'] = function ( n, b ) { - id = 4; - return this['cmp']( n, b ) > 0; - }; - - - /* - * Return true if the value of this BigNumber is greater than or equal to - * the value of BigNumber(n, b), otherwise returns false. - */ - P['greaterThanOrEqualTo'] = P['gte'] = function ( n, b ) { - id = 5; - return ( b = this['cmp']( n, b ) ) == 1 || b === 0; - }; - - - /* - * Return true if the value of this BigNumber is a finite number, otherwise - * returns false. - */ - P['isFinite'] = P['isF'] = function () { - return !!this['c']; - }; - - - /* - * Return true if the value of this BigNumber is NaN, otherwise returns - * false. - */ - P['isNaN'] = function () { - return !this['s']; - }; - - - /* - * Return true if the value of this BigNumber is negative, otherwise - * returns false. - */ - P['isNegative'] = P['isNeg'] = function () { - return this['s'] < 0; - }; - - - /* - * Return true if the value of this BigNumber is 0 or -0, otherwise returns - * false. - */ - P['isZero'] = P['isZ'] = function () { - return !!this['c'] && this['c'][0] == 0; - }; - - - /* - * Return true if the value of this BigNumber is less than the value of - * BigNumber(n, b), otherwise returns false. - */ - P['lessThan'] = P['lt'] = function ( n, b ) { - id = 6; - return this['cmp']( n, b ) < 0; - }; - - - /* - * Return true if the value of this BigNumber is less than or equal to the - * value of BigNumber(n, b), otherwise returns false. - */ - P['lessThanOrEqualTo'] = P['lte'] = function ( n, b ) { - id = 7; - return ( b = this['cmp']( n, b ) ) == -1 || b === 0; - }; - - - /* - * n - 0 = n - * n - N = N - * n - I = -I - * 0 - n = -n - * 0 - 0 = 0 - * 0 - N = N - * 0 - I = -I - * N - n = N - * N - 0 = N - * N - N = N - * N - I = N - * I - n = I - * I - 0 = I - * I - N = N - * I - I = N - * - * Return a new BigNumber whose value is the value of this BigNumber minus - * the value of BigNumber(y, b). - */ - P['minus'] = function ( y, b ) { - var d, i, j, xLTy, - x = this, - a = x['s']; - - b = ( id = 8, y = new BigNumber( y, b ) )['s']; - - // Either NaN? - if ( !a || !b ) { - return new BigNumber(NaN); - } - - // Signs differ? - if ( a != b ) { - return y['s'] = -b, x['plus'](y); - } - - var xc = x['c'], - xe = x['e'], - yc = y['c'], - ye = y['e']; - - if ( !xe || !ye ) { - - // Either Infinity? - if ( !xc || !yc ) { - return xc ? ( y['s'] = -b, y ) : new BigNumber( yc ? x : NaN ); - } - - // Either zero? - if ( !xc[0] || !yc[0] ) { - - // y is non-zero? - return yc[0] - ? ( y['s'] = -b, y ) - - // x is non-zero? - : new BigNumber( xc[0] - ? x - - // Both are zero. - // IEEE 754 (2008) 6.3: n - n = -0 when rounding to -Infinity - : ROUNDING_MODE == 3 ? -0 : 0 ); - } - } - - // Determine which is the bigger number. - // Prepend zeros to equalise exponents. - if ( xc = xc.slice(), a = xe - ye ) { - d = ( xLTy = a < 0 ) ? ( a = -a, xc ) : ( ye = xe, yc ); - - for ( d.reverse(), b = a; b--; d.push(0) ) { - } - d.reverse(); - } else { - - // Exponents equal. Check digit by digit. - j = ( ( xLTy = xc.length < yc.length ) ? xc : yc ).length; - - for ( a = b = 0; b < j; b++ ) { - - if ( xc[b] != yc[b] ) { - xLTy = xc[b] < yc[b]; - break; - } - } - } - - // x < y? Point xc to the array of the bigger number. - if ( xLTy ) { - d = xc, xc = yc, yc = d; - y['s'] = -y['s']; - } - - /* - * Append zeros to xc if shorter. No need to add zeros to yc if shorter - * as subtraction only needs to start at yc.length. - */ - if ( ( b = -( ( j = xc.length ) - yc.length ) ) > 0 ) { - - for ( ; b--; xc[j++] = 0 ) { - } - } - - // Subtract yc from xc. - for ( b = yc.length; b > a; ){ - - if ( xc[--b] < yc[b] ) { - - for ( i = b; i && !xc[--i]; xc[i] = 9 ) { - } - --xc[i]; - xc[b] += 10; - } - xc[b] -= yc[b]; - } - - // Remove trailing zeros. - for ( ; xc[--j] == 0; xc.pop() ) { - } - - // Remove leading zeros and adjust exponent accordingly. - for ( ; xc[0] == 0; xc.shift(), --ye ) { - } - - /* - * No need to check for Infinity as +x - +y != Infinity && -x - -y != Infinity - * when neither x or y are Infinity. - */ - - // Underflow? - if ( ye < MIN_EXP || !xc[0] ) { - - /* - * Following IEEE 754 (2008) 6.3, - * n - n = +0 but n - n = -0 when rounding towards -Infinity. - */ - if ( !xc[0] ) { - y['s'] = ROUNDING_MODE == 3 ? -1 : 1; - } - - // Result is zero. - xc = [ye = 0]; - } - - return y['c'] = xc, y['e'] = ye, y; - }; - - - /* - * n % 0 = N - * n % N = N - * 0 % n = 0 - * -0 % n = -0 - * 0 % 0 = N - * 0 % N = N - * N % n = N - * N % 0 = N - * N % N = N - * - * Return a new BigNumber whose value is the value of this BigNumber modulo - * the value of BigNumber(y, b). - */ - P['modulo'] = P['mod'] = function ( y, b ) { - var x = this, - xc = x['c'], - yc = ( id = 9, y = new BigNumber( y, b ) )['c'], - i = x['s'], - j = y['s']; - - // Is x or y NaN, or y zero? - b = !i || !j || yc && !yc[0]; - - if ( b || xc && !xc[0] ) { - return new BigNumber( b ? NaN : x ); - } - - x['s'] = y['s'] = 1; - b = y['cmp'](x) == 1; - x['s'] = i, y['s'] = j; - - return b - ? new BigNumber(x) - : ( i = DECIMAL_PLACES, j = ROUNDING_MODE, - DECIMAL_PLACES = 0, ROUNDING_MODE = 1, - x = x['div'](y), - DECIMAL_PLACES = i, ROUNDING_MODE = j, - this['minus']( x['times'](y) ) ); - }; - - - /* - * Return a new BigNumber whose value is the value of this BigNumber - * negated, i.e. multiplied by -1. - */ - P['negated'] = P['neg'] = function () { - var x = new BigNumber(this); - - return x['s'] = -x['s'] || null, x; - }; - - - /* - * n + 0 = n - * n + N = N - * n + I = I - * 0 + n = n - * 0 + 0 = 0 - * 0 + N = N - * 0 + I = I - * N + n = N - * N + 0 = N - * N + N = N - * N + I = N - * I + n = I - * I + 0 = I - * I + N = N - * I + I = I - * - * Return a new BigNumber whose value is the value of this BigNumber plus - * the value of BigNumber(y, b). - */ - P['plus'] = function ( y, b ) { - var d, - x = this, - a = x['s']; - - b = ( id = 10, y = new BigNumber( y, b ) )['s']; - - // Either NaN? - if ( !a || !b ) { - return new BigNumber(NaN); - } - - // Signs differ? - if ( a != b ) { - return y['s'] = -b, x['minus'](y); - } - - var xe = x['e'], - xc = x['c'], - ye = y['e'], - yc = y['c']; - - if ( !xe || !ye ) { - - // Either Infinity? - if ( !xc || !yc ) { - - // Return +-Infinity. - return new BigNumber( a / 0 ); - } - - // Either zero? - if ( !xc[0] || !yc[0] ) { - - // y is non-zero? - return yc[0] - ? y - - // x is non-zero? - : new BigNumber( xc[0] - ? x - - // Both are zero. Return zero. - : a * 0 ); - } - } - - // Prepend zeros to equalise exponents. - // Note: Faster to use reverse then do unshifts. - if ( xc = xc.slice(), a = xe - ye ) { - d = a > 0 ? ( ye = xe, yc ) : ( a = -a, xc ); - - for ( d.reverse(); a--; d.push(0) ) { - } - d.reverse(); - } - - // Point xc to the longer array. - if ( xc.length - yc.length < 0 ) { - d = yc, yc = xc, xc = d; - } - - /* - * Only start adding at yc.length - 1 as the - * further digits of xc can be left as they are. - */ - for ( a = yc.length, b = 0; a; - b = ( xc[--a] = xc[a] + yc[a] + b ) / 10 ^ 0, xc[a] %= 10 ) { - } - - // No need to check for zero, as +x + +y != 0 && -x + -y != 0 - - if ( b ) { - xc.unshift(b); - - // Overflow? (MAX_EXP + 1 possible) - if ( ++ye > MAX_EXP ) { - - // Infinity. - xc = ye = null; - } - } - - // Remove trailing zeros. - for ( a = xc.length; xc[--a] == 0; xc.pop() ) { - } - - return y['c'] = xc, y['e'] = ye, y; - }; - - - /* - * Return a BigNumber whose value is the value of this BigNumber raised to - * the power e. If e is negative round according to DECIMAL_PLACES and - * ROUNDING_MODE. - * - * e {number} Integer, -MAX_POWER to MAX_POWER inclusive. - */ - P['toPower'] = P['pow'] = function ( e ) { - - // e to integer, avoiding NaN or Infinity becoming 0. - var i = e * 0 == 0 ? e | 0 : e, - x = new BigNumber(this), - y = new BigNumber(ONE); - - // Use Math.pow? - // Pass +-Infinity for out of range exponents. - if ( ( ( ( outOfRange = e < -MAX_POWER || e > MAX_POWER ) && - (i = e * 1 / 0) ) || - - /* - * Any exponent that fails the parse becomes NaN. - * - * Include 'e !== 0' because on Opera -0 == parseFloat(-0) is false, - * despite -0 === parseFloat(-0) && -0 == parseFloat('-0') is true. - */ - parse(e) != e && e !== 0 && !(i = NaN) ) && - - // 'pow() exponent not an integer: {e}' - // 'pow() exponent out of range: {e}' - !ifExceptionsThrow( e, 'exponent', 'pow' ) || - - // Pass zero to Math.pow, as any value to the power zero is 1. - !i ) { - - // i is +-Infinity, NaN or 0. - return new BigNumber( Math.pow( x['toS'](), i ) ); - } - - for ( i = i < 0 ? -i : i; ; ) { - - if ( i & 1 ) { - y = y['times'](x); - } - i >>= 1; - - if ( !i ) { - break; - } - x = x['times'](x); - } - - return e < 0 ? ONE['div'](y) : y; - }; - - - /* - * Return a new BigNumber whose value is the value of this BigNumber - * rounded to a maximum of dp decimal places using rounding mode rm, or to - * 0 and ROUNDING_MODE respectively if omitted. - * - * [dp] {number} Integer, 0 to MAX inclusive. - * [rm] {number} Integer, 0 to 8 inclusive. - */ - P['round'] = function ( dp, rm ) { - - dp = dp == null || ( ( ( outOfRange = dp < 0 || dp > MAX ) || - parse(dp) != dp ) && - - // 'round() decimal places out of range: {dp}' - // 'round() decimal places not an integer: {dp}' - !ifExceptionsThrow( dp, 'decimal places', 'round' ) ) - ? 0 - : dp | 0; - - rm = rm == null || ( ( ( outOfRange = rm < 0 || rm > 8 ) || - - // Include '&& rm !== 0' because with Opera -0 == parseFloat(-0) is false. - parse(rm) != rm && rm !== 0 ) && - - // 'round() mode not an integer: {rm}' - // 'round() mode out of range: {rm}' - !ifExceptionsThrow( rm, 'mode', 'round' ) ) - ? ROUNDING_MODE - : rm | 0; - - return setMode( this, dp, rm ); - }; - - - /* - * sqrt(-n) = N - * sqrt( N) = N - * sqrt(-I) = N - * sqrt( I) = I - * sqrt( 0) = 0 - * sqrt(-0) = -0 - * - * Return a new BigNumber whose value is the square root of the value of - * this BigNumber, rounded according to DECIMAL_PLACES and ROUNDING_MODE. - */ - P['squareRoot'] = P['sqrt'] = function () { - var n, r, re, t, - x = this, - c = x['c'], - s = x['s'], - e = x['e'], - dp = DECIMAL_PLACES, - rm = ROUNDING_MODE, - half = new BigNumber('0.5'); - - // Negative/NaN/Infinity/zero? - if ( s !== 1 || !c || !c[0] ) { - - return new BigNumber( !s || s < 0 && ( !c || c[0] ) - ? NaN - : c ? x : 1 / 0 ); - } - - // Initial estimate. - s = Math.sqrt( x['toS']() ); - ROUNDING_MODE = 1; - - /* - Math.sqrt underflow/overflow? - Pass x to Math.sqrt as integer, then adjust the exponent of the result. - */ - if ( s == 0 || s == 1 / 0 ) { - n = c.join(''); - - if ( !( n.length + e & 1 ) ) { - n += '0'; - } - r = new BigNumber( Math.sqrt(n) + '' ); - - // r may still not be finite. - if ( !r['c'] ) { - r['c'] = [1]; - } - r['e'] = ( ( ( e + 1 ) / 2 ) | 0 ) - ( e < 0 || e & 1 ); - } else { - r = new BigNumber( n = s.toString() ); - } - re = r['e']; - s = re + ( DECIMAL_PLACES += 4 ); - - if ( s < 3 ) { - s = 0; - } - e = s; - - // Newton-Raphson iteration. - for ( ; ; ) { - t = r; - r = half['times']( t['plus']( x['div'](t) ) ); - - if ( t['c'].slice( 0, s ).join('') === r['c'].slice( 0, s ).join('') ) { - c = r['c']; - - /* - The exponent of r may here be one less than the final result - exponent (re), e.g 0.0009999 (e-4) --> 0.001 (e-3), so adjust - s so the rounding digits are indexed correctly. - */ - s = s - ( n && r['e'] < re ); - - /* - The 4th rounding digit may be in error by -1 so if the 4 rounding - digits are 9999 or 4999 (i.e. approaching a rounding boundary) - continue the iteration. - */ - if ( c[s] == 9 && c[s - 1] == 9 && c[s - 2] == 9 && - ( c[s - 3] == 9 || n && c[s - 3] == 4 ) ) { - - /* - If 9999 on first run through, check to see if rounding up - gives the exact result as the nines may infinitely repeat. - */ - if ( n && c[s - 3] == 9 ) { - t = r['round']( dp, 0 ); - - if ( t['times'](t)['eq'](x) ) { - ROUNDING_MODE = rm; - DECIMAL_PLACES = dp; - - return t; - } - } - DECIMAL_PLACES += 4; - s += 4; - n = ''; - } else { - - /* - If the rounding digits are null, 0000 or 5000, check for an - exact result. If not, then there are further digits so - increment the 1st rounding digit to ensure correct rounding. - */ - if ( !c[e] && !c[e - 1] && !c[e - 2] && - ( !c[e - 3] || c[e - 3] == 5 ) ) { - - // Truncate to the first rounding digit. - if ( c.length > e - 2 ) { - c.length = e - 2; - } - - if ( !r['times'](r)['eq'](x) ) { - - while ( c.length < e - 3 ) { - c.push(0); - } - c[e - 3]++; - } - } - ROUNDING_MODE = rm; - rnd( r, DECIMAL_PLACES = dp, 10 ); - - return r; - } - } - } - }; - - - /* - * n * 0 = 0 - * n * N = N - * n * I = I - * 0 * n = 0 - * 0 * 0 = 0 - * 0 * N = N - * 0 * I = N - * N * n = N - * N * 0 = N - * N * N = N - * N * I = N - * I * n = I - * I * 0 = N - * I * N = N - * I * I = I - * - * Return a new BigNumber whose value is the value of this BigNumber times - * the value of BigNumber(y, b). - */ - P['times'] = function ( y, b ) { - var c, - x = this, - xc = x['c'], - yc = ( id = 11, y = new BigNumber( y, b ) )['c'], - i = x['e'], - j = y['e'], - a = x['s']; - - y['s'] = a == ( b = y['s'] ) ? 1 : -1; - - // Either NaN/Infinity/0? - if ( !i && ( !xc || !xc[0] ) || !j && ( !yc || !yc[0] ) ) { - - // Either NaN? - return new BigNumber( !a || !b || - - // x is 0 and y is Infinity or y is 0 and x is Infinity? - xc && !xc[0] && !yc || yc && !yc[0] && !xc - - // Return NaN. - ? NaN - - // Either Infinity? - : !xc || !yc - - // Return +-Infinity. - ? y['s'] / 0 - - // x or y is 0. Return +-0. - : y['s'] * 0 ); - } - y['e'] = i + j; - - if ( ( a = xc.length ) < ( b = yc.length ) ) { - c = xc, xc = yc, yc = c, j = a, a = b, b = j; - } - - for ( j = a + b, c = []; j--; c.push(0) ) { - } - - // Multiply! - for ( i = b - 1; i > -1; i-- ) { - - for ( b = 0, j = a + i; - j > i; - b = c[j] + yc[i] * xc[j - i - 1] + b, - c[j--] = b % 10 | 0, - b = b / 10 | 0 ) { - } - - if ( b ) { - c[j] = ( c[j] + b ) % 10; - } - } - - b && ++y['e']; - - // Remove any leading zero. - !c[0] && c.shift(); - - // Remove trailing zeros. - for ( j = c.length; !c[--j]; c.pop() ) { - } - - // No zero check needed as only x * 0 == 0 etc. - - // Overflow? - y['c'] = y['e'] > MAX_EXP - - // Infinity. - ? ( y['e'] = null ) - - // Underflow? - : y['e'] < MIN_EXP - - // Zero. - ? [ y['e'] = 0 ] - - // Neither. - : c; - - return y; - }; - - - /* - * Return a string representing the value of this BigNumber in exponential - * notation to dp fixed decimal places and rounded using ROUNDING_MODE if - * necessary. - * - * [dp] {number} Integer, 0 to MAX inclusive. - */ - P['toExponential'] = P['toE'] = function ( dp ) { - - return format( this, - ( dp == null || ( ( outOfRange = dp < 0 || dp > MAX ) || - - /* - * Include '&& dp !== 0' because with Opera -0 == parseFloat(-0) is - * false, despite -0 == parseFloat('-0') && 0 == -0 being true. - */ - parse(dp) != dp && dp !== 0 ) && - - // 'toE() decimal places not an integer: {dp}' - // 'toE() decimal places out of range: {dp}' - !ifExceptionsThrow( dp, 'decimal places', 'toE' ) ) && this['c'] - ? this['c'].length - 1 - : dp | 0, 1 ); - }; - - - /* - * Return a string representing the value of this BigNumber in normal - * notation to dp fixed decimal places and rounded using ROUNDING_MODE if - * necessary. - * - * Note: as with JavaScript's number type, (-0).toFixed(0) is '0', - * but e.g. (-0.00001).toFixed(0) is '-0'. - * - * [dp] {number} Integer, 0 to MAX inclusive. - */ - P['toFixed'] = P['toF'] = function ( dp ) { - var n, str, d, - x = this; - - if ( !( dp == null || ( ( outOfRange = dp < 0 || dp > MAX ) || - parse(dp) != dp && dp !== 0 ) && - - // 'toF() decimal places not an integer: {dp}' - // 'toF() decimal places out of range: {dp}' - !ifExceptionsThrow( dp, 'decimal places', 'toF' ) ) ) { - d = x['e'] + ( dp | 0 ); - } - - n = TO_EXP_NEG, dp = TO_EXP_POS; - TO_EXP_NEG = -( TO_EXP_POS = 1 / 0 ); - - // Note: str is initially undefined. - if ( d == str ) { - str = x['toS'](); - } else { - str = format( x, d ); - - // (-0).toFixed() is '0', but (-0.1).toFixed() is '-0'. - // (-0).toFixed(1) is '0.0', but (-0.01).toFixed(1) is '-0.0'. - if ( x['s'] < 0 && x['c'] ) { - - // As e.g. -0 toFixed(3), will wrongly be returned as -0.000 from toString. - if ( !x['c'][0] ) { - str = str.replace(/^-/, ''); - - // As e.g. -0.5 if rounded to -0 will cause toString to omit the minus sign. - } else if ( str.indexOf('-') < 0 ) { - str = '-' + str; - } - } - } - TO_EXP_NEG = n, TO_EXP_POS = dp; - - return str; - }; - - - /* - * Return a string array representing the value of this BigNumber as a - * simple fraction with an integer numerator and an integer denominator. - * The denominator will be a positive non-zero value less than or equal to - * the specified maximum denominator. If a maximum denominator is not - * specified, the denominator will be the lowest value necessary to - * represent the number exactly. - * - * [maxD] {number|string|BigNumber} Integer >= 1 and < Infinity. - */ - P['toFraction'] = P['toFr'] = function ( maxD ) { - var q, frac, n0, d0, d2, n, e, - n1 = d0 = new BigNumber(ONE), - d1 = n0 = new BigNumber('0'), - x = this, - xc = x['c'], - exp = MAX_EXP, - dp = DECIMAL_PLACES, - rm = ROUNDING_MODE, - d = new BigNumber(ONE); - - // NaN, Infinity. - if ( !xc ) { - return x['toS'](); - } - - e = d['e'] = xc.length - x['e'] - 1; - - // If max denominator is undefined or null... - if ( maxD == null || - - // or NaN... - ( !( id = 12, n = new BigNumber(maxD) )['s'] || - - // or less than 1, or Infinity... - ( outOfRange = n['cmp'](n1) < 0 || !n['c'] ) || - - // or not an integer... - ( ERRORS && n['e'] < n['c'].length - 1 ) ) && - - // 'toFr() max denominator not an integer: {maxD}' - // 'toFr() max denominator out of range: {maxD}' - !ifExceptionsThrow( maxD, 'max denominator', 'toFr' ) || - - // or greater than the maxD needed to specify the value exactly... - ( maxD = n )['cmp'](d) > 0 ) { - - // d is e.g. 10, 100, 1000, 10000... , n1 is 1. - maxD = e > 0 ? d : n1; - } - - MAX_EXP = 1 / 0; - n = new BigNumber( xc.join('') ); - - for ( DECIMAL_PLACES = 0, ROUNDING_MODE = 1; ; ) { - q = n['div'](d); - d2 = d0['plus']( q['times'](d1) ); - - if ( d2['cmp'](maxD) == 1 ) { - break; - } - - d0 = d1, d1 = d2; - - n1 = n0['plus']( q['times']( d2 = n1 ) ); - n0 = d2; - - d = n['minus']( q['times']( d2 = d ) ); - n = d2; - } - - d2 = maxD['minus'](d0)['div'](d1); - n0 = n0['plus']( d2['times'](n1) ); - d0 = d0['plus']( d2['times'](d1) ); - - n0['s'] = n1['s'] = x['s']; - - DECIMAL_PLACES = e * 2; - ROUNDING_MODE = rm; - - // Determine which fraction is closer to x, n0 / d0 or n1 / d1? - frac = n1['div'](d1)['minus'](x)['abs']()['cmp']( - n0['div'](d0)['minus'](x)['abs']() ) < 1 - ? [ n1['toS'](), d1['toS']() ] - : [ n0['toS'](), d0['toS']() ]; - - return MAX_EXP = exp, DECIMAL_PLACES = dp, frac; - }; - - - /* - * Return a string representing the value of this BigNumber to sd significant - * digits and rounded using ROUNDING_MODE if necessary. - * If sd is less than the number of digits necessary to represent the integer - * part of the value in normal notation, then use exponential notation. - * - * sd {number} Integer, 1 to MAX inclusive. - */ - P['toPrecision'] = P['toP'] = function ( sd ) { - - /* - * ERRORS true: Throw if sd not undefined, null or an integer in range. - * ERRORS false: Ignore sd if not a number or not in range. - * Truncate non-integers. - */ - return sd == null || ( ( ( outOfRange = sd < 1 || sd > MAX ) || - parse(sd) != sd ) && - - // 'toP() precision not an integer: {sd}' - // 'toP() precision out of range: {sd}' - !ifExceptionsThrow( sd, 'precision', 'toP' ) ) - ? this['toS']() - : format( this, --sd | 0, 2 ); - }; - - - /* - * Return a string representing the value of this BigNumber in base b, or - * base 10 if b is omitted. If a base is specified, including base 10, - * round according to DECIMAL_PLACES and ROUNDING_MODE. - * If a base is not specified, and this BigNumber has a positive exponent - * that is equal to or greater than TO_EXP_POS, or a negative exponent equal - * to or less than TO_EXP_NEG, return exponential notation. - * - * [b] {number} Integer, 2 to 64 inclusive. - */ - P['toString'] = P['toS'] = function ( b ) { - var u, str, strL, - x = this, - xe = x['e']; - - // Infinity or NaN? - if ( xe === null ) { - str = x['s'] ? 'Infinity' : 'NaN'; - - // Exponential format? - } else if ( b === u && ( xe <= TO_EXP_NEG || xe >= TO_EXP_POS ) ) { - return format( x, x['c'].length - 1, 1 ); - } else { - str = x['c'].join(''); - - // Negative exponent? - if ( xe < 0 ) { - - // Prepend zeros. - for ( ; ++xe; str = '0' + str ) { - } - str = '0.' + str; - - // Positive exponent? - } else if ( strL = str.length, xe > 0 ) { - - if ( ++xe > strL ) { - - // Append zeros. - for ( xe -= strL; xe-- ; str += '0' ) { - } - } else if ( xe < strL ) { - str = str.slice( 0, xe ) + '.' + str.slice(xe); - } - - // Exponent zero. - } else { - if ( u = str.charAt(0), strL > 1 ) { - str = u + '.' + str.slice(1); - - // Avoid '-0' - } else if ( u == '0' ) { - return u; - } - } - - if ( b != null ) { - - if ( !( outOfRange = !( b >= 2 && b < 65 ) ) && - ( b == (b | 0) || !ERRORS ) ) { - str = convert( str, b | 0, 10, x['s'] ); - - // Avoid '-0' - if ( str == '0' ) { - return str; - } - } else { - - // 'toS() base not an integer: {b}' - // 'toS() base out of range: {b}' - ifExceptionsThrow( b, 'base', 'toS' ); - } - } - - } - - return x['s'] < 0 ? '-' + str : str; - }; - - - /* - * Return as toString, but do not accept a base argument. - */ - P['valueOf'] = function () { - return this['toS'](); - }; - - - // Add aliases for BigDecimal methods. - //P['add'] = P['plus']; - //P['subtract'] = P['minus']; - //P['multiply'] = P['times']; - //P['divide'] = P['div']; - //P['remainder'] = P['mod']; - //P['compareTo'] = P['cmp']; - //P['negate'] = P['neg']; - - - // EXPORT - - - // Node and other CommonJS-like environments that support module.exports. - if ( typeof module !== 'undefined' && module.exports ) { - module.exports = BigNumber; - - //AMD. - } else if ( true ) { - !(__WEBPACK_AMD_DEFINE_RESULT__ = (function () { - return BigNumber; - }.call(exports, __webpack_require__, exports, module)), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); - - //Browser. - } else { - global['BigNumber'] = BigNumber; - } - - })( this ); - - /***/ }, /* 112 */ /***/ function(module, exports, __webpack_require__) { - exports.array = __webpack_require__(142); - exports['boolean'] = __webpack_require__(237); - exports.number = __webpack_require__(143); - exports.object = __webpack_require__(3); - exports.string = __webpack_require__(127); - exports.types = __webpack_require__(126); - + var __WEBPACK_AMD_DEFINE_RESULT__;/* WEBPACK VAR INJECTION */(function(module) {/*! decimal.js v2.0.1 https://github.com/MikeMcl/decimal.js/LICENCE */ + ;(function (global) { + 'use strict'; + + + /* + * decimal.js v2.0.1 + * An arbitrary-precision Decimal type for JavaScript. + * https://github.com/MikeMcl/decimal.js + * Copyright (c) 2014 Michael Mclaughlin + * MIT Expat Licence + */ + + + var convertBase, crypto, DecimalConstructor, noConflict, + toString = Object.prototype.toString, + outOfRange, + id = 0, + external = true, + NUMERALS = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_', + P = {}, + + /* + The maximum exponent magnitude. + The limit on the value of #toExpNeg, #toExpPos, #minE and #maxE. + */ + EXP_LIMIT = 9e15, // 0 to 9e15 + + /* + The limit on the value of #precision, and on the argument to #toDecimalPlaces, + #toExponential, #toFixed, #toFormat, #toPrecision and #toSignificantDigits. + */ + MAX_DIGITS = 1E9, // 0 to 1e+9 + + /* + To decide whether or not to calculate x.pow(integer y) using the 'exponentiation by + squaring' algorithm or by exp(y*ln(x)), the number of significant digits of x is multiplied + by y. If this number is less than #INT_POW_LIMIT then the former algorithm is used. + */ + INT_POW_LIMIT = 3000, // 0 to 5000 + + // The natural logarithm of 10 (1025 digits). + LN10 = '2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058'; + + + // Decimal prototype methods + + + /* + * Return a new Decimal whose value is the absolute value of this Decimal. + * + */ + P['absoluteValue'] = P['abs'] = function () { + var x = new this['constructor'](this); + + if ( x['s'] < 0 ) { + x['s'] = 1; + } + + return rnd(x); + }; + + + /* + * Return a new Decimal whose value is the value of this Decimal rounded to a whole number in + * the direction of positive Infinity. + * + */ + P['ceil'] = function () { + + return rnd( new this['constructor'](this), this['e'] + 1, 2 ); + }; + + + /* + * Return + * 1 if the value of this Decimal is greater than the value of Decimal(y, b), + * -1 if the value of this Decimal is less than the value of Decimal(y, b), + * 0 if they have the same value, + * null if the value of either Decimal is NaN. + * + */ + P['comparedTo'] = P['cmp'] = function ( y, b ) { + var a, + x = this, + xc = x['c'], + yc = ( id = -id, y = new x['constructor']( y, b ), y['c'] ), + i = x['s'], + j = y['s'], + k = x['e'], + l = y['e']; + + // Either NaN? + if ( !i || !j ) { + return null; + } + + a = xc && !xc[0]; + b = yc && !yc[0]; + + // Either zero? + if ( a || b ) { + return a ? b ? 0 : -j : i; + } + + // Signs differ? + if ( i != j ) { + return i; + } + + a = i < 0; + + // Either Infinity? + if ( !xc || !yc ) { + return k == l ? 0 : !xc ^ a ? 1 : -1; + } + + // Compare exponents. + if ( k != l ) { + return k > l ^ a ? 1 : -1; + } + + // Compare digit by digit. + for ( i = -1, + j = ( k = xc.length ) < ( l = yc.length ) ? k : l; + ++i < j; ) { + + if ( xc[i] != yc[i] ) { + return xc[i] > yc[i] ^ a ? 1 : -1; + } + } + + // Compare lengths. + return k == l ? 0 : k > l ^ a ? 1 : -1; + }; + + + /* + * Return the number of decimal places of the value of this Decimal. + * + */ + P['decimalPlaces'] = P['dp'] = function () { + var x = this; + + return x['c'] ? Math.max( x['c'].length - x['e'] - 1, 0 ) : null; + }; + + + /* + * n / 0 = I + * n / N = N + * n / I = 0 + * 0 / n = 0 + * 0 / 0 = N + * 0 / N = N + * 0 / I = 0 + * N / n = N + * N / 0 = N + * N / N = N + * N / I = N + * I / n = I + * I / 0 = I + * I / N = N + * I / I = N + * + * Return a new Decimal whose value is the value of this Decimal divided by Decimal(y, b), + * rounded to #precision significant digits using rounding mode #rounding. + * + */ + P['dividedBy'] = P['div'] = function ( y, b ) { + id = 2; + + return div( this, new this['constructor']( y, b ) ); + }; + + + /* + * Return a new Decimal whose value is the integer part of dividing the value of this Decimal by + * the value of Decimal(y, b), rounded to #precision significant digits using rounding mode + * #rounding. + * + */ + P['dividedToIntegerBy'] = P['divToInt'] = function ( y, b ) { + var x = this, + Decimal = x['constructor']; + id = 18; + + return rnd( + div( x, new Decimal( y, b ), 0, 1, 1 ), Decimal['precision'], Decimal['rounding'] + ); + }; + + + /* + * Return true if the value of this Decimal is equal to the value of Decimal(n, b), otherwise + * return false. + * + */ + P['equals'] = P['eq'] = function ( n, b ) { + id = 3; + + return this['cmp']( n, b ) === 0; + }; + + + /* + * Return a new Decimal whose value is the exponential of the value of this Decimal, i.e. the + * base e raised to the power the value of this Decimal, rounded to #precision significant digits + * using rounding mode #rounding. + * + */ + P['exponential'] = P['exp'] = function () { + + return exp(this); + }; + + + /* + * Return a new Decimal whose value is the value of this Decimal rounded to a whole number in + * the direction of negative Infinity. + * + */ + P['floor'] = function () { + + return rnd( new this['constructor'](this), this['e'] + 1, 3 ); + }; + + + /* + * Return true if the value of this Decimal is greater than the value of Decimal(n, b), otherwise + * return false. + * + */ + P['greaterThan'] = P['gt'] = function ( n, b ) { + id = 4; + + return this['cmp']( n, b ) > 0; + }; + + + /* + * Return true if the value of this Decimal is greater than or equal to the value of + * Decimal(n, b), otherwise return false. + * + */ + P['greaterThanOrEqualTo'] = P['gte'] = function ( n, b ) { + id = 5; + b = this['cmp']( n, b ); + + return b == 1 || b === 0; + }; + + + /* + * Return true if the value of this Decimal is a finite number, otherwise return false. + * + */ + P['isFinite'] = function () { + + return !!this['c']; + }; + + + /* + * Return true if the value of this Decimal is an integer, otherwise return false. + * + */ + P['isInteger'] = P['isInt'] = function () { + + return !!this['c'] && this['e'] > this['c'].length - 2; + }; + + + /* + * Return true if the value of this Decimal is NaN, otherwise return false. + * + */ + P['isNaN'] = function () { + + return !this['s']; + }; + + + /* + * Return true if the value of this Decimal is negative, otherwise return false. + * + */ + P['isNegative'] = P['isNeg'] = function () { + + return this['s'] < 0; + }; + + + /* + * Return true if the value of this Decimal is 0 or -0, otherwise return false. + * + */ + P['isZero'] = function () { + + return !!this['c'] && this['c'][0] == 0; + }; + + + /* + * Return true if the value of this Decimal is less than Decimal(n, b), otherwise return false. + * + */ + P['lessThan'] = P['lt'] = function ( n, b ) { + id = 6; + + return this['cmp']( n, b ) < 0; + }; + + + /* + * Return true if the value of this Decimal is less than or equal to Decimal(n, b), otherwise + * return false. + * + */ + P['lessThanOrEqualTo'] = P['lte'] = function ( n, b ) { + id = 7; + b = this['cmp']( n, b ); + + return b == -1 || b === 0; + }; + + + /* + * Return the logarithm of the value of this Decimal to the specified base, rounded + * to #precision significant digits using rounding mode #rounding. + * + * If no base is specified, return log[10](arg). + * + * log[base](arg) = ln(arg) / ln(base) + * + * The result will always be correctly rounded if the base of the log is 2 or 10, and + * 'almost always' if not: + * + * Depending on the rounding mode, the result may be incorrectly rounded if the first fifteen + * rounding digits are [49]99999999999999 or [50]00000000000000. In that case, the maximum error + * between the result and the correctly rounded result will be one ulp (unit in the last place). + * + * log[-b](a) = NaN + * log[0](a) = NaN + * log[1](a) = NaN + * log[NaN](a) = NaN + * log[Infinity](a) = NaN + * log[b](0) = -Infinity + * log[b](-0) = -Infinity + * log[b](-a) = NaN + * log[b](1) = 0 + * log[b](Infinity) = Infinity + * log[b](NaN) = NaN + * + * [base] {number|string|Decimal} The base of the logarithm. + * [b] {number} The base of base. + * + */ + P['logarithm'] = P['log'] = function ( base, b ) { + var base10, c, denom, i, inf, num, sd, sd10, r, + arg = this, + Decimal = arg['constructor'], + pr = Decimal['precision'], + rm = Decimal['rounding'], + guard = 5; + + // Default base is 10. + if ( base == null ) { + base = new Decimal(10); + base10 = true; + } else { + id = 15; + base = new Decimal( base, b ); + c = base['c']; + + // If #base < 0 or +-Infinity/NaN or 0 or 1. + if ( base['s'] < 0 || !c || !c[0] || !base['e'] && c[0] == 1 && c.length == 1 ) { + + return new Decimal(NaN); + } + base10 = base['eq'](10); + } + c = arg['c']; + + // If #arg < 0 or +-Infinity/NaN or 0 or 1. + if ( arg['s'] < 0 || !c || !c[0] || !arg['e'] && c[0] == 1 && c.length == 1 ) { + + return new Decimal( c && !c[0] ? -1 / 0 : arg['s'] != 1 ? NaN : c ? 0 : 1 / 0 ); + } + + /* + The result will have an infinite decimal expansion if #base is 10 and #arg is not an + integer power of 10... + */ + inf = base10 && ( c[0] != 1 || c.length > 1 ) || + + // ...or if #base last digit's evenness is not the same as #arg last digit's evenness... + ( base['c'][ base['c'].length - 1 ] & 1 ) != ( c[ c.length - 1 ] & 1 ) || 0 && + + // ...or if #base is 2 and there is more than one 1 in #arg in base 2. + base['eq'](2) && arg.toString(2).replace( /[^1]+/g, '' ) != '1'; + + external = false; + sd = pr + guard; + sd10 = sd + 10; + num = ln( arg, sd ); + + if (base10) { + + if ( sd10 > LN10.length ) { + ifExceptionsThrow( Decimal, 1, sd10, 'log' ); + } + denom = new Decimal( LN10.slice( 0, sd10 ) ); + } else { + denom = ln( base, sd ); + } + + // The result will have 5 rounding digits. + r = div( num, denom, sd, 1 ); + + /* + If at a rounding boundary, i.e. the result's rounding digits are [49]9999 or [50]0000, + calculate 10 further digits. + + If the result is known to have an infinite decimal expansion, repeat this until it is + clear that the result is above or below the boundary. Otherwise, if after calculating + the 10 further digits, the last 14 are nines, round up and assume the result is exact. + Also assume the result is exact if the last 14 are zero. + + Example of a result that will be incorrectly rounded: + log[1048576](4503599627370502) = 2.60000000000000009610279511444746... + The above result correctly rounded using ROUND_CEIL to 1 decimal place should be 2.7, + but it will be given as 2.6 as there are 15 zeros immediately after the requested + decimal place, so the exact result would be assumed to be 2.6, which rounded using + ROUND_CEIL to 1 decimal place is still 2.6. + */ + if ( checkRoundingDigits( r['c'], i = pr, rm ) ) { + + do { + sd += 10; + num = ln( arg, sd ); + + if (base10) { + sd10 = sd + 10; + + if ( sd10 > LN10.length ) { + ifExceptionsThrow( Decimal, 1, sd10, 'log' ); + } + denom = new Decimal( LN10.slice( 0, sd10 ) ); + } else { + denom = ln( base, sd ); + } + + r = div( num, denom, sd, 1 ); + + if ( !inf ) { + + // Check for 14 nines from the 2nd rounding digit, as the first may be 4. + for ( c = r['c']; c[++i] == 9; ) { + } + + if ( i == pr + guard + 10 ) { + r = rnd( r, pr + 1, 0 ); + } + + break; + } + } while ( checkRoundingDigits( r['c'], i += 10, rm ) ); + } + external = true; + + return rnd( r, pr, rm ); + }; + + + /* + * n - 0 = n + * n - N = N + * n - I = -I + * 0 - n = -n + * 0 - 0 = 0 + * 0 - N = N + * 0 - I = -I + * N - n = N + * N - 0 = N + * N - N = N + * N - I = N + * I - n = I + * I - 0 = I + * I - N = N + * I - I = N + * + * Return a new Decimal whose value is the value of this Decimal minus Decimal(y, b), rounded + * to #precision significant digits using rounding mode #rounding. + * + */ + P['minus'] = function ( y, b ) { + var t, i, j, xLTy, + x = this, + Decimal = x['constructor'], + a = x['s']; + + id = 8; + y = new Decimal( y, b ); + b = y['s']; + + // Either NaN? + if ( !a || !b ) { + + return new Decimal(NaN); + } + + // Signs differ? + if ( a != b ) { + y['s'] = -b; + + return x['plus'](y); + } + + var xc = x['c'], + xe = x['e'], + yc = y['c'], + ye = y['e'], + pr = Decimal['precision'], + rm = Decimal['rounding']; + + if ( !xe || !ye ) { + + // Either Infinity? + if ( !xc || !yc ) { + + return xc ? ( y['s'] = -b, y ) : new Decimal( yc ? x : NaN ); + } + + // Either zero? + if ( !xc[0] || !yc[0] ) { + + // Return #y if #y is non-zero, #x if #x is non-zero, or zero if both are zero. + x = yc[0] ? ( y['s'] = -b, y ) : new Decimal( xc[0] ? x : + + // IEEE 754 (2008) 6.3: n - n = -0 when rounding to -Infinity + rm == 3 ? -0 : 0 ); + + return external ? rnd( x, pr, rm ) : x; + } + } + + xc = xc.slice(); + i = xc.length; + + // Determine which is the bigger number. Prepend zeros to equalise exponents. + if ( a = xe - ye ) { + + if ( xLTy = a < 0 ) { + a = -a; + t = xc; + i = yc.length; + } else { + ye = xe; + t = yc; + } + + if ( pr > i ) { + i = pr; + } + + /* + Numbers with massively different exponents would result in a massive number of + zeros needing to be prepended, but this can be avoided while still ensuring correct + rounding by limiting the number of zeros to max( #precision, #i ) + 2, where #pr is + #precision and #i is the length of the coefficient of whichever is greater #x or #y. + */ + if ( a > ( i += 2 ) ) { + a = i; + t.length = 1; + } + + for ( t.reverse(), b = a; b--; t.push(0) ) { + } + t.reverse(); + } else { + + // Exponents equal. Check digit by digit. + if ( xLTy = i < ( j = yc.length ) ) { + j = i; + } + + for ( a = b = 0; b < j; b++ ) { + + if ( xc[b] != yc[b] ) { + xLTy = xc[b] < yc[b]; + + break; + } + } + } + + // #x < #y? Point #xc to the array of the bigger number. + if ( xLTy ) { + t = xc, xc = yc, yc = t; + y['s'] = -y['s']; + } + + /* + Append zeros to #xc if shorter. No need to add zeros to #yc if shorter as subtraction only + needs to start at #yc length. + */ + if ( ( b = -( ( j = xc.length ) - yc.length ) ) > 0 ) { + + for ( ; b--; xc[j++] = 0 ) { + } + } + + // Subtract #yc from #xc. + for ( b = yc.length; b > a; ){ + + if ( xc[--b] < yc[b] ) { + + for ( i = b; i && !xc[--i]; xc[i] = 9 ) { + } + --xc[i]; + xc[b] += 10; + } + xc[b] -= yc[b]; + } + + // Remove trailing zeros. + for ( ; xc[--j] == 0; xc.pop() ) { + } + + // Remove leading zeros and adjust exponent accordingly. + for ( ; xc[0] == 0; xc.shift(), --ye ) { + } + + if ( !xc[0] ) { + + // Zero. + xc = [ ye = 0 ]; + + // Following IEEE 754 (2008) 6.3, n - n = -0 when rounding towards -Infinity. + y['s'] = rm == 3 ? -1 : 1; + } + + y['c'] = xc; + y['e'] = ye; + + return external ? rnd( y, pr, rm ) : y; + }; + + + /* + * n % 0 = N + * n % N = N + * n % I = n + * 0 % n = 0 + * -0 % n = -0 + * 0 % 0 = N + * 0 % N = N + * 0 % I = 0 + * N % n = N + * N % 0 = N + * N % N = N + * N % I = N + * I % n = N + * I % 0 = N + * I % N = N + * I % I = N + * + * Return a new Decimal whose value is the value of this Decimal modulo Decimal(y, b), rounded + * to #precision significant digits using rounding mode #rounding. + * + * The result depends on the modulo mode. + * + */ + P['modulo'] = P['mod'] = function ( y, b ) { + var n, q, + x = this, + Decimal = x['constructor'], + m = Decimal['modulo']; + + id = 9; + y = new Decimal( y, b ); + b = y['s']; + n = !x['c'] || !b || y['c'] && !y['c'][0]; + + /* + Return NaN if #x is Infinity or NaN, or #y is NaN or zero, else return #x if #y is Infinity + or #x is zero. + */ + if ( n || !y['c'] || x['c'] && !x['c'][0] ) { + + return n + ? new Decimal(NaN) + : rnd( new Decimal(x), Decimal['precision'], Decimal['rounding'] ); + } + + external = false; + + if ( m == 9 ) { + + // Euclidian division: q = sign(y) * floor(x / abs(y)) + // r = x - qy where 0 <= r < abs(y) + y['s'] = 1; + q = div( x, y, 0, 3, 1 ); + y['s'] = b; + q['s'] *= b; + } else { + q = div( x, y, 0, m, 1 ); + } + + q = q['times'](y); + external = true; + + return x['minus'](q); + }; + + + /* + * Return a new Decimal whose value is the natural logarithm of the value of this Decimal, + * rounded to #precision significant digits using rounding mode #rounding. + * + */ + P['naturalLogarithm'] = P['ln'] = function () { + + return ln(this); + }; + + + /* + * Return a new Decimal whose value is the value of this Decimal negated, i.e. as if + * multiplied by -1. + * + */ + P['negated'] = P['neg'] = function () { + var x = new this['constructor'](this); + x['s'] = -x['s'] || null; + + return rnd(x); + }; + + + /* + * n + 0 = n + * n + N = N + * n + I = I + * 0 + n = n + * 0 + 0 = 0 + * 0 + N = N + * 0 + I = I + * N + n = N + * N + 0 = N + * N + N = N + * N + I = N + * I + n = I + * I + 0 = I + * I + N = N + * I + I = I + * + * Return a new Decimal whose value is the value of this Decimal plus Decimal(y, b), rounded + * to #precision significant digits using rounding mode #rounding. + * + */ + P['plus'] = function ( y, b ) { + var t, + x = this, + Decimal = x['constructor'], + a = x['s']; + + id = 10; + y = new Decimal( y, b ) ; + b = y['s']; + + // Either NaN? + if ( !a || !b ) { + + return new Decimal(NaN); + } + + // Signs differ? + if ( a != b ) { + y['s'] = -b; + + return x['minus'](y); + } + + var xe = x['e'], + xc = x['c'], + ye = y['e'], + yc = y['c'], + pr = Decimal['precision'], + rm = Decimal['rounding']; + + if ( !xe || !ye ) { + + // Either Infinity? + if ( !xc || !yc ) { + + // Return +-Infinity. + return new Decimal( a / 0 ); + } + + // Either zero? + if ( !xc[0] || !yc[0] ) { + + // Return #y if #y is non-zero, #x if #x is non-zero, or zero if both are zero. + x = yc[0] ? y: new Decimal( xc[0] ? x : a * 0 ); + + return external ? rnd( x, pr, rm ) : x; + } + } + + xc = xc.slice(); + + // Prepend zeros to equalise exponents. Note: Faster to use reverse then do unshifts. + if ( a = xe - ye ) { + + if ( a < 0 ) { + a = -a; + t = xc; + b = yc.length; + } else { + ye = xe; + t = yc; + b = xc.length; + } + + if ( pr > b ) { + b = pr; + } + + // Limit number of zeros prepended to max( #pr, #b ) + 1. + if ( a > ++b ) { + a = b; + t.length = 1; + } + + for ( t.reverse(); a--; t.push(0) ) { + } + t.reverse(); + } + + // Point #xc to the longer array. + if ( xc.length - yc.length < 0 ) { + t = yc, yc = xc, xc = t; + } + + // Only start adding at yc.length - 1 as the further digits of #xc can be left as they are. + for ( a = yc.length, b = 0; a; xc[a] %= 10 ) { + b = ( xc[--a] = xc[a] + yc[a] + b ) / 10 | 0; + } + + if (b) { + xc.unshift(b); + ++ye; + } + + // Remove trailing zeros. + for ( a = xc.length; xc[--a] == 0; xc.pop() ) { + } + + // No need to check for zero, as +x + +y != 0 && -x + -y != 0 + + y['c'] = xc; + y['e'] = ye; + + return external ? rnd( y, pr, rm ) : y; + }; + + + /* + * Return the number of significant digits of this Decimal. + * + * z {boolean|number} Whether to count integer-part trailing zeros: true, false, 1 or 0. + * + */ + P['precision'] = P['sd'] = function (z) { + var x = this; + + if ( z != null ) { + + if ( z !== !!z && z !== 1 && z !== 0 ) { + + // 'precision() argument not a boolean or binary digit: {z}' + ifExceptionsThrow( x['constructor'], 'argument', z, 'precision', 1 ); + } + } + + return x['c'] ? z ? Math.max( x['e'] + 1, x['c'].length ) : x['c'].length : null; + }; + + + /* + * Return a new Decimal whose value is the value of this Decimal rounded to a whole number using + * rounding mode #rounding. + * + */ + P['round'] = function () { + var x = this, + Decimal = x['constructor']; + + return rnd( new Decimal(x), x['e'] + 1, Decimal['rounding'] ); + }; + + + /* + * sqrt(-n) = N + * sqrt( N) = N + * sqrt(-I) = N + * sqrt( I) = I + * sqrt( 0) = 0 + * sqrt(-0) = -0 + * + * Return a new Decimal whose value is the square root of this Decimal, rounded to #precision + * significant digits using rounding mode #rounding. + * + */ + P['squareRoot'] = P['sqrt'] = function () { + var n, sd, r, rep, t, + x = this, + c = x['c'], + s = x['s'], + e = x['e'], + Decimal = x['constructor'], + half = new Decimal(0.5); + + // Negative/NaN/Infinity/zero? + if ( s !== 1 || !c || !c[0] ) { + + return new Decimal( !s || s < 0 && ( !c || c[0] ) ? NaN : c ? x : 1 / 0 ); + } + + external = false; + + // Initial estimate. + s = Math.sqrt( +x ); + + /* + Math.sqrt underflow/overflow? + Pass x to Math.sqrt as integer, then adjust the exponent of the result. + */ + if ( s == 0 || s == 1 / 0 ) { + n = c.join(''); + + if ( ( n.length + e ) % 2 == 0 ) { + n += '0'; + } + r = new Decimal( Math.sqrt(n) + '' ); + + // r may not be finite. + if ( !r['c'] ) { + r['c'] = [1]; + } + + r['e'] = Math.floor( ( e + 1 ) / 2 ) - ( e < 0 || e % 2 ); + } else { + r = new Decimal( s.toString() ); + } + + sd = ( e = Decimal['precision'] ) + 3; + + // Newton-Raphson iteration. + for ( ; ; ) { + t = r; + r = half['times']( t['plus']( div( x, t, sd + 2, 1 ) ) ); + + if ( t['c'].slice( 0, sd ).join('') === r['c'].slice( 0, sd ).join('') ) { + c = r['c']; + + /* + The 4th rounding digit may be in error by -1 so if the 4 rounding digits are + 9999 or 4999 (i.e. approaching a rounding boundary) continue the iteration. + */ + if ( ( c[sd - 3] == 9 || !rep && c[sd - 3] == 4 ) && + c[sd - 2] == 9 && c[sd - 1] == 9 && c[sd] == 9 ) { + + /* + On the first run through, check to see if rounding up gives the exact result as + the nines may infinitely repeat. + */ + if ( !rep ) { + t = rnd( t, e + 1, 0 ); + + if ( t['times'](t)['eq'](x) ) { + r = t; + + break; + } + } + sd += 4; + rep = 1; + } else { + + /* + If the rounding digits are null, 0000 or 5000, check for an exact result. + If not, then there are further digits so increment the 1st rounding digit + to ensure correct rounding. + */ + if ( ( !c[sd - 3] || c[sd - 3] == 5 ) && !c[sd - 2] && + !c[sd - 1] && !c[sd] ) { + + // Truncate to the first rounding digit. + if ( c.length > e + 1 ) { + c.length = e + 1; + } + + if ( !r['times'](r)['eq'](x) ) { + + while ( c.length < e ) { + c.push(0); + } + c[e]++; + } + } + + break; + } + } + } + external = true; + + return rnd( r, e, Decimal['rounding'] ); + }; + + + /* + * n * 0 = 0 + * n * N = N + * n * I = I + * 0 * n = 0 + * 0 * 0 = 0 + * 0 * N = N + * 0 * I = N + * N * n = N + * N * 0 = N + * N * N = N + * N * I = N + * I * n = I + * I * 0 = N + * I * N = N + * I * I = I + * + * Return a new Decimal whose value is this Decimal times Decimal(y), rounded to #precision + * significant digits using rounding mode #rounding. + * + */ + P['times'] = function ( y, b ) { + var c, + x = this, + Decimal = x['constructor'], + xc = x['c'], + yc = ( id = 11, y = new Decimal( y, b ), y['c'] ), + i = x['e'], + j = y['e'], + a = x['s']; + + b = y['s']; + + y['s'] = a == b ? 1 : -1; + + // Either NaN/Infinity/0? + if ( !i && ( !xc || !xc[0] ) || !j && ( !yc || !yc[0] ) ) { + + // Either NaN? + return new Decimal( !a || !b || + + // #x is 0 and #y is Infinity or #y is 0 and #x is Infinity? + xc && !xc[0] && !yc || yc && !yc[0] && !xc + + // Return NaN. + ? NaN + + // Either Infinity? + : !xc || !yc + + // Return +-Infinity. + ? y['s'] / 0 + + // #x or #y is 0. Return +-0. + : y['s'] * 0 ); + } + + y['e'] = i + j; + a = xc.length; + b = yc.length; + + if ( a < b ) { + + // Swap. + c = xc, xc = yc, yc = c; + j = a, a = b, b = j; + } + + for ( j = a + b, c = []; j--; c.push(0) ) { + } + + // Multiply! + for ( i = b - 1; i > -1; i-- ) { + + for ( b = 0, j = a + i; j > i; b = b / 10 | 0 ) { + b = c[j] + yc[i] * xc[j - i - 1] + b; + c[j--] = b % 10 | 0; + } + + if (b) { + c[j] = ( c[j] + b ) % 10; + } + } + + if (b) { + ++y['e']; + } + + // Remove any leading zero. + if ( !c[0] ) { + c.shift(); + } + + // Remove trailing zeros. + for ( j = c.length; !c[--j]; c.pop() ) { + } + y['c'] = c; + + return external ? rnd( y, Decimal['precision'], Decimal['rounding'] ) : y; + }; + + + /* + * Return a new Decimal whose value is the value of this Decimal rounded to a maximum of #dp + * decimal places using rounding mode #rm or #rounding if #rm is omitted. + * + * If #dp is omitted, return a new Decimal whose value is the value of this Decimal. + * + * [dp] {number} Decimal places. Integer, 0 to MAX_DIGITS inclusive. + * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive. + * + * 'toDP() dp out of range: {dp}' + * 'toDP() dp not an integer: {dp}' + * 'toDP() rounding mode not an integer: {rm}' + * 'toDP() rounding mode out of range: {rm}' + * + */ + P['toDecimalPlaces'] = P['toDP'] = function ( dp, rm ) { + var x = this; + x = new x['constructor'](x); + + return dp == null || !checkArg( x, dp, 'toDP' ) + ? x + : rnd( x, ( dp | 0 ) + x['e'] + 1, checkRM( x, rm, 'toDP' ) ); + }; + + + /* + * Return a string representing the value of this Decimal in exponential notation rounded to #dp + * fixed decimal places using rounding mode #rounding. + * + * [dp] {number} Decimal places. Integer, 0 to MAX_DIGITS inclusive. + * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive. + * + * #errors true: Throw if #dp and #rm are not undefined, null or integers in range. + * #errors false: Ignore #dp and #rm if not numbers or not in range, and truncate non-integers. + * + * 'toExponential() dp not an integer: {dp}' + * 'toExponential() dp out of range: {dp}' + * 'toExponential() rounding mode not an integer: {rm}' + * 'toExponential() rounding mode out of range: {rm}' + * + */ + P['toExponential'] = function ( dp, rm ) { + var x = this; + + return format( x, dp != null && checkArg( x, dp, 'toExponential' ) || !x['c'] + ? dp | 0 : x['c'].length - 1, dp != null && checkRM( x, rm, 'toExponential' ), 1 ); + }; + + + /* + * Return a string representing the value of this Decimal in normal (fixed-point) notation to + * #dp fixed decimal places and rounded using rounding mode #rm or #rounding if #rm is omitted. + * + * Note: as with JS numbers, (-0).toFixed(0) is '0', but e.g. (-0.00001).toFixed(0) is '-0'. + * + * [dp] {number} Decimal places. Integer, -MAX_DIGITS to MAX_DIGITS inclusive. + * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive. + * + * #errors true: Throw if #dp and #rm are not undefined, null or integers in range. + * #errors false: Ignore #dp and #rm if not numbers or not in range, and truncate non-integers. + * + * 'toFixed() dp not an integer: {dp}' + * 'toFixed() dp out of range: {dp}' + * 'toFixed() rounding mode not an integer: {rm}' + * 'toFixed() rounding mode out of range: {rm}' + * + */ + P['toFixed'] = function ( dp, rm ) { + var str, + x = this, + Decimal = x['constructor'], + neg = Decimal['toExpNeg'], + pos = Decimal['toExpPos']; + + if ( dp != null ) { + dp = checkArg( x, dp, str = 'toFixed', -MAX_DIGITS ) ? x['e'] + ( dp | 0 ) : null; + rm = checkRM( x, rm, str ); + } + + // Prevent #toString returning exponential notation; + Decimal['toExpNeg'] = -( Decimal['toExpPos'] = 1 / 0 ); + + if ( dp == null ) { + str = x.toString(); + } else { + str = format( x, dp, rm ); + + // (-0).toFixed() is '0', but (-0.1).toFixed() is '-0'. + // (-0).toFixed(1) is '0.0', but (-0.01).toFixed(1) is '-0.0'. + if ( x['s'] < 0 && x['c'] ) { + + // As e.g. (-0).toFixed(3), will wrongly be returned as -0.000 from toString. + if ( !x['c'][0] ) { + str = str.replace( '-', '' ); + + // As e.g. -0.5 if rounded to -0 will cause toString to omit the minus sign. + } else if ( str.indexOf('-') < 0 ) { + str = '-' + str; + } + } + } + Decimal['toExpNeg'] = neg; + Decimal['toExpPos'] = pos; + + return str; + }; + + + /* + * Return a string representing the value of this Decimal in normal notation rounded using + * rounding mode #rounding to #dp fixed decimal places, with the integer part of the number + * separated into thousands by string #sep1 or ',' if #sep1 is null or undefined, and the fraction + * part separated into groups of five digits by string #sep2. + * + * [sep1] {string} The grouping separator of the integer part of the number. + * [sep2] {string} The grouping separator of the fraction part of the number. + * [dp] {number} Decimal places. Integer, -MAX_DIGITS to MAX_DIGITS inclusive. + * + * Non-breaking thin-space: \u202f + * + * If #dp is invalid the error message will incorrectly give the method as toFixed. + * + */ + P['toFormat'] = function ( sep1, dp, sep2 ) { + var arr = this.toFixed(dp).split('.'); + + return arr[0].replace( /\B(?=(\d{3})+$)/g, sep1 == null ? ',' : sep1 + '' ) + + ( arr[1] ? '.' + ( sep2 ? arr[1].replace( /\d{5}\B/g, '$&' + sep2 ) : arr[1] ) : '' ); + }; + + + /* + * Return a string array representing the value of this Decimal as a simple fraction with an + * integer numerator and an integer denominator. + * + * The denominator will be a positive non-zero value less than or equal to the specified + * maximum denominator. If a maximum denominator is not specified, the denominator will be + * the lowest value necessary to represent the number exactly. + * + * [maxD] {number|string|Decimal} Maximum denominator. Integer >= 1 and < Infinity. + * + */ + P['toFraction'] = function (maxD) { + var d0, d2, e, frac, n, n0, q, + x = this, + Decimal = x['constructor'], + n1 = d0 = new Decimal( Decimal['ONE'] ), + d1 = n0 = new Decimal(0), + xc = x['c'], + d = new Decimal( Decimal['ONE'] ), + pr = Decimal['precision']; + + // NaN, Infinity. + if ( !xc ) { + + return x.toString(); + } + + e = d['e'] = xc.length - x['e'] - 1; + + // If #maxD is undefined or null... + if ( maxD == null || + + // or NaN... + ( !( id = 12, n = new Decimal(maxD) )['s'] || + + // or less than 1, or Infinity... + ( outOfRange = n['cmp'](n1) < 0 || !n['c'] ) || + + // or not an integer... + ( Decimal['errors'] && n['e'] < n['c'].length - 1 ) ) && + + // 'toFraction() max denominator not an integer: {maxD}' + // 'toFraction() max denominator out of range: {maxD}' + !ifExceptionsThrow( Decimal, 'max denominator', maxD, 'toFraction', 0 ) || + + // or greater than the maximum denominator needed to specify the value exactly. + ( maxD = n )['cmp'](d) > 0 ) { + + // d is 10**e, n1 is 1. + maxD = e > 0 ? d : n1; + } + + external = false; + n = new Decimal( xc.join('') ); + + // #plus and #minus need #precision to be at least xc.length. + Decimal['precision'] = xc.length; + + for ( ; ; ) { + q = div( n, d, 0, 1, 1 ); + d2 = d0['plus']( q['times'](d1) ); + + if ( d2['cmp'](maxD) == 1 ) { + + break; + } + d0 = d1, d1 = d2; + + n1 = n0['plus']( q['times']( d2 = n1 ) ); + n0 = d2; + + d = n['minus']( q['times']( d2 = d ) ); + n = d2; + } + + d2 = div( maxD['minus'](d0), d1, 0, 1, 1 ); + n0 = n0['plus']( d2['times'](n1) ); + d0 = d0['plus']( d2['times'](d1) ); + + n0['s'] = n1['s'] = x['s']; + + // The required decimal places. + e *= 2; + + // Determine which fraction is closer to #x, #n0 /# d0 or #n1 / #d1? + frac = div( n1, d1, e, 1, 1 )['minus'](x)['abs']()['cmp']( + div( n0, d0, e, 1, 1 )['minus'](x)['abs']() ) < 1 + ? [ n1.toString(), d1.toString() ] + : [ n0.toString(), d0.toString() ]; + + external = true; + Decimal['precision'] = pr; + + return frac; + }; + + + /* + * Returns a new Decimal whose value is the nearest multiple of the magnitude of #n to the value + * of this Decimal. + * + * If the value of this Decimal is equidistant from two multiples of #n, the rounding mode #rm, + * or #rounding if #rm is omitted or is null or undefined, determines the direction of the + * nearest multiple. + * + * In the context of this method, rounding mode 4 (ROUND_HALF_UP) is the same as rounding mode 0 + * (ROUND_UP), and so on. + * + * The return value will always have the same sign as this Decimal, unless either this Decimal + * or #n is NaN, in which case the return value will be also be NaN. + * + * The return value is not rounded to #precision significant digits. + * + * n {number|string|Decimal} The magnitude to round to a multiple of. + * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive. + * + * 'toNearest() rounding mode not an integer: {rm}' + * 'toNearest() rounding mode out of range: {rm}' + * + */ + P['toNearest'] = function ( n, rm ) { + var x = this, + Decimal = x['constructor']; + + x = new Decimal(x); + + if ( n == null ) { + n = new Decimal( Decimal['ONE'] ); + rm = Decimal['rounding']; + } else { + id = 17; + n = new Decimal(n); + rm = checkRM( x, rm, 'toNearest' ); + } + + // If #n is not NaN/+-Infinity... + if ( n['c'] ) { + + // If #x is not NaN/+-Infinity... + if ( x['c'] ) { + external = false; + + /* + 4 ROUND_HALF_UP + 5 ROUND_HALF_DOWN + 6 ROUND_HALF_EVEN + 7 ROUND_HALF_CEIL + 8 ROUND_HALF_FLOOR + */ + if ( rm < 4 ) { + rm = [4, 5, 7, 8][rm]; + } + + // If #n is a power of 10... + if ( n['c'][0] == 1 && n['c'].length == 1 ) { + x['e'] -= n['e']; + + // 0 dp + rnd( x, x['e'] + 1, rm ); + + if ( x['c'][0] ) { + x['e'] += n['e']; + } + + // else if #n is not zero... + } else if ( n['c'][0] ) { + x = div( x, n, 0, rm, 1 )['times'](n); + } else { + x['c'] = [ x['e'] = 0 ]; + } + + external = true; + rnd(x); + } + + // # is NaN/+-Infinity. If #x is not NaN... + } else if ( x['s'] ) { + + // If #n is not NaN... + if ( n['s'] ) { + n['s'] = x['s']; + } + x = n; + } + + return x; + }; + + + /* + * Return the value of this Decimal converted to a number primitive. + * + */ + P['toNumber'] = function () { + var x = this; + + // Ensure zero has correct sign. + return +x || ( x | 0 ) * x['s']; + }; + + + /* + * Return a new Decimal whose value is the value of this Decimal raised to the power + * Decimal(y, b), rounded to #precision significant digits using rounding mode #rounding. + * + * ECMAScript compliant. + * + * x is any value, including NaN. + * n is any number, including �Infinity unless stated. + * + * pow( x, NaN ) = NaN + * pow( x, �0 ) = 1 + + * pow( NaN, nonzero ) = NaN + * pow( abs(n) > 1, +Infinity ) = +Infinity + * pow( abs(n) > 1, -Infinity ) = +0 + * pow( abs(n) == 1, �Infinity ) = NaN + * pow( abs(n) < 1, +Infinity ) = +0 + * pow( abs(n) < 1, -Infinity ) = +Infinity + * pow( +Infinity, n > 0 ) = +Infinity + * pow( +Infinity, n < 0 ) = +0 + * pow( -Infinity, odd integer > 0 ) = -Infinity + * pow( -Infinity, even integer > 0 ) = +Infinity + * pow( -Infinity, odd integer < 0 ) = -0 + * pow( -Infinity, even integer < 0 ) = +0 + * pow( +0, n > 0 ) = +0 + * pow( +0, n < 0 ) = +Infinity + * pow( -0, odd integer > 0 ) = -0 + * pow( -0, even integer > 0 ) = +0 + * pow( -0, odd integer < 0 ) = -Infinity + * pow( -0, even integer < 0 ) = +Infinity + * pow( finite n < 0, finite non-integer ) = NaN + * + * For non-integer and larger exponents pow(x, y) is calculated using + * + * x^y = exp(y*ln(x)) + * + * Assuming the first 15 rounding digits are each equally likely to be any digit 0-9, the + * probability of an incorrectly rounded result + * P( [49]9{14} | [50]0{14} ) = 2 * 0.2 * 10^-14 = 4e-15 = 1/2.5e+14 + * i.e. 1 in 250,000,000,000,000 + * + * If a result is incorrectly rounded the maximum error will be 1 ulp (unit in last place). + * + * y {number|string|Decimal} The power to which to raise this Decimal. + * [b] {number} The base of y. + * + */ + P['toPower'] = P['pow'] = function ( y, b ) { + var a, e, n, r, + x = this, + Decimal = x['constructor'], + s = x['s'], + yN = +( id = 13, y = new Decimal( y, b ) ), + i = yN < 0 ? -yN : yN, + pr = Decimal['precision'], + rm = Decimal['rounding']; + + // Handle +-Infinity, NaN and +-0. + if ( !x['c'] || !y['c'] || ( n = !x['c'][0] ) || !y['c'][0] ) { + + // valueOf -0 is 0, so check for 0 then multiply it by the sign. + return new Decimal( Math.pow( n ? s * 0 : +x, yN ) ); + } + + x = new Decimal(x); + a = x['c'].length; + + // if #x == 1 + if ( !x['e'] && x['c'][0] == x['s'] && a == 1 ) { + + return x; + } + + b = y['c'].length - 1; + + // if #y == 1 + if ( !y['e'] && y['c'][0] == y['s'] && !b ) { + r = rnd( x, pr, rm ); + } else { + n = y['e'] >= b; + + // If #y is not an integer and #x is negative, return NaN. + if ( !n && s < 0 ) { + r = new Decimal(NaN); + } else { + + /* + If the number of significant digits of #x multiplied by abs(#y) is less than + INT_POW_LIMIT use the 'exponentiation by squaring' algorithm. + */ + if ( n && a * i < INT_POW_LIMIT ) { + r = intPow( Decimal, x, i ); + + if ( y['s'] < 0 ) { + + return Decimal['ONE']['div'](r); + } + } else { + + // Result is negative if #x is negative and the last digit of integer #y is odd. + s = s < 0 && y['c'][ Math.max( y['e'], b ) ] & 1 ? -1 : 1; + + b = Math.pow( +x, yN ); + + // Estimate result exponent. + e = b == 0 || !isFinite(b) + + /* + x^y = 10^e, where e = y * log10(x) + log10(x) = log10(x_significand) + x_exponent + log10(x_significand) = ln(x_significand) / ln(10) + */ + ? Math.floor( yN * ( + Math.log( '0.' + x['c'].join('') ) / Math.LN10 + x['e'] + 1 ) ) + : new Decimal( b + '' )['e']; + + // Estimate may be incorrect e.g.: x: 0.999999999999999999, y: 2.29, e: 0, r.e:-1 + + // Overflow/underflow? + if ( e > Decimal['maxE'] + 1 || e < Decimal['minE'] - 1 ) { + + return new Decimal( e > 0 ? s / 0 : 0 ); + } + + external = false; + Decimal['rounding'] = x['s'] = 1; + + /* + Estimate extra digits needed from ln(x) to ensure five correct rounding digits + in result (#i was unnecessary before max exponent was extended?). + Example of failure before #i was introduced: (precision: 10), + new Decimal(2.32456).pow('2087987436534566.46411') + should be 1.162377823e+764914905173815, but is 1.162355823e+764914905173815 + */ + i = Math.min( 12, ( e + '' ).length ); + + // r = x^y = exp(y*ln(x)) + r = exp( y['times']( ln( x, pr + i ) ), pr ); + + // Truncate to the required precision plus five rounding digits. + r = rnd( r, pr + 5, 1 ); + + /* + If the rounding digits are [49]9999 or [50]0000 increase the precision by 10 + and recalculate the result. + */ + if ( checkRoundingDigits( r['c'], pr, rm ) ) { + e = pr + 10; + + // Truncate to the increased precision plus five rounding digits. + r = rnd( exp( y['times']( ln( x, e + i ) ), e ), e + 5, 1 ); + + /* + Check for 14 nines from the 2nd rounding digit (the first rounding digit + may be 4 or 9). + */ + for ( i = pr; r['c'][++i] == 9; ) { + } + + // If there are 14 nines round up the first rounding digit. + if ( i == pr + 15 ) { + r = rnd( r, pr + 1, 0 ); + } + } + + r['s'] = s; + external = true; + Decimal['rounding'] = rm; + } + + r = rnd( r, pr, rm ); + } + } + + return r; + }; + + + /* + * Return a string representing the value of this Decimal rounded to #sd significant digits + * using rounding mode #rounding. + * + * Return exponential notation if #sd is less than the number of digits necessary to represent + * the integer part of the value in normal notation. + * + * sd {number} Significant digits. Integer, 1 to MAX_DIGITS inclusive. + * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive. + * + * #errors true: Throw if #sd and #rm are not undefined, null or integers in range. + * #errors false: Ignore #sd and #rm if not numbers or not in range, and truncate non-integers. + * + * 'toPrecision() sd not an integer: {sd}' + * 'toPrecision() sd out of range: {sd}' + * 'toPrecision() rounding mode not an integer: {rm}' + * 'toPrecision() rounding mode out of range: {rm}' + * + */ + P['toPrecision'] = function ( sd, rm ) { + + return sd != null && checkArg( this, sd, 'toPrecision', 1 ) + ? format( this, --sd | 0, checkRM( this, rm, 'toPrecision' ), 2 ) + : this.toString(); + }; + + + /* + * Return a new Decimal whose value is this Decimal rounded to a maximum of #d significant + * digits using rounding mode #rm, or to #precision and #rounding respectively if omitted. + * + * [d] {number} Significant digits. Integer, 1 to MAX_DIGITS inclusive. + * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive. + * + * 'toSD() digits out of range: {d}' + * 'toSD() digits not an integer: {d}' + * 'toSD() rounding mode not an integer: {rm}' + * 'toSD() rounding mode out of range: {rm}' + * + */ + P['toSignificantDigits'] = P['toSD'] = function ( d, rm ) { + var x = this, + Decimal = x['constructor']; + + x = new Decimal(x); + + return d == null || !checkArg( x, d, 'toSD', 1 ) + ? rnd( x, Decimal['precision'], Decimal['rounding'] ) + : rnd( x, d | 0, checkRM( x, rm, 'toSD' ) ); + }; + + + /* + * Return a string representing the value of this Decimal in base #b, or base 10 if #b is + * omitted. If a base is specified, including base 10, round to #precision significant digits + * using rounding mode #rounding. + * + * Return exponential notation if a base is not specified, and this Decimal has a positive + * exponent equal to or greater than #toExpPos, or a negative exponent equal to or less than + * #toExpNeg. + * + * [b] {number} Base. Integer, 2 to 64 inclusive. + * + */ + P['toString'] = function (b) { + var u, str, strL, + x = this, + Decimal = x['constructor'], + xe = x['e']; + + // Infinity or NaN? + if ( xe === null ) { + str = x['s'] ? 'Infinity' : 'NaN'; + + // Exponential format? + } else if ( b === u && ( xe <= Decimal['toExpNeg'] || xe >= Decimal['toExpPos'] ) ) { + + return format( x, x['c'].length - 1, Decimal['rounding'], 1 ); + } else { + str = x['c'].join(''); + + // Negative exponent? + if ( xe < 0 ) { + + // Prepend zeros. + for ( ; ++xe; str = '0' + str ) { + } + str = '0.' + str; + + // Positive exponent? + } else if ( strL = str.length, xe > 0 ) { + + if ( ++xe > strL ) { + + // Append zeros. + for ( xe -= strL; xe-- ; str += '0' ) { + } + + } else if ( xe < strL ) { + str = str.slice( 0, xe ) + '.' + str.slice(xe); + } + + // Exponent zero. + } else { + u = str.charAt(0); + + if ( strL > 1 ) { + str = u + '.' + str.slice(1); + + // Avoid '-0' + } else if ( u == '0' ) { + + return u; + } + } + + if ( b != null ) { + + if ( !( outOfRange = !( b >= 2 && b < 65 ) ) && + ( b == (b | 0) || !Decimal['errors'] ) ) { + str = convertBase( Decimal, str, b | 0, 10, x['s'] ); + + // Avoid '-0' + if ( str == '0' ) { + + return str; + } + } else { + + // 'toString() base not an integer: {b}' + // 'toString() base out of range: {b}' + ifExceptionsThrow( Decimal, 'base', b, 'toString', 0 ); + } + } + } + + return x['s'] < 0 ? '-' + str : str; + }; + + + /* + * Return a new Decimal whose value is the value of this Decimal truncated to a whole number. + * + */ + P['truncated'] = P['trunc'] = function () { + + return rnd( new this['constructor'](this), this['e'] + 1, 1 ); + }; + + + /* + * Return as #toString, but do not accept a base argument. + * + * Ensures that JSON.stringify() uses #toString for serialization. + * + */ + P['valueOf'] = P['toJSON'] = function () { + + return this.toString(); + }; + + + /* + // Add aliases to match BigDecimal method names. + P['add'] = P['plus']; + P['subtract'] = P['minus']; + P['multiply'] = P['times']; + P['divide'] = P['div']; + P['remainder'] = P['mod']; + P['compareTo'] = P['cmp']; + P['negate'] = P['neg']; + */ + + + // Private functions for Decimal.prototype methods. + + + /* + * #checkRoundingDigits + * #checkRM + * #checkArg + * #convertBase + * #div + * #exp + * #format + * #ifExceptionsThrow + * #intPow + * #ln + * #rnd + */ + + + /* + * Check 5 rounding digits if #repeating is null, 4 otherwise. + * #repeating == null if caller is #log or #pow, + * #repeating != null if caller is #ln or #exp. + */ + function checkRoundingDigits( c, i, rm, repeating ) { + + return ( !repeating && rm > 3 && c[i] == 4 || + ( repeating || rm < 4 ) && c[i] == 9 ) && c[i + 1] == 9 && c[i + 2] == 9 && + c[i + 3] == 9 && ( repeating != null || c[i + 4] == 9 ) || + repeating == null && ( c[i] == 5 || !c[i] ) && !c[i + 1] && !c[i + 2] && + !c[i + 3] && !c[i + 4]; + } + + + /* + * Check and return rounding mode. If #rm is invalid, return rounding mode #rounding. + */ + function checkRM( x, rm, method ) { + var Decimal = x['constructor']; + + return rm == null || ( ( outOfRange = rm < 0 || rm > 8 ) || + rm !== 0 && ( Decimal['errors'] ? parseInt : parseFloat )(rm) != rm ) && + !ifExceptionsThrow( Decimal, 'rounding mode', rm, method, 0 ) + ? Decimal['rounding'] : rm | 0; + } + + + /* + * Check that argument #n is in range, return true or false. + */ + function checkArg( x, n, method, min ) { + var Decimal = x['constructor']; + + return !( outOfRange = n < ( min || 0 ) || n >= MAX_DIGITS + 1 ) && + + /* + * Include 'n === 0' because Opera has 'parseFloat(-0) == -0' as false + * despite having 'parseFloat(-0) === -0 && parseFloat('-0') === -0 && 0 == -0' as true. + */ + ( n === 0 || ( Decimal['errors'] ? parseInt : parseFloat )(n) == n ) || + ifExceptionsThrow( Decimal, 'argument', n, method, 0 ); + } + + + /* + * Convert a numeric string of #baseIn to a numeric string of #baseOut. + */ + convertBase = (function () { + + /* + * Convert string of #baseIn to an array of numbers of #baseOut. + * Eg. convertBase('255', 10, 16) returns [15, 15]. + * Eg. convertBase('ff', 16, 10) returns [2, 5, 5]. + */ + function toBaseOut( str, baseIn, baseOut ) { + var j, + arr = [0], + arrL, + i = 0, + strL = str.length; + + for ( ; i < strL; ) { + + for ( arrL = arr.length; arrL--; arr[arrL] *= baseIn ) { + } + arr[ j = 0 ] += NUMERALS.indexOf( str.charAt( i++ ) ); + + for ( ; j < arr.length; j++ ) { + + if ( arr[j] > baseOut - 1 ) { + + if ( arr[j + 1] == null ) { + arr[j + 1] = 0; + } + arr[j + 1] += arr[j] / baseOut | 0; + arr[j] %= baseOut; + } + } + } + + return arr.reverse(); + } + + // #sign is needed to enable the correct rounding of the division. + return function ( Decimal, str, baseOut, baseIn, sign ) { + var x, xc, yc, + i = str.indexOf( '.' ), + y = new Decimal(baseIn); + + if ( baseIn < 37 ) { + str = str.toLowerCase(); + } + + if ( i < 0 ) { + x = new Decimal(y); + yc = [1]; + } else { + + /* + Convert the base of #str as if #str is an integer, then divide the result by its + base raised to a power such that the fraction part will be restored. + Use #toFixed to avoid possible exponential notation. + */ + x = intPow( Decimal, y, str.length - i - 1 ); + yc = toBaseOut( x.toFixed(), 10, baseOut ); + str = str.replace( '.', '' ); + } + + // #xc and #yc may have trailing zeros. + + y['c'] = yc; + y['e'] = yc.length; + + // Convert the number as integer. + xc = toBaseOut( str, baseIn, baseOut ); + + x['c'] = xc; + x['e'] = xc.length; + x['s'] = sign; + + x = div( x, y, Decimal['precision'], Decimal['rounding'], 0, baseOut ); + + // E.g. [4, 11, 15] becomes [4, b, f]. + for ( xc = x['c'], i = xc.length; i--; ) { + xc[i] = NUMERALS.charAt( xc[i] ); + } + + // No negative numbers: the caller will add the sign. + x['s'] = 1; + + return x.toFixed(); + } + })(); + + + /* + * Perform division in the specified base. Called by #div and #convertBase. + */ + function div( x, y, pr, rm, dp, b ) { + var Decimal = x['constructor'], + e = x['e'] - y['e'], + s = x['s'] == y['s'] ? 1 : -1, + xc = x['c'], + yc = y['c']; + + // Either NaN, Infinity or 0? + if ( !xc || !xc[0] || !yc || !yc[0] ) { + + return new Decimal( + + // Return NaN if either NaN, or both Infinity or 0. + !x['s'] || !y['s'] || ( xc ? yc && xc[0] == yc[0] : !yc ) ? NaN : + + // Return +-0 if #x is 0 or #y is +-Infinity, or return +-Infinity as y is 0. + xc && xc[0] == 0 || !yc ? s * 0 : s / 0 + ); + } + + var cmp, i, n, ri, t, yL, + yz = yc.slice(), + xi = yL = yc.length, + xL = xc.length, + r = xc.slice( 0, yL ), + rL = r.length, + q = new Decimal(s), + qc = q['c'] = []; + + for ( i = s = 0; yc[i] == ( xc[i] || 0 ); i++ ) { + } + + // Result exponent may be one less then the current value of #e. + // The coefficients of the Decimals from #convertBase may have trailing zeros. + if ( yc[i] > ( xc[i] || 0 ) ) { + e--; + + /* + The result of the division has a leading zero so an extra digit will be needed to + maintain the correct precision (plus the rounding digit). + */ + s = 1; + } + + q['e'] = e; + + if ( pr == null ) { + pr = Decimal['precision']; + rm = Decimal['rounding']; + } else if (dp) { + pr += e + 1; + } + + // Default base is 10. + b = b || 10; + + if ( pr >= 0 ) { + s += pr; + + // Add zeros to make remainder as long as divisor. + for ( ; rL++ < yL; r.push(0) ) { + } + + // Create version of divisor with leading zero. + yz.unshift( i = 0 ); + + do { + + // #n is how many times the divisor goes into the current remainder. + for ( n = 0; n < b; n++ ) { + + // Compare divisor and remainder. + if ( yL != ( rL = r.length ) ) { + cmp = yL > rL ? 1 : -1; + } else { + + for ( ri = -1, cmp = 0; ++ri < yL; ) { + + if ( yc[ri] != r[ri] ) { + cmp = yc[ri] > r[ri] ? 1 : -1; + + break; + } + } + } + + // If divisor < remainder, subtract divisor from remainder. + if ( cmp < 0 ) { + + // Remainder cannot be more than one digit longer than divisor. + // Equalise lengths using divisor with extra leading zero? + for ( t = rL == yL ? yc : yz; rL; ) { + + if ( r[--rL] < t[rL] ) { + + for ( ri = rL; + ri && !r[--ri]; + r[ri] = b - 1 ) { + } + --r[ri]; + r[rL] += b; + } + r[rL] -= t[rL]; + } + + for ( ; !r[0]; r.shift() ) { + } + } else { + + break; + } + } + + // Add the next digit n to the result array. + qc[i++] = cmp ? n : ++n; + + // Update the remainder. + if ( r[0] && cmp ) { + r[rL] = xc[xi] || 0; + } else { + r = [ xc[xi] ]; + } + + } while ( ( xi++ < xL || r[0] != null ) && s-- ); + + // Leading zero? Do not remove if result is simply zero, i.e. i is 1. + if ( !qc[0] && i > 1 ) { + qc.shift(); + } + + // No need to round if #i <= #pr, just check for underflow/overflow. + if ( i <= pr ) { + pr = null; + } + } + + // If #pr < 0, r[0] != null will be true. + return rnd( q, pr, rm, r[0] != null, b ); + } + + + /* + * Taylor/Maclaurin series. + * + * exp(x) = x^0/0! + x^1/1! + x^2/2! + x^3/3! + ... + * + * Argument reduction: + * Repeat x = x / 32, k += 5, until |x| < 0.1 + * exp(x) = exp(x / 2^k)^(2^k) + * + * Previously, the argument was initially reduced by + * exp(x) = exp(r) * 10^k where r = x - k * ln10, k = floor(x / ln10) + * to first put r in the range [0, ln10], before dividing by 32 until |x| < 0.1, but this was + * found to be slower than just dividing repeatedly by 32 as above. + * + * Max integer argument: exp('20723265836946413') = 6.3e+9000000000000000 + * Min integer argument: exp('-20723265836946411') = 1.2e-9000000000000000 + * ( Math object integer min/max: Math.exp(709) = 8.2e+307, Math.exp(-745) = 5e-324 ) + * + * exp(Infinity) = Infinity + * exp(-Infinity) = 0 + * exp(NaN) = NaN + * exp(+-0) = 1 + * + * exp(x) is non-terminating for any finite, non-zero x. + * + * The result will always be correctly rounded. + * + */ + function exp( x, pr ) { + var denom, guard, j, pow, sd, sum, t, + rep = 0, + i = 0, + k = 0, + Decimal = x['constructor'], + one = Decimal['ONE'], + rm = Decimal['rounding'], + precision = Decimal['precision']; + + // 0/NaN/Infinity? + if ( !x['c'] || !x['c'][0] || x['e'] > 17 ) { + + return new Decimal( x['c'] + ? !x['c'][0] ? one : x['s'] < 0 ? 0 : 1 / 0 + : x['s'] ? x['s'] < 0 ? 0 : x : NaN ); + } + + if ( pr == null ) { + + /* + Estimate result exponent. + e^x = 10^j, where j = x * log10(e) and + log10(e) = ln(e) / ln(10) = 1 / ln(10), + so j = x / ln(10) + j = Math.floor( x / Math.LN10 ); + + // Overflow/underflow? Estimate may be +-1 of true value. + if ( j > Decimal['maxE'] + 1 || j < Decimal['minE'] - 1 ) { + + return new Decimal( j > 0 ? 1 / 0 : 0 ); + } + */ + + external = false; + sd = precision; + } else { + sd = pr; + } + + t = new Decimal(0.03125); + + // while abs(x) >= 0.1 + while ( x['e'] > -2 ) { + + // x = x / 2^5 + x = x['times'](t); + k += 5; + } + + /* + Use 2 * log10(2^k) + 5 to estimate the increase in precision necessary to ensure the first + 4 rounding digits are correct. + */ + guard = Math.log( Math.pow( 2, k ) ) / Math.LN10 * 2 + 5 | 0; + sd += guard; + denom = pow = sum = new Decimal(one); + Decimal['precision'] = sd; + + for( ; ; ) { + pow = rnd( pow['times'](x), sd, 1 ); + denom = denom['times'](++i); + t = sum['plus']( div( pow, denom, sd, 1 ) ); + + if ( t['c'].slice( 0, sd ).join('') === sum['c'].slice( 0, sd ).join('') ) { + j = k; + + while ( j-- ) { + sum = rnd( sum['times'](sum), sd, 1 ); + } + + /* + Check to see if the first 4 rounding digits are [49]999. + If so, repeat the summation with a higher precision, otherwise + E.g. with #precision: 18, #rounding: 1 + exp(18.404272462595034083567793919843761) = 98372560.1229999999 + when it should be 98372560.123 + + #sd - #guard is the index of first rounding digit. + */ + if ( pr == null ) { + + if ( rep < 3 && checkRoundingDigits( sum['c'], sd - guard, rm, rep ) ) { + Decimal['precision'] = sd += 10; + denom = pow = t = new Decimal(one); + i = 0; + rep++; + } else { + + return rnd( sum, Decimal['precision'] = precision, rm, external = true ); + } + } else { + Decimal['precision'] = precision; + + return sum; + } + } + sum = t; + } + } + + + /* + * Return a string representing the value of Decimal #n in normal or exponential notation + * rounded to the specified decimal places or significant digits. + * Called by #toString, #toExponential (#exp is 1), #toFixed, and #toPrecision (#exp is 2). + * #i is the index (with the value in normal notation) of the digit that may be rounded up. + */ + function format( n, i, rm, exp ) { + var Decimal = n['constructor'], + e = ( n = new Decimal(n) )['e'], + c = n['c']; + + // +-Infinity or NaN? + if ( !c ) { + + return n.toString(); + } + + // Round? + if ( c.length > ++i ) { + rnd( n, i, rm ); + } + + // If #toFixed, n['e'] may have changed if the value was rounded up. + e = exp ? i : i + n['e'] - e; + + // Append zeros? + for ( ; c.length < e; c.push(0) ) { + } + e = n['e']; + + /* + #toPrecision returns exponential notation if the number of significant digits specified + is less than the number of digits necessary to represent the integer part of the value + in normal notation. + */ + return exp == 1 || exp == 2 && ( i <= e || e <= Decimal['toExpNeg'] ) + + // Exponential notation. + ? ( n['s'] < 0 && c[0] ? '-' : '' ) + + ( c.length > 1 ? c[0] + '.' + c.slice(1).join('') : c[0] ) + + ( e < 0 ? 'e' : 'e+' ) + e + + // Normal notation. + : n.toString(); + } + + + /* + * Assemble error messages. Throw Decimal Errors. + */ + function ifExceptionsThrow( Decimal, message, arg, method, more ) { + + if ( Decimal['errors'] ) { + var error = new Error( ( method || [ + 'new Decimal', 'cmp', 'div', 'eq', 'gt', 'gte', 'lt', 'lte', 'minus', 'mod', + 'plus', 'times', 'toFraction', 'pow', 'random', 'log', 'sqrt', 'toNearest', 'divToInt' + ][ id ? id < 0 ? -id : id : 1 / id < 0 ? 1 : 0 ] ) + '() ' + ( [ + 'number type has more than 15 significant digits', 'LN10 out of digits' ][message] + || message + ( [ outOfRange ? ' out of range' : ' not an integer', + ' not a boolean or binary digit' ][more] || '' ) ) + ': ' + arg + ); + error['name'] = 'Decimal Error'; + outOfRange = id = 0; + + throw error; + } + } + + + /* + * Use 'exponentiation by squaring' for small integers. Called by #convertBase and #pow. + */ + function intPow( Decimal, x, i ) { + var r = new Decimal( Decimal['ONE'] ); + + for ( external = false; ; ) { + + if ( i & 1 ) { + r = r['times'](x); + } + i >>= 1; + + if ( !i ) { + + + break; + } + x = x['times'](x); + } + external = true; + + return r; + } + + + /* + * ln(-n) = NaN + * ln(0) = -Infinity + * ln(-0) = -Infinity + * ln(1) = 0 + * ln(Infinity) = Infinity + * ln(-Infinity) = NaN + * ln(NaN) = NaN + * + * ln(n) (n != 1) is non-terminating. + * + */ + function ln( y, pr ) { + var denom, e, num, rep, sd, sum, t, x1, x2, + n = 1, + guard = 10, + x = y, + c = x['c'], + Decimal = x['constructor'], + one = Decimal['ONE'], + rm = Decimal['rounding'], + precision = Decimal['precision']; + + // #x < 0 or +-Infinity/NaN or 0 or 1. + if ( x['s'] < 0 || !c || !c[0] || !x['e'] && c[0] == 1 && c.length == 1 ) { + + return new Decimal( c && !c[0] ? -1 / 0 : x['s'] != 1 ? NaN : c ? 0 : x ); + } + + if ( pr == null ) { + external = false; + sd = precision; + } else { + sd = pr; + } + + Decimal['precision'] = sd += guard; + + if ( Math.abs( e = x['e'] ) < 1.5e15 ) { + + /* + Argument reduction. + The series converges faster the closer the argument is to 1, so using + ln(a^b) = b * ln(a), ln(a) = ln(a^b) / b + multiply the argument by itself until the leading digits of the significand are 7, 8, + 9, 10, 11, 12 or 13 recording the number of multiplications so the sum of the series + can later be divided by this number, then separate out the power of 10 using + ln(a*10^b) = ln(a) + b*ln(10). + */ + // max #n is 6 ( gives 0.7 - 1.3 ) + while ( c[0] < 7 && c[0] != 1 || c[0] == 1 && c[1] > 3 ) { + + // max #n is 21 ( gives 0.9, 1.0 or 1.1 ) ( 9e15 / 21 = 4.2e14 ). + //while ( c[0] < 9 && c[0] != 1 || c[0] == 1 && c[1] > 1 ) { + x = x['times'](y); + c = x['c']; + n++; + } + + e = x['e']; + + if ( c[0] > 1 ) { + + if ( n == 1 ) { + x = new Decimal( '0.' + c.join('') ); + } else { + x['e'] = -1; + } + e++; + } else { + x = new Decimal( '1.' + c.slice(1).join('') ); + } + } else { + + /* + The argument reduction method above may result in overflow if the argument #y is a + massive number with exponent >= 1500000000000000 ( 9e15 / 6 = 1.5e15 ), so instead + recall this function using ln(x*10^e) = ln(x) + e*ln(10). + */ + x = new Decimal(x); + x['e'] = 0; + + if ( sd + 2 > LN10.length ) { + ifExceptionsThrow( Decimal, 1, sd + 2, 'ln' ); + } + + x = ln( x, sd - guard )['plus']( + new Decimal( LN10.slice( 0, sd + 2 ) )['times']( e + '' ) + ); + + Decimal['precision'] = precision; + + return pr == null ? rnd( x, precision, rm, external = true ) : x; + } + + // #x1 is #x reduced to a value near 1. + x1 = x; + + /* + Taylor series. + ln(y) = ln( (1 + x)/(1 - x) ) = 2( x + x^3/3 + x^5/5 + x^7/7 + ... ) + where + x = (y - 1)/(y + 1) ( |x| < 1 ) + */ + sum = num = x = div( x['minus'](one), x['plus'](one), sd, 1 ); + x2 = rnd( x['times'](x), sd, 1 ); + denom = 3; + + for( ; ; ) { + num = rnd( num['times'](x2), sd, 1 ); + t = sum['plus']( div( num, new Decimal(denom), sd, 1 ) ); + + if ( t['c'].slice( 0, sd ).join('') === sum['c'].slice( 0, sd ).join('') ) { + sum = sum['times'](2); + + /* + Reverse the argument reduction. Check that #e is not 0 because, as well as + preventing an unnecessary calculation, -0 + 0 = +0 and to ensure correct + rounding later -0 needs to stay -0. + */ + if ( e !== 0 ) { + + if ( sd + 2 > LN10.length ) { + ifExceptionsThrow( Decimal, 1, sd + 2, 'ln' ); + } + + sum = sum['plus']( + new Decimal( LN10.slice( 0, sd + 2 ) )['times']( e + '' ) + ); + } + + sum = div( sum, new Decimal(n), sd, 1 ); + + /* + Is #rm > 3 and the first 4 rounding digits 4999, or #rm < 4 (or the summation has + been repeated previously) and the first 4 rounding digits 9999? + + If so, restart the summation with a higher precision, otherwise + E.g. with #precision: 12, #rounding: 1 + ln(135520028.6126091714265381533) = 18.7246299999 when it should be 18.72463. + + #sd - #guard is the index of first rounding digit. + */ + if ( pr == null ) { + + if ( checkRoundingDigits( sum['c'], sd - guard, rm, rep ) ) { + Decimal['precision'] = sd += guard; + t = num = x = div( x1['minus'](one), x1['plus'](one), sd, 1 ); + x2 = rnd( x['times'](x), sd, 1 ); + denom = rep = 1; + } else { + + return rnd( sum, Decimal['precision'] = precision, rm, external = true ); + } + } else { + Decimal['precision'] = precision; + + return sum; + } + } + + sum = t; + denom += 2; + } + } + + + /* + * Round #x to #sd significant digits using rounding mode #rm. Check for over/under-flow. + */ + function rnd( x, sd, rm, r, b ) { + var rd, half, isNeg, xc, + Decimal = x['constructor']; + + // Don't round if #sd is null or undefined. + if ( sd != rd ) { + + if ( !( xc = x['c'] ) ) { + + return x; + } + + isNeg = x['s'] < 0, + half = ( b = b || 10 ) / 2; + + // #rd is the rounding digit, i.e. the digit after the digit that may be rounded up. + rd = xc[sd]; + r = r || sd < 0 || xc[sd + 1] != null; + + r = rm < 4 + ? ( rd != null || r ) && ( rm == 0 || rm == 2 && !isNeg || rm == 3 && isNeg ) + : rd > half || rd == half && ( rm == 4 || r || rm == 6 && xc[sd - 1] & 1 || + rm == 7 && !isNeg || rm == 8 && isNeg ); + + if ( sd < 1 || !xc[0] ) { + xc.length = 0; + + if (r) { + + // Convert #sd to decimal places. + sd = sd - x['e'] - 1; + + // 1, 0.1, 0.01, 0.001, 0.0001 etc. + xc[0] = 1; + x['e'] = -sd || 0; + } else { + + // Zero. + xc[0] = x['e'] = 0; + } + + return x; + } + + // Remove any digits after the required decimal places. + if ( xc.length > sd ) { + xc.length = sd; + } + sd--; + + // Round up? + if (r) { + + // Set to zero any undefined elements before the digit to be rounded up. + // Only used by #ln? + for ( rd = sd; xc[rd] == null; xc[rd--] = 0 ) { + } + + // Rounding up may mean the previous digit has to be rounded up and so on. + for ( --b; ++xc[sd] > b; ) { + xc[sd] = 0; + + if ( !sd-- ) { + ++x['e']; + xc.unshift(1); + } + } + } + + // Remove trailing zeros. + for ( sd = xc.length; !xc[--sd]; xc.pop() ) { + } + } + + if (external) { + + // Overflow? + if ( x['e'] > Decimal['maxE'] ) { + + // Infinity. + x['c'] = x['e'] = null; + + // Underflow? + } else if ( x['e'] < Decimal['minE'] ) { + + // Zero. + x['c'] = [ x['e'] = 0 ]; + } + } + + return x; + } + + + DecimalConstructor = (function () { + + + // Private functions used by static Decimal methods. + + + /* + * The following emulations or wrappers of #Math object functions are currently + * commented-out and not in the public API. + * + * #abs + * #acos + * #asin + * #atan + * #atan2 + * #ceil + * #cos + * #floor + * #round + * #sin + * #tan + * #trunc + */ + + + /* + * Return a new Decimal whose value is the absolute value of #n. + * + * n {number|string|Decimal} + * + function abs(n) { return new this(n)['abs']() } + */ + + + /* + * Return a new Decimal whose value is the arccosine in radians of #n. + * + * n {number|string|Decimal} + * + function acos(n) { return new this( Math.acos(n) + '' ) } + */ + + + /* + * Return a new Decimal whose value is the arcsine in radians of #n. + * + * n {number|string|Decimal} + * + function asin(n) { return new this( Math.asin(n) + '' ) } + */ + + + /* + * Return a new Decimal whose value is the arctangent in radians of #n. + * + * n {number|string|Decimal} + * + function atan(n) { return new this( Math.atan(n) + '' ) } + */ + + + /* + * Return a new Decimal whose value is the arctangent in radians of #y/#x in the range + * -PI to PI (inclusive). + * + * y {number|string|Decimal} The y-coordinate. + * x {number|string|Decimal} The x-coordinate. + * + function atan2( y, x ) { return new this( Math.atan2( y, x ) + '' ) } + */ + + + /* + * Return a new Decimal whose value is #n round to an integer using ROUND_CEIL. + * + * n {number|string|Decimal} + * + function ceil(n) { return new this(n)['ceil']() } + */ + + + /* + * Configure global settings for a Decimal constructor. + * + * #obj is an object with any of the following properties, + * + * #precision {number} + * #rounding {number} + * #toExpNeg {number} + * #toExpPos {number} + * #minE {number} + * #maxE {number} + * #errors {boolean|number} + * #crypto {boolean|number} + * #modulo {number} + * + * E.g. + * Decimal.config({ precision: 20, rounding: 4 }) + * + */ + function config(obj) { + var p, u, v, + Decimal = this, + c = 'config', + parse = Decimal['errors'] ? parseInt : parseFloat; + + if ( obj == u || typeof obj != 'object' && + !ifExceptionsThrow( Decimal, 'object expected', obj, c ) ) { + + return Decimal; + } + + // #precision {number|number[]} Integer, 1 to MAX_DIGITS inclusive. + if ( ( v = obj[ p = 'precision' ] ) != u ) { + + if ( !( outOfRange = v < 1 || v > MAX_DIGITS ) && parse(v) == v ) { + Decimal[p] = v | 0; + } else { + + // 'config() precision not an integer: {v}' + // 'config() precision out of range: {v}' + ifExceptionsThrow( Decimal, p, v, c, 0 ); + } + } + + // #rounding {number} Integer, 0 to 8 inclusive. + if ( ( v = obj[ p = 'rounding' ] ) != u ) { + + if ( !( outOfRange = v < 0 || v > 8 ) && parse(v) == v ) { + Decimal[p] = v | 0; + } else { + + // 'config() rounding not an integer: {v}' + // 'config() rounding out of range: {v}' + ifExceptionsThrow( Decimal, p, v, c, 0 ); + } + } + + // #toExpNeg {number} Integer, -EXP_LIMIT to 0 inclusive. + if ( ( v = obj[ p = 'toExpNeg' ] ) != u ) { + + if ( !( outOfRange = v < -EXP_LIMIT || v > 0 ) && parse(v) == v ) { + Decimal[p] = Math.floor(v); + } else { + + // 'config() toExpNeg not an integer: {v}' + // 'config() toExpNeg out of range: {v}' + ifExceptionsThrow( Decimal, p, v, c, 0 ); + } + } + + // #toExpPos {number} Integer, 0 to EXP_LIMIT inclusive. + if ( ( v = obj[ p = 'toExpPos' ] ) != u ) { + + if ( !( outOfRange = v < 0 || v > EXP_LIMIT ) && parse(v) == v ) { + Decimal[p] = Math.floor(v); + } else { + + // 'config() toExpPos not an integer: {v}' + // 'config() toExpPos out of range: {v}' + ifExceptionsThrow( Decimal, p, v, c, 0 ); + } + } + + // #minE {number} Integer, -EXP_LIMIT to 0 inclusive. + if ( ( v = obj[ p = 'minE' ] ) != u ) { + + if ( !( outOfRange = v < -EXP_LIMIT || v > 0 ) && parse(v) == v ) { + Decimal[p] = Math.floor(v); + } else { + + // 'config() minE not an integer: {v}' + // 'config() minE out of range: {v}' + ifExceptionsThrow( Decimal, p, v, c, 0 ); + } + } + + // #maxE {number} Integer, 0 to EXP_LIMIT inclusive. + if ( ( v = obj[ p = 'maxE' ] ) != u ) { + + if ( !( outOfRange = v < 0 || v > EXP_LIMIT ) && parse(v) == v ) { + Decimal[p] = Math.floor(v); + } else { + + // 'config() maxE not an integer: {v}' + // 'config() maxE out of range: {v}' + ifExceptionsThrow( Decimal, p, v, c, 0 ); + } + } + + // #errors {boolean|number} true, false, 1 or 0. + if ( ( v = obj[ p = 'errors' ] ) != u ) { + + if ( v === !!v || v === 1 || v === 0 ) { + outOfRange = id = 0; + Decimal[p] = !!v; + } else { + + // 'config() errors not a boolean or binary digit: {v}' + ifExceptionsThrow( Decimal, p, v, c, 1 ); + } + } + + // #crypto {boolean|number} true, false, 1 or 0. + if ( ( v = obj[ p = 'crypto' ] ) != u ) { + + if ( v === !!v || v === 1 || v === 0 ) { + Decimal[p] = !!( v && crypto && typeof crypto == 'object' ); + } else { + + // 'config() crypto not a boolean or binary digit: {v}' + ifExceptionsThrow( Decimal, p, v, c, 1 ); + } + } + + // #modulo {number} Integer, 0 to 9 inclusive. + if ( ( v = obj[ p = 'modulo' ] ) != u ) { + + if ( !( outOfRange = v < 0 || v > 9 ) && parse(v) == v ) { + Decimal[p] = v | 0; + } else { + + // 'config() modulo not an integer: {v}' + // 'config() modulo out of range: {v}' + ifExceptionsThrow( Decimal, p, v, c, 0 ); + } + } + + return Decimal; + } + + + /* + * Return a new Decimal whose value is the cosine of #n. + * + * n {number|string|Decimal} A number given in radians. + * + function cos(n) { return new this( Math.cos(n) + '' ) } + */ + + + /* + * Return a new Decimal whose value is the exponential of #n, + * + * n {number|string|Decimal} The power to which to raise the base of the natural log. + * + */ + function exp(n) { return new this(n)['exp']() } + + + /* + * Return a new Decimal whose value is #n round to an integer using ROUND_FLOOR. + * + * n {number|string|Decimal} + * + function floor(n) { return new this(n)['floor']() } + */ + + + /* + * Return a new Decimal whose value is the natural logarithm of #n. + * + * n {number|string|Decimal} + * + */ + function ln(n) { return new this(n)['ln']() } + + + /* + * Return a new Decimal whose value is the log of #x to the base #y, or to base 10 if no + * base is specified. + * + * log[y](x) + * + * x {number|string|Decimal} The argument of the logarithm. + * y {number|string|Decimal} The base of the logarithm. + * + */ + function log( x, y ) { return new this(x)['log'](y) } + + + /* + * Handle #max and #min. #ltgt is 'lt' or 'gt'. + */ + function maxOrMin( Decimal, args, ltgt ) { + var m, n, + i = 0; + + if ( toString.call( args[0] ) == '[object Array]' ) { + args = args[0]; + } + + m = new Decimal( args[0] ); + + for ( ; ++i < args.length; ) { + n = new Decimal( args[i] ); + + if ( !n['s'] ) { + m = n; + + break; + } else if ( m[ltgt](n) ) { + m = n; + } + } + + return m; + } + + + /* + * Return a new Decimal whose value is the maximum of the arguments. + * + * arguments {number|string|Decimal} + * + */ + function max() { return maxOrMin( this, arguments, 'lt' ) } + + + /* + * Return a new Decimal whose value is the minimum of the arguments. + * + * arguments {number|string|Decimal} + * + */ + function min() { return maxOrMin( this, arguments, 'gt' ) } + + + /* + * Parse the value of a new Decimal from a number or string. + */ + var parseDecimal = (function () { + var isValid = /^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i, + trim = String.prototype.trim || function () {return this.replace(/^\s+|\s+$/g, '')}; + + return function ( Decimal, x, n, b ) { + var d, e, i, isNum, orig, valid; + + if ( typeof n != 'string' ) { + + // If #n is a number, check if minus zero. + n = ( isNum = typeof n == 'number' || toString.call(n) == '[object Number]' ) && + n === 0 && 1 / n < 0 ? '-0' : n + ''; + } + orig = n; + + if ( b == e && isValid.test(n) ) { + + // Determine sign. + x['s'] = n.charAt(0) == '-' ? ( n = n.slice(1), -1 ) : 1; + + // Either #n is not a valid Decimal or a base has been specified. + } else { + + /* + Enable exponential notation to be used with base 10 argument. + Ensure return value is rounded to #precision as with other bases. + */ + if ( b == 10 ) { + + return rnd( new Decimal(n), Decimal['precision'], Decimal['rounding'] ); + } + + n = trim.call(n).replace( /^\+(?!-)/, '' ); + + x['s'] = n.charAt(0) == '-' ? ( n = n.replace( /^-(?!-)/, '' ), -1 ) : 1; + + if ( b != e ) { + + if ( ( b == (b | 0) || !Decimal['errors'] ) && + !( outOfRange = !( b >= 2 && b < 65 ) ) ) { + d = '[' + NUMERALS.slice( 0, b = b | 0 ) + ']+'; + + // Remove the `.` from e.g. '1.', and replace e.g. '.1' with '0.1'. + n = n.replace( /\.$/, '' ).replace( /^\./, '0.' ); + + + // Any number in exponential form will fail due to the e+/-. + if ( valid = new RegExp( + '^' + d + '(?:\\.' + d + ')?$', b < 37 ? 'i' : '' ).test(n) + ) { + + if (isNum) { + + if ( n.replace( /^0\.0*|\./, '' ).length > 15 ) { + + // '{method} number type has more than 15 significant digits: {n}' + ifExceptionsThrow( Decimal, 0, orig ); + } + + // Prevent later check for length on converted number. + isNum = !isNum; + } + n = convertBase( Decimal, n, 10, b, x['s'] ); + + } else if ( n != 'Infinity' && n != 'NaN' ) { + + // '{method} not a base {b} number: {n}' + ifExceptionsThrow( Decimal, 'not a base ' + b + ' number', orig ); + n = 'NaN'; + } + } else { + + // '{method} base not an integer: {b}' + // '{method} base out of range: {b}' + ifExceptionsThrow( Decimal, 'base', b, 0, 0 ); + + // Ignore base. + valid = isValid.test(n); + } + } else { + valid = isValid.test(n); + } + + if ( !valid ) { + + // Infinity/NaN + x['c'] = x['e'] = null; + + // NaN + if ( n != 'Infinity' ) { + + // No exception on NaN. + if ( n != 'NaN' ) { + + // '{method} not a number: {n}' + ifExceptionsThrow( Decimal, 'not a number', orig ); + } + x['s'] = null; + } + id = 0; + + return x; + } + } + + // Decimal point? + if ( ( e = n.indexOf('.') ) > -1 ) { + + n = n.replace( '.', '' ); + } + + // Exponential form? + if ( ( i = n.search( /e/i ) ) > 0 ) { + + // Determine exponent. + if ( e < 0 ) { + e = i; + } + e += +n.slice( i + 1 ); + n = n.substring( 0, i ); + + } else if ( e < 0 ) { + + // Integer. + e = n.length; + } + + // Determine leading zeros. + for ( i = 0; n.charAt(i) == '0'; i++ ) { + } + + if ( i == ( b = n.length ) ) { + + // Zero. + x['c'] = [ x['e'] = 0 ]; + } else { + + // Disallow numbers with over 15 significant digits if number type. + if ( isNum && b > 15 && n.slice(i).length > 15 ) { + + // '{method} number type has more than 15 significant digits: {n}' + ifExceptionsThrow( Decimal, 0, orig ); + } + + // Determine trailing zeros. + for ( ; n.charAt(--b) == '0'; ) { + } + + x['e'] = e - i - 1; + x['c'] = []; + + // Convert string to array of digits (without leading and trailing zeros). + for ( e = 0; i <= b; x['c'][e++] = +n.charAt(i++) ) { + } + + if (external) { + + // Overflow? + if ( x['e'] > Decimal['maxE'] ) { + + // Infinity. + x['c'] = x['e'] = null; + + // Underflow? + } else if ( x['e'] < Decimal['minE'] ) { + + // Zero. + x['c'] = [ x['e'] = 0 ]; + } + } + } + id = 0; + } + })(); + + + /* + * Return a new Decimal whose value is #x raised to the power #y. + * + * x {number|string|Decimal} The base. + * y {number|string|Decimal} The exponent. + * + */ + function pow( x, y ) { return new this(x)['pow'](y) } + + + /* + * Generate a new Decimal with a random value. + */ + var random = (function () { + + /* + * #crypto false. + * + * Return a string of random decimal digits. + * If #max is falsey return up to 14 digits (almost always 13 or 14 digits), + * else return a number >= 0 and < #max (#max < 256). + */ + function getMathRandom(max) { + var r = Math.random(); + + /* + Add 1 to avoid exponential notation and keep leading zeros. Omit the first and the + last two digits for a maximum of 14 significant digits and to ensure that trailing + digits can be zero. + */ + return max ? ( r * max | 0 ) + '' : ( 1 + r + '' ).slice( 2, -2 ); + } + + + /* + * #crypto true. + * Browsers supporting crypto.getRandomValues. + * + * Return a string of random decimal digits. + * If #max is falsey return 9 digits, else return a number >= 0 and < #max (#max < 256). + */ + function getRandomValues(max) { + var n; + + return max + + // 0 >= n < 256 + ? ( n = crypto['getRandomValues']( new global['Uint8Array'](1) )[0], + n > ( 256 / max | 0 ) * max - 1 + + // Probability of recall if #max is 10 is 6 / 256 = 0.023 (i.e. 1 in 42.7). + ? getRandomValues(max) + : n % max + '' ) + + // 0 >= n < 4294967296 + : ( n = crypto['getRandomValues']( new global['Uint32Array'](1) )[0], + n >= 4e9 + + // Probability of recall is 294967297 / 4294967296 = 0.0687 (i.e. 1 in 14.6). + ? getRandomValues(max) + + // Add 1e9 so 1000000000 >= n <= 4999999999 and omit leading digit. + : ( n + 1e9 + '' ).slice(1) ); + } + + + /* + * #crypto true. + * Node.js supporting crypto.randomBytes. + * + * Return a string of random decimal digits. + * If #max is falsey return 14 digits, else return a number >= 0 and < #max (#max < 256). + */ + function getRandomBytes(max) { + var buf, n, + rb = crypto['randomBytes']; + + return max + ? ( n = rb(1)[0], n > ( 256 / max | 0 ) * max - 1 + ? getRandomBytes(max) + : n % max + '' ) + + // 01000011 0011XXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX + : ( buf = rb(8), buf[0] = 0x43, buf[1] = buf[1] & 0xf | 0x30, + + /* + (mantissa all zeros) 4503599627370496 >= n <= 9007199254740991 (mantissa all ones). + 4503599627370496 - 3599627370496 = 4500000000000000 + 9007199254740991 - 3599627370496 = 9003599627370495 + */ + n = buf.readDoubleBE(0), + n > 9003599627370495 + + /* + Probability of recall is + 3599627370497 / 4503599627370496 = 0.000799 (i.e. 1 in 1251). + */ + ? getRandomBytes(max) + + /* + Subtracting 4503599627370496 gives 0 >= n <= 4499999999999999, + so subtracting 1e15 less than that gives + 1000000000000000 >= n <= 5499999999999999. + Return the last 14 digits as a string. + */ + : ( n - 3503599627370496 + '' ).slice(2) ); + } + + /* + * Returns a new Decimal with a random value equal to or greater than 0 and lower in + * magnitude than #limit. + * + * If #limit is omitted then it will be 1 and the return value will have #precision + * significant digits (or less if trailing zeros are produced). + * + * If #limit is included and #pr is omitted then the return value will be an integer. If + * #pr is included, the return value will have #pr significant digits (or less if + * trailing zeros are produced). + * + * [limit] {number|string|Decimal} + * [pr] {number} Significant digits. Integer, 0 to MAX_DIGITS inclusive. + * + */ + return function ( limit, pr ) { + var c, e, i, ld, n, one, rd, str, + Decimal = this, + r = new Decimal(0), + rand = getMathRandom; + + // null/+-Infinity/NaN? + if ( one = limit == e || !( id = 14, limit = new Decimal(limit) )['c'] && + !ifExceptionsThrow( Decimal, 'limit must be finite', limit, 'random' ) ) { + limit = new Decimal( Decimal['ONE'] ); + + // Zero? + } else if ( !limit['c'][0] ) { + + return r; + } + + if ( Decimal['crypto'] ) { + + // Recent browsers. + if ( crypto['getRandomValues'] ) { + rand = getRandomValues; + + // Node.js. + } else if ( crypto['randomBytes'] ) { + rand = getRandomBytes; + } + } + + e = limit['e']; + n = ( c = limit['c'] ).length; + + // Ensure #r < limit. + do { + i = 0; + str = rand( c[0] + 1 ) + rand(); + + do { + ld = c[i]; // #limit digit + rd = str.charAt(i++); // random digit + } while ( ld == rd ); + } while ( rd > ld || i > n || rd == '' ); + + // Decrement exponent of result for every leading zero. + for ( i = 0; str.charAt(i) == '0'; i++, e-- ) { + } + + if (one) { + pr = Decimal['precision']; + } else if ( pr == null || !checkArg( limit, pr, 'random', 1 ) ) { + pr = e + 1; + } else { + pr |= 0; + } + + pr += i; + + // Add further random digits. + while ( str.length < pr ) { + str += rand(); + } + + // Determine trailing zeros. + for ( ; str.charAt(--pr) == '0'; ) { + } + + if ( ++pr > 0 ) { + + // Convert #str to number array without leading and trailing zeros. + for ( r['c'] = []; i < pr; r['c'].push( +str.charAt(i++) ) ) { + } + } else { + + // Zero. + r['c'] = [ e = 0 ]; + } + + r['e'] = e; + r['s'] = limit['s']; + + return r; + } + })(); + + + /* + * Not currently in public api. + * + * Generate random numbers for testing purposes. + * + * Returns a Decimal with a random sign, a random exponent in the range [-MIN.E, MAX-E] + * and a random number of significant digits in the range [1, #precision]. + * + * Within the limits of the #precision setting, this method can produce any finite Decimal. + * It will not, though, produce a uniform distribution. Intentionally, it is heavily biased + * toward smaller exponents. + * + * Math.random is always used as the source of randomness. + * + function randomE() { + var i, + Decimal = this, + // 1 in 4 chance of negative exponent. + isNeg = Math.random() < 0.25, + n = Math.floor( Math.random() * ( ( + isNeg ? -Decimal['minE'] : Decimal['maxE'] ) + 1 ) ) + '', + c = [ Math.random() * 9 + 1 | 0 ], + pr = i = Math.random() * Decimal['precision'] | 0, + r = new Decimal( Decimal['ONE'] ); + + while ( i-- ) { + c.push( Math.random() * 10 | 0 ); + } + c[pr] = Math.random() * 9 + 1 | 0; + + // Further increase likelihood of smaller exponent. Comment-out if not required. + while ( Math.random() < 0.9 ) { + n = n.slice( Math.random() * n.length | 0 ); + } + + r['e'] = ( isNeg ? -1 : 1 ) * n.slice( Math.random() * n.length | 0 ); + r['c'] = r['e'] == Decimal['minE'] ? [1] : c; + r['s'] = Math.random() < 0.4 ? -1 : 1; + + return r; + } + */ + + + /* + * Return a new Decimal whose value is #n round to an integer using rounding mode #rounding. + * + * To emulate Math.round, set #rounding to 7 (ROUND_HALF_CEIL). + * + * n {number|string|Decimal} + * + function round(n) { + var x = new this(n); + + return rnd( x, x['e'] + 1, this['rounding'] ); + } + */ + + + /* + * Return a new Decimal whose value is the sine of #n. + * + * n {number|string|Decimal} A number given in radians. + * + function sin(n) { return new this( Math.sin(n) + '' ) } + */ + + + /* + * Return a new Decimal whose value is the square root of #n. + * + * n {number|string|Decimal} + * + */ + function sqrt(n) { return new this(n)['sqrt']() } + + + /* + * Return a new Decimal whose value is the tangent of #n. + * + * n {number|string|Decimal} A number given in radians. + * + function tan(n) { return new this( Math.tan(n) + '' ) } + */ + + + /* + * Return a new Decimal whose value is #n truncated to an integer. + * + * n {number|string|Decimal} + * + function trunc(n) { return new this(n)['trunc']() } + */ + + + /* + * Create and return a new Decimal constructor. + * + */ + function DecimalFactory(obj) { + + /* + * The Decimal constructor. + * Create and return a new instance of a Decimal object. + * + * n {number|string|Decimal} A numeric value. + * [b] {number} The base of n. Integer, 2 to 64 inclusive. + * + */ + function Decimal( n, b ) { + var x = this; + + // Constructor called without new. + if ( !( x instanceof Decimal ) ) { + ifExceptionsThrow( Decimal, 'Decimal called without new', n ); + + return new Decimal( n, b ); + } + + // Duplicate. + if ( n instanceof Decimal ) { + + if ( b == null ) { + id = 0; + x['constructor'] = n['constructor']; + x['s'] = n['s']; + x['e'] = n['e']; + x['c'] = ( n = n['c'] ) ? n.slice() : n; + + return; + } else if ( b == 10 ) { + + return rnd( new Decimal(n), Decimal['precision'], Decimal['rounding'] ); + } else { + n += ''; + } + } + + return parseDecimal( x['constructor'] = Decimal, x, n, b ); + } + + + /* ************************ CONSTRUCTOR DEFAULT PROPERTIES ***************************** + + + These default values must be integers within the stated ranges (inclusive). + Most of these values can be changed during run-time using Decimal.config. + */ + + /* + The maximum number of significant digits of the result of a calculation or base + conversion. + E.g. Decimal.config({ precision: 20 }) + */ + Decimal['precision'] = 20; // 1 to MAX_DIGITS + + /* + The rounding mode used when rounding to #precision. + + ROUND_UP 0 Away from zero. + ROUND_DOWN 1 Towards zero. + ROUND_CEIL 2 Towards +Infinity. + ROUND_FLOOR 3 Towards -Infinity. + ROUND_HALF_UP 4 Towards nearest neighbour. If equidistant, up. + ROUND_HALF_DOWN 5 Towards nearest neighbour. If equidistant, down. + ROUND_HALF_EVEN 6 Towards nearest neighbour. If equidistant, towards even neighbour. + ROUND_HALF_CEIL 7 Towards nearest neighbour. If equidistant, towards +Infinity. + ROUND_HALF_FLOOR 8 Towards nearest neighbour. If equidistant, towards -Infinity. + + E.g. + Decimal.rounding = 4; + Decimal.rounding = Decimal.ROUND_HALF_UP; + */ + Decimal['rounding'] = 4; // 0 to 8 + + /* + The modulo mode used when calculating the modulus: a mod n. + The quotient (q = a / n) is calculated according to the corresponding rounding mode. + The remainder (r) is calculated as: r = a - n * q. + + UP 0 The remainder is positive if the dividend is negative, else is negative. + DOWN 1 The remainder has the same sign as the dividend. + This modulo mode is commonly known as "truncated division" and matches + as closely as possible, the behaviour of JS remainder operator (a % n). + FLOOR 3 The remainder has the same sign as the divisor (Python %). + HALF_EVEN 6 This modulo mode implements the IEEE 754 remainder function. + EUCLID 9 Euclidian division. q = sign(n) * floor(a / abs(n)). + The remainder is always positive. + + The above modes - truncated division, floored division, Euclidian division and IEEE 754 + remainder - are commonly used for the modulus operation. Although any other of the + rounding modes can be used, they may not give useful results. + */ + Decimal['modulo'] = 1; // 0 to 9 + + // The exponent value at and beneath which #toString returns exponential notation. + // Number type: -7 + Decimal['toExpNeg'] = -7; // 0 to -EXP_LIMIT + + // The exponent value at and above which #toString returns exponential notation. + // Number type: 21 + Decimal['toExpPos'] = 21; // 0 to EXP_LIMIT + + // The minimum exponent value, beneath which underflow to zero occurs. + // Number type: -324 (5e-324) + Decimal['minE'] = -EXP_LIMIT; // -1 to -EXP_LIMIT + + // The maximum exponent value, above which overflow to Infinity occurs. + // Number type: 308 (1.7976931348623157e+308) + Decimal['maxE'] = EXP_LIMIT; // 1 to EXP_LIMIT + + // Whether Decimal Errors are ever thrown. + Decimal['errors'] = true; // true/false + + // Whether to use cryptographically-secure random number generation, if available. + Decimal['crypto'] = false; // true/false + + + /* ********************** END OF CONSTRUCTOR DEFAULT PROPERTIES ********************* */ + + + Decimal.prototype = P; + + Decimal['ONE'] = new Decimal(1); + + /* + // Pi to 80 s.d. + Decimal['PI'] = new Decimal( + '3.1415926535897932384626433832795028841971693993751058209749445923078164062862089' + ); + */ + + Decimal['ROUND_UP'] = 0; + Decimal['ROUND_DOWN'] = 1; + Decimal['ROUND_CEIL'] = 2; + Decimal['ROUND_FLOOR'] = 3; + Decimal['ROUND_HALF_UP'] = 4; + Decimal['ROUND_HALF_DOWN'] = 5; + Decimal['ROUND_HALF_EVEN'] = 6; + Decimal['ROUND_HALF_CEIL'] = 7; + Decimal['ROUND_HALF_FLOOR'] = 8; + + // modulo mode + Decimal['EUCLID'] = 9; + + //Decimal['abs'] = abs; + //Decimal['acos'] = acos; + //Decimal['asin'] = asin; + //Decimal['atan'] = atan; + //Decimal['atan2'] = atan2; + //Decimal['ceil'] = ceil; + //Decimal['cos'] = cos; + //Decimal['floor'] = floor; + //Decimal['round'] = round; + //Decimal['sin'] = sin; + //Decimal['tan'] = tan; + //Decimal['trunc'] = trunc; + + Decimal['config'] = config; + Decimal['constructor'] = DecimalFactory; + Decimal['exp'] = exp; + Decimal['ln'] = ln; + Decimal['log'] = log; + Decimal['max'] = max; + Decimal['min'] = min; + Decimal['pow'] = pow; + Decimal['sqrt'] = sqrt; + Decimal['random'] = random; + //Decimal['randomE'] = randomE; + + if ( obj != null ) { + Decimal['config'](obj); + } + + return Decimal; + } + + return DecimalFactory(); + })(); + + + // Export. + + + // Node and other CommonJS-like environments that support module.exports. + if ( typeof module != 'undefined' && module && module.exports ) { + module.exports = DecimalConstructor; + + if ( true ) { + crypto = __webpack_require__(246); + } + } else { + crypto = global['crypto']; + + //AMD. + if ( true ) { + !(__WEBPACK_AMD_DEFINE_RESULT__ = (function () { return DecimalConstructor }.call(exports, __webpack_require__, exports, module)), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); + + //Browser. + } else { + noConflict = global['Decimal']; + + DecimalConstructor['noConflict'] = function () { + global['Decimal'] = noConflict; + + return DecimalConstructor; + }; + global['Decimal'] = DecimalConstructor; + } + } + })(this); + + /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(247)(module))) /***/ }, /* 113 */ /***/ function(module, exports, __webpack_require__) { - var Node = __webpack_require__(125), + /** + * Create a syntax error with the message: + * 'Wrong number of arguments in function ( provided, - expected)' + * @param {String} fn Function name + * @param {Number} count Actual argument count + * @param {Number} min Minimum required argument count + * @param {Number} [max] Maximum required argument count + * @extends Error + */ + function ArgumentsError(fn, count, min, max) { + if (!(this instanceof ArgumentsError)) { + throw new SyntaxError('Constructor must be called with the new operator'); + } + + this.fn = fn; + this.count = count; + this.min = min; + this.max = max; + + this.message = 'Wrong number of arguments in function ' + fn + + ' (' + count + ' provided, ' + + min + ((max != undefined) ? ('-' + max) : '') + ' expected)'; + + this.stack = (new Error()).stack; + } + + ArgumentsError.prototype = new Error(); + ArgumentsError.prototype.constructor = Error; + ArgumentsError.prototype.name = 'ArgumentsError'; + + module.exports = ArgumentsError; + + +/***/ }, +/* 114 */ +/***/ function(module, exports, __webpack_require__) { + + /** + * Create a range error with the message: + * 'Dimension mismatch ( != )' + * @param {number | number[]} actual The actual size + * @param {number | number[]} expected The expected size + * @param {string} [relation='!='] Optional relation between actual + * and expected size: '!=', '<', etc. + * @extends RangeError + */ + function DimensionError(actual, expected, relation) { + if (!(this instanceof DimensionError)) { + throw new SyntaxError('Constructor must be called with the new operator'); + } + + this.actual = actual; + this.expected = expected; + this.relation = relation; + + this.message = 'Dimension mismatch (' + + (Array.isArray(actual) ? ('[' + actual.join(', ') + ']') : actual) + + ' ' + (this.relation || '!=') + ' ' + + (Array.isArray(expected) ? ('[' + expected.join(', ') + ']') : expected) + + ')'; + + this.stack = (new Error()).stack; + } + + DimensionError.prototype = new RangeError(); + DimensionError.prototype.constructor = RangeError; + DimensionError.prototype.name = 'DimensionError'; + + module.exports = DimensionError; + + +/***/ }, +/* 115 */ +/***/ function(module, exports, __webpack_require__) { + + /** + * Create a range error with the message: + * 'Index out of range (index < min)' + * 'Index out of range (index < max)' + * + * @param {number} index The actual index + * @param {number} [min=0] Minimum index (included) + * @param {number} [max] Maximum index (excluded) + * @extends RangeError + */ + function IndexError(index, min, max) { + if (!(this instanceof IndexError)) { + throw new SyntaxError('Constructor must be called with the new operator'); + } + + this.index = index; + if (arguments.length < 3) { + this.min = 0; + this.max = min; + } + else { + this.min = min; + this.max = max; + } + + if (this.min !== undefined && this.index < this.min) { + this.message = 'Index out of range (' + this.index + ' < ' + this.min + ')'; + } + else if (this.max !== undefined && this.index >= this.max) { + this.message = 'Index out of range (' + this.index + ' > ' + (this.max - 1) + ')'; + } + else { + this.message = 'Index out of range (' + this.index + ')'; + } + + this.stack = (new Error()).stack; + } + + IndexError.prototype = new RangeError(); + IndexError.prototype.constructor = RangeError; + IndexError.prototype.name = 'IndexError'; + + module.exports = IndexError; + + +/***/ }, +/* 116 */ +/***/ function(module, exports, __webpack_require__) { + + /** + * Create a TypeError with message: + * 'Function does not support a parameter of type '; + * @param {String} fn Function name + * @param {*...} [types] The types of the function arguments + * @extends TypeError + */ + function UnsupportedTypeError(fn, types) { + if (!(this instanceof UnsupportedTypeError)) { + throw new SyntaxError('Constructor must be called with the new operator'); + } + + this.fn = fn; + this.types = Array.prototype.splice.call(arguments, 1); + + if (!fn) { + this.message = 'Unsupported type of argument'; + } + else { + if (this.types.length == 0) { + this.message = 'Unsupported type of argument in function ' + fn; + } + else { + this.message = 'Function ' + fn + '(' + this.types.join(', ') + ') not supported'; + } + } + + this.stack = (new Error()).stack; + } + + UnsupportedTypeError.prototype = new TypeError(); + UnsupportedTypeError.prototype.constructor = TypeError; + UnsupportedTypeError.prototype.name = 'UnsupportedTypeError'; + + module.exports = UnsupportedTypeError; + + +/***/ }, +/* 117 */ +/***/ function(module, exports, __webpack_require__) { + + exports.array = __webpack_require__(147); + exports['boolean'] = __webpack_require__(244); + exports.number = __webpack_require__(148); + exports.bignumber = __webpack_require__(245); + exports.object = __webpack_require__(3); + exports.string = __webpack_require__(132); + exports.types = __webpack_require__(150); + + +/***/ }, +/* 118 */ +/***/ function(module, exports, __webpack_require__) { + + var Node = __webpack_require__(131), object = __webpack_require__(3), - string = __webpack_require__(127), - collection = __webpack_require__(14), - Matrix = __webpack_require__(11), - util = __webpack_require__(112), + string = __webpack_require__(132), + collection = __webpack_require__(11), + util = __webpack_require__(117), isArray = Array.isArray, isNode = Node.isNode; @@ -15110,7 +17211,7 @@ return /******/ (function(modules) { // webpackBootstrap /** * Find all nodes matching given filter - * @param {Object} filter See Node.find for a description of the filter settings + * @param {Object} filter See Node.find for a description of the filter options * @returns {Node[]} nodes */ ArrayNode.prototype.find = function (filter) { @@ -15143,11 +17244,11 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 114 */ +/* 119 */ /***/ function(module, exports, __webpack_require__) { - var Node = __webpack_require__(125), - isString = __webpack_require__(127).isString; + var Node = __webpack_require__(131), + isString = __webpack_require__(132).isString; /** * @constructor AssignmentNode @@ -15185,7 +17286,7 @@ return /******/ (function(modules) { // webpackBootstrap /** * Find all nodes matching given filter - * @param {Object} filter See Node.find for a description of the filter settings + * @param {Object} filter See Node.find for a description of the filter options * @returns {Node[]} nodes */ AssignmentNode.prototype.find = function (filter) { @@ -15213,11 +17314,11 @@ return /******/ (function(modules) { // webpackBootstrap module.exports = AssignmentNode; /***/ }, -/* 115 */ +/* 120 */ /***/ function(module, exports, __webpack_require__) { - var Node = __webpack_require__(125), - isBoolean = __webpack_require__(237).isBoolean; + var Node = __webpack_require__(131), + isBoolean = __webpack_require__(244).isBoolean; /** * @constructor BlockNode @@ -15282,7 +17383,7 @@ return /******/ (function(modules) { // webpackBootstrap /** * Find all nodes matching given filter - * @param {Object} filter See Node.find for a description of the filter settings + * @param {Object} filter See Node.find for a description of the filter options * @returns {Node[]} nodes */ BlockNode.prototype.find = function (filter) { @@ -15317,13 +17418,11 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 116 */ +/* 121 */ /***/ function(module, exports, __webpack_require__) { - var Node = __webpack_require__(125), - Complex = __webpack_require__(8), - BigNumber = __webpack_require__(111), - string = __webpack_require__(127), + var Node = __webpack_require__(131), + string = __webpack_require__(132), isString = string.isString; /** @@ -15409,11 +17508,11 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 117 */ +/* 122 */ /***/ function(module, exports, __webpack_require__) { - var Node = __webpack_require__(125), - isString = __webpack_require__(127).isString; + var Node = __webpack_require__(131), + isString = __webpack_require__(132).isString; isArray = Array.isArray; /** @@ -15456,7 +17555,7 @@ return /******/ (function(modules) { // webpackBootstrap ' scope = Object.create(scope); ' + ' var fn = function ' + this.name + '(' + this.args.join(',') + ') {' + ' if (arguments.length != ' + this.args.length + ') {' + - // TODO: use math.error.ArgumentsError here + // TODO: use util.error.ArgumentsError here // TODO: test arguments error ' throw new SyntaxError("Wrong number of arguments in function ' + this.name + ' (" + arguments.length + " provided, ' + this.args.length + ' expected)");' + ' }' + @@ -15472,7 +17571,7 @@ return /******/ (function(modules) { // webpackBootstrap /** * Find all nodes matching given filter - * @param {Object} filter See Node.find for a description of the filter settings + * @param {Object} filter See Node.find for a description of the filter options * @returns {Node[]} nodes */ FunctionNode.prototype.find = function (filter) { @@ -15503,26 +17602,21 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 118 */ +/* 123 */ /***/ function(module, exports, __webpack_require__) { - var number= __webpack_require__(143), + var Node = __webpack_require__(131), + RangeNode = __webpack_require__(126), + SymbolNode = __webpack_require__(127), - Node = __webpack_require__(125), - RangeNode = __webpack_require__(121), - SymbolNode = __webpack_require__(122), - - BigNumber = __webpack_require__(111), - Index = __webpack_require__(10), - Range = __webpack_require__(9), - - isNumber = number.isNumber, - toNumber = number.toNumber, isNode = Node.isNode; /** * @constructor IndexNode + * @extends Node + * * get a subset of a matrix + * * @param {Node} object * @param {Node[]} ranges */ @@ -15698,10 +17792,10 @@ return /******/ (function(modules) { // webpackBootstrap module.exports = IndexNode; /***/ }, -/* 119 */ +/* 124 */ /***/ function(module, exports, __webpack_require__) { - var Node = __webpack_require__(125); + var Node = __webpack_require__(131); /** * @constructor OperatorNode @@ -15746,7 +17840,7 @@ return /******/ (function(modules) { // webpackBootstrap /** * Find all nodes matching given filter - * @param {Object} filter See Node.find for a description of the filter settings + * @param {Object} filter See Node.find for a description of the filter options * @returns {Node[]} nodes */ OperatorNode.prototype.find = function (filter) { @@ -15806,21 +17900,11 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 120 */ +/* 125 */ /***/ function(module, exports, __webpack_require__) { - var number= __webpack_require__(143), + var Node = __webpack_require__(131), - Node = __webpack_require__(125), - RangeNode = __webpack_require__(121), - SymbolNode = __webpack_require__(122), - - BigNumber = __webpack_require__(111), - Index = __webpack_require__(10), - Range = __webpack_require__(9), - - isNumber = number.isNumber, - toNumber = number.toNumber, isNode = Node.isNode; /** @@ -15866,7 +17950,7 @@ return /******/ (function(modules) { // webpackBootstrap /** * Find all nodes matching given filter - * @param {Object} filter See Node.find for a description of the filter settings + * @param {Object} filter See Node.find for a description of the filter options * @returns {Node[]} nodes */ ParamsNode.prototype.find = function (filter) { @@ -15902,18 +17986,11 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 121 */ +/* 126 */ /***/ function(module, exports, __webpack_require__) { - var number = __webpack_require__(143), - Node = __webpack_require__(125), + var Node = __webpack_require__(131), - BigNumber = __webpack_require__(111), - Range = __webpack_require__(9), - Matrix = __webpack_require__(11), - - toNumber = number.toNumber, - isArray = Array.isArray; isNode = Node.isNode; /** @@ -15928,7 +18005,7 @@ return /******/ (function(modules) { // webpackBootstrap } // validate inputs - if (!isArray(params) || + if (!Array.isArray(params) || (params.length != 2 && params.length != 3) || !params.every(isNode)) { throw new TypeError('Expected an Array containing 2 or 3 Nodes as parameter "params"'); @@ -15959,7 +18036,7 @@ return /******/ (function(modules) { // webpackBootstrap /** * Find all nodes matching given filter - * @param {Object} filter See Node.find for a description of the filter settings + * @param {Object} filter See Node.find for a description of the filter options * @returns {Node[]} nodes */ RangeNode.prototype.find = function (filter) { @@ -15999,13 +18076,13 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 122 */ +/* 127 */ /***/ function(module, exports, __webpack_require__) { - var Node = __webpack_require__(125), - Unit = __webpack_require__(12), + var Node = __webpack_require__(131), + Unit = __webpack_require__(9), - isString = __webpack_require__(127).isString; + isString = __webpack_require__(132).isString; /** * @constructor SymbolNode @@ -16043,7 +18120,7 @@ return /******/ (function(modules) { // webpackBootstrap return '(' + 'scope["' + this.name + '"] !== undefined ? scope["' + this.name + '"] : ' + 'math["' + this.name + '"] !== undefined ? math["' + this.name + '"] : ' + - (Unit.isPlainUnit(this.name) ? + (Unit.isValuelessUnit(this.name) ? 'new Unit(null, "' + this.name + '")' : 'undef("' + this.name + '")') + ')'; @@ -16070,17 +18147,58 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 123 */ +/* 128 */ /***/ function(module, exports, __webpack_require__) { - var Node = __webpack_require__(125), + var OperatorNode = __webpack_require__(124); - BigNumber = __webpack_require__(111), - Complex = __webpack_require__(8), - Unit = __webpack_require__(12), + /** + * @constructor TernaryNode + * @extends {OperatorNode} + * + * A conditional expression + * + * condition ? truePart : falsePart + * + * @param {String[]} ops The operator symbols, for example ['?', ':'] + * @param {String} fn The function name, for example 'ifElse' + * @param {Node[]} params The operator parameters, should contain three parameters. + */ + function TernaryNode (ops, fn, params) { + if (!(this instanceof TernaryNode)) { + throw new SyntaxError('Constructor must be called with the new operator'); + } - toNumber = __webpack_require__(143).toNumber, - isString = __webpack_require__(127).isString; + // TODO: validate input + this.ops = ops; + this.fn = fn; + this.params = params; + } + + TernaryNode.prototype = new OperatorNode(); + + /** + * Get string representation + * @return {String} str + */ + TernaryNode.prototype.toString = function() { + return this.params[0] + ' ' + this.ops[0] + ' ' + + this.params[1] + ' ' + this.ops[1] + ' ' + + this.params[2]; + }; + + module.exports = TernaryNode; + + +/***/ }, +/* 129 */ +/***/ function(module, exports, __webpack_require__) { + + var Node = __webpack_require__(131), + + Unit = __webpack_require__(9), + + isString = __webpack_require__(132).isString; /** * @constructor UnitNode @@ -16118,7 +18236,7 @@ return /******/ (function(modules) { // webpackBootstrap /** * Find all nodes matching given filter - * @param {Object} filter See Node.find for a description of the filter settings + * @param {Object} filter See Node.find for a description of the filter options * @returns {Node[]} nodes */ UnitNode.prototype.find = function (filter) { @@ -16147,22 +18265,11 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 124 */ +/* 130 */ /***/ function(module, exports, __webpack_require__) { - var number= __webpack_require__(143), - - Node = __webpack_require__(125), - RangeNode = __webpack_require__(121), - IndexNode = __webpack_require__(118), - SymbolNode = __webpack_require__(122), - - BigNumber = __webpack_require__(111), - Index = __webpack_require__(10), - Range = __webpack_require__(9), - - isNumber = number.isNumber, - toNumber = number.toNumber; + var Node = __webpack_require__(131), + IndexNode = __webpack_require__(123); /** * @constructor UpdateNode @@ -16205,7 +18312,7 @@ return /******/ (function(modules) { // webpackBootstrap /** * Find all nodes matching given filter - * @param {Object} filter See Node.find for a description of the filter settings + * @param {Object} filter See Node.find for a description of the filter options * @returns {Node[]} nodes */ UpdateNode.prototype.find = function (filter) { @@ -16237,10 +18344,12 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 125 */ +/* 131 */ /***/ function(module, exports, __webpack_require__) { - /** + var error = __webpack_require__(4); + + /** * Node */ function Node() { @@ -16274,7 +18383,8 @@ return /******/ (function(modules) { // webpackBootstrap // definitions globally available inside the closure of the compiled expressions var defs = { - math: math + math: math, + error: error }; var code = this._compile(defs); @@ -16285,12 +18395,20 @@ return /******/ (function(modules) { // webpackBootstrap var factoryCode = defsCode.join(' ') + - 'return {' + - ' "eval": function (scope) {' + - ' scope = scope || {};' + - ' return ' + code + ';' + - ' }' + - '};'; + 'return {' + + ' "eval": function (scope) {' + + ' try {' + + ' scope = scope || {};' + + ' return ' + code + ';' + + ' } catch (err) {' + + // replace an index-out-of-range-error with a one-based message + ' if (err instanceof defs.error.IndexError) {' + + ' err = new defs.error.IndexError(err.index + 1, err.min + 1, err.max + 1);' + + ' }' + + ' throw err;' + + ' }' + + ' }' + + '};'; var factory = new Function ('defs', factoryCode); return factory(defs); @@ -16380,52 +18498,12 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 126 */ +/* 132 */ /***/ function(module, exports, __webpack_require__) { - /** - * Determine the type of a variable - * - * typeof(x) - * - * @param {*} x - * @return {String} type Lower case type, for example 'number', 'string', - * 'array', 'date'. - */ - exports.type = function type (x) { - var type = typeof x; - - if (type === 'object') { - if (x === null) { - return 'null'; - } - if (x instanceof Boolean) { - return 'boolean'; - } - if (x instanceof Number) { - return 'number'; - } - if (x instanceof String) { - return 'string'; - } - if (Array.isArray(x)) { - return 'array'; - } - if (x instanceof Date) { - return 'date'; - } - } - - return type; - }; - - -/***/ }, -/* 127 */ -/***/ function(module, exports, __webpack_require__) { - - var number = __webpack_require__(143), - BigNumber = __webpack_require__(111); + var number = __webpack_require__(148), + bignumber = __webpack_require__(245), + BigNumber = __webpack_require__(112); /** * Test whether value is a String @@ -16471,10 +18549,14 @@ return /******/ (function(modules) { // webpackBootstrap * @return {String} str */ exports.format = function format(value, options) { - if (number.isNumber(value) || value instanceof BigNumber) { + if (number.isNumber(value)) { return number.format(value, options); } + if (value instanceof BigNumber) { + return bignumber.format(value, options); + } + if (Array.isArray(value)) { return formatArray(value, options); } @@ -16529,7 +18611,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 128 */ +/* 133 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -16550,7 +18632,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 129 */ +/* 134 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -16568,7 +18650,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 130 */ +/* 135 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -16588,7 +18670,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 131 */ +/* 136 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -16607,7 +18689,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 132 */ +/* 137 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -16626,7 +18708,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 133 */ +/* 138 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -16645,7 +18727,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 134 */ +/* 139 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -16664,7 +18746,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 135 */ +/* 140 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -16683,7 +18765,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 136 */ +/* 141 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -16702,7 +18784,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 137 */ +/* 142 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -16721,7 +18803,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 138 */ +/* 143 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -16740,7 +18822,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 139 */ +/* 144 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -16759,7 +18841,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 140 */ +/* 145 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -16778,7 +18860,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 141 */ +/* 146 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -16796,13 +18878,17 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 142 */ +/* 147 */ /***/ function(module, exports, __webpack_require__) { - var number = __webpack_require__(143), - string = __webpack_require__(127), + var number = __webpack_require__(148), + string = __webpack_require__(132), object = __webpack_require__(3), - types = __webpack_require__(126), + types = __webpack_require__(150), + + DimensionError = __webpack_require__(114), + IndexError = __webpack_require__(115), + isArray = Array.isArray; /** @@ -16847,7 +18933,7 @@ return /******/ (function(modules) { // webpackBootstrap * @param {Array} array Array to be validated * @param {Number[]} size Array with the size of each dimension * @param {Number} dim Current dimension - * @throws RangeError + * @throws DimensionError * @private */ function _validate(array, size, dim) { @@ -16855,7 +18941,7 @@ return /******/ (function(modules) { // webpackBootstrap var len = array.length; if (len != size[dim]) { - throw new RangeError('Dimension mismatch (' + len + ' != ' + size[dim] + ')'); + throw new DimensionError(len, size[dim]); } if (dim < size.length - 1) { @@ -16864,8 +18950,7 @@ return /******/ (function(modules) { // webpackBootstrap for (i = 0; i < len; i++) { var child = array[i]; if (!isArray(child)) { - throw new RangeError('Dimension mismatch ' + - '(' + (size.length - 1) + ' < ' + size.length + ')'); + throw new DimensionError(size.length - 1, size.length, '<'); } _validate(array[i], size, dimNext); } @@ -16874,8 +18959,7 @@ return /******/ (function(modules) { // webpackBootstrap // last dimension. none of the childs may be an array for (i = 0; i < len; i++) { if (isArray(array[i])) { - throw new RangeError('Dimension mismatch ' + - '(' + (size.length + 1) + ' > ' + size.length + ')'); + throw new DimensionError(size.length + 1, size.length, '>'); } } } @@ -16886,14 +18970,14 @@ return /******/ (function(modules) { // webpackBootstrap * a size corresponding to the provided size array. * @param {Array} array Array to be validated * @param {Number[]} size Array with the size of each dimension - * @throws RangeError + * @throws DimensionError */ exports.validate = function validate(array, size) { var isScalar = (size.length == 0); if (isScalar) { // scalar if (isArray(array)) { - throw new RangeError('Dimension mismatch (' + array.length + ' != 0)'); + throw new DimensionError(array.length, 0); } } else { @@ -16904,7 +18988,7 @@ return /******/ (function(modules) { // webpackBootstrap /** * Test whether index is an integer number with index >= 0 and index < length - * @param {*} index Zero-based index + * @param {Number} index Zero-based index * @param {Number} [length] Length of the array */ exports.validateIndex = function validateIndex (index, length) { @@ -16912,10 +18996,10 @@ return /******/ (function(modules) { // webpackBootstrap throw new TypeError('Index must be an integer (value: ' + index + ')'); } if (index < 0) { - throw new RangeError('Index out of range (' + index + ' < 0)'); + throw new IndexError(index); } if (length !== undefined && index >= length) { - throw new RangeError('Index out of range (' + index + ' > ' + (length - 1) + ')'); + throw new IndexError(index, length); } }; @@ -16980,9 +19064,7 @@ return /******/ (function(modules) { // webpackBootstrap * @private */ function _resize (array, size, dim, defaultValue) { - if (!isArray(array)) { - throw Error('Array expected'); - } + if (!isArray(array)) throw Error('Array expected'); var i, elem, oldLen = array.length, @@ -17085,11 +19167,9 @@ return /******/ (function(modules) { // webpackBootstrap exports.isArray = isArray; /***/ }, -/* 143 */ +/* 148 */ /***/ function(module, exports, __webpack_require__) { - var BigNumber = __webpack_require__(111); - /** * Test whether value is a Number * @param {*} value @@ -17186,7 +19266,7 @@ return /******/ (function(modules) { // webpackBootstrap * format(2.3, {notation: 'fixed', precision: 2}); // '2.30' * format(52.8, {notation: 'exponential'}); // '5.28e+1' * - * @param {Number | BigNumber} value + * @param {Number} value * @param {Object | Function | Number} [options] * @return {String} str The formatted value */ @@ -17231,10 +19311,6 @@ return /******/ (function(modules) { // webpackBootstrap case 'fixed': return exports.toFixed(value, precision); - // TODO: notation 'scientific' is deprecated since version 0.16.0, remove this some day - case 'scientific': - throw new Error('Format notation "scientific" is deprecated. Use "exponential" instead.'); - case 'exponential': return exports.toExponential(value, precision); @@ -17251,53 +19327,26 @@ return /******/ (function(modules) { // webpackBootstrap upper = options.exponential.upper; } } - else if (options && options.scientific) { - // TODO: 'options.scientific' is deprecated since version 0.16.0, remove this some day - throw new Error('options.scientific is deprecated, use options.exponential instead.'); - } - - // adjust BigNumber configuration - var isBigNumber = value instanceof BigNumber; - if (isBigNumber) { - var oldScientific = BigNumber.config().EXPONENTIAL_AT; - BigNumber.config({ - EXPONENTIAL_AT: [ - Math.round(Math.log(lower) / Math.LN10), - Math.round(Math.log(upper) / Math.LN10) - ] - }); - } // handle special case zero - if (_isZero(value)) { - return '0'; - } + if (value === 0) return '0'; // determine whether or not to output exponential notation var str; - if (_isBetween(value, lower, upper)) { + var abs = Math.abs(value); + if (abs >= lower && abs < upper) { // normal number notation - if (isBigNumber) { - str = new BigNumber(value.toPrecision(precision)).toString(); - } - else { // Number - // Note: IE7 does not allow value.toPrecision(undefined) - var valueStr = precision ? - value.toPrecision(Math.min(precision, 21)) : - value.toPrecision(); - str = parseFloat(valueStr) + ''; - } + // Note: IE7 does not allow value.toPrecision(undefined) + var valueStr = precision ? + value.toPrecision(Math.min(precision, 21)) : + value.toPrecision(); + str = parseFloat(valueStr) + ''; } else { // exponential notation str = exports.toExponential(value, precision); } - // restore BigNumber configuration - if (isBigNumber) { - BigNumber.config({EXPONENTIAL_AT: oldScientific}); - } - // remove trailing zeros after the decimal point return str.replace(/((\.\d*?)(0+))($|e)/, function () { var digits = arguments[2]; @@ -17311,42 +19360,9 @@ return /******/ (function(modules) { // webpackBootstrap } }; - /** - * Test whether a value is zero - * @param {Number | BigNumber} value - * @return {boolean} isZero - * @private - */ - function _isZero (value) { - return (value instanceof BigNumber) ? value.isZero() : (value === 0); - } - - /** - * Test whether a value is inside a range: - * - * lower >= value < upper - * - * @param {Number | BigNumber} value - * @param {Number} lower Included lower bound - * @param {Number} upper Excluded upper bound - * @return {boolean} isBetween - * @private - */ - function _isBetween(value, lower, upper) { - var abs; - if (value instanceof BigNumber) { - abs = value.abs(); - return (abs.gte(lower) && abs.lt(upper)); - } - else { - abs = Math.abs(value); - return (abs >= lower && abs < upper); - } - } - /** * Format a number in exponential notation. Like '1.23e+5', '2.3e+0', '3.500e-3' - * @param {Number | BigNumber} value + * @param {Number} value * @param {Number} [precision] Number of digits in formatted output. * If not provided, the maximum available digits * is used. @@ -17354,12 +19370,7 @@ return /******/ (function(modules) { // webpackBootstrap */ exports.toExponential = function toExponential (value, precision) { if (precision !== undefined) { - if (value instanceof BigNumber) { - return value.toExponential(precision - 1); - } - else { // Number - return value.toExponential(Math.min(precision - 1, 20)); - } + return value.toExponential(Math.min(precision - 1, 20)); } else { return value.toExponential(); @@ -17368,19 +19379,12 @@ return /******/ (function(modules) { // webpackBootstrap /** * Format a number with fixed notation. - * @param {Number | BigNumber} value + * @param {Number} value * @param {Number} [precision=0] Optional number of decimals after the * decimal point. Zero by default. */ exports.toFixed = function toFixed (value, precision) { - if (value instanceof BigNumber) { - return value.toFixed(precision || 0); - // Note: the (precision || 0) is needed as the toFixed of BigNumber has an - // undefined default precision instead of 0. - } - else { // Number - return value.toFixed(Math.min(precision, 20)); - } + return value.toFixed(Math.min(precision, 20)); }; /** @@ -17389,7 +19393,7 @@ return /******/ (function(modules) { // webpackBootstrap * For example: * 2.34 returns 3 * 0.0034 returns 2 - * 120.5e+3 returns 4 + * 120.5e+30 returns 4 * * @param {Number} value * @return {Number} digits Number of significant digits @@ -17397,59 +19401,74 @@ return /******/ (function(modules) { // webpackBootstrap exports.digits = function digits (value) { return value .toExponential() - .replace(/e[\+\-0-9]*$/, '') // remove exponential notation - .replace( /^0\.0*|\./, '') // remove decimal point and leading zeros + .replace(/e.*$/, '') // remove exponential notation + .replace( /^0\.?0*|\./, '') // remove decimal point and leading zeros .length }; /** - * Convert a Number in to a BigNumber. If the number has 15 or mor significant - * digits, the Number cannot be converted to BigNumber and will return the - * original number. - * @param {Number} number - * @return {BigNumber | Number} bignumber + * Minimum number added to one that makes the result different than one */ - exports.toBigNumber = function toBigNumber (number) { - if (exports.digits(number) > 15) { - return number; - } - else { - return new BigNumber(number); - } - }; + exports.DBL_EPSILON = Number.EPSILON || 2.2204460492503130808472633361816E-16; /** - * Convert a BigNumber into a Number. If the number is out of range, it will - * get the value Infinity or 0. - * @param {BigNumber} bignumber - * @return {Number} number - */ - exports.toNumber = function toNumber (bignumber) { - return parseFloat(bignumber.valueOf()); + * Compares two floating point numbers. + * @param {Number} x First value to compare + * @param {Number} y Second value to compare + * @param {Number} [epsilon] The maximum relative difference between x and y + * If epsilon is undefined or null, the function will + * test whether x and y are exactly equal. + * @return {boolean} whether the two numbers are equal + */ + exports.nearlyEqual = function(x, y, epsilon) { + // if epsilon is null or undefined, test whether x and y are exactly equal + if (epsilon == null) return x == y; + + // use "==" operator, handles infinities + if (x == y) return true; + + // NaN + if (isNaN(x) || isNaN(y)) return false; + + // at this point x and y should be finite + if(isFinite(x) && isFinite(y)) { + // check numbers are very close, needed when comparing numbers near zero + var diff = Math.abs(x - y); + if (diff < exports.DBL_EPSILON) { + return true; + } + else { + // use relative error + return diff <= Math.max(Math.abs(x), Math.abs(y)) * epsilon; + } + } + + // Infinite and Number or negative Infinite and positive Infinite cases + return false; }; /***/ }, -/* 144 */ +/* 149 */ /***/ function(module, exports, __webpack_require__) { var map = { - "./clone": 103, - "./clone.js": 103, - "./forEach": 110, - "./forEach.js": 110, - "./format": 104, - "./format.js": 104, - "./ifElse": 105, - "./ifElse.js": 105, - "./import": 106, - "./import.js": 106, - "./map": 107, - "./map.js": 107, - "./print": 108, - "./print.js": 108, - "./typeof": 109, - "./typeof.js": 109 + "./clone": 104, + "./clone.js": 104, + "./forEach": 111, + "./forEach.js": 111, + "./format": 105, + "./format.js": 105, + "./ifElse": 106, + "./ifElse.js": 106, + "./import": 107, + "./import.js": 107, + "./map": 108, + "./map.js": 108, + "./print": 109, + "./print.js": 109, + "./typeof": 110, + "./typeof.js": 110 }; function webpackContext(req) { return __webpack_require__(webpackContextResolve(req)); @@ -17465,7 +19484,48 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 145 */ +/* 150 */ +/***/ function(module, exports, __webpack_require__) { + + /** + * Determine the type of a variable + * + * typeof(x) + * + * @param {*} x + * @return {String} type Lower case type, for example 'number', 'string', + * 'array', 'date'. + */ + exports.type = function type (x) { + var type = typeof x; + + if (type === 'object') { + if (x === null) { + return 'null'; + } + if (x instanceof Boolean) { + return 'boolean'; + } + if (x instanceof Number) { + return 'number'; + } + if (x instanceof String) { + return 'string'; + } + if (Array.isArray(x)) { + return 'array'; + } + if (x instanceof Date) { + return 'date'; + } + } + + return type; + }; + + +/***/ }, +/* 151 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -17484,7 +19544,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 146 */ +/* 152 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -17509,7 +19569,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 147 */ +/* 153 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -17530,7 +19590,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 148 */ +/* 154 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -17555,7 +19615,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 149 */ +/* 155 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -17579,7 +19639,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 150 */ +/* 156 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -17605,7 +19665,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 151 */ +/* 157 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -17630,7 +19690,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 152 */ +/* 158 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -17655,7 +19715,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 153 */ +/* 159 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -17678,7 +19738,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 154 */ +/* 160 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -17705,7 +19765,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 155 */ +/* 161 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -17731,7 +19791,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 156 */ +/* 162 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -17753,7 +19813,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 157 */ +/* 163 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -17774,7 +19834,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 158 */ +/* 164 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -17795,7 +19855,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 159 */ +/* 165 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -17823,7 +19883,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 160 */ +/* 166 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -17849,7 +19909,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 161 */ +/* 167 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -17869,7 +19929,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 162 */ +/* 168 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -17897,7 +19957,7 @@ return /******/ (function(modules) { // webpackBootstrap }; /***/ }, -/* 163 */ +/* 169 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -17922,7 +19982,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 164 */ +/* 170 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -17948,7 +20008,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 165 */ +/* 171 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -17973,7 +20033,28 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 166 */ +/* 172 */ +/***/ function(module, exports, __webpack_require__) { + + module.exports = { + 'name': 'norm', + 'category': 'Arithmetic', + 'syntax': [ + 'norm(x)', + 'norm(x, p)' + ], + 'description': 'Calculate the norm of a number, vector or matrix.', + 'examples': [ + 'norm([[1, 2], [3, 4]])', + 'norm([[1, 2, 3, 4]], 3.5)', + 'norm(-4.2)', + 'norm([[1, 2], [-3, -4]], \'fro\')' + ] + }; + + +/***/ }, +/* 173 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -17997,7 +20078,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 167 */ +/* 174 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18022,7 +20103,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 168 */ +/* 175 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18045,7 +20126,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 169 */ +/* 176 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18072,7 +20153,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 170 */ +/* 177 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18098,7 +20179,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 171 */ +/* 178 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18122,7 +20203,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 172 */ +/* 179 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18149,7 +20230,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 173 */ +/* 180 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18174,7 +20255,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 174 */ +/* 181 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18197,7 +20278,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 175 */ +/* 182 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18225,7 +20306,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 176 */ +/* 183 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18245,7 +20326,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 177 */ +/* 184 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18271,7 +20352,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 178 */ +/* 185 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18297,7 +20378,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 179 */ +/* 186 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18323,7 +20404,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 180 */ +/* 187 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18349,7 +20430,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 181 */ +/* 188 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18374,7 +20455,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 182 */ +/* 189 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18401,7 +20482,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 183 */ +/* 190 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18426,7 +20507,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 184 */ +/* 191 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18457,7 +20538,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 185 */ +/* 192 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18485,7 +20566,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 186 */ +/* 193 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18513,7 +20594,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 187 */ +/* 194 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18537,7 +20618,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 188 */ +/* 195 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18563,7 +20644,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 189 */ +/* 196 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18583,7 +20664,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 190 */ +/* 197 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18603,7 +20684,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 191 */ +/* 198 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18629,7 +20710,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 192 */ +/* 199 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18650,7 +20731,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 193 */ +/* 200 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18674,7 +20755,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 194 */ +/* 201 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18700,7 +20781,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 195 */ +/* 202 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18722,7 +20803,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 196 */ +/* 203 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18752,7 +20833,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 197 */ +/* 204 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18783,7 +20864,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 198 */ +/* 205 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18807,7 +20888,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 199 */ +/* 206 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18831,7 +20912,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 200 */ +/* 207 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18854,7 +20935,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 201 */ +/* 208 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18885,7 +20966,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 202 */ +/* 209 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18908,7 +20989,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 203 */ +/* 210 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18937,7 +21018,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 204 */ +/* 211 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18955,7 +21036,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 205 */ +/* 212 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18978,7 +21059,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 206 */ +/* 213 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -18999,7 +21080,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 207 */ +/* 214 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -19019,7 +21100,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 208 */ +/* 215 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -19039,7 +21120,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 209 */ +/* 216 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -19065,7 +21146,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 210 */ +/* 217 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -19090,7 +21171,7 @@ return /******/ (function(modules) { // webpackBootstrap }; /***/ }, -/* 211 */ +/* 218 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -19123,7 +21204,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 212 */ +/* 219 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -19155,7 +21236,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 213 */ +/* 220 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -19183,7 +21264,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 214 */ +/* 221 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -19216,7 +21297,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 215 */ +/* 222 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -19246,7 +21327,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 216 */ +/* 223 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -19279,7 +21360,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 217 */ +/* 224 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -19309,7 +21390,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 218 */ +/* 225 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -19342,7 +21423,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 219 */ +/* 226 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -19365,7 +21446,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 220 */ +/* 227 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -19388,7 +21469,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 221 */ +/* 228 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -19411,7 +21492,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 222 */ +/* 229 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -19438,7 +21519,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 223 */ +/* 230 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -19464,7 +21545,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 224 */ +/* 231 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -19487,7 +21568,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 225 */ +/* 232 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -19510,7 +21591,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 226 */ +/* 233 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -19533,7 +21614,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 227 */ +/* 234 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -19559,7 +21640,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 228 */ +/* 235 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -19584,7 +21665,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 229 */ +/* 236 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -19605,7 +21686,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 230 */ +/* 237 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -19627,7 +21708,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 231 */ +/* 238 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -19645,7 +21726,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 232 */ +/* 239 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -19663,7 +21744,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 233 */ +/* 240 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -19685,25 +21766,27 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 234 */ +/* 241 */ /***/ function(module, exports, __webpack_require__) { module.exports = { 'name': 'ifElse', 'category': 'Utils', 'syntax': [ - 'ifElse(conditionalExpr, trueExpr, falseExpr)' + 'ifElse(conditional, trueExpr, falseExpr)' ], - 'description': 'Executes a ternary operation.', + 'description': 'Executes a conditional expression.', 'examples': [ - 'ifElse(10 > 0, 10, 0)' + 'ifElse(10 > 0, 10, 0)', + 'ifElse("", true, false)', + 'ifElse([4, 6, 0, -1], true, false)' ], 'seealso': [] }; /***/ }, -/* 235 */ +/* 242 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -19722,7 +21805,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 236 */ +/* 243 */ /***/ function(module, exports, __webpack_require__) { module.exports = { @@ -19743,7 +21826,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 237 */ +/* 244 */ /***/ function(module, exports, __webpack_require__) { /** @@ -19756,6 +21839,3286 @@ return /******/ (function(modules) { // webpackBootstrap }; +/***/ }, +/* 245 */ +/***/ function(module, exports, __webpack_require__) { + + var BigNumber = __webpack_require__(112), + isNumber = __webpack_require__(148).isNumber; + digits = __webpack_require__(148).digits; + + /** + * Test whether value is a BigNumber + * @param {*} value + * @return {Boolean} isBigNumber + */ + exports.isBigNumber = function isBigNumber(value) { + return (value instanceof BigNumber); + }; + + /** + * Convert a number to a formatted string representation. + * + * Syntax: + * + * format(value) + * format(value, options) + * format(value, precision) + * format(value, fn) + * + * Where: + * + * {Number} value The value to be formatted + * {Object} options An object with formatting options. Available options: + * {String} notation + * Number notation. Choose from: + * 'fixed' Always use regular number notation. + * For example '123.40' and '14000000' + * 'exponential' Always use exponential notation. + * For example '1.234e+2' and '1.4e+7' + * 'auto' (default) Regular number notation for numbers + * having an absolute value between + * `lower` and `upper` bounds, and uses + * exponential notation elsewhere. + * Lower bound is included, upper bound + * is excluded. + * For example '123.4' and '1.4e7'. + * {Number} precision A number between 0 and 16 to round + * the digits of the number. + * In case of notations 'exponential' and + * 'auto', `precision` defines the total + * number of significant digits returned + * and is undefined by default. + * In case of notation 'fixed', + * `precision` defines the number of + * significant digits after the decimal + * point, and is 0 by default. + * {Object} exponential An object containing two parameters, + * {Number} lower and {Number} upper, + * used by notation 'auto' to determine + * when to return exponential notation. + * Default values are `lower=1e-3` and + * `upper=1e5`. + * Only applicable for notation `auto`. + * {Function} fn A custom formatting function. Can be used to override the + * built-in notations. Function `fn` is called with `value` as + * parameter and must return a string. Is useful for example to + * format all values inside a matrix in a particular way. + * + * Examples: + * + * format(6.4); // '6.4' + * format(1240000); // '1.24e6' + * format(1/3); // '0.3333333333333333' + * format(1/3, 3); // '0.333' + * format(21385, 2); // '21000' + * format(12.071, {notation: 'fixed'}); // '12' + * format(2.3, {notation: 'fixed', precision: 2}); // '2.30' + * format(52.8, {notation: 'exponential'}); // '5.28e+1' + * + * @param {BigNumber} value + * @param {Object | Function | Number} [options] + * @return {String} str The formatted value + */ + exports.format = function format(value, options) { + if (typeof options === 'function') { + // handle format(value, fn) + return options(value); + } + + // handle special cases + if (!value.isFinite()) { + return value.isNaN() ? 'NaN' : (value.gt(0) ? 'Infinity' : '-Infinity'); + } + + // default values for options + var notation = 'auto'; + var precision = undefined; + + if (options !== undefined) { + // determine notation from options + if (options.notation) { + notation = options.notation; + } + + // determine precision from options + if (isNumber(options)) { + precision = options; + } + else if (options.precision) { + precision = options.precision; + } + } + + // handle the various notations + switch (notation) { + case 'fixed': + return exports.toFixed(value, precision); + + case 'exponential': + return exports.toExponential(value, precision); + + case 'auto': + // determine lower and upper bound for exponential notation. + // TODO: implement support for upper and lower to be BigNumbers themselves + var lower = 1e-3; + var upper = 1e5; + if (options && options.exponential) { + if (options.exponential.lower !== undefined) { + lower = options.exponential.lower; + } + if (options.exponential.upper !== undefined) { + upper = options.exponential.upper; + } + } + + // adjust the configuration of the BigNumber constructor (yeah, this is quite tricky...) + var oldConfig = { + toExpNeg: value.constructor.toExpNeg, + toExpPos: value.constructor.toExpPos + }; + + value.constructor.config({ + toExpNeg: Math.round(Math.log(lower) / Math.LN10), + toExpPos: Math.round(Math.log(upper) / Math.LN10) + }); + + // handle special case zero + if (value.isZero()) return '0'; + + // determine whether or not to output exponential notation + var str; + var abs = value.abs(); + if (abs.gte(lower) && abs.lt(upper)) { + // normal number notation + str = value.toSignificantDigits(precision).toFixed(); + } + else { + // exponential notation + str = exports.toExponential(value, precision); + } + + // remove trailing zeros after the decimal point + return str.replace(/((\.\d*?)(0+))($|e)/, function () { + var digits = arguments[2]; + var e = arguments[4]; + return (digits !== '.') ? digits + e : e; + }); + + default: + throw new Error('Unknown notation "' + notation + '". ' + + 'Choose "auto", "exponential", or "fixed".'); + } + }; + + /** + * Format a number in exponential notation. Like '1.23e+5', '2.3e+0', '3.500e-3' + * @param {BigNumber} value + * @param {Number} [precision] Number of digits in formatted output. + * If not provided, the maximum available digits + * is used. + * @returns {string} str + */ + exports.toExponential = function toExponential (value, precision) { + if (precision !== undefined) { + return value.toExponential(precision - 1); // Note the offset of one + } + else { + return value.toExponential(); + } + }; + + /** + * Format a number with fixed notation. + * @param {BigNumber} value + * @param {Number} [precision=0] Optional number of decimals after the + * decimal point. Zero by default. + */ + exports.toFixed = function toFixed (value, precision) { + return value.toFixed(precision || 0); + // Note: the (precision || 0) is needed as the toFixed of BigNumber has an + // undefined default precision instead of 0. + }; + + +/***/ }, +/* 246 */ +/***/ function(module, exports, __webpack_require__) { + + var Buffer = __webpack_require__(252).Buffer + var rng = __webpack_require__(248) + + function error () { + var m = [].slice.call(arguments).join(' ') + throw new Error([ + m, + 'we accept pull requests', + 'http://github.com/dominictarr/crypto-browserify' + ].join('\n')) + } + + exports.createHash = __webpack_require__(249) + + exports.createHmac = __webpack_require__(250) + + exports.randomBytes = function(size, callback) { + if (callback && callback.call) { + try { + callback.call(this, undefined, new Buffer(rng(size))) + } catch (err) { callback(err) } + } else { + return new Buffer(rng(size)) + } + } + + function each(a, f) { + for(var i in a) + f(a[i], i) + } + + var p = __webpack_require__(251)(exports.createHmac) + exports.pbkdf2 = p.pbkdf2 + exports.pbkdf2Sync = p.pbkdf2Sync + + + // the least I can do is make error messages for the rest of the node.js/crypto api. + each(['createCredentials' + , 'createCipher' + , 'createCipheriv' + , 'createDecipher' + , 'createDecipheriv' + , 'createSign' + , 'createVerify' + , 'createDiffieHellman' + ], function (name) { + exports[name] = function () { + error('sorry,', name, 'is not implemented yet') + } + }) + + +/***/ }, +/* 247 */ +/***/ function(module, exports, __webpack_require__) { + + module.exports = function(module) { + if(!module.webpackPolyfill) { + module.deprecate = function() {}; + module.paths = []; + // module.parent = undefined by default + module.children = []; + module.webpackPolyfill = 1; + } + return module; + } + + +/***/ }, +/* 248 */ +/***/ function(module, exports, __webpack_require__) { + + /* WEBPACK VAR INJECTION */(function(Buffer) {// Original code adapted from Robert Kieffer. + // details at https://github.com/broofa/node-uuid + + (function() { + var _global = this; + + var mathRNG, whatwgRNG; + + // NOTE: Math.random() does not guarantee "cryptographic quality" + mathRNG = function(size) { + var bytes = new Buffer(size); + var r; + + for (var i = 0, r; i < size; i++) { + if ((i & 0x03) == 0) r = Math.random() * 0x100000000; + bytes[i] = r >>> ((i & 0x03) << 3) & 0xff; + } + + return bytes; + } + + if (_global.crypto && crypto.getRandomValues) { + whatwgRNG = function(size) { + var bytes = new Buffer(size); //in browserify, this is an extended Uint8Array + crypto.getRandomValues(bytes.buffer || bytes); + return bytes; + } + } + + module.exports = whatwgRNG || mathRNG; + + }()) + + /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(252).Buffer)) + +/***/ }, +/* 249 */ +/***/ function(module, exports, __webpack_require__) { + + /* WEBPACK VAR INJECTION */(function(Buffer) {var createHash = __webpack_require__(254) + + var md5 = toConstructor(__webpack_require__(253)) + + function toConstructor (fn) { + return function () { + var buffers = [] + var m= { + update: function (data, enc) { + if(!Buffer.isBuffer(data)) data = new Buffer(data, enc) + buffers.push(data) + return this + }, + digest: function (enc) { + var buf = Buffer.concat(buffers) + var r = fn(buf) + buffers = null + return enc ? r.toString(enc) : r + } + } + return m + } + } + + module.exports = function (alg) { + if('md5' === alg) return new md5() + return createHash(alg) + } + + /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(252).Buffer)) + +/***/ }, +/* 250 */ +/***/ function(module, exports, __webpack_require__) { + + /* WEBPACK VAR INJECTION */(function(Buffer) {var createHash = __webpack_require__(249) + + var blocksize = 64 + var zeroBuffer = new Buffer(blocksize); zeroBuffer.fill(0) + + module.exports = Hmac + + function Hmac (alg, key) { + if(!(this instanceof Hmac)) return new Hmac(alg, key) + this._opad = opad + this._alg = alg + + key = this._key = !Buffer.isBuffer(key) ? new Buffer(key) : key + + if(key.length > blocksize) { + key = createHash(alg).update(key).digest() + } else if(key.length < blocksize) { + key = Buffer.concat([key, zeroBuffer], blocksize) + } + + var ipad = this._ipad = new Buffer(blocksize) + var opad = this._opad = new Buffer(blocksize) + + for(var i = 0; i < blocksize; i++) { + ipad[i] = key[i] ^ 0x36 + opad[i] = key[i] ^ 0x5C + } + + this._hash = createHash(alg).update(ipad) + } + + Hmac.prototype.update = function (data, enc) { + this._hash.update(data, enc) + return this + } + + Hmac.prototype.digest = function (enc) { + var h = this._hash.digest() + return createHash(this._alg).update(this._opad).update(h).digest(enc) + } + + + /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(252).Buffer)) + +/***/ }, +/* 251 */ +/***/ function(module, exports, __webpack_require__) { + + // JavaScript PBKDF2 Implementation + // Based on http://git.io/qsv2zw + // Licensed under LGPL v3 + // Copyright (c) 2013 jduncanator + + var Buffer = __webpack_require__(252).Buffer + + var blocksize = 64 + var zeroBuffer = new Buffer(blocksize); zeroBuffer.fill(0) + + module.exports = function (createHmac, exports) { + exports = exports || {} + + exports.pbkdf2 = function(password, salt, iterations, keylen, callback) { + if('function' !== typeof callback) + throw new Error('No callback provided to pbkdf2'); + setTimeout(function () { + cb(null, exports.pbkdf2(password, salt, iterations, keylen)) + }) + } + + exports.pbkdf2Sync = function(key, salt, iterations, keylen) { + if('number' !== typeof iterations) + throw new TypeError('Iterations not a number') + if(iterations < 0) + throw new TypeError('Bad iterations') + if('number' !== typeof keylen) + throw new TypeError('Key length not a number') + if(keylen < 0) + throw new TypeError('Bad key length') + + //stretch key to the correct length that hmac wants it, + //otherwise this will happen every time hmac is called + //twice per iteration. + var key = !Buffer.isBuffer(key) ? new Buffer(key) : key + + if(key.length > blocksize) { + key = createHash(alg).update(key).digest() + } else if(key.length < blocksize) { + key = Buffer.concat([key, zeroBuffer], blocksize) + } + + var HMAC; + var cplen, p = 0, i = 1, itmp = new Buffer(4), digtmp; + var out = new Buffer(keylen); + out.fill(0); + while(keylen) { + if(keylen > 20) + cplen = 20; + else + cplen = keylen; + + /* We are unlikely to ever use more than 256 blocks (5120 bits!) + * but just in case... + */ + itmp[0] = (i >> 24) & 0xff; + itmp[1] = (i >> 16) & 0xff; + itmp[2] = (i >> 8) & 0xff; + itmp[3] = i & 0xff; + + HMAC = createHmac('sha1', key); + HMAC.update(salt) + HMAC.update(itmp); + digtmp = HMAC.digest(); + digtmp.copy(out, p, 0, cplen); + + for(var j = 1; j < iterations; j++) { + HMAC = createHmac('sha1', key); + HMAC.update(digtmp); + digtmp = HMAC.digest(); + for(var k = 0; k < cplen; k++) { + out[k] ^= digtmp[k]; + } + } + keylen -= cplen; + i++; + p += cplen; + } + + return out; + } + + return exports + } + + +/***/ }, +/* 252 */ +/***/ function(module, exports, __webpack_require__) { + + /* WEBPACK VAR INJECTION */(function(Buffer) {/** + * The buffer module from node.js, for the browser. + * + * Author: Feross Aboukhadijeh + * License: MIT + * + * `npm install buffer` + */ + + var base64 = __webpack_require__(260) + var ieee754 = __webpack_require__(259) + + exports.Buffer = Buffer + exports.SlowBuffer = Buffer + exports.INSPECT_MAX_BYTES = 50 + Buffer.poolSize = 8192 + + /** + * If `Buffer._useTypedArrays`: + * === true Use Uint8Array implementation (fastest) + * === false Use Object implementation (compatible down to IE6) + */ + Buffer._useTypedArrays = (function () { + // Detect if browser supports Typed Arrays. Supported browsers are IE 10+, Firefox 4+, + // Chrome 7+, Safari 5.1+, Opera 11.6+, iOS 4.2+. If the browser does not support adding + // properties to `Uint8Array` instances, then that's the same as no `Uint8Array` support + // because we need to be able to add all the node Buffer API methods. This is an issue + // in Firefox 4-29. Now fixed: https://bugzilla.mozilla.org/show_bug.cgi?id=695438 + try { + var buf = new ArrayBuffer(0) + var arr = new Uint8Array(buf) + arr.foo = function () { return 42 } + return 42 === arr.foo() && + typeof arr.subarray === 'function' // Chrome 9-10 lack `subarray` + } catch (e) { + return false + } + })() + + /** + * Class: Buffer + * ============= + * + * The Buffer constructor returns instances of `Uint8Array` that are augmented + * with function properties for all the node `Buffer` API functions. We use + * `Uint8Array` so that square bracket notation works as expected -- it returns + * a single octet. + * + * By augmenting the instances, we can avoid modifying the `Uint8Array` + * prototype. + */ + function Buffer (subject, encoding, noZero) { + if (!(this instanceof Buffer)) + return new Buffer(subject, encoding, noZero) + + var type = typeof subject + + // Workaround: node's base64 implementation allows for non-padded strings + // while base64-js does not. + if (encoding === 'base64' && type === 'string') { + subject = stringtrim(subject) + while (subject.length % 4 !== 0) { + subject = subject + '=' + } + } + + // Find the length + var length + if (type === 'number') + length = coerce(subject) + else if (type === 'string') + length = Buffer.byteLength(subject, encoding) + else if (type === 'object') + length = coerce(subject.length) // assume that object is array-like + else + throw new Error('First argument needs to be a number, array or string.') + + var buf + if (Buffer._useTypedArrays) { + // Preferred: Return an augmented `Uint8Array` instance for best performance + buf = Buffer._augment(new Uint8Array(length)) + } else { + // Fallback: Return THIS instance of Buffer (created by `new`) + buf = this + buf.length = length + buf._isBuffer = true + } + + var i + if (Buffer._useTypedArrays && typeof subject.byteLength === 'number') { + // Speed optimization -- use set if we're copying from a typed array + buf._set(subject) + } else if (isArrayish(subject)) { + // Treat array-ish objects as a byte array + for (i = 0; i < length; i++) { + if (Buffer.isBuffer(subject)) + buf[i] = subject.readUInt8(i) + else + buf[i] = subject[i] + } + } else if (type === 'string') { + buf.write(subject, 0, encoding) + } else if (type === 'number' && !Buffer._useTypedArrays && !noZero) { + for (i = 0; i < length; i++) { + buf[i] = 0 + } + } + + return buf + } + + // STATIC METHODS + // ============== + + Buffer.isEncoding = function (encoding) { + switch (String(encoding).toLowerCase()) { + case 'hex': + case 'utf8': + case 'utf-8': + case 'ascii': + case 'binary': + case 'base64': + case 'raw': + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return true + default: + return false + } + } + + Buffer.isBuffer = function (b) { + return !!(b !== null && b !== undefined && b._isBuffer) + } + + Buffer.byteLength = function (str, encoding) { + var ret + str = str + '' + switch (encoding || 'utf8') { + case 'hex': + ret = str.length / 2 + break + case 'utf8': + case 'utf-8': + ret = utf8ToBytes(str).length + break + case 'ascii': + case 'binary': + case 'raw': + ret = str.length + break + case 'base64': + ret = base64ToBytes(str).length + break + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + ret = str.length * 2 + break + default: + throw new Error('Unknown encoding') + } + return ret + } + + Buffer.concat = function (list, totalLength) { + assert(isArray(list), 'Usage: Buffer.concat(list, [totalLength])\n' + + 'list should be an Array.') + + if (list.length === 0) { + return new Buffer(0) + } else if (list.length === 1) { + return list[0] + } + + var i + if (typeof totalLength !== 'number') { + totalLength = 0 + for (i = 0; i < list.length; i++) { + totalLength += list[i].length + } + } + + var buf = new Buffer(totalLength) + var pos = 0 + for (i = 0; i < list.length; i++) { + var item = list[i] + item.copy(buf, pos) + pos += item.length + } + return buf + } + + // BUFFER INSTANCE METHODS + // ======================= + + function _hexWrite (buf, string, offset, length) { + offset = Number(offset) || 0 + var remaining = buf.length - offset + if (!length) { + length = remaining + } else { + length = Number(length) + if (length > remaining) { + length = remaining + } + } + + // must be an even number of digits + var strLen = string.length + assert(strLen % 2 === 0, 'Invalid hex string') + + if (length > strLen / 2) { + length = strLen / 2 + } + for (var i = 0; i < length; i++) { + var byte = parseInt(string.substr(i * 2, 2), 16) + assert(!isNaN(byte), 'Invalid hex string') + buf[offset + i] = byte + } + Buffer._charsWritten = i * 2 + return i + } + + function _utf8Write (buf, string, offset, length) { + var charsWritten = Buffer._charsWritten = + blitBuffer(utf8ToBytes(string), buf, offset, length) + return charsWritten + } + + function _asciiWrite (buf, string, offset, length) { + var charsWritten = Buffer._charsWritten = + blitBuffer(asciiToBytes(string), buf, offset, length) + return charsWritten + } + + function _binaryWrite (buf, string, offset, length) { + return _asciiWrite(buf, string, offset, length) + } + + function _base64Write (buf, string, offset, length) { + var charsWritten = Buffer._charsWritten = + blitBuffer(base64ToBytes(string), buf, offset, length) + return charsWritten + } + + function _utf16leWrite (buf, string, offset, length) { + var charsWritten = Buffer._charsWritten = + blitBuffer(utf16leToBytes(string), buf, offset, length) + return charsWritten + } + + Buffer.prototype.write = function (string, offset, length, encoding) { + // Support both (string, offset, length, encoding) + // and the legacy (string, encoding, offset, length) + if (isFinite(offset)) { + if (!isFinite(length)) { + encoding = length + length = undefined + } + } else { // legacy + var swap = encoding + encoding = offset + offset = length + length = swap + } + + offset = Number(offset) || 0 + var remaining = this.length - offset + if (!length) { + length = remaining + } else { + length = Number(length) + if (length > remaining) { + length = remaining + } + } + encoding = String(encoding || 'utf8').toLowerCase() + + var ret + switch (encoding) { + case 'hex': + ret = _hexWrite(this, string, offset, length) + break + case 'utf8': + case 'utf-8': + ret = _utf8Write(this, string, offset, length) + break + case 'ascii': + ret = _asciiWrite(this, string, offset, length) + break + case 'binary': + ret = _binaryWrite(this, string, offset, length) + break + case 'base64': + ret = _base64Write(this, string, offset, length) + break + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + ret = _utf16leWrite(this, string, offset, length) + break + default: + throw new Error('Unknown encoding') + } + return ret + } + + Buffer.prototype.toString = function (encoding, start, end) { + var self = this + + encoding = String(encoding || 'utf8').toLowerCase() + start = Number(start) || 0 + end = (end !== undefined) + ? Number(end) + : end = self.length + + // Fastpath empty strings + if (end === start) + return '' + + var ret + switch (encoding) { + case 'hex': + ret = _hexSlice(self, start, end) + break + case 'utf8': + case 'utf-8': + ret = _utf8Slice(self, start, end) + break + case 'ascii': + ret = _asciiSlice(self, start, end) + break + case 'binary': + ret = _binarySlice(self, start, end) + break + case 'base64': + ret = _base64Slice(self, start, end) + break + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + ret = _utf16leSlice(self, start, end) + break + default: + throw new Error('Unknown encoding') + } + return ret + } + + Buffer.prototype.toJSON = function () { + return { + type: 'Buffer', + data: Array.prototype.slice.call(this._arr || this, 0) + } + } + + // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) + Buffer.prototype.copy = function (target, target_start, start, end) { + var source = this + + if (!start) start = 0 + if (!end && end !== 0) end = this.length + if (!target_start) target_start = 0 + + // Copy 0 bytes; we're done + if (end === start) return + if (target.length === 0 || source.length === 0) return + + // Fatal error conditions + assert(end >= start, 'sourceEnd < sourceStart') + assert(target_start >= 0 && target_start < target.length, + 'targetStart out of bounds') + assert(start >= 0 && start < source.length, 'sourceStart out of bounds') + assert(end >= 0 && end <= source.length, 'sourceEnd out of bounds') + + // Are we oob? + if (end > this.length) + end = this.length + if (target.length - target_start < end - start) + end = target.length - target_start + start + + var len = end - start + + if (len < 100 || !Buffer._useTypedArrays) { + for (var i = 0; i < len; i++) + target[i + target_start] = this[i + start] + } else { + target._set(this.subarray(start, start + len), target_start) + } + } + + function _base64Slice (buf, start, end) { + if (start === 0 && end === buf.length) { + return base64.fromByteArray(buf) + } else { + return base64.fromByteArray(buf.slice(start, end)) + } + } + + function _utf8Slice (buf, start, end) { + var res = '' + var tmp = '' + end = Math.min(buf.length, end) + + for (var i = start; i < end; i++) { + if (buf[i] <= 0x7F) { + res += decodeUtf8Char(tmp) + String.fromCharCode(buf[i]) + tmp = '' + } else { + tmp += '%' + buf[i].toString(16) + } + } + + return res + decodeUtf8Char(tmp) + } + + function _asciiSlice (buf, start, end) { + var ret = '' + end = Math.min(buf.length, end) + + for (var i = start; i < end; i++) + ret += String.fromCharCode(buf[i]) + return ret + } + + function _binarySlice (buf, start, end) { + return _asciiSlice(buf, start, end) + } + + function _hexSlice (buf, start, end) { + var len = buf.length + + if (!start || start < 0) start = 0 + if (!end || end < 0 || end > len) end = len + + var out = '' + for (var i = start; i < end; i++) { + out += toHex(buf[i]) + } + return out + } + + function _utf16leSlice (buf, start, end) { + var bytes = buf.slice(start, end) + var res = '' + for (var i = 0; i < bytes.length; i += 2) { + res += String.fromCharCode(bytes[i] + bytes[i+1] * 256) + } + return res + } + + Buffer.prototype.slice = function (start, end) { + var len = this.length + start = clamp(start, len, 0) + end = clamp(end, len, len) + + if (Buffer._useTypedArrays) { + return Buffer._augment(this.subarray(start, end)) + } else { + var sliceLen = end - start + var newBuf = new Buffer(sliceLen, undefined, true) + for (var i = 0; i < sliceLen; i++) { + newBuf[i] = this[i + start] + } + return newBuf + } + } + + // `get` will be removed in Node 0.13+ + Buffer.prototype.get = function (offset) { + console.log('.get() is deprecated. Access using array indexes instead.') + return this.readUInt8(offset) + } + + // `set` will be removed in Node 0.13+ + Buffer.prototype.set = function (v, offset) { + console.log('.set() is deprecated. Access using array indexes instead.') + return this.writeUInt8(v, offset) + } + + Buffer.prototype.readUInt8 = function (offset, noAssert) { + if (!noAssert) { + assert(offset !== undefined && offset !== null, 'missing offset') + assert(offset < this.length, 'Trying to read beyond buffer length') + } + + if (offset >= this.length) + return + + return this[offset] + } + + function _readUInt16 (buf, offset, littleEndian, noAssert) { + if (!noAssert) { + assert(typeof littleEndian === 'boolean', 'missing or invalid endian') + assert(offset !== undefined && offset !== null, 'missing offset') + assert(offset + 1 < buf.length, 'Trying to read beyond buffer length') + } + + var len = buf.length + if (offset >= len) + return + + var val + if (littleEndian) { + val = buf[offset] + if (offset + 1 < len) + val |= buf[offset + 1] << 8 + } else { + val = buf[offset] << 8 + if (offset + 1 < len) + val |= buf[offset + 1] + } + return val + } + + Buffer.prototype.readUInt16LE = function (offset, noAssert) { + return _readUInt16(this, offset, true, noAssert) + } + + Buffer.prototype.readUInt16BE = function (offset, noAssert) { + return _readUInt16(this, offset, false, noAssert) + } + + function _readUInt32 (buf, offset, littleEndian, noAssert) { + if (!noAssert) { + assert(typeof littleEndian === 'boolean', 'missing or invalid endian') + assert(offset !== undefined && offset !== null, 'missing offset') + assert(offset + 3 < buf.length, 'Trying to read beyond buffer length') + } + + var len = buf.length + if (offset >= len) + return + + var val + if (littleEndian) { + if (offset + 2 < len) + val = buf[offset + 2] << 16 + if (offset + 1 < len) + val |= buf[offset + 1] << 8 + val |= buf[offset] + if (offset + 3 < len) + val = val + (buf[offset + 3] << 24 >>> 0) + } else { + if (offset + 1 < len) + val = buf[offset + 1] << 16 + if (offset + 2 < len) + val |= buf[offset + 2] << 8 + if (offset + 3 < len) + val |= buf[offset + 3] + val = val + (buf[offset] << 24 >>> 0) + } + return val + } + + Buffer.prototype.readUInt32LE = function (offset, noAssert) { + return _readUInt32(this, offset, true, noAssert) + } + + Buffer.prototype.readUInt32BE = function (offset, noAssert) { + return _readUInt32(this, offset, false, noAssert) + } + + Buffer.prototype.readInt8 = function (offset, noAssert) { + if (!noAssert) { + assert(offset !== undefined && offset !== null, + 'missing offset') + assert(offset < this.length, 'Trying to read beyond buffer length') + } + + if (offset >= this.length) + return + + var neg = this[offset] & 0x80 + if (neg) + return (0xff - this[offset] + 1) * -1 + else + return this[offset] + } + + function _readInt16 (buf, offset, littleEndian, noAssert) { + if (!noAssert) { + assert(typeof littleEndian === 'boolean', 'missing or invalid endian') + assert(offset !== undefined && offset !== null, 'missing offset') + assert(offset + 1 < buf.length, 'Trying to read beyond buffer length') + } + + var len = buf.length + if (offset >= len) + return + + var val = _readUInt16(buf, offset, littleEndian, true) + var neg = val & 0x8000 + if (neg) + return (0xffff - val + 1) * -1 + else + return val + } + + Buffer.prototype.readInt16LE = function (offset, noAssert) { + return _readInt16(this, offset, true, noAssert) + } + + Buffer.prototype.readInt16BE = function (offset, noAssert) { + return _readInt16(this, offset, false, noAssert) + } + + function _readInt32 (buf, offset, littleEndian, noAssert) { + if (!noAssert) { + assert(typeof littleEndian === 'boolean', 'missing or invalid endian') + assert(offset !== undefined && offset !== null, 'missing offset') + assert(offset + 3 < buf.length, 'Trying to read beyond buffer length') + } + + var len = buf.length + if (offset >= len) + return + + var val = _readUInt32(buf, offset, littleEndian, true) + var neg = val & 0x80000000 + if (neg) + return (0xffffffff - val + 1) * -1 + else + return val + } + + Buffer.prototype.readInt32LE = function (offset, noAssert) { + return _readInt32(this, offset, true, noAssert) + } + + Buffer.prototype.readInt32BE = function (offset, noAssert) { + return _readInt32(this, offset, false, noAssert) + } + + function _readFloat (buf, offset, littleEndian, noAssert) { + if (!noAssert) { + assert(typeof littleEndian === 'boolean', 'missing or invalid endian') + assert(offset + 3 < buf.length, 'Trying to read beyond buffer length') + } + + return ieee754.read(buf, offset, littleEndian, 23, 4) + } + + Buffer.prototype.readFloatLE = function (offset, noAssert) { + return _readFloat(this, offset, true, noAssert) + } + + Buffer.prototype.readFloatBE = function (offset, noAssert) { + return _readFloat(this, offset, false, noAssert) + } + + function _readDouble (buf, offset, littleEndian, noAssert) { + if (!noAssert) { + assert(typeof littleEndian === 'boolean', 'missing or invalid endian') + assert(offset + 7 < buf.length, 'Trying to read beyond buffer length') + } + + return ieee754.read(buf, offset, littleEndian, 52, 8) + } + + Buffer.prototype.readDoubleLE = function (offset, noAssert) { + return _readDouble(this, offset, true, noAssert) + } + + Buffer.prototype.readDoubleBE = function (offset, noAssert) { + return _readDouble(this, offset, false, noAssert) + } + + Buffer.prototype.writeUInt8 = function (value, offset, noAssert) { + if (!noAssert) { + assert(value !== undefined && value !== null, 'missing value') + assert(offset !== undefined && offset !== null, 'missing offset') + assert(offset < this.length, 'trying to write beyond buffer length') + verifuint(value, 0xff) + } + + if (offset >= this.length) return + + this[offset] = value + } + + function _writeUInt16 (buf, value, offset, littleEndian, noAssert) { + if (!noAssert) { + assert(value !== undefined && value !== null, 'missing value') + assert(typeof littleEndian === 'boolean', 'missing or invalid endian') + assert(offset !== undefined && offset !== null, 'missing offset') + assert(offset + 1 < buf.length, 'trying to write beyond buffer length') + verifuint(value, 0xffff) + } + + var len = buf.length + if (offset >= len) + return + + for (var i = 0, j = Math.min(len - offset, 2); i < j; i++) { + buf[offset + i] = + (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>> + (littleEndian ? i : 1 - i) * 8 + } + } + + Buffer.prototype.writeUInt16LE = function (value, offset, noAssert) { + _writeUInt16(this, value, offset, true, noAssert) + } + + Buffer.prototype.writeUInt16BE = function (value, offset, noAssert) { + _writeUInt16(this, value, offset, false, noAssert) + } + + function _writeUInt32 (buf, value, offset, littleEndian, noAssert) { + if (!noAssert) { + assert(value !== undefined && value !== null, 'missing value') + assert(typeof littleEndian === 'boolean', 'missing or invalid endian') + assert(offset !== undefined && offset !== null, 'missing offset') + assert(offset + 3 < buf.length, 'trying to write beyond buffer length') + verifuint(value, 0xffffffff) + } + + var len = buf.length + if (offset >= len) + return + + for (var i = 0, j = Math.min(len - offset, 4); i < j; i++) { + buf[offset + i] = + (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff + } + } + + Buffer.prototype.writeUInt32LE = function (value, offset, noAssert) { + _writeUInt32(this, value, offset, true, noAssert) + } + + Buffer.prototype.writeUInt32BE = function (value, offset, noAssert) { + _writeUInt32(this, value, offset, false, noAssert) + } + + Buffer.prototype.writeInt8 = function (value, offset, noAssert) { + if (!noAssert) { + assert(value !== undefined && value !== null, 'missing value') + assert(offset !== undefined && offset !== null, 'missing offset') + assert(offset < this.length, 'Trying to write beyond buffer length') + verifsint(value, 0x7f, -0x80) + } + + if (offset >= this.length) + return + + if (value >= 0) + this.writeUInt8(value, offset, noAssert) + else + this.writeUInt8(0xff + value + 1, offset, noAssert) + } + + function _writeInt16 (buf, value, offset, littleEndian, noAssert) { + if (!noAssert) { + assert(value !== undefined && value !== null, 'missing value') + assert(typeof littleEndian === 'boolean', 'missing or invalid endian') + assert(offset !== undefined && offset !== null, 'missing offset') + assert(offset + 1 < buf.length, 'Trying to write beyond buffer length') + verifsint(value, 0x7fff, -0x8000) + } + + var len = buf.length + if (offset >= len) + return + + if (value >= 0) + _writeUInt16(buf, value, offset, littleEndian, noAssert) + else + _writeUInt16(buf, 0xffff + value + 1, offset, littleEndian, noAssert) + } + + Buffer.prototype.writeInt16LE = function (value, offset, noAssert) { + _writeInt16(this, value, offset, true, noAssert) + } + + Buffer.prototype.writeInt16BE = function (value, offset, noAssert) { + _writeInt16(this, value, offset, false, noAssert) + } + + function _writeInt32 (buf, value, offset, littleEndian, noAssert) { + if (!noAssert) { + assert(value !== undefined && value !== null, 'missing value') + assert(typeof littleEndian === 'boolean', 'missing or invalid endian') + assert(offset !== undefined && offset !== null, 'missing offset') + assert(offset + 3 < buf.length, 'Trying to write beyond buffer length') + verifsint(value, 0x7fffffff, -0x80000000) + } + + var len = buf.length + if (offset >= len) + return + + if (value >= 0) + _writeUInt32(buf, value, offset, littleEndian, noAssert) + else + _writeUInt32(buf, 0xffffffff + value + 1, offset, littleEndian, noAssert) + } + + Buffer.prototype.writeInt32LE = function (value, offset, noAssert) { + _writeInt32(this, value, offset, true, noAssert) + } + + Buffer.prototype.writeInt32BE = function (value, offset, noAssert) { + _writeInt32(this, value, offset, false, noAssert) + } + + function _writeFloat (buf, value, offset, littleEndian, noAssert) { + if (!noAssert) { + assert(value !== undefined && value !== null, 'missing value') + assert(typeof littleEndian === 'boolean', 'missing or invalid endian') + assert(offset !== undefined && offset !== null, 'missing offset') + assert(offset + 3 < buf.length, 'Trying to write beyond buffer length') + verifIEEE754(value, 3.4028234663852886e+38, -3.4028234663852886e+38) + } + + var len = buf.length + if (offset >= len) + return + + ieee754.write(buf, value, offset, littleEndian, 23, 4) + } + + Buffer.prototype.writeFloatLE = function (value, offset, noAssert) { + _writeFloat(this, value, offset, true, noAssert) + } + + Buffer.prototype.writeFloatBE = function (value, offset, noAssert) { + _writeFloat(this, value, offset, false, noAssert) + } + + function _writeDouble (buf, value, offset, littleEndian, noAssert) { + if (!noAssert) { + assert(value !== undefined && value !== null, 'missing value') + assert(typeof littleEndian === 'boolean', 'missing or invalid endian') + assert(offset !== undefined && offset !== null, 'missing offset') + assert(offset + 7 < buf.length, + 'Trying to write beyond buffer length') + verifIEEE754(value, 1.7976931348623157E+308, -1.7976931348623157E+308) + } + + var len = buf.length + if (offset >= len) + return + + ieee754.write(buf, value, offset, littleEndian, 52, 8) + } + + Buffer.prototype.writeDoubleLE = function (value, offset, noAssert) { + _writeDouble(this, value, offset, true, noAssert) + } + + Buffer.prototype.writeDoubleBE = function (value, offset, noAssert) { + _writeDouble(this, value, offset, false, noAssert) + } + + // fill(value, start=0, end=buffer.length) + Buffer.prototype.fill = function (value, start, end) { + if (!value) value = 0 + if (!start) start = 0 + if (!end) end = this.length + + if (typeof value === 'string') { + value = value.charCodeAt(0) + } + + assert(typeof value === 'number' && !isNaN(value), 'value is not a number') + assert(end >= start, 'end < start') + + // Fill 0 bytes; we're done + if (end === start) return + if (this.length === 0) return + + assert(start >= 0 && start < this.length, 'start out of bounds') + assert(end >= 0 && end <= this.length, 'end out of bounds') + + for (var i = start; i < end; i++) { + this[i] = value + } + } + + Buffer.prototype.inspect = function () { + var out = [] + var len = this.length + for (var i = 0; i < len; i++) { + out[i] = toHex(this[i]) + if (i === exports.INSPECT_MAX_BYTES) { + out[i + 1] = '...' + break + } + } + return '' + } + + /** + * Creates a new `ArrayBuffer` with the *copied* memory of the buffer instance. + * Added in Node 0.12. Only available in browsers that support ArrayBuffer. + */ + Buffer.prototype.toArrayBuffer = function () { + if (typeof Uint8Array !== 'undefined') { + if (Buffer._useTypedArrays) { + return (new Buffer(this)).buffer + } else { + var buf = new Uint8Array(this.length) + for (var i = 0, len = buf.length; i < len; i += 1) + buf[i] = this[i] + return buf.buffer + } + } else { + throw new Error('Buffer.toArrayBuffer not supported in this browser') + } + } + + // HELPER FUNCTIONS + // ================ + + function stringtrim (str) { + if (str.trim) return str.trim() + return str.replace(/^\s+|\s+$/g, '') + } + + var BP = Buffer.prototype + + /** + * Augment a Uint8Array *instance* (not the Uint8Array class!) with Buffer methods + */ + Buffer._augment = function (arr) { + arr._isBuffer = true + + // save reference to original Uint8Array get/set methods before overwriting + arr._get = arr.get + arr._set = arr.set + + // deprecated, will be removed in node 0.13+ + arr.get = BP.get + arr.set = BP.set + + arr.write = BP.write + arr.toString = BP.toString + arr.toLocaleString = BP.toString + arr.toJSON = BP.toJSON + arr.copy = BP.copy + arr.slice = BP.slice + arr.readUInt8 = BP.readUInt8 + arr.readUInt16LE = BP.readUInt16LE + arr.readUInt16BE = BP.readUInt16BE + arr.readUInt32LE = BP.readUInt32LE + arr.readUInt32BE = BP.readUInt32BE + arr.readInt8 = BP.readInt8 + arr.readInt16LE = BP.readInt16LE + arr.readInt16BE = BP.readInt16BE + arr.readInt32LE = BP.readInt32LE + arr.readInt32BE = BP.readInt32BE + arr.readFloatLE = BP.readFloatLE + arr.readFloatBE = BP.readFloatBE + arr.readDoubleLE = BP.readDoubleLE + arr.readDoubleBE = BP.readDoubleBE + arr.writeUInt8 = BP.writeUInt8 + arr.writeUInt16LE = BP.writeUInt16LE + arr.writeUInt16BE = BP.writeUInt16BE + arr.writeUInt32LE = BP.writeUInt32LE + arr.writeUInt32BE = BP.writeUInt32BE + arr.writeInt8 = BP.writeInt8 + arr.writeInt16LE = BP.writeInt16LE + arr.writeInt16BE = BP.writeInt16BE + arr.writeInt32LE = BP.writeInt32LE + arr.writeInt32BE = BP.writeInt32BE + arr.writeFloatLE = BP.writeFloatLE + arr.writeFloatBE = BP.writeFloatBE + arr.writeDoubleLE = BP.writeDoubleLE + arr.writeDoubleBE = BP.writeDoubleBE + arr.fill = BP.fill + arr.inspect = BP.inspect + arr.toArrayBuffer = BP.toArrayBuffer + + return arr + } + + // slice(start, end) + function clamp (index, len, defaultValue) { + if (typeof index !== 'number') return defaultValue + index = ~~index; // Coerce to integer. + if (index >= len) return len + if (index >= 0) return index + index += len + if (index >= 0) return index + return 0 + } + + function coerce (length) { + // Coerce length to a number (possibly NaN), round up + // in case it's fractional (e.g. 123.456) then do a + // double negate to coerce a NaN to 0. Easy, right? + length = ~~Math.ceil(+length) + return length < 0 ? 0 : length + } + + function isArray (subject) { + return (Array.isArray || function (subject) { + return Object.prototype.toString.call(subject) === '[object Array]' + })(subject) + } + + function isArrayish (subject) { + return isArray(subject) || Buffer.isBuffer(subject) || + subject && typeof subject === 'object' && + typeof subject.length === 'number' + } + + function toHex (n) { + if (n < 16) return '0' + n.toString(16) + return n.toString(16) + } + + function utf8ToBytes (str) { + var byteArray = [] + for (var i = 0; i < str.length; i++) { + var b = str.charCodeAt(i) + if (b <= 0x7F) + byteArray.push(str.charCodeAt(i)) + else { + var start = i + if (b >= 0xD800 && b <= 0xDFFF) i++ + var h = encodeURIComponent(str.slice(start, i+1)).substr(1).split('%') + for (var j = 0; j < h.length; j++) + byteArray.push(parseInt(h[j], 16)) + } + } + return byteArray + } + + function asciiToBytes (str) { + var byteArray = [] + for (var i = 0; i < str.length; i++) { + // Node's code seems to be doing this and not & 0x7F.. + byteArray.push(str.charCodeAt(i) & 0xFF) + } + return byteArray + } + + function utf16leToBytes (str) { + var c, hi, lo + var byteArray = [] + for (var i = 0; i < str.length; i++) { + c = str.charCodeAt(i) + hi = c >> 8 + lo = c % 256 + byteArray.push(lo) + byteArray.push(hi) + } + + return byteArray + } + + function base64ToBytes (str) { + return base64.toByteArray(str) + } + + function blitBuffer (src, dst, offset, length) { + var pos + for (var i = 0; i < length; i++) { + if ((i + offset >= dst.length) || (i >= src.length)) + break + dst[i + offset] = src[i] + } + return i + } + + function decodeUtf8Char (str) { + try { + return decodeURIComponent(str) + } catch (err) { + return String.fromCharCode(0xFFFD) // UTF 8 invalid char + } + } + + /* + * We have to make sure that the value is a valid integer. This means that it + * is non-negative. It has no fractional component and that it does not + * exceed the maximum allowed value. + */ + function verifuint (value, max) { + assert(typeof value === 'number', 'cannot write a non-number as a number') + assert(value >= 0, 'specified a negative value for writing an unsigned value') + assert(value <= max, 'value is larger than maximum value for type') + assert(Math.floor(value) === value, 'value has a fractional component') + } + + function verifsint (value, max, min) { + assert(typeof value === 'number', 'cannot write a non-number as a number') + assert(value <= max, 'value larger than maximum allowed value') + assert(value >= min, 'value smaller than minimum allowed value') + assert(Math.floor(value) === value, 'value has a fractional component') + } + + function verifIEEE754 (value, max, min) { + assert(typeof value === 'number', 'cannot write a non-number as a number') + assert(value <= max, 'value larger than maximum allowed value') + assert(value >= min, 'value smaller than minimum allowed value') + } + + function assert (test, message) { + if (!test) throw new Error(message || 'Failed assertion') + } + + /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(252).Buffer)) + +/***/ }, +/* 253 */ +/***/ function(module, exports, __webpack_require__) { + + /* + * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message + * Digest Algorithm, as defined in RFC 1321. + * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002. + * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet + * Distributed under the BSD License + * See http://pajhome.org.uk/crypt/md5 for more info. + */ + + var helpers = __webpack_require__(255); + + /* + * Perform a simple self-test to see if the VM is working + */ + function md5_vm_test() + { + return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72"; + } + + /* + * Calculate the MD5 of an array of little-endian words, and a bit length + */ + function core_md5(x, len) + { + /* append padding */ + x[len >> 5] |= 0x80 << ((len) % 32); + x[(((len + 64) >>> 9) << 4) + 14] = len; + + var a = 1732584193; + var b = -271733879; + var c = -1732584194; + var d = 271733878; + + for(var i = 0; i < x.length; i += 16) + { + var olda = a; + var oldb = b; + var oldc = c; + var oldd = d; + + a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936); + d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586); + c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819); + b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330); + a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897); + d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426); + c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341); + b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983); + a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416); + d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417); + c = md5_ff(c, d, a, b, x[i+10], 17, -42063); + b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162); + a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682); + d = md5_ff(d, a, b, c, x[i+13], 12, -40341101); + c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290); + b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329); + + a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510); + d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632); + c = md5_gg(c, d, a, b, x[i+11], 14, 643717713); + b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302); + a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691); + d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083); + c = md5_gg(c, d, a, b, x[i+15], 14, -660478335); + b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848); + a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438); + d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690); + c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961); + b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501); + a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467); + d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784); + c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473); + b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734); + + a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558); + d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463); + c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562); + b = md5_hh(b, c, d, a, x[i+14], 23, -35309556); + a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060); + d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353); + c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632); + b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640); + a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174); + d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222); + c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979); + b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189); + a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487); + d = md5_hh(d, a, b, c, x[i+12], 11, -421815835); + c = md5_hh(c, d, a, b, x[i+15], 16, 530742520); + b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651); + + a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844); + d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415); + c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905); + b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055); + a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571); + d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606); + c = md5_ii(c, d, a, b, x[i+10], 15, -1051523); + b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799); + a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359); + d = md5_ii(d, a, b, c, x[i+15], 10, -30611744); + c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380); + b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649); + a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070); + d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379); + c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259); + b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551); + + a = safe_add(a, olda); + b = safe_add(b, oldb); + c = safe_add(c, oldc); + d = safe_add(d, oldd); + } + return Array(a, b, c, d); + + } + + /* + * These functions implement the four basic operations the algorithm uses. + */ + function md5_cmn(q, a, b, x, s, t) + { + return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b); + } + function md5_ff(a, b, c, d, x, s, t) + { + return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t); + } + function md5_gg(a, b, c, d, x, s, t) + { + return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t); + } + function md5_hh(a, b, c, d, x, s, t) + { + return md5_cmn(b ^ c ^ d, a, b, x, s, t); + } + function md5_ii(a, b, c, d, x, s, t) + { + return md5_cmn(c ^ (b | (~d)), a, b, x, s, t); + } + + /* + * Add integers, wrapping at 2^32. This uses 16-bit operations internally + * to work around bugs in some JS interpreters. + */ + function safe_add(x, y) + { + var lsw = (x & 0xFFFF) + (y & 0xFFFF); + var msw = (x >> 16) + (y >> 16) + (lsw >> 16); + return (msw << 16) | (lsw & 0xFFFF); + } + + /* + * Bitwise rotate a 32-bit number to the left. + */ + function bit_rol(num, cnt) + { + return (num << cnt) | (num >>> (32 - cnt)); + } + + module.exports = function md5(buf) { + return helpers.hash(buf, core_md5, 16); + }; + + +/***/ }, +/* 254 */ +/***/ function(module, exports, __webpack_require__) { + + var exports = module.exports = function (alg) { + var Alg = exports[alg] + if(!Alg) throw new Error(alg + ' is not supported (we accept pull requests)') + return new Alg() + } + + var Buffer = __webpack_require__(252).Buffer + var Hash = __webpack_require__(256)(Buffer) + + exports.sha = + exports.sha1 = __webpack_require__(257)(Buffer, Hash) + exports.sha256 = __webpack_require__(258)(Buffer, Hash) + + +/***/ }, +/* 255 */ +/***/ function(module, exports, __webpack_require__) { + + var Buffer = __webpack_require__(252).Buffer; + var intSize = 4; + var zeroBuffer = new Buffer(intSize); zeroBuffer.fill(0); + var chrsz = 8; + + function toArray(buf, bigEndian) { + if ((buf.length % intSize) !== 0) { + var len = buf.length + (intSize - (buf.length % intSize)); + buf = Buffer.concat([buf, zeroBuffer], len); + } + + var arr = []; + var fn = bigEndian ? buf.readInt32BE : buf.readInt32LE; + for (var i = 0; i < buf.length; i += intSize) { + arr.push(fn.call(buf, i)); + } + return arr; + } + + function toBuffer(arr, size, bigEndian) { + var buf = new Buffer(size); + var fn = bigEndian ? buf.writeInt32BE : buf.writeInt32LE; + for (var i = 0; i < arr.length; i++) { + fn.call(buf, arr[i], i * 4, true); + } + return buf; + } + + function hash(buf, fn, hashSize, bigEndian) { + if (!Buffer.isBuffer(buf)) buf = new Buffer(buf); + var arr = fn(toArray(buf, bigEndian), buf.length * chrsz); + return toBuffer(arr, hashSize, bigEndian); + } + + module.exports = { hash: hash }; + + +/***/ }, +/* 256 */ +/***/ function(module, exports, __webpack_require__) { + + var u = __webpack_require__(261) + var write = u.write + var fill = u.zeroFill + + module.exports = function (Buffer) { + + //prototype class for hash functions + function Hash (blockSize, finalSize) { + this._block = new Buffer(blockSize) //new Uint32Array(blockSize/4) + this._finalSize = finalSize + this._blockSize = blockSize + this._len = 0 + this._s = 0 + } + + Hash.prototype.init = function () { + this._s = 0 + this._len = 0 + } + + function lengthOf(data, enc) { + if(enc == null) return data.byteLength || data.length + if(enc == 'ascii' || enc == 'binary') return data.length + if(enc == 'hex') return data.length/2 + if(enc == 'base64') return data.length/3 + } + + Hash.prototype.update = function (data, enc) { + var bl = this._blockSize + + //I'd rather do this with a streaming encoder, like the opposite of + //http://nodejs.org/api/string_decoder.html + var length + if(!enc && 'string' === typeof data) + enc = 'utf8' + + if(enc) { + if(enc === 'utf-8') + enc = 'utf8' + + if(enc === 'base64' || enc === 'utf8') + data = new Buffer(data, enc), enc = null + + length = lengthOf(data, enc) + } else + length = data.byteLength || data.length + + var l = this._len += length + var s = this._s = (this._s || 0) + var f = 0 + var buffer = this._block + while(s < l) { + var t = Math.min(length, f + bl) + write(buffer, data, enc, s%bl, f, t) + var ch = (t - f); + s += ch; f += ch + + if(!(s%bl)) + this._update(buffer) + } + this._s = s + + return this + + } + + Hash.prototype.digest = function (enc) { + var bl = this._blockSize + var fl = this._finalSize + var len = this._len*8 + + var x = this._block + + var bits = len % (bl*8) + + //add end marker, so that appending 0's creats a different hash. + x[this._len % bl] = 0x80 + fill(this._block, this._len % bl + 1) + + if(bits >= fl*8) { + this._update(this._block) + u.zeroFill(this._block, 0) + } + + //TODO: handle case where the bit length is > Math.pow(2, 29) + x.writeInt32BE(len, fl + 4) //big endian + + var hash = this._update(this._block) || this._hash() + if(enc == null) return hash + return hash.toString(enc) + } + + Hash.prototype._update = function () { + throw new Error('_update must be implemented by subclass') + } + + return Hash + } + + +/***/ }, +/* 257 */ +/***/ function(module, exports, __webpack_require__) { + + /* + * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined + * in FIPS PUB 180-1 + * Version 2.1a Copyright Paul Johnston 2000 - 2002. + * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet + * Distributed under the BSD License + * See http://pajhome.org.uk/crypt/md5 for details. + */ + module.exports = function (Buffer, Hash) { + + var inherits = __webpack_require__(263).inherits + + inherits(Sha1, Hash) + + var A = 0|0 + var B = 4|0 + var C = 8|0 + var D = 12|0 + var E = 16|0 + + var BE = false + var LE = true + + var W = new Int32Array(80) + + var POOL = [] + + function Sha1 () { + if(POOL.length) + return POOL.pop().init() + + if(!(this instanceof Sha1)) return new Sha1() + this._w = W + Hash.call(this, 16*4, 14*4) + + this._h = null + this.init() + } + + Sha1.prototype.init = function () { + this._a = 0x67452301 + this._b = 0xefcdab89 + this._c = 0x98badcfe + this._d = 0x10325476 + this._e = 0xc3d2e1f0 + + Hash.prototype.init.call(this) + return this + } + + Sha1.prototype._POOL = POOL + + // assume that array is a Uint32Array with length=16, + // and that if it is the last block, it already has the length and the 1 bit appended. + + + var isDV = new Buffer(1) instanceof DataView + function readInt32BE (X, i) { + return isDV + ? X.getInt32(i, false) + : X.readInt32BE(i) + } + + Sha1.prototype._update = function (array) { + + var X = this._block + var h = this._h + var a, b, c, d, e, _a, _b, _c, _d, _e + + a = _a = this._a + b = _b = this._b + c = _c = this._c + d = _d = this._d + e = _e = this._e + + var w = this._w + + for(var j = 0; j < 80; j++) { + var W = w[j] + = j < 16 + //? X.getInt32(j*4, false) + //? readInt32BE(X, j*4) //*/ X.readInt32BE(j*4) //*/ + ? X.readInt32BE(j*4) + : rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1) + + var t = + add( + add(rol(a, 5), sha1_ft(j, b, c, d)), + add(add(e, W), sha1_kt(j)) + ); + + e = d + d = c + c = rol(b, 30) + b = a + a = t + } + + this._a = add(a, _a) + this._b = add(b, _b) + this._c = add(c, _c) + this._d = add(d, _d) + this._e = add(e, _e) + } + + Sha1.prototype._hash = function () { + if(POOL.length < 100) POOL.push(this) + var H = new Buffer(20) + //console.log(this._a|0, this._b|0, this._c|0, this._d|0, this._e|0) + H.writeInt32BE(this._a|0, A) + H.writeInt32BE(this._b|0, B) + H.writeInt32BE(this._c|0, C) + H.writeInt32BE(this._d|0, D) + H.writeInt32BE(this._e|0, E) + return H + } + + /* + * Perform the appropriate triplet combination function for the current + * iteration + */ + function sha1_ft(t, b, c, d) { + if(t < 20) return (b & c) | ((~b) & d); + if(t < 40) return b ^ c ^ d; + if(t < 60) return (b & c) | (b & d) | (c & d); + return b ^ c ^ d; + } + + /* + * Determine the appropriate additive constant for the current iteration + */ + function sha1_kt(t) { + return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 : + (t < 60) ? -1894007588 : -899497514; + } + + /* + * Add integers, wrapping at 2^32. This uses 16-bit operations internally + * to work around bugs in some JS interpreters. + * //dominictarr: this is 10 years old, so maybe this can be dropped?) + * + */ + function add(x, y) { + return (x + y ) | 0 + //lets see how this goes on testling. + // var lsw = (x & 0xFFFF) + (y & 0xFFFF); + // var msw = (x >> 16) + (y >> 16) + (lsw >> 16); + // return (msw << 16) | (lsw & 0xFFFF); + } + + /* + * Bitwise rotate a 32-bit number to the left. + */ + function rol(num, cnt) { + return (num << cnt) | (num >>> (32 - cnt)); + } + + return Sha1 + } + + +/***/ }, +/* 258 */ +/***/ function(module, exports, __webpack_require__) { + + + /** + * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined + * in FIPS 180-2 + * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009. + * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet + * + */ + + var inherits = __webpack_require__(263).inherits + var BE = false + var LE = true + var hexpp = __webpack_require__(262) + var u = __webpack_require__(261) + + module.exports = function (Buffer, Hash) { + + var K = [ + 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, + 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5, + 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, + 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174, + 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC, + 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA, + 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, + 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967, + 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, + 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85, + 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, + 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070, + 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, + 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3, + 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, + 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2 + ] + + inherits(Sha256, Hash) + var W = new Array(64) + var POOL = [] + function Sha256() { + if(POOL.length) { + //return POOL.shift().init() + } + //this._data = new Buffer(32) + + this.init() + + this._w = W //new Array(64) + + Hash.call(this, 16*4, 14*4) + }; + + Sha256.prototype.init = function () { + + this._a = 0x6a09e667|0 + this._b = 0xbb67ae85|0 + this._c = 0x3c6ef372|0 + this._d = 0xa54ff53a|0 + this._e = 0x510e527f|0 + this._f = 0x9b05688c|0 + this._g = 0x1f83d9ab|0 + this._h = 0x5be0cd19|0 + + this._len = this._s = 0 + + return this + } + + var safe_add = function(x, y) { + var lsw = (x & 0xFFFF) + (y & 0xFFFF); + var msw = (x >> 16) + (y >> 16) + (lsw >> 16); + return (msw << 16) | (lsw & 0xFFFF); + } + + function S (X, n) { + return (X >>> n) | (X << (32 - n)); + } + + function R (X, n) { + return (X >>> n); + } + + function Ch (x, y, z) { + return ((x & y) ^ ((~x) & z)); + } + + function Maj (x, y, z) { + return ((x & y) ^ (x & z) ^ (y & z)); + } + + function Sigma0256 (x) { + return (S(x, 2) ^ S(x, 13) ^ S(x, 22)); + } + + function Sigma1256 (x) { + return (S(x, 6) ^ S(x, 11) ^ S(x, 25)); + } + + function Gamma0256 (x) { + return (S(x, 7) ^ S(x, 18) ^ R(x, 3)); + } + + function Gamma1256 (x) { + return (S(x, 17) ^ S(x, 19) ^ R(x, 10)); + } + + Sha256.prototype._update = function(m) { + var M = this._block + var W = this._w + var a, b, c, d, e, f, g, h + var T1, T2 + + a = this._a | 0 + b = this._b | 0 + c = this._c | 0 + d = this._d | 0 + e = this._e | 0 + f = this._f | 0 + g = this._g | 0 + h = this._h | 0 + + for (var j = 0; j < 64; j++) { + var w = W[j] = j < 16 + ? M.readInt32BE(j * 4) + : Gamma1256(W[j - 2]) + W[j - 7] + Gamma0256(W[j - 15]) + W[j - 16] + + T1 = h + Sigma1256(e) + Ch(e, f, g) + K[j] + w + + T2 = Sigma0256(a) + Maj(a, b, c); + h = g; g = f; f = e; e = d + T1; d = c; c = b; b = a; a = T1 + T2; + } + + this._a = (a + this._a) | 0 + this._b = (b + this._b) | 0 + this._c = (c + this._c) | 0 + this._d = (d + this._d) | 0 + this._e = (e + this._e) | 0 + this._f = (f + this._f) | 0 + this._g = (g + this._g) | 0 + this._h = (h + this._h) | 0 + + }; + + Sha256.prototype._hash = function () { + if(POOL.length < 10) + POOL.push(this) + + var H = new Buffer(32) + + H.writeInt32BE(this._a, 0) + H.writeInt32BE(this._b, 4) + H.writeInt32BE(this._c, 8) + H.writeInt32BE(this._d, 12) + H.writeInt32BE(this._e, 16) + H.writeInt32BE(this._f, 20) + H.writeInt32BE(this._g, 24) + H.writeInt32BE(this._h, 28) + + return H + } + + return Sha256 + + } + + +/***/ }, +/* 259 */ +/***/ function(module, exports, __webpack_require__) { + + exports.read = function(buffer, offset, isLE, mLen, nBytes) { + var e, m, + eLen = nBytes * 8 - mLen - 1, + eMax = (1 << eLen) - 1, + eBias = eMax >> 1, + nBits = -7, + i = isLE ? (nBytes - 1) : 0, + d = isLE ? -1 : 1, + s = buffer[offset + i]; + + i += d; + + e = s & ((1 << (-nBits)) - 1); + s >>= (-nBits); + nBits += eLen; + for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8); + + m = e & ((1 << (-nBits)) - 1); + e >>= (-nBits); + nBits += mLen; + for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8); + + if (e === 0) { + e = 1 - eBias; + } else if (e === eMax) { + return m ? NaN : ((s ? -1 : 1) * Infinity); + } else { + m = m + Math.pow(2, mLen); + e = e - eBias; + } + return (s ? -1 : 1) * m * Math.pow(2, e - mLen); + }; + + exports.write = function(buffer, value, offset, isLE, mLen, nBytes) { + var e, m, c, + eLen = nBytes * 8 - mLen - 1, + eMax = (1 << eLen) - 1, + eBias = eMax >> 1, + rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0), + i = isLE ? 0 : (nBytes - 1), + d = isLE ? 1 : -1, + s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0; + + value = Math.abs(value); + + if (isNaN(value) || value === Infinity) { + m = isNaN(value) ? 1 : 0; + e = eMax; + } else { + e = Math.floor(Math.log(value) / Math.LN2); + if (value * (c = Math.pow(2, -e)) < 1) { + e--; + c *= 2; + } + if (e + eBias >= 1) { + value += rt / c; + } else { + value += rt * Math.pow(2, 1 - eBias); + } + if (value * c >= 2) { + e++; + c /= 2; + } + + if (e + eBias >= eMax) { + m = 0; + e = eMax; + } else if (e + eBias >= 1) { + m = (value * c - 1) * Math.pow(2, mLen); + e = e + eBias; + } else { + m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen); + e = 0; + } + } + + for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8); + + e = (e << mLen) | m; + eLen += mLen; + for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8); + + buffer[offset + i - d] |= s * 128; + }; + + +/***/ }, +/* 260 */ +/***/ function(module, exports, __webpack_require__) { + + var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; + + ;(function (exports) { + 'use strict'; + + var Arr = (typeof Uint8Array !== 'undefined') + ? Uint8Array + : Array + + var ZERO = '0'.charCodeAt(0) + var PLUS = '+'.charCodeAt(0) + var SLASH = '/'.charCodeAt(0) + var NUMBER = '0'.charCodeAt(0) + var LOWER = 'a'.charCodeAt(0) + var UPPER = 'A'.charCodeAt(0) + + function decode (elt) { + var code = elt.charCodeAt(0) + if (code === PLUS) + return 62 // '+' + if (code === SLASH) + return 63 // '/' + if (code < NUMBER) + return -1 //no match + if (code < NUMBER + 10) + return code - NUMBER + 26 + 26 + if (code < UPPER + 26) + return code - UPPER + if (code < LOWER + 26) + return code - LOWER + 26 + } + + function b64ToByteArray (b64) { + var i, j, l, tmp, placeHolders, arr + + if (b64.length % 4 > 0) { + throw new Error('Invalid string. Length must be a multiple of 4') + } + + // the number of equal signs (place holders) + // if there are two placeholders, than the two characters before it + // represent one byte + // if there is only one, then the three characters before it represent 2 bytes + // this is just a cheap hack to not do indexOf twice + var len = b64.length + placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0 + + // base64 is 4/3 + up to two characters of the original data + arr = new Arr(b64.length * 3 / 4 - placeHolders) + + // if there are placeholders, only get up to the last complete 4 chars + l = placeHolders > 0 ? b64.length - 4 : b64.length + + var L = 0 + + function push (v) { + arr[L++] = v + } + + for (i = 0, j = 0; i < l; i += 4, j += 3) { + tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3)) + push((tmp & 0xFF0000) >> 16) + push((tmp & 0xFF00) >> 8) + push(tmp & 0xFF) + } + + if (placeHolders === 2) { + tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4) + push(tmp & 0xFF) + } else if (placeHolders === 1) { + tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2) + push((tmp >> 8) & 0xFF) + push(tmp & 0xFF) + } + + return arr + } + + function uint8ToBase64 (uint8) { + var i, + extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes + output = "", + temp, length + + function encode (num) { + return lookup.charAt(num) + } + + function tripletToBase64 (num) { + return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F) + } + + // go through the array every three bytes, we'll deal with trailing stuff later + for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) { + temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]) + output += tripletToBase64(temp) + } + + // pad the end with zeros, but make sure to not forget the extra bytes + switch (extraBytes) { + case 1: + temp = uint8[uint8.length - 1] + output += encode(temp >> 2) + output += encode((temp << 4) & 0x3F) + output += '==' + break + case 2: + temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]) + output += encode(temp >> 10) + output += encode((temp >> 4) & 0x3F) + output += encode((temp << 2) & 0x3F) + output += '=' + break + } + + return output + } + + module.exports.toByteArray = b64ToByteArray + module.exports.fromByteArray = uint8ToBase64 + }()) + + +/***/ }, +/* 261 */ +/***/ function(module, exports, __webpack_require__) { + + exports.write = write + exports.zeroFill = zeroFill + + exports.toString = toString + + function write (buffer, string, enc, start, from, to, LE) { + var l = (to - from) + if(enc === 'ascii' || enc === 'binary') { + for( var i = 0; i < l; i++) { + buffer[start + i] = string.charCodeAt(i + from) + } + } + else if(enc == null) { + for( var i = 0; i < l; i++) { + buffer[start + i] = string[i + from] + } + } + else if(enc === 'hex') { + for(var i = 0; i < l; i++) { + var j = from + i + buffer[start + i] = parseInt(string[j*2] + string[(j*2)+1], 16) + } + } + else if(enc === 'base64') { + throw new Error('base64 encoding not yet supported') + } + else + throw new Error(enc +' encoding not yet supported') + } + + //always fill to the end! + function zeroFill(buf, from) { + for(var i = from; i < buf.length; i++) + buf[i] = 0 + } + + + +/***/ }, +/* 262 */ +/***/ function(module, exports, __webpack_require__) { + + /* WEBPACK VAR INJECTION */(function(module, Buffer) { + + function toHex (buf, group, wrap, LE) { + buf = buf.buffer || buf + var s = '' + var l = buf.byteLength || buf.length + for(var i = 0; i < l ; i++) { + var byte = (i&0xfffffffc)|(!LE ? i%4 : 3 - i%4) + s = s + ((buf[byte]>>4).toString(16)) + + ((buf[byte]&0xf).toString(16)) + + (group-1==i%group ? ' ' : '') + + (wrap-1==i%wrap ? '\n' : '') + } + return s + } + + function reverseByteOrder(n) { + return ( + ((n << 24) & 0xff000000) + | ((n << 8) & 0x00ff0000) + | ((n >> 8) & 0x0000ff00) + | ((n >> 24) & 0x000000ff) + ) + } + + var hexpp = module.exports = function (buffer, opts) { + opts = opts || {} + opts.groups = opts.groups || 4 + opts.wrap = opts.wrap || 16 + return toHex(buffer, opts.groups, opts.wrap, opts.bigendian, opts.ints) + } + + hexpp.defaults = function (opts) { + return function (b) { + return hexpp(b, opts) + } + } + + if(!module.parent) { + var b = new Buffer (64) + console.log(hexpp(b)) + console.log(hexpp(b, {bigendian: true})) + } + + + /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(247)(module), __webpack_require__(252).Buffer)) + +/***/ }, +/* 263 */ +/***/ function(module, exports, __webpack_require__) { + + /* WEBPACK VAR INJECTION */(function(global, process) {// Copyright Joyent, Inc. and other Node contributors. + // + // Permission is hereby granted, free of charge, to any person obtaining a + // copy of this software and associated documentation files (the + // "Software"), to deal in the Software without restriction, including + // without limitation the rights to use, copy, modify, merge, publish, + // distribute, sublicense, and/or sell copies of the Software, and to permit + // persons to whom the Software is furnished to do so, subject to the + // following conditions: + // + // The above copyright notice and this permission notice shall be included + // in all copies or substantial portions of the Software. + // + // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + // USE OR OTHER DEALINGS IN THE SOFTWARE. + + var formatRegExp = /%[sdj%]/g; + exports.format = function(f) { + if (!isString(f)) { + var objects = []; + for (var i = 0; i < arguments.length; i++) { + objects.push(inspect(arguments[i])); + } + return objects.join(' '); + } + + var i = 1; + var args = arguments; + var len = args.length; + var str = String(f).replace(formatRegExp, function(x) { + if (x === '%%') return '%'; + if (i >= len) return x; + switch (x) { + case '%s': return String(args[i++]); + case '%d': return Number(args[i++]); + case '%j': + try { + return JSON.stringify(args[i++]); + } catch (_) { + return '[Circular]'; + } + default: + return x; + } + }); + for (var x = args[i]; i < len; x = args[++i]) { + if (isNull(x) || !isObject(x)) { + str += ' ' + x; + } else { + str += ' ' + inspect(x); + } + } + return str; + }; + + + // Mark that a method should not be used. + // Returns a modified function which warns once by default. + // If --no-deprecation is set, then it is a no-op. + exports.deprecate = function(fn, msg) { + // Allow for deprecating things in the process of starting up. + if (isUndefined(global.process)) { + return function() { + return exports.deprecate(fn, msg).apply(this, arguments); + }; + } + + if (process.noDeprecation === true) { + return fn; + } + + var warned = false; + function deprecated() { + if (!warned) { + if (process.throwDeprecation) { + throw new Error(msg); + } else if (process.traceDeprecation) { + console.trace(msg); + } else { + console.error(msg); + } + warned = true; + } + return fn.apply(this, arguments); + } + + return deprecated; + }; + + + var debugs = {}; + var debugEnviron; + exports.debuglog = function(set) { + if (isUndefined(debugEnviron)) + debugEnviron = process.env.NODE_DEBUG || ''; + set = set.toUpperCase(); + if (!debugs[set]) { + if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) { + var pid = process.pid; + debugs[set] = function() { + var msg = exports.format.apply(exports, arguments); + console.error('%s %d: %s', set, pid, msg); + }; + } else { + debugs[set] = function() {}; + } + } + return debugs[set]; + }; + + + /** + * Echos the value of a value. Trys to print the value out + * in the best way possible given the different types. + * + * @param {Object} obj The object to print out. + * @param {Object} opts Optional options object that alters the output. + */ + /* legacy: obj, showHidden, depth, colors*/ + function inspect(obj, opts) { + // default options + var ctx = { + seen: [], + stylize: stylizeNoColor + }; + // legacy... + if (arguments.length >= 3) ctx.depth = arguments[2]; + if (arguments.length >= 4) ctx.colors = arguments[3]; + if (isBoolean(opts)) { + // legacy... + ctx.showHidden = opts; + } else if (opts) { + // got an "options" object + exports._extend(ctx, opts); + } + // set default options + if (isUndefined(ctx.showHidden)) ctx.showHidden = false; + if (isUndefined(ctx.depth)) ctx.depth = 2; + if (isUndefined(ctx.colors)) ctx.colors = false; + if (isUndefined(ctx.customInspect)) ctx.customInspect = true; + if (ctx.colors) ctx.stylize = stylizeWithColor; + return formatValue(ctx, obj, ctx.depth); + } + exports.inspect = inspect; + + + // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics + inspect.colors = { + 'bold' : [1, 22], + 'italic' : [3, 23], + 'underline' : [4, 24], + 'inverse' : [7, 27], + 'white' : [37, 39], + 'grey' : [90, 39], + 'black' : [30, 39], + 'blue' : [34, 39], + 'cyan' : [36, 39], + 'green' : [32, 39], + 'magenta' : [35, 39], + 'red' : [31, 39], + 'yellow' : [33, 39] + }; + + // Don't use 'blue' not visible on cmd.exe + inspect.styles = { + 'special': 'cyan', + 'number': 'yellow', + 'boolean': 'yellow', + 'undefined': 'grey', + 'null': 'bold', + 'string': 'green', + 'date': 'magenta', + // "name": intentionally not styling + 'regexp': 'red' + }; + + + function stylizeWithColor(str, styleType) { + var style = inspect.styles[styleType]; + + if (style) { + return '\u001b[' + inspect.colors[style][0] + 'm' + str + + '\u001b[' + inspect.colors[style][1] + 'm'; + } else { + return str; + } + } + + + function stylizeNoColor(str, styleType) { + return str; + } + + + function arrayToHash(array) { + var hash = {}; + + array.forEach(function(val, idx) { + hash[val] = true; + }); + + return hash; + } + + + function formatValue(ctx, value, recurseTimes) { + // Provide a hook for user-specified inspect functions. + // Check that value is an object with an inspect function on it + if (ctx.customInspect && + value && + isFunction(value.inspect) && + // Filter out the util module, it's inspect function is special + value.inspect !== exports.inspect && + // Also filter out any prototype objects using the circular check. + !(value.constructor && value.constructor.prototype === value)) { + var ret = value.inspect(recurseTimes, ctx); + if (!isString(ret)) { + ret = formatValue(ctx, ret, recurseTimes); + } + return ret; + } + + // Primitive types cannot have properties + var primitive = formatPrimitive(ctx, value); + if (primitive) { + return primitive; + } + + // Look up the keys of the object. + var keys = Object.keys(value); + var visibleKeys = arrayToHash(keys); + + if (ctx.showHidden) { + keys = Object.getOwnPropertyNames(value); + } + + // IE doesn't make error fields non-enumerable + // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx + if (isError(value) + && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) { + return formatError(value); + } + + // Some type of object without properties can be shortcutted. + if (keys.length === 0) { + if (isFunction(value)) { + var name = value.name ? ': ' + value.name : ''; + return ctx.stylize('[Function' + name + ']', 'special'); + } + if (isRegExp(value)) { + return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); + } + if (isDate(value)) { + return ctx.stylize(Date.prototype.toString.call(value), 'date'); + } + if (isError(value)) { + return formatError(value); + } + } + + var base = '', array = false, braces = ['{', '}']; + + // Make Array say that they are Array + if (isArray(value)) { + array = true; + braces = ['[', ']']; + } + + // Make functions say that they are functions + if (isFunction(value)) { + var n = value.name ? ': ' + value.name : ''; + base = ' [Function' + n + ']'; + } + + // Make RegExps say that they are RegExps + if (isRegExp(value)) { + base = ' ' + RegExp.prototype.toString.call(value); + } + + // Make dates with properties first say the date + if (isDate(value)) { + base = ' ' + Date.prototype.toUTCString.call(value); + } + + // Make error with message first say the error + if (isError(value)) { + base = ' ' + formatError(value); + } + + if (keys.length === 0 && (!array || value.length == 0)) { + return braces[0] + base + braces[1]; + } + + if (recurseTimes < 0) { + if (isRegExp(value)) { + return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); + } else { + return ctx.stylize('[Object]', 'special'); + } + } + + ctx.seen.push(value); + + var output; + if (array) { + output = formatArray(ctx, value, recurseTimes, visibleKeys, keys); + } else { + output = keys.map(function(key) { + return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array); + }); + } + + ctx.seen.pop(); + + return reduceToSingleString(output, base, braces); + } + + + function formatPrimitive(ctx, value) { + if (isUndefined(value)) + return ctx.stylize('undefined', 'undefined'); + if (isString(value)) { + var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '') + .replace(/'/g, "\\'") + .replace(/\\"/g, '"') + '\''; + return ctx.stylize(simple, 'string'); + } + if (isNumber(value)) + return ctx.stylize('' + value, 'number'); + if (isBoolean(value)) + return ctx.stylize('' + value, 'boolean'); + // For some reason typeof null is "object", so special case here. + if (isNull(value)) + return ctx.stylize('null', 'null'); + } + + + function formatError(value) { + return '[' + Error.prototype.toString.call(value) + ']'; + } + + + function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { + var output = []; + for (var i = 0, l = value.length; i < l; ++i) { + if (hasOwnProperty(value, String(i))) { + output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, + String(i), true)); + } else { + output.push(''); + } + } + keys.forEach(function(key) { + if (!key.match(/^\d+$/)) { + output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, + key, true)); + } + }); + return output; + } + + + function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { + var name, str, desc; + desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] }; + if (desc.get) { + if (desc.set) { + str = ctx.stylize('[Getter/Setter]', 'special'); + } else { + str = ctx.stylize('[Getter]', 'special'); + } + } else { + if (desc.set) { + str = ctx.stylize('[Setter]', 'special'); + } + } + if (!hasOwnProperty(visibleKeys, key)) { + name = '[' + key + ']'; + } + if (!str) { + if (ctx.seen.indexOf(desc.value) < 0) { + if (isNull(recurseTimes)) { + str = formatValue(ctx, desc.value, null); + } else { + str = formatValue(ctx, desc.value, recurseTimes - 1); + } + if (str.indexOf('\n') > -1) { + if (array) { + str = str.split('\n').map(function(line) { + return ' ' + line; + }).join('\n').substr(2); + } else { + str = '\n' + str.split('\n').map(function(line) { + return ' ' + line; + }).join('\n'); + } + } + } else { + str = ctx.stylize('[Circular]', 'special'); + } + } + if (isUndefined(name)) { + if (array && key.match(/^\d+$/)) { + return str; + } + name = JSON.stringify('' + key); + if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { + name = name.substr(1, name.length - 2); + name = ctx.stylize(name, 'name'); + } else { + name = name.replace(/'/g, "\\'") + .replace(/\\"/g, '"') + .replace(/(^"|"$)/g, "'"); + name = ctx.stylize(name, 'string'); + } + } + + return name + ': ' + str; + } + + + function reduceToSingleString(output, base, braces) { + var numLinesEst = 0; + var length = output.reduce(function(prev, cur) { + numLinesEst++; + if (cur.indexOf('\n') >= 0) numLinesEst++; + return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1; + }, 0); + + if (length > 60) { + return braces[0] + + (base === '' ? '' : base + '\n ') + + ' ' + + output.join(',\n ') + + ' ' + + braces[1]; + } + + return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; + } + + + // NOTE: These type checking functions intentionally don't use `instanceof` + // because it is fragile and can be easily faked with `Object.create()`. + function isArray(ar) { + return Array.isArray(ar); + } + exports.isArray = isArray; + + function isBoolean(arg) { + return typeof arg === 'boolean'; + } + exports.isBoolean = isBoolean; + + function isNull(arg) { + return arg === null; + } + exports.isNull = isNull; + + function isNullOrUndefined(arg) { + return arg == null; + } + exports.isNullOrUndefined = isNullOrUndefined; + + function isNumber(arg) { + return typeof arg === 'number'; + } + exports.isNumber = isNumber; + + function isString(arg) { + return typeof arg === 'string'; + } + exports.isString = isString; + + function isSymbol(arg) { + return typeof arg === 'symbol'; + } + exports.isSymbol = isSymbol; + + function isUndefined(arg) { + return arg === void 0; + } + exports.isUndefined = isUndefined; + + function isRegExp(re) { + return isObject(re) && objectToString(re) === '[object RegExp]'; + } + exports.isRegExp = isRegExp; + + function isObject(arg) { + return typeof arg === 'object' && arg !== null; + } + exports.isObject = isObject; + + function isDate(d) { + return isObject(d) && objectToString(d) === '[object Date]'; + } + exports.isDate = isDate; + + function isError(e) { + return isObject(e) && + (objectToString(e) === '[object Error]' || e instanceof Error); + } + exports.isError = isError; + + function isFunction(arg) { + return typeof arg === 'function'; + } + exports.isFunction = isFunction; + + function isPrimitive(arg) { + return arg === null || + typeof arg === 'boolean' || + typeof arg === 'number' || + typeof arg === 'string' || + typeof arg === 'symbol' || // ES6 symbol + typeof arg === 'undefined'; + } + exports.isPrimitive = isPrimitive; + + exports.isBuffer = __webpack_require__(264); + + function objectToString(o) { + return Object.prototype.toString.call(o); + } + + + function pad(n) { + return n < 10 ? '0' + n.toString(10) : n.toString(10); + } + + + var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', + 'Oct', 'Nov', 'Dec']; + + // 26 Feb 16:19:34 + function timestamp() { + var d = new Date(); + var time = [pad(d.getHours()), + pad(d.getMinutes()), + pad(d.getSeconds())].join(':'); + return [d.getDate(), months[d.getMonth()], time].join(' '); + } + + + // log is just a thin wrapper to console.log that prepends a timestamp + exports.log = function() { + console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments)); + }; + + + /** + * Inherit the prototype methods from one constructor into another. + * + * The Function.prototype.inherits from lang.js rewritten as a standalone + * function (not on Function.prototype). NOTE: If this file is to be loaded + * during bootstrapping this function needs to be rewritten using some native + * functions as prototype setup using normal JavaScript does not work as + * expected during bootstrapping (see mirror.js in r114903). + * + * @param {function} ctor Constructor function which needs to inherit the + * prototype. + * @param {function} superCtor Constructor function to inherit prototype from. + */ + exports.inherits = __webpack_require__(266); + + exports._extend = function(origin, add) { + // Don't do anything if add isn't an object + if (!add || !isObject(add)) return origin; + + var keys = Object.keys(add); + var i = keys.length; + while (i--) { + origin[keys[i]] = add[keys[i]]; + } + return origin; + }; + + function hasOwnProperty(obj, prop) { + return Object.prototype.hasOwnProperty.call(obj, prop); + } + + /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }()), __webpack_require__(265))) + +/***/ }, +/* 264 */ +/***/ function(module, exports, __webpack_require__) { + + module.exports = function isBuffer(arg) { + return arg && typeof arg === 'object' + && typeof arg.copy === 'function' + && typeof arg.fill === 'function' + && typeof arg.readUInt8 === 'function'; + } + +/***/ }, +/* 265 */ +/***/ function(module, exports, __webpack_require__) { + + // shim for using process in browser + + var process = module.exports = {}; + + process.nextTick = (function () { + var canSetImmediate = typeof window !== 'undefined' + && window.setImmediate; + var canPost = typeof window !== 'undefined' + && window.postMessage && window.addEventListener + ; + + if (canSetImmediate) { + return function (f) { return window.setImmediate(f) }; + } + + if (canPost) { + var queue = []; + window.addEventListener('message', function (ev) { + var source = ev.source; + if ((source === window || source === null) && ev.data === 'process-tick') { + ev.stopPropagation(); + if (queue.length > 0) { + var fn = queue.shift(); + fn(); + } + } + }, true); + + return function nextTick(fn) { + queue.push(fn); + window.postMessage('process-tick', '*'); + }; + } + + return function nextTick(fn) { + setTimeout(fn, 0); + }; + })(); + + process.title = 'browser'; + process.browser = true; + process.env = {}; + process.argv = []; + + function noop() {} + + process.on = noop; + process.once = noop; + process.off = noop; + process.emit = noop; + + process.binding = function (name) { + throw new Error('process.binding is not supported'); + } + + // TODO(shtylman) + process.cwd = function () { return '/' }; + process.chdir = function (dir) { + throw new Error('process.chdir is not supported'); + }; + + +/***/ }, +/* 266 */ +/***/ function(module, exports, __webpack_require__) { + + if (typeof Object.create === 'function') { + // implementation from standard node.js 'util' module + module.exports = function inherits(ctor, superCtor) { + ctor.super_ = superCtor + ctor.prototype = Object.create(superCtor.prototype, { + constructor: { + value: ctor, + enumerable: false, + writable: true, + configurable: true + } + }); + }; + } else { + // old school shim for old browsers + module.exports = function inherits(ctor, superCtor) { + ctor.super_ = superCtor + var TempCtor = function () {} + TempCtor.prototype = superCtor.prototype + ctor.prototype = new TempCtor() + ctor.prototype.constructor = ctor + } + } + + /***/ } /******/ ]) }) diff --git a/dist/math.map b/dist/math.map index 9188c72f4..ba4165deb 100644 --- a/dist/math.map +++ b/dist/math.map @@ -1 +1 @@ -{"version":3,"file":"math.map","sources":["./dist/math.js"],"names":["root","factory","exports","module","define","amd","this","modules","__webpack_require__","moduleId","installedModules","id","loaded","call","m","c","p","mathjs","settings","Object","create","Error","math","_settings","matrix","number","config","BigNumber","object","deepExtend","decimals","DECIMAL_PLACES","defaultType","precision","current","clone","expression","node","parse","Scope","Parser","docs","type","Complex","Range","Index","Matrix","Unit","Help","collection","chaining","Selector","pi","Math","PI","e","E","tau","i","Infinity","NaN","LN2","LN10","LOG2E","LOG10E","SQRT1_2","SQRT2","x","undefined","Array","isArray","map","value","Number","valueOf","String","Boolean","Date","RegExp","TypeError","key","hasOwnProperty","extend","a","b","prop","constructor","deepEqual","len","length","expr","nodes","arguments","SyntaxError","extra_nodes","isString","parseStart","deepMap","elem","first","index","charAt","next","nextPreview","getToken","token_type","TOKENTYPE","NULL","token","DELIMITER","c2","DELIMITERS","isDigitDot","isAlpha","isDigit","NAMED_DELIMITERS","SYMBOL","UNKNOWN","createSyntaxError","NUMBER","skipNewlines","parseBlock","createError","block","visible","ConstantNode","parseAns","BlockNode","add","parseFunctionAssignment","name","AssignmentNode","parseAssignment","args","parseRange","SymbolNode","IndexNode","UpdateNode","ParamsNode","valid","params","forEach","param","FunctionNode","parseBitwiseConditions","push","step","RangeNode","parseComparison","operators","fn","parseConditions","==","!=","<",">","<=",">=","OperatorNode","parseAddSubtract","to","in","parseMultiplyDivide","+","-","parseUnit","*",".*","/","./","%","mod","symbol","parseUnary","UnitNode","parsePow","leftNode","ops","parseLeftHandOperators","pop","parseCustomNodes","!","'","handler","parseSymbol","parseParams","parseString","bracket","str","tPrev","parseMatrix","array","rows","cols","row","parseRow","r","ArrayNode","parseNumber","parseParentheses","parseEnd","col","createErrorMessage","message","util","toNumber","string","types",",","(",")","[","]","\"","\n",";","^",".^","=",":","scope","_parse","prototype","compile","eval","get","set","remove","clear","Node","abs","ceil","compare","cube","divide","edivide","emultiply","epow","exp","fix","floor","gcd","larger","largereq","lcm","log","log10","multiply","pow","round","sign","smaller","smallereq","sqrt","square","subtract","unary","unequal","xgcd","arg","conj","re","im","bignumber","complex","unit","help","det","diag","eye","inv","ones","range","resize","size","squeeze","subset","transpose","zeros","combinations","distribution","factorial","permutations","pickRandom","random","randomInt","max","mean","median","min","prod","std","sum","acos","asin","atan","atan2","cos","cot","csc","sec","sin","tan","format","ifElse","isNumber","skipWhitespace","text","revert","oldIndex","parseComplex","cnext","isComplex","separator","second","substring","equals","other","options","strRe","strIm","toString","start","end","parseFloat","split","nums","invalid","some","num","isNaN","isRange","diff","callback","obj","toArray","_ranges","ii","_createRange","isInteger","validateIndex","isIndex","ranges","apply","values","dim","isScalar","strings","join","data","_data","preprocess","_size","_get","RangeError","submatrix","_getSubmatrix","shift","dims","last","child","_set","defaultValue","sSize","iSize","unshift","_fit","_setSubmatrix","dataIndex","subIndex","newSize","changed","isMatrix","replacement","index_i","me","recurse","res","_findUnit","prefix","UNIT_NONE","PREFIX_NONE","_normalize","fixPrefix","UNITS","endsWith","prefixLen","prefixName","prefixes","isUnit","offset","_unnormalize","prefixValue","isPlainUnit","hasBase","base","equalBase","plainUnit","_bestPrefix","bestPrefix","absValue","bestDiff","scientific","PREFIXES","NONE","SHORT","da","h","k","M","G","T","P","Z","Y","d","u","n","f","z","y","LONG","deca","hecto","kilo","mega","giga","tera","peta","exa","zetta","yotta","deci","centi","milli","micro","nano","pico","femto","atto","zepto","yocto","SQUARED","CUBIC","BINARY_SHORT","Ki","Mi","Gi","Ti","Pi","Ei","Zi","Yi","BINARY_LONG","kibi","mebi","gibi","tebi","pebi","exi","zebi","yobi","BASE_UNITS","LENGTH","MASS","TIME","CURRENT","TEMPERATURE","LUMINOUS_INTENSITY","AMOUNT_OF_SUBSTANCE","FORCE","SURFACE","VOLUME","ANGLE","BIT","BASE_UNIT_NONE","meter","inch","foot","yard","mile","link","rod","chain","angstrom","ft","yd","mi","li","rd","ch","mil","m2","sqin","sqft","sqyd","sqmi","sqrd","sqch","sqmil","m3","L","l","litre","cuin","cuft","cuyd","teaspoon","tablespoon","minim","fluiddram","fluidounce","gill","cc","cup","pint","quart","gallon","beerbarrel","oilbarrel","hogshead","fldr","floz","gi","cp","pt","qt","gal","bbl","obl","g","gram","ton","tonne","grain","dram","ounce","poundmass","hundredweight","stick","gr","dr","oz","lbm","cwt","s","minute","hour","day","rad","deg","grad","cycle","A","ampere","K","degC","degF","degR","kelvin","celsius","fahrenheit","rankine","mol","mole","cd","candela","N","newton","lbf","poundforce","bits","B","bytes","PLURALS","meters","inches","feet","yards","miles","links","rods","chains","angstroms","litres","teaspoons","tablespoons","minims","fluiddrams","fluidounces","gills","cups","pints","quarts","gallons","beerbarrels","oilbarrels","hogsheads","grams","tons","tonnes","grains","drams","ounces","poundmasses","hundredweights","sticks","seconds","minutes","hours","days","radians","degrees","gradients","cycles","amperes","moles","plural","lt","liter","liters","lb","doc","isHelp","desc","category","description","syntax","examples","parser","seealso","toJSON","_reduce","mat","ret","val","tran","_switch","j","I","J","tmp","argsToArray","slice","isCollection","deepMap2","array1","array2","reduce","deepForEach","error","UnsupportedTypeError","value1","type1","splice","stack","ArgumentsError","count","createProxy","concat","done","search","isBoolean","toBigNumber","plus","cmp","times","_divideComplex","den","div","epsilon","DBL_EPSILON","_nearlyEqual","equal","eq","isNegative","gt","gte","t","_mod","_multiplyMatrixMatrix","result","_multiplyVectorMatrix","_multiplyMatrixVector","_multiplyVectorVector","dot","_multiplyComplex","sizeX","sizeY","powComplex","temp1","temp2","px","roundNumber","lte","minus","neg","_xgcd","q","lastx","lasty","bool","isZero","lcase","toLowerCase","select","_concat","concatDim","prevDim","asMatrix","matrices","_det","lead","temp","vector","iMax","asArray","kSuper","kSub","asBigNumber","one","minimum","_inv","Ac","Bc","Ar","Br","_range","_rangeInc","_bigRange","zero","_bigRangeInc","err","includeEnd","_resizeString","defaultChar","_getSubset","_getSubstring","substr","strLen","v","_setSubset","_setSubstring","chars","transposedRow","transposed","isPositiveInteger","distributions","uniform","normal","u1","u2","picked","randFunctions","arg1","arg2","arg3","_randomDataForMatrix","_random","_randomInt","possibles","randFunc","uniformRandFunctions","arity","dividedBy","_getSmaller","_min","_getLarger","_max","_nmean","_mean","_median","flat","flatten","sort","left","right","middle","_prod","variance","_sum","_var","normalization","DEFAULT_NORMALIZATION","temp3","temp4","conditionalExpr","trueExpr","falseExpr","_import","override","wrap","isSupportedType","math_import","opts","_module","_mapArray","arrayIn","print","template","replace","original","keys","_forEachArray","__WEBPACK_AMD_DEFINE_RESULT__","global","isNum","digits","orig","isValid","test","setMode","ROUNDING_MODE","trim","ERRORS","outOfRange","ifExceptionsThrow","DIGITS","convert","indexOf","MAX_EXP","MIN_EXP","isErrors","method","nStr","baseOut","baseIn","strToArr","bIn","arrL","strL","arr","reverse","arrToStr","dvs","dvd","nArr","fracArr","fracBN","ONE","isOdd","dvsL","dvsT","remI","dvsZ","dvdI","dvdL","rem","remL","quo","qc","qi","dig","rnd","TO_EXP_NEG","dp","xc","isNeg","half","more","rm","MAX","MAX_POWER","TO_EXP_POS","parseInt","o","inRange","lo","hi","has","yc","xe","xs","ye","ys","xLTy","maxD","frac","n0","d0","d2","n1","d1","sd","every","isNode","_compile","defs","find","filter","results","match","js","variable","compileSubset","properties","someUseEnd","rangesUseEnd","useEnd","objectName","op","lhs","rhs","undef","code","defsCode","factoryCode","Function","formatArray","_validate","dimNext","_resize","oldLen","newLen","minLen","validate","unsqueeze","_isZero","_isBetween","lower","upper","notation","toFixed","toExponential","exponential","isBigNumber","oldScientific","EXPONENTIAL_AT","toPrecision","valueStr","webpackContext","req","webpackContextResolve","./clone","./clone.js","./forEach","./forEach.js","./format","./format.js","./ifElse","./ifElse.js","./import","./import.js","./map","./map.js","./print","./print.js","./typeof","./typeof.js","resolve"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;CA2BA,SAA2CA,EAAMC,GAC1B,gBAAZC,UAA0C,gBAAXC,QACxCA,OAAOD,QAAUD,IACQ,kBA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+e,SAAY,YACZE,QACE,QACA,gBAEFD,YAAe,qBACfE,UACE,QACA,UACA,UACA,YACA,cACA,eAEFE,SACE,cAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,UACR+e,SAAY,YACZE,QACE,SACA,iBAEFD,YAAe,kCACfE,UACE,yBACA,yBACA,UAEFE,SACE,WACA,YACA,YAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,YACR+e,SAAY,YACZE,QACE,SACA,mBAEFD,YAAe,oCACfE,UACE,yBACA,yBACA,UAEFE,SACE,WACA,SACA,aAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,OACR+e,SAAY,YACZE,QACE,SACA,cAEFD,YACI,+CACJE,UACE,yBACA,UAEFE,SACE,SAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,QACR+e,SAAY,YACZE,QACE,SACA,eAEFD,YACI,wFACJE,UACE,WACA,WACA,UACA,YACA,SACA,gBAEFE,SACE,UAAW,UAAW,SAAU,YAAa,WAAY,aAOxD,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,MACR+e,SAAY,aACZE,QACE,UAEFD,YAAe,qCACfE,UACE,WACA,UACA,gBACA,UACA,uDAEFE,SACE,SACA,WACA,SAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,MACR+e,SAAY,aACZE,QACE,UAEFD,YACI,qGACJE,UACE,WACA,WACA,YACA,aAEFE,SAAY,OAAQ,QAAS,WAM1B,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,QACR+e,SAAY,aACZE,QACE,YAEFD,YACI,yHACJE,UACE,aACA,aACA,eAEFE,SAAY,OAAQ,MAAO,WAMxB,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,MACR+e,SAAY,aACZE,QACE,YACA,qBAEFD,YAAe,uCACfE,UACE,aACA,aACA,oBAEFE,SAAa,MAAO,UAMjB,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,SACR+e,SAAY,YACZE,QACE,QACA,gBAEFD,YACI,2FACJE,UACE,QACA,UACA,UACA,YACA,UACA,UACA,iBAEFE,SACE,QAAS,UAAW,UAAW,YAAa,WAAY,aAOvD,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,WACR+e,SAAY,YACZE,QACE,SACA,kBAEFD,YACI,yGACJE,UACE,UACA,WACA,UACA,YACA,WAEFE,SACE,QAAS,UAAW,YAAa,UAAW,WAAY,aAOvD,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,MACR+e,SAAY,aACZE,QACE,aAEFD,YAAe,qCACfE,UACE,YACA,aACA,iBAEFE,SAAa,SAMV,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,MACR+e,SAAY,aACZE,QACE,SACA,gBAEFD,YAAe,8NACfE,UACE,WACA,eACA,SACA,SACA,gBACA,sBACA,oBACA,SAEFE,SACE,MACA,WAMC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,QACR+e,SAAY,aACZE,QACE,YAEFD,YAAe,4CACfE,UACE,cACA,SACA,cACA,sBACA,iBAEFE,SACE,MACA,SAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,MACR+e,SAAY,YACZE,QACE,QACA,UACA,aAEFD,YACI,gEACJE,UACE,QACA,SACA,WACA,4BACA,WACA,YAEFE,aAMG,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,WACR+e,SAAY,YACZE,QACE,QACA,kBAEFD,YAAe,uBACfE,UACE,YACA,YACA,YACA,cACA,cAEFE,SACE,YAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,MACR+e,SAAY,YACZE,QACE,QACA,aAEFD,YACI,uCACJE,UACE,UACA,QACA,oBAEFE,SACE,UAAW,UAAW,SAAU,YAAa,cAO5C,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,QACR+e,SAAY,aACZE,QACE,WACA,eAEFD,YACI,4LACJE,UACE,aACA,aACA,cACA,cACA,eACA,uBAEFE,SAAY,OAAQ,QAAS,SAM1B,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,OACR+e,SAAY,aACZE,QACE,WAEFD,YACI,iGACJE,UACE,YACA,aACA,WAEFE,SACE,SAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,UACR+e,SAAY,YACZE,QACE,QACA,iBAEFD,YACI,mGACJE,UACE,QACA,UACA,UACA,YACA,UACA,iBAEFE,SACE,QAAS,UAAW,SAAU,YAAa,WAAY,aAOtD,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,YACR+e,SAAY,YACZE,QACE,SACA,mBAEFD,YACI,0GACJE,UACE,UACA,WACA,UACA,YACA,WAEFE,SACE,QAAS,UAAW,SAAU,UAAW,WAAY,aAOpD,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,OACR+e,SAAY,aACZE,QACE,WAEFD,YACI,+EACJE,UACE,WACA,QACA,YAEFE,SACE,SACA,cAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,SACR+e,SAAY,aACZE,QACE,aAEFD,YACI,2DACJE,UACE,YACA,UACA,MACA,SAEFE,SACE,WACA,MACA,OACA,UAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,WACR+e,SAAY,YACZE,QACE,QACA,kBAEFD,YAAe,uBACfE,UACE,UACA,UACA,YACA,YACA,iBAEFE,SACE,SAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,QACR+e,SAAY,YACZE,QACE,KACA,YAEFD,YACI,+BACJE,UACE,OACA,WAEFE,SACE,MAAO,cAON,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,UACR+e,SAAY,YACZE,QACE,SACA,iBAEFD,YACI,uGACJE,UACE,WACA,WACA,UACA,YACA,SACA,eACA,kBAEFE,SACE,QAAS,UAAW,SAAU,YAAa,WAAY,aAOtD,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,OACR+e,SAAY,aACZE,QACE,cAEFD,YAAe,gEACfE,UACE,cACA,aACA,sBAEFE,SAAa,MAAO,SAMjB,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,MACR+e,SAAY,UACZE,QACE,UAEFD,YACI,iGACJE,UACE,cACA,cACA,eAEFE,SACE,KACA,KACA,OACA,SAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,OACR+e,SAAY,UACZE,QACE,WAEFD,YACI,gGACJE,UACE,eACA,eACA,eAEFE,SACE,KACA,KACA,MACA,SAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,KACR+e,SAAY,UACZE,QACE,SAEFD,YAAe,yCACfE,UACE,aACA,aACA,YACA,WAEFE,SACE,KACA,OACA,MACA,SAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,KACR+e,SAAY,UACZE,QACE,SAEFD,YAAe,8CACfE,UACE,aACA,aACA,YACA,WAEFE,SACE,KACA,OACA,MACA,SAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,YACR+e,SAAY,OACZE,QACE,gBAEFD,YACI,+CACJE,UACE,YACA,kCACA,mBACA,uBACA,8BAEFE,SACE,UAAW,UAAW,QAAS,SAAU,SAAU,UAOlD,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,UACR+e,SAAY,OACZE,QACE,IACA,cAEFD,YACI,6CACJE,UACE,aACA,aACA,aACA,kBACA,mBACA,yBAEFE,SACE,YAAa,UAAW,QAAS,SAAU,SAAU,SAAU,UAO9D,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,UACR+e,SAAY,OACZE,QACE,YACA,kBACA,mBAEFD,YACI,2BACJE,UACE,YACA,gBACA,qBAEFE,SACE,YAAa,UAAW,QAAS,SAAU,SAAU,SAAU,UAO9D,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,QACR+e,SAAY,OACZE,QACE,UACA,cACA,mBACA,yBACA,kCACA,+CAEFD,YACI,yDACJE,UACE,KACA,YACA,yBACA,UACA,eACA,4BAEFE,SACE,YAAa,UAAW,UAAW,UAAW,SAAU,QAAS,SAAU,UAO1E,SAASnnB,GAEdA,EA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D,SACLgI,KAAQ,YACR+e,SAAY,cACZE,QACE,KACA,gBAEFD,YAAe,mCACfE,UACE,KACA,YACA,MAEFE,aAMG,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,eACR+e,SAAY,cACZE,QACE,kBACA,sBAEFD,YAAe,kEACfE,UACE,kBACA,sBAEFE,SAAY,eAAgB,eAMzB,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,aACR+e,SAAY,cACZE,QACE,qBAEFD,YACI,0CACJE,UACE,mBACA,4BAEFE,SAAY,eAAgB,SAAU,eAMnC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,SACR+e,SAAY,cACZE,QACE,WACA,cACA,mBACA,eACA,oBACA,0BAEFD,YACI,0BACJE,UACE,WACA,iBACA,kBAEFE,SAAY,eAAgB,aAAc,eAMvC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,UACR+e,SAAY,cACZE,QACE,YACA,eACA,oBACA,gBACA,qBACA,2BAEFD,YACI,iCACJE,UACE,YACA,kBACA,uBAEFE,SAAY,eAAgB,aAAc,YAKvC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,MACR+e,SAAY,aACZE,QACE,oBACA,SACA,eAEFD,YAAe,iDACfE,UACE,kBACA,oBACA,uBACA,uBACA,gCACA,iCAEFE,SACE,OACA,SACA,MACA,OACA,MACA,MACA,SAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,OACR+e,SAAY,aACZE,QACE,qBACA,UACA,gBAEFD,YAAe,mDACfE,UACE,mBACA,qBACA,wBACA,wBACA,8BAEFE,SACE,MACA,SACA,MACA,OACA,MACA,MACA,SAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,SACR+e,SAAY,aACZE,QACE,uBACA,aAEFD,YAAe,mLACfE,UACE,kBACA,yBAEFE,SACE,MACA,OACA,MACA,OACA,MACA,MACA,SAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,MACR+e,SAAY,aACZE,QACE,oBACA,SACA,eAEFD,YAAe,iDACfE,UACE,kBACA,oBACA,uBACA,uBACA,gCACA,iCAEFE,SACE,MACA,OACA,SACA,OACA,MACA,MACA,SAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,OACR+e,SAAY,aACZE,QACE,qBACA,WAEFD,YAAe,qCACfE,UACE,gBACA,kBACA,sBAEFE,SACE,MACA,OACA,MACA,SACA,MACA,MACA,MACA,SAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,MACR+e,SAAY,aACZE,QACE,oBACA,SACA,yBAEFD,YAAe,4KACfE,UACE,eACA,oBACA,mCACA,8BACA,2BAEFE,SACE,MACA,OACA,MACA,SACA,MACA,OACA,MACA,SAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,MACR+e,SAAY,aACZE,QACE,oBACA,UAEFD,YAAe,iCACfE,UACE,kBACA,oBACA,qBAEFE,SACE,MACA,OACA,SACA,MACA,OACA,MACA,MACA,SAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,MACR+e,SAAY,aACZE,QACE,oBACA,SACA,yBAEFD,YAAe,gIACfE,UACE,eACA,oBACA,mCACA,8BACA,2BAEFE,SACE,MACA,OACA,MACA,SACA,MACA,OACA,MACA,SAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,OACR+e,SAAY,eACZE,QACE,WAEFD,YAAe,oDACfE,UACE,YACA,kBAEFE,SACE,MACA,OACA,UAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,OACR+e,SAAY,eACZE,QACE,WAEFD,YAAe,kDACfE,UACE,YACA,kBAEFE,SACE,MACA,OACA,UAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,OACR+e,SAAY,eACZE,QACE,WAEFD,YAAe,qDACfE,UACE,YACA,kBAEFE,SACE,MACA,OACA,UAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,QACR+e,SAAY,eACZE,QACE,eAEFD,YACI,qEACJE,UACE,mBACA,wBACA,iBACA,iBACA,eAEFE,SACE,MACA,MACA,SAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,MACR+e,SAAY,eACZE,QACE,UAEFD,YAAe,sCACfE,UACE,SACA,kBACA,eACA,cACA,2BAEFE,SACE,OACA,MACA,SAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,MACR+e,SAAY,eACZE,QACE,UAEFD,YAAe,6DACfE,UACE,SACA,cAEFE,SACE,MACA,MACA,SAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,MACR+e,SAAY,eACZE,QACE,UAEFD,YAAe,4DACfE,UACE,SACA,cAEFE,SACE,MACA,MACA,SAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,MACR+e,SAAY,eACZE,QACE,UAEFD,YAAe,0DACfE,UACE,SACA,cAEFE,SACE,MACA,MACA,SAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,MACR+e,SAAY,eACZE,QACE,UAEFD,YAAe,oCACfE,UACE,SACA,kBACA,cACA,cACA,2BAEFE,SACE,OACA,MACA,SAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,MACR+e,SAAY,eACZE,QACE,UAEFD,YAAe,uCACfE,UACE,WACA,sBACA,cACA,eAEFE,SACE,OACA,MACA,SAOC,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,KACR+e,SAAY,QACZE,QACE,YACA,eAEFD,YAAe,8BACfE,UACE,eACA,aACA,oBAEFE,aAMG,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,QACR+e,SAAY,QACZE,QACE,YAEFD,YAAe,sFACfE,UACE,aACA,gBACA,gBACA,sBACA,wBAEFE,aAMG,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,MACR+e,SAAY,QACZE,QACE,oBAEFD,YAAe,qHACfE,UACE,+DAEFE,aAMG,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,UACR+e,SAAY,QACZE,QACE,wBAEFD,YAAe,iFACfE,UACE,0DAEFE,aAMG,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,SACR+e,SAAY,QACZE,QACE,gBACA,4BAEFD,YAAe,wCACfE,UACE,cACA,iBACA,aACA,iBAEFE,SAAY,WAMT,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,SACR+e,SAAY,QACZE,QACE,gDAEFD,YAAe,gCACfE,UACE,yBAEFE,aAMG,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,SACR+e,SAAY,QACZE,QACE,kBAEFD,YAAe,gCACfE,UACE,oBACA,wBAEFE,aAMG,SAASnnB,GAEdA,EAAOD,SACLgI,KAAQ,SACR+e,SAAY,QACZE,QACE,aAEFD,YAAe,8BACfE,UACE,cACA,iBACA,iBACA,yBAEFE,aAMG,SAASnnB,EAAQD,GAOtBA,EAAQopB,UAAY,SAAmB9kB,GACrC,MAAQA,aAAiBI,UAA6B,iBAATJ"} \ No newline at end of file +{"version":3,"file":"math.map","sources":["./dist/math.js"],"names":["root","factory","exports","module","define","amd","this","modules","__webpack_require__","moduleId","installedModules","id","loaded","call","m","c","p","mathjs","config","Object","create","Error","math","_config","matrix","number","precision","epsilon","options","object","deepExtend","type","BigNumber","defaultType","decimals","clone","constructor","prototype","convert","digits","error","Complex","Range","Index","Matrix","Unit","Help","collection","expression","node","parse","Scope","Parser","docs","chaining","Selector","pi","Math","PI","e","E","tau","i","Infinity","NaN","LN2","LN10","LOG2E","LOG10E","SQRT1_2","SQRT2","x","undefined","Array","isArray","map","value","Number","valueOf","String","Boolean","Date","RegExp","TypeError","key","hasOwnProperty","extend","a","b","prop","deepEqual","len","length","ArgumentsError","DimensionError","IndexError","UnsupportedTypeError","re","im","SyntaxError","arguments","arg","construct","fromPolar","r","phi","isNumber","skipWhitespace","next","isDigitDot","isDigit","index","text","charAt","revert","oldIndex","parseNumber","parseComplex","cnext","util","isUnit","isString","string","isComplex","str","first","separator","second","substring","hasBase","BASE_UNITS","ANGLE","toNumber","cos","sin","toPolar","sqrt","atan2","equals","other","format","strRe","strIm","toString","start","end","step","parseFloat","array","args","split","nums","invalid","some","num","isNaN","isRange","size","diff","sign","ceil","min","max","forEach","callback","obj","toArray","_ranges","ii","push","_createRange","isInteger","validateIndex","isIndex","ranges","apply","range","values","dim","isScalar","row","strings","join","data","_data","preprocess","types","_size","_get","get","submatrix","_getSubmatrix","shift","dims","last","child","_set","defaultValue","sSize","iSize","set","unshift","_fit","_setSubmatrix","dataIndex","subIndex","newSize","changed","resize","elem","isMatrix","subset","replacement","index_i","me","recurse","name","res","_findUnit","unit","prefix","UNIT_NONE","PREFIX_NONE","_normalize","fixPrefix","parseUnit","unitName","UNITS","endsWith","prefixLen","prefixName","prefixes","err","offset","_unnormalize","prefixValue","isValuelessUnit","base","equalBase","to","valuelessUnit","bestPrefix","_bestPrefix","absValue","abs","bestDiff","log","scientific","PREFIXES","NONE","SHORT","da","h","k","M","G","T","P","Z","Y","d","u","n","f","z","y","LONG","deca","hecto","kilo","mega","giga","tera","peta","exa","zetta","yotta","deci","centi","milli","micro","nano","pico","femto","atto","zepto","yocto","SQUARED","CUBIC","BINARY_SHORT","pow","Ki","Mi","Gi","Ti","Pi","Ei","Zi","Yi","BINARY_LONG","kibi","mebi","gibi","tebi","pebi","exi","zebi","yobi","LENGTH","MASS","TIME","CURRENT","TEMPERATURE","LUMINOUS_INTENSITY","AMOUNT_OF_SUBSTANCE","FORCE","SURFACE","VOLUME","BIT","BASE_UNIT_NONE","meter","inch","foot","yard","mile","link","rod","chain","angstrom","in","ft","yd","mi","li","rd","ch","mil","m2","sqin","sqft","sqyd","sqmi","sqrd","sqch","sqmil","m3","L","l","litre","cuin","cuft","cuyd","teaspoon","tablespoon","minim","fluiddram","fluidounce","gill","cc","cup","pint","quart","gallon","beerbarrel","oilbarrel","hogshead","fldr","floz","gi","cp","pt","qt","gal","bbl","obl","g","gram","ton","tonne","grain","dram","ounce","poundmass","hundredweight","stick","gr","dr","oz","lbm","cwt","s","sec","minute","hour","day","rad","deg","grad","cycle","A","ampere","K","degC","degF","degR","kelvin","celsius","fahrenheit","rankine","mol","mole","cd","candela","N","newton","lbf","poundforce","bits","B","bytes","PLURALS","meters","inches","feet","yards","miles","links","rods","chains","angstroms","litres","teaspoons","tablespoons","minims","fluiddrams","fluidounces","gills","cups","pints","quarts","gallons","beerbarrels","oilbarrels","hogsheads","grams","tons","tonnes","grains","drams","ounces","poundmasses","hundredweights","sticks","seconds","minutes","hours","days","radians","degrees","gradients","cycles","amperes","moles","plural","lt","liter","liters","lb","lbs","doc","isHelp","desc","category","description","syntax","examples","parser","expr","eval","seealso","toJSON","_reduce","mat","ret","val","tran","_switch","j","I","J","tmp","argsToArray","slice","isCollection","deepMap","deepMap2","array1","array2","reduce","deepForEach","nodes","extra_nodes","parseStart","nextPreview","getToken","token_type","TOKENTYPE","NULL","token","DELIMITER","c2","DELIMITERS","isAlpha","NAMED_DELIMITERS","SYMBOL","UNKNOWN","createSyntaxError","NUMBER","skipNewlines","parseBlock","createError","block","visible","ConstantNode","parseAns","BlockNode","add","parseFunctionAssignment","AssignmentNode","parseAssignment","parseRange","SymbolNode","IndexNode","UpdateNode","ParamsNode","valid","params","param","FunctionNode","parseBitwiseConditions","RangeNode","parseIfElse","parseComparison","TernaryNode","operators","fn","parseConditions","==","!=","<",">","<=",">=","OperatorNode","parseAddSubtract","parseMultiplyDivide","+","-","*",".*","/","./","%","mod","symbol","parseUnary","UnitNode","parsePow","parseLeftHandOperators","parseCustomNodes","!","'","handler","parseSymbol","parseParams","parseString","bracket","tPrev","parseMatrix","rows","cols","parseRow","ArrayNode","parseParentheses","parseEnd","col","createErrorMessage","message",",","(",")","[","]","\"","\n",";","^",".^","=",":","?","scope","_parse","compile","remove","clear","Node","compare","cube","divide","edivide","emultiply","epow","exp","fix","floor","gcd","larger","largereq","lcm","log10","multiply","norm","round","smaller","smallereq","square","subtract","unary","unequal","xgcd","conj","bignumber","complex","help","det","diag","eye","inv","ones","squeeze","transpose","zeros","combinations","distribution","factorial","permutations","pickRandom","random","randomInt","mean","median","prod","std","sum","acos","asin","atan","cot","csc","tan","ifElse","createProxy","concat","done","search","isBoolean","plus","nearlyEqual","cmp","times","_divideComplex","den","div","equal","eq","isNegative","gt","gte","t","ln","_mod","isZero","_multiplyMatrixMatrix","result","_multiplyVectorMatrix","_multiplyMatrixVector","_multiplyVectorVector","dot","_multiplyComplex","sizeX","sizeY","RangeError","POSITIVE_INFINITY","v","NEGATIVE_INFINITY","rs","powComplex","temp1","temp2","px","roundNumber","toDecimalPlaces","lte","minus","neg","_xgcd","q","lastx","lasty","bool","lcase","toLowerCase","select","_concat","concatDim","prevDim","asMatrix","matrices","_det","compute_mu","mu","fa","vector","iMax","asArray","kSuper","kSub","asBigNumber","one","minimum","_inv","temp","Ac","Bc","Ar","Br","_range","_rangeInc","_bigRange","zero","_bigRangeInc","includeEnd","pop","_resizeString","defaultChar","_getSubset","_getSubstring","substr","strLen","_setSubset","_setSubstring","chars","transposedRow","transposed","isPositiveInteger","distributions","uniform","normal","u1","u2","picked","randFunctions","arg1","arg2","arg3","_randomDataForMatrix","_random","_randomInt","possibles","randFunc","uniformRandFunctions","arity","dividedBy","_getSmaller","_min","_getLarger","_max","_nmean","_mean","_median","flat","flatten","sort","left","right","middle","_prod","variance","_sum","_var","normalization","DEFAULT_NORMALIZATION","temp3","temp4","_ifElseCollection","condition","trueExpr","falseExpr","trueIsMatrix","falseIsMatrix","_import","override","wrap","isSupportedType","math_import","opts","_module","_mapArray","arrayIn","print","template","replace","original","keys","_forEachArray","__WEBPACK_AMD_DEFINE_RESULT__","global","checkRoundingDigits","rm","repeating","checkRM","method","Decimal","outOfRange","parseInt","ifExceptionsThrow","checkArg","MAX_DIGITS","pr","dp","xc","yc","ri","yL","yz","xi","xL","rL","qc","rnd","denom","guard","sd","rep","external","more","intPow","x1","x2","half","isNeg","convertBase","crypto","DecimalConstructor","NUMERALS","EXP_LIMIT","INT_POW_LIMIT","base10","inf","sd10","xLTy","xe","ye","reverse","pos","indexOf","sep1","sep2","arr","toFixed","maxD","d0","d2","frac","n0","n1","d1","yN","isFinite","strL","toBaseOut","baseIn","baseOut","arrL","maxOrMin","ltgt","DecimalFactory","parseDecimal","isValid","trim","isNum","orig","test","getMathRandom","getRandomValues","getRandomBytes","buf","rb","readDoubleBE","limit","ld","rand","count","stack","actual","expected","relation","splice","every","isNode","_compile","defs","find","filter","results","match","js","variable","compileSubset","properties","someUseEnd","rangesUseEnd","useEnd","objectName","op","lhs","rhs","undef","ops","code","defsCode","factoryCode","Function","formatArray","_validate","dimNext","_resize","oldLen","newLen","minLen","validate","unsqueeze","notation","toExponential","lower","upper","exponential","valueStr","toPrecision","DBL_EPSILON","EPSILON","webpackContext","req","webpackContextResolve","./clone","./clone.js","./forEach","./forEach.js","./format","./format.js","./ifElse","./ifElse.js","./import","./import.js","./map","./map.js","./print","./print.js","./typeof","./typeof.js","resolve","isBigNumber","toExpNeg","toExpPos","toSignificantDigits","each","Buffer","rng","createHash","createHmac","randomBytes","pbkdf2","pbkdf2Sync","webpackPolyfill","deprecate","paths","children","mathRNG","whatwgRNG","_global","buffer","toConstructor","buffers","update","enc","isBuffer","digest","md5","alg","Hmac","_opad","opad","_alg","_key","blocksize","zeroBuffer","ipad","_ipad","_hash","fill","password","salt","iterations","keylen","setTimeout","cb","HMAC","cplen","digtmp","itmp","out","copy","subject","encoding","noZero","stringtrim","coerce","byteLength","_useTypedArrays","_augment","Uint8Array","_isBuffer","isArrayish","readUInt8","write","_hexWrite","remaining","assert","byte","_charsWritten","_utf8Write","charsWritten","blitBuffer","utf8ToBytes","_asciiWrite","asciiToBytes","_binaryWrite","_base64Write","base64ToBytes","_utf16leWrite","utf16leToBytes","_base64Slice","base64","fromByteArray","_utf8Slice","decodeUtf8Char","fromCharCode","_asciiSlice","_binarySlice","_hexSlice","toHex","_utf16leSlice","_readUInt16","littleEndian","noAssert","_readUInt32","_readInt16","_readInt32","_readFloat","ieee754","read","_readDouble","_writeUInt16","verifuint","_writeUInt32","_writeInt16","verifsint","_writeInt32","_writeFloat","verifIEEE754","_writeDouble","clamp","byteArray","charCodeAt","encodeURIComponent","hi","lo","toByteArray","src","dst","decodeURIComponent","SlowBuffer","INSPECT_MAX_BYTES","poolSize","ArrayBuffer","foo","subarray","isEncoding","list","totalLength","item","swap","self","_arr","target","target_start","source","sliceLen","newBuf","console","writeUInt8","readUInt16LE","readUInt16BE","readUInt32LE","readUInt32BE","readInt8","readInt16LE","readInt16BE","readInt32LE","readInt32BE","readFloatLE","readFloatBE","readDoubleLE","writeUInt16LE","writeUInt16BE","writeUInt32LE","writeUInt32BE","writeInt8","writeInt16LE","writeInt16BE","writeInt32LE","writeInt32BE","writeFloatLE","writeFloatBE","writeDoubleLE","writeDoubleBE","inspect","toArrayBuffer","BP","toLocaleString","core_md5","olda","oldb","oldc","oldd","md5_ff","md5_gg","md5_hh","md5_ii","safe_add","md5_cmn","bit_rol","lsw","msw","cnt","helpers","hash","Alg","Hash","sha","sha1","sha256","bigEndian","intSize","toBuffer","hashSize","chrsz","zeroFill","blockSize","finalSize","_block","_finalSize","_blockSize","_len","_s","lengthOf","init","bl","_update","fl","Sha1","POOL","_w","W","_h","sha1_ft","sha1_kt","rol","inherits","C","D","Int32Array","_a","_b","_c","_d","_e","_POOL","DataView","X","w","H","Sha256","S","R","Ch","Maj","Sigma0256","Sigma1256","Gamma0256","Gamma1256","_f","_g","T1","T2","isLE","mLen","nBytes","eLen","eMax","eBias","nBits","rt","lookup","decode","elt","PLUS","SLASH","UPPER","LOWER","b64ToByteArray","b64","placeHolders","Arr","uint8ToBase64","uint8","encode","tripletToBase64","extraBytes","output","from","group","LE","hexpp","groups","bigendian","ints","defaults","parent","process","ctx","seen","stylize","stylizeNoColor","depth","colors","showHidden","_extend","isUndefined","customInspect","stylizeWithColor","formatValue","styleType","style","styles","arrayToHash","recurseTimes","isFunction","primitive","formatPrimitive","visibleKeys","getOwnPropertyNames","isError","formatError","isRegExp","isDate","braces","toUTCString","formatProperty","reduceToSingleString","simple","JSON","stringify","isNull","getOwnPropertyDescriptor","line","numLinesEst","prev","cur","ar","isNullOrUndefined","isSymbol","isObject","objectToString","isPrimitive","o","pad","timestamp","time","getHours","getMinutes","getSeconds","getDate","months","getMonth","formatRegExp","objects","_","msg","deprecated","warned","throwDeprecation","traceDeprecation","trace","noDeprecation","debugEnviron","debugs","debuglog","env","NODE_DEBUG","toUpperCase","pid","bold","italic","underline","inverse","white","grey","black","blue","cyan","green","magenta","red","yellow","special","boolean","null","date","regexp","origin","noop","nextTick","canSetImmediate","window","setImmediate","canPost","postMessage","addEventListener","queue","ev","stopPropagation","title","browser","argv","on","once","off","emit","binding","cwd","chdir","ctor","superCtor","super_","enumerable","writable","configurable","TempCtor"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;CA2BA,SAA2CA,EAAMC,GAC1B,gBAAZC,UAA0C,gBAAXC,QACxCA,OAAOD,QAAUD,IACQ,kBAAXG,SAAyBA,OAAOC,IAC9CD,OAAOH,GACmB,gBAAZC,SACdA,QAAgB,OAAID,IAEpBD,EAAa,OAAIC,KAChBK,KAAM,WACT,MAAgB,UAAUC,GAMhB,QAASC,GAAoBC,GAE5B,GAAGC,EAAiBD,GACnB,MAAOC,GAAiBD,GAAUP,OAGnC,IAAIC,GAASO,EAAiBD,IAC7BP,WACAS,GAAIF,EACJG,QAAQ,EAUT,OANAL,GAAQE,GAAUI,KAAKV,EAAOD,QAASC,EAAQA,EAAOD,QAASM,GAG/DL,EAAOS,QAAS,EAGTT,EAAOD,QAtBf,GAAIQ,KAqCJ,OAVAF,GAAoBM,EAAIP,EAGxBC,EAAoBO,EAAIL,EAGxBF,EAAoBQ,EAAI,GAIjBR,EAAoB,KAK/B,SAASL,EAAQD,EAASM,GAE/BL,EAAOD,QAAUM,EAAoB,IAKhC,SAASL,EAAQD,EAASM,GAqB/B,QAASS,GAAQC,GAEf,GAA6B,kBAAlBC,QAAOC,OAChB,KAAM,IAAIC,OAAM,gHAKlB,IAAIC,MAGAC,GAEFC,OAAQ,SA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AAe,iDACfE,UACE,kBACA,oBACA,uBACA,uBACA,gCACA,iCAEFI,SACE,MACA,OACA,SACA,OACA,MACA,MACA,SAOC,SAAS5d,GAEdA,EAAOD,SACLsN,KAAQ,OACRgQ,SAAY,aACZE,QACE,qBACA,WAEFD,YAAe,qCACfE,UACE,gBACA,kBACA,sBAEFI,SACE,MACA,OACA,MACA,SACA,MACA,MACA,MACA,SAOC,SAAS5d,GAEdA,EAAOD,SACLsN,KAAQ,MACRgQ,SAAY,aACZE,QACE,oBACA,SACA,yBAEFD,YAAe,4KACfE,UACE,eACA,oBACA,mCACA,8BACA,2BAEFI,SACE,MACA,OACA,MACA,SACA,MACA,OACA,MACA,SAOC,SAAS5d,GAEdA,EAAOD,SACLsN,KAAQ,MACRgQ,SAAY,aACZE,QACE,oBACA,UAEFD,YAAe,iCACfE,UACE,kBACA,oBACA,qBAEFI,SACE,MACA,OACA,SACA,MACA,OACA,MACA,MACA,SAOC,SAAS5d,GAEdA,EAAOD,SACLsN,KAAQ,MACRgQ,SAAY,aACZE,QACE,oBACA,SACA,yBAEFD,YAAe,gIACfE,UACE,eACA,oBACA,mCACA,8BACA,2BAEFI,SACE,MACA,OACA,MACA,SACA,MACA,OACA,MACA,SAOC,SAAS5d,GAEdA,EAAOD,SACLsN,KAAQ,OACRgQ,SAAY,eACZE,QACE,WAEFD,YAAe,oDACfE,UACE,YACA,kBAEFI,SACE,MACA,OACA,UAOC,SAAS5d,GAEdA,EAAOD,SACLsN,KAAQ,OACRgQ,SAAY,eACZE,QACE,WAEFD,YAAe,kDACfE,UACE,YACA,kBAEFI,SACE,MACA,OACA,UAOC,SAAS5d,GAEdA,EAAOD,SACLsN,KAAQ,OACRgQ,SAAY,eACZE,QACE,WAEFD,YAAe,qDACfE,UACE,YACA,kBAEFI,SACE,MACA,OACA,UAOC,SAAS5d,GAEdA,EAAOD,SACLsN,KAAQ,QACRgQ,SAAY,eACZE,QACE,eAEFD,YACI,qEACJE,UACE,mBACA,wBACA,iBACA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ACPG,YAAY,EACZC,UAAU,EACVC,cAAc,MAMH,SAAkBL,EAAMC,GACvCD,EAAKE,OAASD,CACd,IAAIK,GAAW,YACfA,GAASpzC,UAAY+yC,EAAU/yC,UAC/B8yC,EAAK9yC,UAAY,GAAIozC,GACrBN,EAAK9yC,UAAUD,YAAc+yC"} \ No newline at end of file diff --git a/dist/math.min.js b/dist/math.min.js index 623d211df..52b0ff8c6 100644 --- a/dist/math.min.js +++ b/dist/math.min.js @@ -6,8 +6,8 @@ * It features real and complex numbers, units, matrices, a large set of * mathematical functions, and a flexible expression parser. * - * @version 0.19.0 - * @date 2014-03-30 + * @version 0.20.0 + * @date 2014-04-16 * * @license * Copyright (C) 2013-2014 Jos de Jong @@ -24,10 +24,11 @@ * License for the specific language governing permissions and limitations under * the License. */ -!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):"object"==typeof exports?exports.mathjs=r():e.mathjs=r()}(this,function(){return function(e){function r(t){if(n[t])return n[t].exports;var i=n[t]={exports:{},id:t,loaded:!1};return e[t].call(i.exports,i,i.exports,r),i.loaded=!0,i.exports}var n={};return r.m=e,r.c=n,r.p="",r(0)}([function(e,r,n){e.exports=n(1)},function(e,r,n){function t(e){if("function"!=typeof Object.create)throw new Error("ES5 not supported by this JavaScript engine. Please load the es5-shim and es5-sham library for compatibility.");var r={},t={matrix:"matrix",number:"number"};return r.config=function(e){var r=n(111);if(e){if(i.deepExtend(t,e),e.decimals&&r.config({DECIMAL_PLACES:e.decimals}),e.number&&e.number.defaultType)throw new Error("setting `number.defaultType` is deprecated. Use `number` instead.");if(e.number&&e.number.precision)throw new Error("setting `number.precision` is deprecated. Use `decimals` instead.");if(e.matrix&&e.matrix.defaultType)throw new Error("setting `matrix.defaultType` is deprecated. Use `matrix` instead.");if(e.matrix&&e.matrix["default"])throw new Error("setting `matrix.default` is deprecated. Use `matrix` instead.")}var o=i.clone(t);return o.decimals=r.config().DECIMAL_PLACES,o},r.config(e),r.expression={},r.expression.node=n(6),r.expression.parse=n(4),r.expression.Scope=function(){throw new Error("Scope is deprecated. Use a regular Object instead")},r.expression.Parser=n(5),r.expression.docs=n(7),r.type={},r.type.BigNumber=n(111),r.type.Complex=n(8),r.type.Range=n(9),r.type.Index=n(10),r.type.Matrix=n(11),r.type.Unit=n(12),r.type.Help=n(13),r.collection=n(14),n(15)(r),n(17)(r,t),n(18)(r,t),n(19)(r,t),n(20)(r,t),n(21)(r,t),n(22)(r,t),n(23)(r,t),n(24)(r,t),n(25)(r,t),n(26)(r,t),n(27)(r,t),n(28)(r,t),n(29)(r,t),n(30)(r,t),n(31)(r,t),n(32)(r,t),n(33)(r,t),n(34)(r,t),n(35)(r,t),n(36)(r,t),n(37)(r,t),n(38)(r,t),n(39)(r,t),n(40)(r,t),n(41)(r,t),n(42)(r,t),n(43)(r,t),n(44)(r,t),n(45)(r,t),n(46)(r,t),n(47)(r,t),n(48)(r,t),n(49)(r,t),n(50)(r,t),n(51)(r,t),n(52)(r,t),n(53)(r,t),n(54)(r,t),n(55)(r,t),n(56)(r,t),n(57)(r,t),n(58)(r,t),n(59)(r,t),n(60)(r,t),n(61)(r,t),n(62)(r,t),n(63)(r,t),n(64)(r,t),n(65)(r,t),n(66)(r,t),n(67)(r,t),n(68)(r,t),n(69)(r,t),n(70)(r,t),n(71)(r,t),n(72)(r,t),n(73)(r,t),n(74)(r,t),n(75)(r,t),n(76)(r,t),n(77)(r,t),n(78)(r,t),n(79)(r,t),n(80)(r,t),n(81)(r,t),n(82)(r,t),n(83)(r,t),n(84)(r,t),n(85)(r,t),n(86)(r,t),n(87)(r,t),n(88)(r,t),n(89)(r,t),n(90)(r,t),n(91)(r,t),n(92)(r,t),n(93)(r,t),n(94)(r,t),n(95)(r,t),n(96)(r,t),n(97)(r,t),n(98)(r,t),n(99)(r,t),n(100)(r,t),n(101)(r,t),n(102)(r,t),n(103)(r,t),n(104)(r,t),n(105)(r,t),n(106)(r,t),n(107)(r,t),n(108)(r,t),n(109)(r,t),n(110)(r,t),n(2)(r,t),r.chaining={},r.chaining.Selector=n(16)(r,t),r}var i=n(3);e.exports=t},function(e,r,n){e.exports=function(e){var r=n(8);e.pi=Math.PI,e.e=Math.E,e.tau=2*Math.PI,e.i=new r(0,1),e.Infinity=1/0,e.NaN=0/0,e["true"]=!0,e["false"]=!1,e.E=Math.E,e.LN2=Math.LN2,e.LN10=Math.LN10,e.LOG2E=Math.LOG2E,e.LOG10E=Math.LOG10E,e.PI=Math.PI,e.SQRT1_2=Math.SQRT1_2,e.SQRT2=Math.SQRT2}},function(e,r){r.clone=function n(e){var r=typeof e;if("number"===r||"string"===r||"boolean"===r||null===e||void 0===e)return e;if("function"==typeof e.clone)return e.clone();if(Array.isArray(e))return e.map(function(e){return n(e)});if(e instanceof Number)return new Number(e.valueOf());if(e instanceof String)return new String(e.valueOf());if(e instanceof Boolean)return new Boolean(e.valueOf());if(e instanceof Date)return new Date(e.valueOf());if(e instanceof RegExp)throw new TypeError("Cannot clone "+e);var t={};for(var i in e)e.hasOwnProperty(i)&&(t[i]=n(e[i]));return t},r.extend=function(e,r){for(var n in r)r.hasOwnProperty(n)&&(e[n]=r[n]);return e},r.deepExtend=function t(e,r){if(Array.isArray(r))throw new TypeError("Arrays are not supported by deepExtend");for(var n in r)if(r.hasOwnProperty(n))if(r[n]&&r[n].constructor===Object)void 0===e[n]&&(e[n]={}),e[n].constructor===Object?t(e[n],r[n]):e[n]=r[n];else{if(Array.isArray(r[n]))throw new TypeError("Arrays are not supported by deepExtend");e[n]=r[n]}return e},r.deepEqual=function(e,n){var t,i,o;if(Array.isArray(e)){if(!Array.isArray(n))return!1;if(e.length!=n.length)return!1;for(i=0,o=e.length;o>i;i++)if(!r.deepEqual(e[i],n[i]))return!1;return!0}if(e instanceof Object){if(Array.isArray(n)||!(n instanceof Object))return!1;for(t in e)if(!r.deepEqual(e[t],n[t]))return!1;for(t in n)if(!r.deepEqual(e[t],n[t]))return!1;return!0}return typeof e==typeof n&&e==n}},function(e,r,n){function t(e,r){if(1!=arguments.length&&2!=arguments.length)throw new SyntaxError("Wrong number of arguments: 1 or 2 expected");if(sr="object"===D(r)?r:{},F(e))return ur=e,m();if(G(e)||e instanceof H)return V.deepMap(e,function(e){if(!F(e))throw new TypeError("String expected");return ur=e,m()});throw new TypeError("String or matrix expected")}function i(){fr=0,cr=ur.charAt(0)}function o(){fr++,cr=ur.charAt(fr)}function a(){return ur.charAt(fr+1)}function s(){for(mr=ir.NULL,lr="";" "==cr||" "==cr;)o();if("#"==cr)for(;"\n"!=cr&&""!=cr;)o();if(""==cr)return void(mr=ir.DELIMITER);var e=cr+a();if(or[e])return mr=ir.DELIMITER,lr=e,o(),void o();if(or[cr])return mr=ir.DELIMITER,lr=cr,void o();if(!c(cr)){if(f(cr)){for(;f(cr)||l(cr);)lr+=cr,o();return void(mr=ar[lr]?ir.DELIMITER:ir.SYMBOL)}for(mr=ir.UNKNOWN;""!=cr;)lr+=cr,o();throw j('Syntax error in part "'+lr+'"')}if(mr=ir.NUMBER,"."==cr)lr+=cr,o(),l(cr)||(mr=ir.UNKNOWN);else{for(;l(cr);)lr+=cr,o();"."==cr&&(lr+=cr,o())}for(;l(cr);)lr+=cr,o();if("E"==cr||"e"==cr)for(lr+=cr,o(),("+"==cr||"-"==cr)&&(lr+=cr,o()),l(cr)||(mr=ir.UNKNOWN);l(cr);)lr+=cr,o()}function u(){for(;"\n"==lr;)s()}function f(e){return e>="a"&&"z">=e||e>="A"&&"Z">=e||"_"==e}function c(e){return e>="0"&&"9">=e||"."==e}function l(e){return e>="0"&&"9">=e}function m(){i(),s();var e=p();if(""!=lr)throw mr==ir.DELIMITER?P("Unknown operator "+lr):j('Unexpected part "'+lr+'"');return e}function p(){var e,r,n;if(""==lr)return new Q("undefined","undefined");for("\n"!=lr&&";"!=lr&&(e=h());"\n"==lr||";"==lr;)r||(r=new Z,e&&(n=";"!=lr,r.add(e,n))),s(),"\n"!=lr&&";"!=lr&&""!=lr&&(e=h(),n=";"!=lr,r.add(e,n));return r?r:e}function h(){var e=g(),r="ans";return new Y(r,e)}function g(){if(mr==ir.SYMBOL&&"function"==lr)throw new Error('Deprecated keyword "function". Functions can now be assigned without it, like "f(x) = x^2".');return d()}function d(){var e,r,n,t=x();if("="==lr){if(t instanceof rr)return e=t.name,s(),n=d(),new Y(e,n);if(t instanceof $)return s(),n=d(),new tr(t,n);if(t instanceof J){var i=!0;if(r=[],t.object instanceof rr?(e=t.object.name,t.params.forEach(function(e,n){e instanceof rr?r[n]=e.name:i=!1})):i=!1,i)return s(),n=d(),new K(e,r,n)}throw j("Invalid left hand side of assignment operator =")}return t}function x(){var e,r=[];if(e=":"==lr?new Q("number","1"):w(),":"==lr){for(r.push(e);":"==lr;)s(),r.push(")"==lr||"]"==lr||","==lr||""==lr?new rr("end"):w());if(3==r.length){var n=r[2];r[2]=r[1],r[1]=n}e=new er(r)}return e}function w(){var e=v();return e}function v(){var e,r,n,t,i;for(e=y(),r={"==":"equal","!=":"unequal","<":"smaller",">":"larger","<=":"smallereq",">=":"largereq"};lr in r;)n=lr,t=r[n],s(),i=[e,y()],e=new X(n,t,i);return e}function y(){var e,r,n,t,i;for(e=b(),r={to:"to","in":"to"};lr in r;)n=lr,t=r[n],s(),i=[e,b()],e=new X(n,t,i);return e}function b(){var e,r,n,t,i;for(e=E(),r={"+":"add","-":"subtract"};lr in r;)n=lr,t=r[n],s(),i=[e,E()],e=new X(n,t,i);return e}function E(){var e,r,n,t,i;for(e=N(),r={"*":"multiply",".*":"emultiply","/":"divide","./":"edivide","%":"mod",mod:"mod"};lr in r;)n=lr,t=r[n],s(),i=[e,N()],e=new X(n,t,i);return e}function N(){var e,r;return e=M(),(mr==ir.SYMBOL||"in"==lr)&&(r=lr,s(),e=new nr(e,r)),e}function M(){var e,r,n;return"-"==lr?(e=lr,r="unary",s(),n=[M()],new X(e,r,n)):A()}function A(){var e,r,n,t,i,o,a;for(n=[T()],t=[];"^"==lr||".^"==lr;)t.push(lr),s(),n.push(T());for(e=n.pop();n.length;)r=n.pop(),i=t.pop(),o="^"==i?"pow":"epow",a=[r,e],e=new X(i,o,a);return e}function T(){var e,r,n,t,i;for(e=O(),r={"!":"factorial","'":"transpose"};lr in r;)n=lr,t=r[n],s(),i=[e],e=new X(n,t,i);return e}function O(){var e,r=[];if(mr==ir.SYMBOL&&sr[lr]){if(e=sr[lr],s(),"("==lr){if(r=[],s(),")"!=lr)for(r.push(x());","==lr;)s(),r.push(x());if(")"!=lr)throw j("Parenthesis ) expected");s()}return new e(r)}return S()}function S(){var e,r;return mr==ir.SYMBOL||mr==ir.DELIMITER&&lr in ar?(r=lr,s(),e=new rr(r),C(e)):U()}function C(e){for(var r,n;"("==lr||"["==lr;){if(r=lr,n=[],s(),")"!=lr&&"]"!=lr)for(n.push(x());","==lr;)s(),n.push(x());if("("==r&&")"!=lr)throw j("Parenthesis ) expected");if("["==r&&"]"!=lr)throw j("Parenthesis ] expected");s(),e="("==r?new J(e,n):new $(e,n)}return e}function U(){var e,r,n;if('"'==lr){for(r="",n="";""!=cr&&('"'!=cr||"\\"==n);)r+=cr,n=cr,o();if(s(),'"'!=lr)throw j('End of string " expected');return s(),e=new Q("string",r),e=C(e)}return q()}function q(){var e,r,n,t;if("["==lr){if(s(),u(),"]"!=lr){var i=z();if(";"==lr){for(n=1,r=[i];";"==lr;)s(),u(),r[n]=z(),n++,u();if("]"!=lr)throw j("End of matrix ] expected");s(),t=r[0].nodes.length;for(var o=1;n>o;o++)if(r[o].nodes.length!=t)throw P("Column dimensions mismatch ("+r[o].nodes.length+" != "+t+")");e=new W(r)}else{if("]"!=lr)throw j("End of matrix ] expected");s(),e=i}}else s(),e=new W([]);return e=C(e)}return R()}function z(){for(var e=[d()],r=1;","==lr;)s(),u(),e[r]=d(),r++,u();return new W(e)}function R(){var e,r;return mr==ir.NUMBER?(r=lr,s(),"i"==lr||"I"==lr?(s(),e=new Q("complex",r)):e=new Q("number",r),e=C(e)):I()}function I(){var e;if("("==lr){if(s(),e=d(),")"!=lr)throw j("Parenthesis ) expected");return s(),e=C(e)}return _()}function _(){throw j(""==lr?"Unexpected end of expression":"Value expected")}function L(){return fr-lr.length+1}function B(e){return e+" (char "+L()+")"}function j(e){return new SyntaxError(B(e))}function P(e){return new Error(B(e))}var k=n(112),F=(k.number.toNumber,k.string.isString),G=Array.isArray,D=k.types.type,H=(n(8),n(11)),V=(n(12),n(14)),W=n(113),Y=n(114),Z=n(115),Q=n(116),K=n(117),$=n(118),X=n(119),J=n(120),er=n(121),rr=n(122),nr=n(123),tr=n(124),ir={NULL:0,DELIMITER:1,NUMBER:2,SYMBOL:3,UNKNOWN:4},or={",":!0,"(":!0,")":!0,"[":!0,"]":!0,'"':!0,"\n":!0,";":!0,"+":!0,"-":!0,"*":!0,".*":!0,"/":!0,"./":!0,"%":!0,"^":!0,".^":!0,"!":!0,"'":!0,"=":!0,":":!0,"==":!0,"!=":!0,"<":!0,">":!0,"<=":!0,">=":!0},ar={mod:!0,to:!0,"in":!0},sr={},ur="",fr=0,cr="",lr="",mr=ir.NULL;e.exports=t},function(e,r,n){function t(e){if(!(this instanceof t))throw new SyntaxError("Constructor must be called with the new operator");if("object"!=typeof e)throw new TypeError("Object expected as parameter math");this.math=e,this.scope={}}var i=n(4);t.prototype.parse=function(e){return i(e)},t.prototype.compile=function(e){return i(e).compile(this.math)},t.prototype.eval=function(e){return i(e).compile(this.math).eval(this.scope)},t.prototype.get=function(e){return this.scope[e]},t.prototype.set=function(e,r){return this.scope[e]=r},t.prototype.remove=function(e){delete this.scope[e]},t.prototype.clear=function(){for(var e in this.scope)this.scope.hasOwnProperty(e)&&delete this.scope[e]},e.exports=t},function(e,r,n){r.ArrayNode=n(113),r.AssignmentNode=n(114),r.BlockNode=n(115),r.ConstantNode=n(116),r.IndexNode=n(118),r.FunctionNode=n(117),r.Node=n(125),r.OperatorNode=n(119),r.ParamsNode=n(120),r.RangeNode=n(121),r.SymbolNode=n(122),r.UnitNode=n(123),r.UpdateNode=n(124)},function(e,r,n){r.e=n(128),r.E=n(128),r["false"]=n(129),r.i=n(130),r.Infinity=n(131),r.LN2=n(132),r.LN10=n(133),r.LOG2E=n(134),r.LOG10E=n(135),r.NaN=n(136),r.pi=n(137),r.PI=n(137),r.SQRT1_2=n(138),r.SQRT2=n(139),r.tau=n(140),r["true"]=n(141),r.abs=n(145),r.add=n(146),r.ceil=n(147),r.compare=n(148),r.cube=n(149),r.divide=n(150),r.edivide=n(151),r.emultiply=n(152),r.epow=n(153),r.equal=n(154),r.exp=n(155),r.fix=n(156),r.floor=n(157),r.gcd=n(158),r.larger=n(159),r.largereq=n(160),r.lcm=n(161),r.log=n(162),r.log10=n(163),r.mod=n(164),r.multiply=n(165),r.pow=n(166),r.round=n(167),r.sign=n(168),r.smaller=n(169),r.smallereq=n(170),r.sqrt=n(171),r.square=n(172),r.subtract=n(173),r.unary=n(174),r.unequal=n(175),r.xgcd=n(176),r.arg=n(177),r.conj=n(178),r.re=n(179),r.im=n(180),r.bignumber=n(181),r["boolean"]=n(182),r.complex=n(183),r.index=n(184),r.matrix=n(185),r.number=n(186),r.string=n(187),r.unit=n(188),r.eval=n(189),r.help=n(190),r.concat=n(191),r.det=n(192),r.diag=n(193),r.eye=n(194),r.inv=n(195),r.ones=n(196),r.range=n(197),r.resize=n(198),r.size=n(199),r.squeeze=n(200),r.subset=n(201),r.transpose=n(202),r.zeros=n(203),r.combinations=n(204),r.distribution=n(205),r.factorial=n(206),r.permutations=n(207),r.pickRandom=n(208),r.random=n(209),r.randomInt=n(210),r.max=n(211),r.mean=n(212),r.median=n(213),r.min=n(214),r.prod=n(215),r.std=n(216),r.sum=n(217),r["var"]=n(218),r.acos=n(219),r.asin=n(220),r.atan=n(221),r.atan2=n(222),r.cos=n(223),r.cot=n(224),r.csc=n(225),r.sec=n(226),r.sin=n(227),r.tan=n(228),r.to=n(229),r.clone=n(230),r.map=n(231),r.forEach=n(232),r.format=n(233),r.ifElse=n(234),r["import"]=n(235),r["typeof"]=n(236)},function(e,r,n){function t(e,r){if(!(this instanceof t))throw new SyntaxError("Constructor must be called with the new operator");switch(arguments.length){case 0:this.re=0,this.im=0;break;case 2:if(!p(e)||!p(r))throw new TypeError("Two numbers expected in Complex constructor");this.re=e,this.im=r;break;default:throw new SyntaxError("Two or zero arguments expected in Complex constructor")}}function i(){for(;" "==x||" "==x;)s()}function o(e){return e>="0"&&"9">=e||"."==e}function a(e){return e>="0"&&"9">=e}function s(){d++,x=g.charAt(d)}function u(e){d=e,x=g.charAt(d)}function f(){var e,r="";if(e=d,"+"==x?s():"-"==x&&(r+=x,s()),!o(x))return u(e),null;if("."==x){if(r+=x,s(),!a(x))return u(e),null}else{for(;a(x);)r+=x,s();"."==x&&(r+=x,s())}for(;a(x);)r+=x,s();if("E"==x||"e"==x){if(r+=x,s(),("+"==x||"-"==x)&&(r+=x,s()),!a(x))return u(e),null;for(;a(x);)r+=x,s()}return r}function c(){var e=g.charAt(d+1);if("I"==x||"i"==x)return s(),"1";if(!("+"!=x&&"-"!=x||"I"!=e&&"i"!=e)){var r="+"==x?"1":"-1";return s(),s(),r}return null}var l=n(112),m=l.number,p=l.number.isNumber,h=l.string.isString;t.isComplex=function(e){return e instanceof t};var g,d,x;t.parse=function(e){if(g=e,d=-1,x="",!h(g))return null;s(),i();var r=f();if(r){if("I"==x||"i"==x)return s(),i(),x?null:new t(0,Number(r));i();var n=x;if("+"!=n&&"-"!=n)return i(),x?null:new t(Number(r),0);s(),i();var o=f();if(o){if("I"!=x&&"i"!=x)return null;s()}else if(o=c(),!o)return null;return"-"==n&&(o="-"==o[0]?"+"+o.substring(1):"-"+o),s(),i(),x?null:new t(Number(r),Number(o))}return(r=c())?(i(),x?null:new t(0,Number(r))):null},t.prototype.clone=function(){return new t(this.re,this.im)},t.prototype.equals=function(e){return this.re===e.re&&this.im===e.im},t.prototype.format=function(e){var r="",n=m.format(this.re,e),t=m.format(this.im,e);return r=0==this.im?n:0==this.re?1==this.im?"i":-1==this.im?"-i":t+"i":this.im>0?1==this.im?n+" + i":n+" + "+t+"i":-1==this.im?n+" - i":n+" - "+t.substring(1)+"i"},t.prototype.toString=function(){return this.format()},e.exports=t,r.isComplex=t.isComplex,r.parse=t.parse},function(e,r,n){function t(e,r,n){if(!(this instanceof t))throw new SyntaxError("Constructor must be called with the new operator");if(null!=e&&!o.isNumber(e))throw new TypeError("Parameter start must be a number");if(null!=r&&!o.isNumber(r))throw new TypeError("Parameter end must be a number");if(null!=n&&!o.isNumber(n))throw new TypeError("Parameter step must be a number");this.start=null!=e?parseFloat(e):0,this.end=null!=r?parseFloat(r):0,this.step=null!=n?parseFloat(n):1}{var i=n(112),o=i.number,a=i.string;i.array}t.parse=function(e){if(!a.isString(e))return null;var r=e.split(":"),n=r.map(function(e){return parseFloat(e)}),i=n.some(function(e){return isNaN(e)});if(i)return null;switch(n.length){case 2:return new t(n[0],n[1]);case 3:return new t(n[0],n[2],n[1]);default:return null}},t.prototype.clone=function(){return new t(this.start,this.end,this.step)},t.isRange=function(e){return e instanceof t},t.prototype.size=function(){var e=0,r=this.start,n=this.step,t=this.end,i=t-r;return o.sign(n)==o.sign(i)?e=Math.ceil(i/n):0==i&&(e=0),isNaN(e)&&(e=0),[e]},t.prototype.min=function(){var e=this.size()[0];return e>0?this.step>0?this.start:this.start+(e-1)*this.step:void 0},t.prototype.max=function(){var e=this.size()[0];return e>0?this.step>0?this.start+(e-1)*this.step:this.start:void 0},t.prototype.forEach=function(e){var r=this.start,n=this.step,t=this.end,i=0;if(n>0)for(;t>r;)e(r,i,this),r+=n,i++;else if(0>n)for(;r>t;)e(r,i,this),r+=n,i++},t.prototype.map=function(e){var r=[];return this.forEach(function(n,t,i){r[t]=e(n,t,i)}),r},t.prototype.toArray=function(){var e=[];return this.forEach(function(r,n){e[n]=r}),e},t.prototype.valueOf=function(){return this.toArray()},t.prototype.format=function(e){var r=o.format(this.start,e);return 1!=this.step&&(r+=":"+o.format(this.step,e)),r+=":"+o.format(this.end,e)},t.prototype.toString=function(){return this.format()},e.exports=t,r.isRange=t.isRange,r.parse=t.parse},function(e,r,n){function t(){if(!(this instanceof t))throw new SyntaxError("Constructor must be called with the new operator");this._ranges=[];for(var e=0,r=arguments.length;r>e;e++){var n=arguments[e];if(n instanceof a)this._ranges.push(n);else if(c(n))this._ranges.push(i(n));else{if(!u(n))throw new TypeError("Ranges must be an Array, Number, or Range");this._ranges.push(i([n,n+1]))}}}function i(e){for(var r=e.length,n=0;r>n;n++)if(!u(e[n])||!f(e[n]))throw new TypeError("Index parameters must be integer numbers");switch(e.length){case 2:return new a(e[0],e[1]);case 3:return new a(e[0],e[1],e[2]);default:throw new SyntaxError("Wrong number of arguments in Index (2 or 3 expected)")}}{var o=n(112),a=n(9),s=o.number,u=s.isNumber,f=s.isInteger,c=Array.isArray;o.array.validateIndex}t.prototype.clone=function(){var e=new t;return e._ranges=o.object.clone(this._ranges),e},t.isIndex=function(e){return e instanceof t},t.create=function(e){var r=new t;return t.apply(r,e),r},t.prototype.size=function l(){for(var l=[],e=0,r=this._ranges.length;r>e;e++){var n=this._ranges[e];l[e]=n.size()[0]}return l},t.prototype.max=function(){for(var e=[],r=0,n=this._ranges.length;n>r;r++){var t=this._ranges[r];e[r]=t.max()}return e},t.prototype.min=function(){for(var e=[],r=0,n=this._ranges.length;n>r;r++){var t=this._ranges[r];e[r]=t.min()}return e},t.prototype.forEach=function(e){for(var r=0,n=this._ranges.length;n>r;r++)e(this._ranges[r],r,this)},t.prototype.range=function(e){return this._ranges[e]||null},t.prototype.isScalar=function(){for(var e=this.size(),r=0,n=e.length;n>r;r++)if(1!==e[r])return!1;return!0},t.prototype.toArray=function(){for(var e=[],r=0,n=this._ranges.length;n>r;r++){var t=this._ranges[r],i=[],o=t.start,a=t.end,s=t.step;if(s>0)for(;a>o;)i.push(o),o+=s;else if(0>s)for(;o>a;)i.push(o),o+=s;e.push(i)}return e},t.prototype.valueOf=t.prototype.toArray,t.prototype.toString=function(){for(var e=[],r=0,n=this._ranges.length;n>r;r++){var t=this._ranges[r],i=s.format(t.start);1!=t.step&&(i+=":"+s.format(t.step)),i+=":"+s.format(t.end),e.push(i)}return"["+e.join(", ")+"]"},e.exports=t,r.isIndex=t.isIndex,r.create=t.create},function(e,r,n){function t(e){if(!(this instanceof t))throw new SyntaxError("Constructor must be called with the new operator");if(e instanceof t)this._data=e.clone()._data;else if(g(e))this._data=f(e);else{if(null!=e)throw new TypeError("Unsupported type of data ("+c.types.type(e)+")");this._data=[]}this._size=p.size(this._data)}function i(e,r){if(!(r instanceof l))throw new TypeError("Invalid index");var n=r.isScalar();if(n)return e.get(r.min());var i=r.size();if(i.length!=e._size.length)throw new RangeError("Dimension mismatch ("+i.length+" != "+e._size.length+")");for(var a=new t(o(e._data,r,i.length,0));g(a._data)&&1==a._data.length;)a._data=a._data[0],a._size.shift();return a}function o(e,r,n,t){var i=t==n-1,a=r.range(t);return a.map(i?function(r){return d(r,e.length),e[r]}:function(i){d(i,e.length);var a=e[i];return o(a,r,n,t+1)})}function a(e,r,n,i){if(!(r instanceof l))throw new TypeError("Invalid index");var o,a=r.size(),f=r.isScalar();if(n instanceof t?(o=n.size(),n=n.valueOf()):o=p.size(n),f){if(0!=o.length)throw new TypeError("Scalar value expected");e.set(r.min(),n,i)}else{if(a.lengthc;c++)n=[n],o.unshift(1);if(!h.deepEqual(a,o))throw new RangeError("Dimensions mismatch ("+m.format(a)+" != "+m.format(o)+")");var d=r.max().map(function(e){return e+1});u(e,d,i);var x=a.length,w=0;s(e._data,r,n,x,w)}return e}function s(e,r,n,t,i){var o=i==t-1,a=r.range(i);a.forEach(o?function(r,t){d(r),e[r]=n[t]}:function(o,a){d(o),s(e[o],r,n[a],t,i+1)})}function u(e,r,n){if(!g(r))throw new Error("Array expected");for(var t=h.clone(e._size),i=!1;t.lengtho;o++)r[o]>t[o]&&(t[o]=r[o],i=!0);i&&e.resize(t,n)}function f(e){for(var r=0,n=e.length;n>r;r++){var i=e[r];g(i)?e[r]=f(i):i instanceof t&&(e[r]=f(i._data))}return e}var c=n(112),l=n(10),m=(c.number,c.string),p=c.array,h=c.object,g=Array.isArray,d=p.validateIndex;t.isMatrix=function(e){return e instanceof t},t.prototype.subset=function(e,r,n){switch(arguments.length){case 1:return i(this,e);case 2:case 3:return a(this,e,r,n);default:throw new SyntaxError("Wrong number of arguments")}},t.prototype.get=function(e){if(!g(e))throw new Error("Array expected");if(e.length!=this._size.length)throw new RangeError("Dimension mismatch ("+e.length+" != "+this._size.length+")");for(var r=this._data,n=0,t=e.length;t>n;n++){var i=e[n];d(i,r.length),r=r[i]}return h.clone(r)},t.prototype.set=function(e,r,n){var t,i;if(!g(e))throw new Error("Array expected");if(e.lengtht;t++){var s=e[t];d(s,a.length),a=a[s]}return s=e[e.length-1],d(s,a.length),a[s]=r,this},t.prototype.resize=function(e,r){return this._size=h.clone(e),this._data=p.resize(this._data,this._size,r),this},t.prototype.clone=function(){var e=new t;return e._data=h.clone(this._data),e._size=h.clone(this._size),e},t.prototype.size=function(){return this._size},t.prototype.map=function(e){var r=this,n=new t,i=[],o=function(n,t){return g(n)?n.map(function(e,r){return i[t]=r,o(e,t+1)}):e(n,i,r)};return n._data=o(this._data,0),n._size=h.clone(this._size),n},t.prototype.forEach=function(e){var r=this,n=[],t=function(i,o){g(i)?i.forEach(function(e,r){n[o]=r,t(e,o+1)}):e(i,n,r)};t(this._data,0)},t.prototype.toArray=function(){return h.clone(this._data)},t.prototype.valueOf=function(){return this._data},t.prototype.format=function(e){return m.format(this._data,e)},t.prototype.toString=function(){return m.format(this._data)},e.exports=t,r.isMatrix=t.isMatrix},function(e,r,n){function t(e,r){if(!(this instanceof t))throw new Error("Constructor must be called with the new operator");if(null!=e&&!w(e))throw new TypeError("First parameter in Unit constructor must be a number");if(null!=r&&!v(r))throw new TypeError("Second parameter in Unit constructor must be a string");if(null!=r){var n=l(r);if(!n)throw new SyntaxError('Unknown unit "'+r+'"');this.unit=n.unit,this.prefix=n.prefix}else this.unit=UNIT_NONE,this.prefix=b;null!=e?(this.value=this._normalize(e),this.fixPrefix=!1):(this.value=null,this.fixPrefix=!0)}function i(){for(;" "==h||" "==h;)s()}function o(e){return e>="0"&&"9">=e||"."==e}function a(e){return e>="0"&&"9">=e}function s(){p++,h=m.charAt(p)}function u(e){p=e,h=m.charAt(p)}function f(){var e,r="";if(e=p,"+"==h?s():"-"==h&&(r+=h,s()),!o(h))return u(e),null;if("."==h){if(r+=h,s(),!a(h))return u(e),null}else{for(;a(h);)r+=h,s();"."==h&&(r+=h,s())}for(;a(h);)r+=h,s();if("E"==h||"e"==h){if(r+=h,s(),("+"==h||"-"==h)&&(r+=h,s()),!a(h))return u(e),null;for(;a(h);)r+=h,s()}return r}function c(){var e="";for(i();h&&" "!=h&&" "!=h;)e+=h,s();return e||null}function l(e){for(var r in N)if(N.hasOwnProperty(r)&&x.endsWith(e,r)){var n=N[r],t=e.length-r.length,i=e.substring(0,t),o=n.prefixes[i];if(void 0!==o)return{unit:n,prefix:o}}return null}var m,p,h,g=n(112),d=g.number,x=g.string,w=g.number.isNumber,v=g.string.isString;t.parse=function(e){if(m=e,p=-1,h="",!v(m))return null;s(),i();var r,n=f();return n?(r=c(),s(),i(),h?null:n&&r?new t(Number(n),r):null):(r=c(),s(),i(),h?null:new t(null,r))},t.isUnit=function(e){return e instanceof t},t.prototype.clone=function(){var e=new t;for(var r in this)this.hasOwnProperty(r)&&(e[r]=this[r]);return e},t.prototype._normalize=function(e){return(e+this.unit.offset)*this.unit.value*this.prefix.value},t.prototype._unnormalize=function(e,r){return void 0==r?e/this.unit.value/this.prefix.value-this.unit.offset:e/this.unit.value/r-this.unit.offset},t.isPlainUnit=function(e){return null!=l(e)},t.prototype.hasBase=function(e){return void 0===this.unit.base?void 0===e:this.unit.base===e},t.prototype.equalBase=function(e){return this.unit.base===e.unit.base},t.prototype.equals=function(e){return this.equalBase(e)&&this.value==e.value},t.prototype.to=function(e){var r;if(v(e)){if(r=new t(null,e),!this.equalBase(r))throw new Error("Units do not match");return r.value=this.value,r}if(e instanceof t){if(!this.equalBase(e))throw new Error("Units do not match");if(null!=e.value)throw new Error("Cannot convert to a unit with a value");if(null==e.unit)throw new Error("Unit expected on the right hand side of function in");return r=e.clone(),r.value=this.value,r.fixPrefix=!0,r}throw new Error("String or Unit expected as parameter")},t.prototype.toNumber=function(e){var r=this.to(e),n=this.fixPrefix?r._bestPrefix():r.prefix;return r._unnormalize(r.value,n.value)},t.prototype.toString=function(){return this.format()},t.prototype.format=function(e){var r,n;if(this.fixPrefix)r=this._unnormalize(this.value),n=null!=this.value?d.format(r,e)+" ":"",n+=this.prefix.name+this.unit.name;else{var t=this._bestPrefix();r=this._unnormalize(this.value,t.value),n=null!=this.value?d.format(r,e)+" ":"",n+=t.name+this.unit.name}return n},t.prototype._bestPrefix=function(){var e=Math.abs(this.value/this.unit.value),r=b,n=Math.abs(Math.log(e/r.value)/Math.LN10-1.2),t=this.unit.prefixes;for(var i in t)if(t.hasOwnProperty(i)){var o=t[i];if(o.scientific){var a=Math.abs(Math.log(e/o.value)/Math.LN10-1.2);n>a&&(r=o,n=a)}}return r};var y={NONE:{"":{name:"",value:1,scientific:!0}},SHORT:{"":{name:"",value:1,scientific:!0},da:{name:"da",value:10,scientific:!1},h:{name:"h",value:100,scientific:!1},k:{name:"k",value:1e3,scientific:!0},M:{name:"M",value:1e6,scientific:!0},G:{name:"G",value:1e9,scientific:!0},T:{name:"T",value:1e12,scientific:!0},P:{name:"P",value:1e15,scientific:!0},E:{name:"E",value:1e18,scientific:!0},Z:{name:"Z",value:1e21,scientific:!0},Y:{name:"Y",value:1e24,scientific:!0},d:{name:"d",value:.1,scientific:!1},c:{name:"c",value:.01,scientific:!1},m:{name:"m",value:.001,scientific:!0},u:{name:"u",value:1e-6,scientific:!0},n:{name:"n",value:1e-9,scientific:!0},p:{name:"p",value:1e-12,scientific:!0},f:{name:"f",value:1e-15,scientific:!0},a:{name:"a",value:1e-18,scientific:!0},z:{name:"z",value:1e-21,scientific:!0},y:{name:"y",value:1e-24,scientific:!0}},LONG:{"":{name:"",value:1,scientific:!0},deca:{name:"deca",value:10,scientific:!1},hecto:{name:"hecto",value:100,scientific:!1},kilo:{name:"kilo",value:1e3,scientific:!0},mega:{name:"mega",value:1e6,scientific:!0},giga:{name:"giga",value:1e9,scientific:!0},tera:{name:"tera",value:1e12,scientific:!0},peta:{name:"peta",value:1e15,scientific:!0},exa:{name:"exa",value:1e18,scientific:!0},zetta:{name:"zetta",value:1e21,scientific:!0},yotta:{name:"yotta",value:1e24,scientific:!0},deci:{name:"deci",value:.1,scientific:!1},centi:{name:"centi",value:.01,scientific:!1},milli:{name:"milli",value:.001,scientific:!0},micro:{name:"micro",value:1e-6,scientific:!0},nano:{name:"nano",value:1e-9,scientific:!0},pico:{name:"pico",value:1e-12,scientific:!0},femto:{name:"femto",value:1e-15,scientific:!0},atto:{name:"atto",value:1e-18,scientific:!0},zepto:{name:"zepto",value:1e-21,scientific:!0},yocto:{name:"yocto",value:1e-24,scientific:!0}},SQUARED:{"":{name:"",value:1,scientific:!0},da:{name:"da",value:100,scientific:!1},h:{name:"h",value:1e4,scientific:!1},k:{name:"k",value:1e6,scientific:!0},M:{name:"M",value:1e12,scientific:!0},G:{name:"G",value:1e18,scientific:!0},T:{name:"T",value:1e24,scientific:!0},P:{name:"P",value:1e30,scientific:!0},E:{name:"E",value:1e36,scientific:!0},Z:{name:"Z",value:1e42,scientific:!0},Y:{name:"Y",value:1e48,scientific:!0},d:{name:"d",value:.01,scientific:!1},c:{name:"c",value:1e-4,scientific:!1},m:{name:"m",value:1e-6,scientific:!0},u:{name:"u",value:1e-12,scientific:!0},n:{name:"n",value:1e-18,scientific:!0},p:{name:"p",value:1e-24,scientific:!0},f:{name:"f",value:1e-30,scientific:!0},a:{name:"a",value:1e-36,scientific:!0},z:{name:"z",value:1e-42,scientific:!0},y:{name:"y",value:1e-42,scientific:!0}},CUBIC:{"":{name:"",value:1,scientific:!0},da:{name:"da",value:1e3,scientific:!1},h:{name:"h",value:1e6,scientific:!1},k:{name:"k",value:1e9,scientific:!0},M:{name:"M",value:1e18,scientific:!0},G:{name:"G",value:1e27,scientific:!0},T:{name:"T",value:1e36,scientific:!0},P:{name:"P",value:1e45,scientific:!0},E:{name:"E",value:1e54,scientific:!0},Z:{name:"Z",value:1e63,scientific:!0},Y:{name:"Y",value:1e72,scientific:!0},d:{name:"d",value:.001,scientific:!1},c:{name:"c",value:1e-6,scientific:!1},m:{name:"m",value:1e-9,scientific:!0},u:{name:"u",value:1e-18,scientific:!0},n:{name:"n",value:1e-27,scientific:!0},p:{name:"p",value:1e-36,scientific:!0},f:{name:"f",value:1e-45,scientific:!0},a:{name:"a",value:1e-54,scientific:!0},z:{name:"z",value:1e-63,scientific:!0},y:{name:"y",value:1e-72,scientific:!0}},BINARY_SHORT:{"":{name:"",value:1,scientific:!0},k:{name:"k",value:1024,scientific:!0},M:{name:"M",value:Math.pow(1024,2),scientific:!0},G:{name:"G",value:Math.pow(1024,3),scientific:!0},T:{name:"T",value:Math.pow(1024,4),scientific:!0},P:{name:"P",value:Math.pow(1024,5),scientific:!0},E:{name:"E",value:Math.pow(1024,6),scientific:!0},Z:{name:"Z",value:Math.pow(1024,7),scientific:!0},Y:{name:"Y",value:Math.pow(1024,8),scientific:!0},Ki:{name:"Ki",value:1024,scientific:!0},Mi:{name:"Mi",value:Math.pow(1024,2),scientific:!0},Gi:{name:"Gi",value:Math.pow(1024,3),scientific:!0},Ti:{name:"Ti",value:Math.pow(1024,4),scientific:!0},Pi:{name:"Pi",value:Math.pow(1024,5),scientific:!0},Ei:{name:"Ei",value:Math.pow(1024,6),scientific:!0},Zi:{name:"Zi",value:Math.pow(1024,7),scientific:!0},Yi:{name:"Yi",value:Math.pow(1024,8),scientific:!0}},BINARY_LONG:{"":{name:"",value:1,scientific:!0},kilo:{name:"kilo",value:1024,scientific:!0},mega:{name:"mega",value:Math.pow(1024,2),scientific:!0},giga:{name:"giga",value:Math.pow(1024,3),scientific:!0},tera:{name:"tera",value:Math.pow(1024,4),scientific:!0},peta:{name:"peta",value:Math.pow(1024,5),scientific:!0},exa:{name:"exa",value:Math.pow(1024,6),scientific:!0},zetta:{name:"zetta",value:Math.pow(1024,7),scientific:!0},yotta:{name:"yotta",value:Math.pow(1024,8),scientific:!0},kibi:{name:"kibi",value:1024,scientific:!0},mebi:{name:"mebi",value:Math.pow(1024,2),scientific:!0},gibi:{name:"gibi",value:Math.pow(1024,3),scientific:!0},tebi:{name:"tebi",value:Math.pow(1024,4),scientific:!0},pebi:{name:"pebi",value:Math.pow(1024,5),scientific:!0},exi:{name:"exi",value:Math.pow(1024,6),scientific:!0},zebi:{name:"zebi",value:Math.pow(1024,7),scientific:!0},yobi:{name:"yobi",value:Math.pow(1024,8),scientific:!0}}},b={name:"",value:1,scientific:!0},E={NONE:{},LENGTH:{},MASS:{},TIME:{},CURRENT:{},TEMPERATURE:{},LUMINOUS_INTENSITY:{},AMOUNT_OF_SUBSTANCE:{},FORCE:{},SURFACE:{},VOLUME:{},ANGLE:{},BIT:{}};BASE_UNIT_NONE={},UNIT_NONE={name:"",base:BASE_UNIT_NONE,value:1,offset:0}; -var N={meter:{name:"meter",base:E.LENGTH,prefixes:y.LONG,value:1,offset:0},inch:{name:"inch",base:E.LENGTH,prefixes:y.NONE,value:.0254,offset:0},foot:{name:"foot",base:E.LENGTH,prefixes:y.NONE,value:.3048,offset:0},yard:{name:"yard",base:E.LENGTH,prefixes:y.NONE,value:.9144,offset:0},mile:{name:"mile",base:E.LENGTH,prefixes:y.NONE,value:1609.344,offset:0},link:{name:"link",base:E.LENGTH,prefixes:y.NONE,value:.201168,offset:0},rod:{name:"rod",base:E.LENGTH,prefixes:y.NONE,value:5.02921,offset:0},chain:{name:"chain",base:E.LENGTH,prefixes:y.NONE,value:20.1168,offset:0},angstrom:{name:"angstrom",base:E.LENGTH,prefixes:y.NONE,value:1e-10,offset:0},m:{name:"m",base:E.LENGTH,prefixes:y.SHORT,value:1,offset:0},"in":{name:"in",base:E.LENGTH,prefixes:y.NONE,value:.0254,offset:0},ft:{name:"ft",base:E.LENGTH,prefixes:y.NONE,value:.3048,offset:0},yd:{name:"yd",base:E.LENGTH,prefixes:y.NONE,value:.9144,offset:0},mi:{name:"mi",base:E.LENGTH,prefixes:y.NONE,value:1609.344,offset:0},li:{name:"li",base:E.LENGTH,prefixes:y.NONE,value:.201168,offset:0},rd:{name:"rd",base:E.LENGTH,prefixes:y.NONE,value:5.02921,offset:0},ch:{name:"ch",base:E.LENGTH,prefixes:y.NONE,value:20.1168,offset:0},mil:{name:"mil",base:E.LENGTH,prefixes:y.NONE,value:254e-7,offset:0},m2:{name:"m2",base:E.SURFACE,prefixes:y.SQUARED,value:1,offset:0},sqin:{name:"sqin",base:E.SURFACE,prefixes:y.NONE,value:64516e-8,offset:0},sqft:{name:"sqft",base:E.SURFACE,prefixes:y.NONE,value:.09290304,offset:0},sqyd:{name:"sqyd",base:E.SURFACE,prefixes:y.NONE,value:.83612736,offset:0},sqmi:{name:"sqmi",base:E.SURFACE,prefixes:y.NONE,value:2589988.110336,offset:0},sqrd:{name:"sqrd",base:E.SURFACE,prefixes:y.NONE,value:25.29295,offset:0},sqch:{name:"sqch",base:E.SURFACE,prefixes:y.NONE,value:404.6873,offset:0},sqmil:{name:"sqmil",base:E.SURFACE,prefixes:y.NONE,value:6.4516e-10,offset:0},m3:{name:"m3",base:E.VOLUME,prefixes:y.CUBIC,value:1,offset:0},L:{name:"L",base:E.VOLUME,prefixes:y.SHORT,value:.001,offset:0},l:{name:"l",base:E.VOLUME,prefixes:y.SHORT,value:.001,offset:0},litre:{name:"litre",base:E.VOLUME,prefixes:y.LONG,value:.001,offset:0},cuin:{name:"cuin",base:E.VOLUME,prefixes:y.NONE,value:16387064e-12,offset:0},cuft:{name:"cuft",base:E.VOLUME,prefixes:y.NONE,value:.028316846592,offset:0},cuyd:{name:"cuyd",base:E.VOLUME,prefixes:y.NONE,value:.764554857984,offset:0},teaspoon:{name:"teaspoon",base:E.VOLUME,prefixes:y.NONE,value:5e-6,offset:0},tablespoon:{name:"tablespoon",base:E.VOLUME,prefixes:y.NONE,value:15e-6,offset:0},minim:{name:"minim",base:E.VOLUME,prefixes:y.NONE,value:6.161152e-8,offset:0},fluiddram:{name:"fluiddram",base:E.VOLUME,prefixes:y.NONE,value:36966911e-13,offset:0},fluidounce:{name:"fluidounce",base:E.VOLUME,prefixes:y.NONE,value:2957353e-11,offset:0},gill:{name:"gill",base:E.VOLUME,prefixes:y.NONE,value:.0001182941,offset:0},cc:{name:"cc",base:E.VOLUME,prefixes:y.NONE,value:1e-6,offset:0},cup:{name:"cup",base:E.VOLUME,prefixes:y.NONE,value:.0002365882,offset:0},pint:{name:"pint",base:E.VOLUME,prefixes:y.NONE,value:.0004731765,offset:0},quart:{name:"quart",base:E.VOLUME,prefixes:y.NONE,value:.0009463529,offset:0},gallon:{name:"gallon",base:E.VOLUME,prefixes:y.NONE,value:.003785412,offset:0},beerbarrel:{name:"beerbarrel",base:E.VOLUME,prefixes:y.NONE,value:.1173478,offset:0},oilbarrel:{name:"oilbarrel",base:E.VOLUME,prefixes:y.NONE,value:.1589873,offset:0},hogshead:{name:"hogshead",base:E.VOLUME,prefixes:y.NONE,value:.238481,offset:0},fldr:{name:"fldr",base:E.VOLUME,prefixes:y.NONE,value:36966911e-13,offset:0},floz:{name:"floz",base:E.VOLUME,prefixes:y.NONE,value:2957353e-11,offset:0},gi:{name:"gi",base:E.VOLUME,prefixes:y.NONE,value:.0001182941,offset:0},cp:{name:"cp",base:E.VOLUME,prefixes:y.NONE,value:.0002365882,offset:0},pt:{name:"pt",base:E.VOLUME,prefixes:y.NONE,value:.0004731765,offset:0},qt:{name:"qt",base:E.VOLUME,prefixes:y.NONE,value:.0009463529,offset:0},gal:{name:"gal",base:E.VOLUME,prefixes:y.NONE,value:.003785412,offset:0},bbl:{name:"bbl",base:E.VOLUME,prefixes:y.NONE,value:.1173478,offset:0},obl:{name:"obl",base:E.VOLUME,prefixes:y.NONE,value:.1589873,offset:0},g:{name:"g",base:E.MASS,prefixes:y.SHORT,value:.001,offset:0},gram:{name:"gram",base:E.MASS,prefixes:y.LONG,value:.001,offset:0},ton:{name:"ton",base:E.MASS,prefixes:y.SHORT,value:907.18474,offset:0},tonne:{name:"tonne",base:E.MASS,prefixes:y.SHORT,value:1e3,offset:0},grain:{name:"grain",base:E.MASS,prefixes:y.NONE,value:6479891e-11,offset:0},dram:{name:"dram",base:E.MASS,prefixes:y.NONE,value:.0017718451953125,offset:0},ounce:{name:"ounce",base:E.MASS,prefixes:y.NONE,value:.028349523125,offset:0},poundmass:{name:"poundmass",base:E.MASS,prefixes:y.NONE,value:.45359237,offset:0},hundredweight:{name:"hundredweight",base:E.MASS,prefixes:y.NONE,value:45.359237,offset:0},stick:{name:"stick",base:E.MASS,prefixes:y.NONE,value:.115,offset:0},gr:{name:"gr",base:E.MASS,prefixes:y.NONE,value:6479891e-11,offset:0},dr:{name:"dr",base:E.MASS,prefixes:y.NONE,value:.0017718451953125,offset:0},oz:{name:"oz",base:E.MASS,prefixes:y.NONE,value:.028349523125,offset:0},lbm:{name:"lbm",base:E.MASS,prefixes:y.NONE,value:.45359237,offset:0},cwt:{name:"cwt",base:E.MASS,prefixes:y.NONE,value:45.359237,offset:0},s:{name:"s",base:E.TIME,prefixes:y.SHORT,value:1,offset:0},min:{name:"min",base:E.TIME,prefixes:y.NONE,value:60,offset:0},h:{name:"h",base:E.TIME,prefixes:y.NONE,value:3600,offset:0},second:{name:"second",base:E.TIME,prefixes:y.LONG,value:1,offset:0},sec:{name:"sec",base:E.TIME,prefixes:y.LONG,value:1,offset:0},minute:{name:"minute",base:E.TIME,prefixes:y.NONE,value:60,offset:0},hour:{name:"hour",base:E.TIME,prefixes:y.NONE,value:3600,offset:0},day:{name:"day",base:E.TIME,prefixes:y.NONE,value:86400,offset:0},rad:{name:"rad",base:E.ANGLE,prefixes:y.NONE,value:1,offset:0},deg:{name:"deg",base:E.ANGLE,prefixes:y.NONE,value:.017453292519943295,offset:0},grad:{name:"grad",base:E.ANGLE,prefixes:y.NONE,value:.015707963267948967,offset:0},cycle:{name:"cycle",base:E.ANGLE,prefixes:y.NONE,value:6.283185307179586,offset:0},A:{name:"A",base:E.CURRENT,prefixes:y.SHORT,value:1,offset:0},ampere:{name:"ampere",base:E.CURRENT,prefixes:y.LONG,value:1,offset:0},K:{name:"K",base:E.TEMPERATURE,prefixes:y.NONE,value:1,offset:0},degC:{name:"degC",base:E.TEMPERATURE,prefixes:y.NONE,value:1,offset:273.15},degF:{name:"degF",base:E.TEMPERATURE,prefixes:y.NONE,value:1/1.8,offset:459.67},degR:{name:"degR",base:E.TEMPERATURE,prefixes:y.NONE,value:1/1.8,offset:0},kelvin:{name:"kelvin",base:E.TEMPERATURE,prefixes:y.NONE,value:1,offset:0},celsius:{name:"celsius",base:E.TEMPERATURE,prefixes:y.NONE,value:1,offset:273.15},fahrenheit:{name:"fahrenheit",base:E.TEMPERATURE,prefixes:y.NONE,value:1/1.8,offset:459.67},rankine:{name:"rankine",base:E.TEMPERATURE,prefixes:y.NONE,value:1/1.8,offset:0},mol:{name:"mol",base:E.AMOUNT_OF_SUBSTANCE,prefixes:y.NONE,value:1,offset:0},mole:{name:"mole",base:E.AMOUNT_OF_SUBSTANCE,prefixes:y.NONE,value:1,offset:0},cd:{name:"cd",base:E.LUMINOUS_INTENSITY,prefixes:y.NONE,value:1,offset:0},candela:{name:"candela",base:E.LUMINOUS_INTENSITY,prefixes:y.NONE,value:1,offset:0},N:{name:"N",base:E.FORCE,prefixes:y.SHORT,value:1,offset:0},newton:{name:"newton",base:E.FORCE,prefixes:y.LONG,value:1,offset:0},lbf:{name:"lbf",base:E.FORCE,prefixes:y.NONE,value:4.4482216152605,offset:0},poundforce:{name:"poundforce",base:E.FORCE,prefixes:y.NONE,value:4.4482216152605,offset:0},b:{name:"b",base:E.BIT,prefixes:y.BINARY_SHORT,value:1,offset:0},bits:{name:"bits",base:E.BIT,prefixes:y.BINARY_LONG,value:1,offset:0},B:{name:"B",base:E.BIT,prefixes:y.BINARY_SHORT,value:8,offset:0},bytes:{name:"bytes",base:E.BIT,prefixes:y.BINARY_LONG,value:8,offset:0}},M={meters:"meter",inches:"inch",feet:"foot",yards:"yard",miles:"mile",links:"link",rods:"rod",chains:"chain",angstroms:"angstrom",litres:"litre",teaspoons:"teaspoon",tablespoons:"tablespoon",minims:"minim",fluiddrams:"fluiddram",fluidounces:"fluidounce",gills:"gill",cups:"cup",pints:"pint",quarts:"quart",gallons:"gallon",beerbarrels:"beerbarrel",oilbarrels:"oilbarrel",hogsheads:"hogshead",grams:"gram",tons:"ton",tonnes:"tonne",grains:"grain",drams:"dram",ounces:"ounce",poundmasses:"poundmass",hundredweights:"hundredweight",sticks:"stick",seconds:"second",minutes:"minute",hours:"hour",days:"day",radians:"rad",degrees:"deg",gradients:"grad",cycles:"cycle",amperes:"ampere",moles:"mole"};for(var A in M)if(M.hasOwnProperty(A)){var T=N[M[A]],O=Object.create(T);O.name=A,N[A]=O}N.lt=N.l,N.liter=N.litre,N.liters=N.litres,N.lb=N.lbm,t.PREFIXES=y,t.BASE_UNITS=E,t.UNITS=N,e.exports=t,r.isUnit=t.isUnit,r.isPlainUnit=t.isPlainUnit,r.parse=t.parse},function(e,r,n){function t(e,r){if(!(this instanceof t))throw new SyntaxError("Constructor must be called with the new operator");this.math=e,this.doc=r}var i=n(112),o=i.object,a=i.string;t.isHelp=function(e){return e instanceof t},t.prototype.toString=function(){var e=this.doc||{},r="\n";if(e.name&&(r+="Name: "+e.name+"\n\n"),e.category&&(r+="Category: "+e.category+"\n\n"),e.description&&(r+="Description:\n "+e.description+"\n\n"),e.syntax&&(r+="Syntax:\n "+e.syntax.join("\n ")+"\n\n"),e.examples){var n=this.math.parser();r+="Examples:\n";for(var i=0;i=r){if(s(e[0])){for(f=i(e),a=[],o=0;on;n++){var a=[];for(r=0;t>r;r++)a.push(e[r][n]);o.push(a)}return o}{var o=n(112),a=n(11),s=o.array.isArray;o.string.isString}r.argsToArray=function(e){var r;return 0==e.length?r=[]:1==e.length?(r=e[0],r instanceof a&&(r=r.valueOf()),s(r)||(r=[r])):r=Array.prototype.slice.apply(e),r},r.isCollection=function(e){return s(e)||e instanceof a},r.deepMap=function u(e,r){return e&&"function"==typeof e.map?e.map(function(e){return u(e,r)}):r(e)},r.deepMap2=function f(e,r,n){var t,i,o;if(s(e))if(s(r)){if(e.length!=r.length)throw new RangeError("Dimension mismatch ("+e.length+" != "+r.length+")");for(t=[],i=e.length,o=0;i>o;o++)t[o]=f(e[o],r[o],n)}else{if(r instanceof a)return t=f(e,r.valueOf(),n),new a(t);for(t=[],i=e.length,o=0;i>o;o++)t[o]=f(e[o],r,n)}else{if(e instanceof a)return r instanceof a?(t=f(e.valueOf(),r.valueOf(),n),new a(t)):(t=f(e.valueOf(),r,n),new a(t));if(s(r))for(t=[],i=r.length,o=0;i>o;o++)t[o]=f(e,r[o],n);else{if(r instanceof a)return t=f(e,r.valueOf(),n),new a(t);t=n(e,r)}}return t},r.reduce=function(e,r,n){return e instanceof a?new a(t(e.valueOf(),r,n)):t(e,r,n)},r.deepForEach=function c(e,r){e instanceof a&&(e=e.valueOf());for(var n=0,t=e.length;t>n;n++){var i=e[n];s(i)?c(i,r):r(i)}}},function(e,r,n){e.exports=function(e){var r=(n(126),{});e.error=r,r.UnsupportedTypeError=function t(r,n){if(!(this instanceof t))throw new SyntaxError("Constructor must be called with the new operator");switch(arguments.length){case 0:this.message="Unsupported type of argument";break;case 1:this.message="Unsupported type of argument in function "+r;break;case 2:var i=e["typeof"](n);this.message="Function "+r+"("+i+") not supported";break;default:var o=Array.prototype.splice.call(arguments,1),a=o.map(function(r){return e["typeof"](r)});this.message="Function "+r+"("+a.join(", ")+") not supported"}this.stack=(new Error).stack},r.UnsupportedTypeError.prototype=new TypeError,r.UnsupportedTypeError.prototype.constructor=TypeError,r.UnsupportedTypeError.prototype.name="UnsupportedTypeError",r.ArgumentsError=function i(e,r,n,t){if(!(this instanceof i))throw new SyntaxError("Constructor must be called with the new operator");this.message="Wrong number of arguments in function "+e+" ("+r+" provided, "+n+(void 0!=t?"-"+t:"")+" expected)",this.stack=(new Error).stack},r.ArgumentsError.prototype=new Error,r.ArgumentsError.prototype.constructor=Error,r.ArgumentsError.prototype.name="ArgumentsError"}},function(e,r,n){e.exports=function(e){function r(e){if(!(this instanceof r))throw new SyntaxError("Constructor must be called with the new operator");this.value=e instanceof r?e.value:e}function t(e,n){var t=Array.prototype.slice;r.prototype[e]="function"==typeof n?function(){var e=[this.value].concat(t.call(arguments,0));return new r(n.apply(this,e))}:new r(n)}var i=n(127);r.prototype.done=function(){return this.value},r.prototype.valueOf=function(){return this.value},r.prototype.toString=function(){return i.format(this.value)},r.createProxy=t;for(var o in e)e.hasOwnProperty(o)&&t(o,e[o]);return r}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(4),i=n(14),o=r.string.isString,a=i.isCollection;e.compile=function(r){if(1!=arguments.length)throw new e.error.ArgumentsError("compile",arguments.length,1);if(o(r))return t(r).compile(e);if(a(r))return i.deepMap(r,function(r){return t(r).compile(e)});throw new TypeError("String, array, or matrix expected")}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(4),i=n(14),o=r.string.isString,a=i.isCollection;e.eval=function(r,n){if(1!=arguments.length&&2!=arguments.length)throw new e.error.ArgumentsError("eval",arguments.length,1,2);if(n=n||{},o(r))return t(r).compile(e).eval(n);if(a(r))return i.deepMap(r,function(r){return t(r).compile(e).eval(n)});throw new TypeError("String, array, or matrix expected")}}},function(e,r,n){e.exports=function(e){var r=n(13);e.help=function(n){if(1!=arguments.length)throw new SyntaxError("Wrong number of arguments in function help ("+arguments.length+" provided, 1 expected)");var t=null;if(n instanceof String||"string"==typeof n)t=n;else{var i;for(i in e)if(e.hasOwnProperty(i)&&n===e[i]){t=i;break}}var o=e.expression.docs[t];if(!t||!o)throw new Error('No documentation found on "'+t+'"');return new r(e,o)}}},function(e,r,n){e.exports=function(e){var r=n(4);e.parse=function(){return r.apply(r,arguments)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=(n(11),n(14)),a=r.number.isNumber,s=r["boolean"].isBoolean,u=i.isComplex,f=o.isCollection;e.abs=function c(r){if(1!=arguments.length)throw new e.error.ArgumentsError("abs",arguments.length,1);if(a(r))return Math.abs(r);if(u(r))return Math.sqrt(r.re*r.re+r.im*r.im);if(r instanceof t)return r.abs();if(f(r))return o.deepMap(r,c);if(s(r))return Math.abs(r);throw new e.error.UnsupportedTypeError("abs",r)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=(n(11),n(12)),a=n(14),s=r["boolean"].isBoolean,u=r.number.isNumber,f=r.number.toNumber,c=r.number.toBigNumber,l=r.string.isString,m=i.isComplex,p=o.isUnit,h=a.isCollection;e.add=function g(r,n){if(2!=arguments.length)throw new e.error.ArgumentsError("add",arguments.length,2);if(u(r)){if(u(n))return r+n;if(m(n))return new i(r+n.re,n.im)}if(m(r)){if(m(n))return new i(r.re+n.re,r.im+n.im);if(u(n))return new i(r.re+n,r.im)}if(p(r)&&p(n)){if(null==r.value)throw new Error("Parameter x contains a unit with undefined value");if(null==n.value)throw new Error("Parameter y contains a unit with undefined value");if(!r.equalBase(n))throw new Error("Units do not match");var o=r.clone();return o.value+=n.value,o.fixPrefix=!1,o}if(r instanceof t)return u(n)?n=c(n):s(n)&&(n=new t(n?1:0)),n instanceof t?r.plus(n):g(f(r),n);if(n instanceof t)return u(r)?r=c(r):s(r)&&(r=new t(r?1:0)),r instanceof t?r.plus(n):g(r,f(n));if(l(r)||l(n))return r+n;if(h(r)||h(n))return a.deepMap2(r,n,g);if(s(r))return g(+r,n);if(s(n))return g(r,+n);throw new e.error.UnsupportedTypeError("add",r,n)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=n(14),a=r.number.isNumber,s=r["boolean"].isBoolean,u=o.isCollection,f=i.isComplex;e.ceil=function c(r){if(1!=arguments.length)throw new e.error.ArgumentsError("ceil",arguments.length,1);if(a(r))return Math.ceil(r);if(f(r))return new i(Math.ceil(r.re),Math.ceil(r.im));if(r instanceof t)return r.ceil();if(u(r))return o.deepMap(r,c);if(s(r))return Math.ceil(r);throw new e.error.UnsupportedTypeError("ceil",r)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=n(12),a=n(14),s=r.number.isNumber,u=r.number.toNumber,f=r.number.toBigNumber,c=r["boolean"].isBoolean,l=r.string.isString,m=i.isComplex,p=o.isUnit,h=a.isCollection;e.compare=function g(r,n){if(2!=arguments.length)throw new e.error.ArgumentsError("compare",arguments.length,2);if(s(r)&&s(n))return r>n?1:n>r?-1:0;if(r instanceof t)return s(n)?n=f(n):c(n)&&(n=new t(n?1:0)),n instanceof t?new t(r.cmp(n)):g(u(r),n);if(n instanceof t)return s(r)?r=f(r):c(r)&&(r=new t(r?1:0)),r instanceof t?new t(r.cmp(n)):g(r,u(n));if(p(r)&&p(n)){if(!r.equalBase(n))throw new Error("Cannot compare units with different base");return r.value>n.value?1:r.valuen?1:n>r?-1:0;if(h(r)||h(n))return a.deepMap2(r,n,g);if(c(r))return g(+r,n);if(c(n))return g(r,+n);if(m(r)||m(n))throw new TypeError("No ordering relation is defined for complex numbers");throw new e.error.UnsupportedTypeError("compare",r,n)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=n(14),a=r.number.isNumber,s=r["boolean"].isBoolean,u=i.isComplex,f=o.isCollection;e.cube=function c(r){if(1!=arguments.length)throw new e.error.ArgumentsError("cube",arguments.length,1);if(a(r))return r*r*r;if(u(r))return e.multiply(e.multiply(r,r),r);if(r instanceof t)return r.times(r).times(r);if(f(r))return o.deepMap(r,c);if(s(r))return c(+r);throw new e.error.UnsupportedTypeError("cube",r)}}},function(e,r,n){e.exports=function(e){function r(e,r){var n=r.re*r.re+r.im*r.im;return 0!=n?new o((e.re*r.re+e.im*r.im)/n,(e.im*r.re-e.re*r.im)/n):new o(0!=e.re?e.re/0:0,0!=e.im?e.im/0:0)}var t=n(112),i=n(111),o=n(8),a=(n(11),n(12)),s=n(14),u=t.number.isNumber,f=t.number.toNumber,c=t.number.toBigNumber,l=t["boolean"].isBoolean,m=o.isComplex,p=a.isUnit,h=s.isCollection;e.divide=function g(n,t){if(2!=arguments.length)throw new e.error.ArgumentsError("divide",arguments.length,2);if(u(n)){if(u(t))return n/t;if(m(t))return r(new o(n,0),t)}if(m(n)){if(m(t))return r(n,t);if(u(t))return r(n,new o(t,0))}if(n instanceof i)return u(t)?t=c(t):l(t)&&(t=new i(t?1:0)),t instanceof i?n.div(t):g(f(n),t);if(t instanceof i)return u(n)?n=c(n):l(n)&&(n=new i(n?1:0)),n instanceof i?n.div(t):g(n,f(t));if(p(n)&&u(t)){var a=n.clone();return a.value/=t,a}if(h(n))return h(t)?e.multiply(n,e.inv(t)):s.deepMap2(n,t,g);if(h(t))return e.multiply(n,e.inv(t));if(l(n))return g(+n,t);if(l(t))return g(n,+t);throw new e.error.UnsupportedTypeError("divide",n,t)}}},function(e,r,n){e.exports=function(e){var r=n(14);e.edivide=function(n,t){if(2!=arguments.length)throw new e.error.ArgumentsError("edivide",arguments.length,2);return r.deepMap2(n,t,e.divide)}}},function(e,r,n){e.exports=function(e){var r=n(14);e.emultiply=function(n,t){if(2!=arguments.length)throw new e.error.ArgumentsError("emultiply",arguments.length,2);return r.deepMap2(n,t,e.multiply)}}},function(e,r,n){e.exports=function(e){var r=n(14);e.epow=function(n,t){if(2!=arguments.length)throw new e.error.ArgumentsError("epow",arguments.length,2);return r.deepMap2(n,t,e.pow)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=n(12),a=n(14),s=r.number.isNumber,u=r.number.toNumber,f=r.number.toBigNumber,c=r["boolean"].isBoolean,l=r.string.isString,m=i.isComplex,p=o.isUnit,h=a.isCollection;e.equal=function g(r,n){if(2!=arguments.length)throw new e.error.ArgumentsError("equal",arguments.length,2);if(s(r)){if(s(n))return r==n;if(m(n))return r==n.re&&0==n.im}if(m(r)){if(s(n))return r.re==n&&0==r.im;if(m(n))return r.re==n.re&&r.im==n.im}if(r instanceof t)return s(n)?n=f(n):c(n)&&(n=new t(n?1:0)),n instanceof t?r.eq(n):g(u(r),n);if(n instanceof t)return s(r)?r=f(r):c(r)&&(r=new t(r?1:0)),r instanceof t?r.eq(n):g(r,u(n));if(p(r)&&p(n)){if(!r.equalBase(n))throw new Error("Cannot compare units with different base");return r.value==n.value}if(l(r)||l(n))return r==n;if(h(r)||h(n))return a.deepMap2(r,n,g);if(c(r))return g(+r,n);if(c(n))return g(r,+n);throw new e.error.UnsupportedTypeError("equal",r,n)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=(n(11),n(14)),a=r.number.isNumber,s=r["boolean"].isBoolean,u=i.isComplex,f=o.isCollection;e.exp=function c(n){if(1!=arguments.length)throw new e.error.ArgumentsError("exp",arguments.length,1);if(a(n))return Math.exp(n);if(u(n)){var l=Math.exp(n.re);return new i(l*Math.cos(n.im),l*Math.sin(n.im))}if(n instanceof t)return c(r.number.toNumber(n));if(f(n))return o.deepMap(n,c);if(s(n))return Math.exp(n);throw new e.error.UnsupportedTypeError("exp",n)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=n(14),a=r.number.isNumber,s=r["boolean"].isBoolean,u=i.isComplex,f=o.isCollection;e.fix=function c(r){if(1!=arguments.length)throw new e.error.ArgumentsError("fix",arguments.length,1);if(a(r))return r>0?Math.floor(r):Math.ceil(r);if(u(r))return new i(r.re>0?Math.floor(r.re):Math.ceil(r.re),r.im>0?Math.floor(r.im):Math.ceil(r.im));if(r instanceof t)return r.isNegative()?r.ceil():r.floor();if(f(r))return o.deepMap(r,c);if(s(r))return c(+r);throw new e.error.UnsupportedTypeError("fix",r)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=n(14),a=r.number.isNumber,s=r["boolean"].isBoolean,u=i.isComplex,f=o.isCollection;e.floor=function c(r){if(1!=arguments.length)throw new e.error.ArgumentsError("floor",arguments.length,1);if(a(r))return Math.floor(r);if(u(r))return new i(Math.floor(r.re),Math.floor(r.im));if(r instanceof t)return r.floor();if(f(r))return o.deepMap(r,c);if(s(r))return c(+r);throw new e.error.UnsupportedTypeError("floor",r)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(14),o=r.number.isNumber,a=r.number.toNumber,s=r["boolean"].isBoolean,u=r.number.isInteger,f=i.isCollection;e.gcd=function c(){var r,n=arguments[0],l=arguments[1];if(2==arguments.length){if(o(n)&&o(l)){if(!u(n)||!u(l))throw new Error("Parameters in function gcd must be integer numbers");for(;0!=l;)r=n%l,n=l,l=r;return 0>n?-n:n}if(f(n)||f(l))return i.deepMap2(n,l,c);if(n instanceof t)return c(a(n),l);if(l instanceof t)return c(n,a(l));if(s(n))return c(+n,l);if(s(l))return c(n,+l);throw new e.error.UnsupportedTypeError("gcd",n,l)}if(arguments.length>2){for(var m=1;mn;if(r instanceof t)return s(n)?n=f(n):c(n)&&(n=new t(n?1:0)),n instanceof t?r.gt(n):g(u(r),n);if(n instanceof t)return s(r)?r=f(r):c(r)&&(r=new t(r?1:0)),r instanceof t?r.gt(n):g(r,u(n));if(p(r)&&p(n)){if(!r.equalBase(n))throw new Error("Cannot compare units with different base");return r.value>n.value}if(l(r)||l(n))return r>n;if(h(r)||h(n))return a.deepMap2(r,n,g);if(c(r))return g(+r,n);if(c(n))return g(r,+n);if(m(r)||m(n))throw new TypeError("No ordering relation is defined for complex numbers");throw new e.error.UnsupportedTypeError("larger",r,n)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=n(12),a=n(14),s=r.number.isNumber,u=r.number.toNumber,f=r.number.toBigNumber,c=r["boolean"].isBoolean,l=r.string.isString,m=i.isComplex,p=o.isUnit,h=a.isCollection;e.largereq=function g(r,n){if(2!=arguments.length)throw new e.error.ArgumentsError("largereq",arguments.length,2);if(s(r)&&s(n))return r>=n;if(r instanceof t)return s(n)?n=f(n):c(n)&&(n=new t(n?1:0)),n instanceof t?r.gte(n):g(u(r),n);if(n instanceof t)return s(r)?r=f(r):c(r)&&(r=new t(r?1:0)),r instanceof t?r.gte(n):g(r,u(n));if(p(r)&&p(n)){if(!r.equalBase(n))throw new Error("Cannot compare units with different base");return r.value>=n.value}if(l(r)||l(n))return r>=n;if(h(r)||h(n))return a.deepMap2(r,n,g);if(c(r))return g(+r,n);if(c(n))return g(r,+n);if(m(r)||m(n))throw new TypeError("No ordering relation is defined for complex numbers");throw new e.error.UnsupportedTypeError("largereq",r,n)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(14),o=r.number.isNumber,a=r.number.toNumber,s=r["boolean"].isBoolean,u=r.number.isInteger,f=i.isCollection;e.lcm=function c(){var r,n=arguments[0],l=arguments[1];if(2==arguments.length){if(o(n)&&o(l)){if(!u(n)||!u(l))throw new Error("Parameters in function lcm must be integer numbers");if(0==n||0==l)return 0;for(var m=n*l;0!=l;)r=l,l=n%r,n=r;return Math.abs(m/n)}if(f(n)||f(l))return i.deepMap2(n,l,c);if(s(n))return c(+n,l);if(s(l))return c(n,+l);if(n instanceof t)return c(a(n),l);if(l instanceof t)return c(n,a(l));throw new e.error.UnsupportedTypeError("lcm",n,l)}if(arguments.length>2){for(var p=1;p=0?Math.log(n):c(new i(n,0));if(u(n))return new i(Math.log(Math.sqrt(n.re*n.re+n.im*n.im)),Math.atan2(n.im,n.re));if(n instanceof t)return c(r.number.toNumber(n));if(f(n))return o.deepMap(n,c);if(s(n))return c(+n);throw new e.error.UnsupportedTypeError("log",n)}if(2==arguments.length)return e.divide(c(n),c(l));throw new e.error.ArgumentsError("log",arguments.length,1,2)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=n(14),a=r.number.isNumber,s=r["boolean"].isBoolean,u=i.isComplex,f=o.isCollection;e.log10=function c(n){if(1!=arguments.length)throw new e.error.ArgumentsError("log10",arguments.length,1);if(a(n))return n>=0?Math.log(n)/Math.LN10:c(new i(n,0));if(n instanceof t)return c(r.number.toNumber(n));if(u(n))return new i(Math.log(Math.sqrt(n.re*n.re+n.im*n.im))/Math.LN10,Math.atan2(n.im,n.re)/Math.LN10);if(f(n))return o.deepMap(n,c);if(s(n))return c(+n);throw new e.error.UnsupportedTypeError("log10",n)}}},function(e,r,n){e.exports=function(e){function r(e,r){if(r>0)return e>0?e%r:0==e?0:e-r*Math.floor(e/r);if(0==r)return e;throw new Error("Cannot calculate mod for a negative divisor")}var t=n(112),i=n(111),o=n(14),a=t.number.isNumber,s=t.number.toNumber,u=t.number.toBigNumber,f=t["boolean"].isBoolean,c=o.isCollection;e.mod=function l(n,t){if(2!=arguments.length)throw new e.error.ArgumentsError("mod",arguments.length,2);if(a(n)&&a(t))return r(n,t);if(n instanceof i)return a(t)?t=u(t):f(t)&&(t=new i(t?1:0)),t instanceof i?n.mod(t):l(s(n),t);if(t instanceof i)return a(n)?n=u(n):f(n)&&(n=new i(n?1:0)),n instanceof i?n.mod(t):l(n,s(t));if(c(n)||c(t))return o.deepMap2(n,t,l);if(f(n))return l(+n,t);if(f(t))return l(n,+t);throw new e.error.UnsupportedTypeError("mod",n,t)}}},function(e,r,n){e.exports=function(e){function r(r,n){for(var t=[],i=r.length,o=n[0].length,a=r[0].length,s=0;i>s;s++){t[s]=[];for(var u=0;o>u;u++){for(var f=null,c=0;a>c;c++){var l=e.multiply(r[s][c],n[c][u]);f=null===f?l:e.add(f,l)}t[s][u]=f}}return t}function t(r,n){for(var t=[],i=n.length,o=n[0].length,a=0;o>a;a++){for(var s=null,u=0;i>u;u++){var f=e.multiply(r[u],n[u][a]);s=0===u?f:e.add(s,f)}t[a]=s}return t}function i(r,n){for(var t=[],i=r.length,o=r[0].length,a=0;i>a;a++){for(var s=null,u=0;o>u;u++){var f=e.multiply(r[a][u],n[u]);s=0===u?f:e.add(s,f)}t[a]=s}return t}function o(r,n){var t=r.length;if(!t)throw new Error("Cannot multiply two empty vectors");for(var i=0,o=0;t>o;o++)i=e.add(i,e.multiply(r[o],n[o]));return i}function a(e,r){return 0==e.im?0==r.im?new f(e.re*r.re,0):0==r.re?new f(0,e.re*r.im):new f(e.re*r.re,e.re*r.im):0==e.re?0==r.im?new f(0,e.im*r.re):0==r.re?new f(-e.im*r.im,0):new f(-e.im*r.im,e.im*r.re):0==r.im?new f(e.re*r.re,e.im*r.re):0==r.re?new f(-e.im*r.im,e.re*r.im):new f(e.re*r.re-e.im*r.im,e.re*r.im+e.im*r.re)}var s=n(112),u=n(111),f=n(8),c=n(11),l=n(12),m=n(14),p=s.array,h=s.number.isNumber,g=s.number.toNumber,d=s.number.toBigNumber,x=s["boolean"].isBoolean,w=f.isComplex,v=Array.isArray,y=l.isUnit;e.multiply=function b(n,s){if(2!=arguments.length)throw new e.error.ArgumentsError("multiply",arguments.length,2);if(h(n)){if(h(s))return n*s;if(w(s))return a(new f(n,0),s);if(y(s))return res=s.clone(),res.value*=n,res}if(w(n)){if(h(s))return a(n,new f(s,0));if(w(s))return a(n,s)}if(n instanceof u)return h(s)?s=d(s):x(s)&&(s=new u(s?1:0)),s instanceof u?n.times(s):b(g(n),s);if(s instanceof u)return h(n)?n=d(n):x(n)&&(n=new u(n?1:0)),n instanceof u?n.times(s):b(n,g(s));if(y(n)&&h(s))return res=n.clone(),res.value*=s,res;if(v(n)){if(v(s)){var l=p.size(n),E=p.size(s);if(1==l.length){if(1==E.length){if(l[0]!=E[0])throw new RangeError("Dimensions mismatch in multiplication. Length of A must match length of B (A is "+l[0]+", B is "+E[0]+l[0]+" != "+E[0]+")");return o(n,s)}if(2==E.length){if(l[0]!=E[0])throw new RangeError("Dimensions mismatch in multiplication. Length of A must match rows of B (A is "+l[0]+", B is "+E[0]+"x"+E[1]+", "+l[0]+" != "+E[0]+")");return t(n,s)}throw new Error("Can only multiply a 1 or 2 dimensional matrix (B has "+E.length+" dimensions)")}if(2==l.length){if(1==E.length){if(l[1]!=E[0])throw new RangeError("Dimensions mismatch in multiplication. Columns of A must match length of B (A is "+l[0]+"x"+l[0]+", B is "+E[0]+", "+l[1]+" != "+E[0]+")");return i(n,s)}if(2==E.length){if(l[1]!=E[0])throw new RangeError("Dimensions mismatch in multiplication. Columns of A must match rows of B (A is "+l[0]+"x"+l[1]+", B is "+E[0]+"x"+E[1]+", "+l[1]+" != "+E[0]+")");return r(n,s)}throw new Error("Can only multiply a 1 or 2 dimensional matrix (B has "+E.length+" dimensions)")}throw new Error("Can only multiply a 1 or 2 dimensional matrix (A has "+l.length+" dimensions)")}return s instanceof c?new c(b(n,s.valueOf())):m.deepMap2(n,s,b)}if(n instanceof c)return new c(s instanceof c?b(n.valueOf(),s.valueOf()):b(n.valueOf(),s));if(v(s))return m.deepMap2(n,s,b);if(s instanceof c)return new c(m.deepMap2(n,s.valueOf(),b));if(x(n))return b(+n,s);if(x(s))return b(n,+s);throw new e.error.UnsupportedTypeError("multiply",n,s)}}},function(e,r,n){e.exports=function(e){function r(r,n){var t=e.log(r),i=e.multiply(t,n);return e.exp(i)}var t=n(112),i=n(111),o=n(8),a=n(11),s=(n(14),t.array),u=t.number.isNumber,f=t.number.toNumber,c=t.number.toBigNumber,l=t["boolean"].isBoolean,m=Array.isArray,p=t.number.isInteger,h=o.isComplex;e.pow=function g(n,t){if(2!=arguments.length)throw new e.error.ArgumentsError("pow",arguments.length,2);if(u(n)){if(u(t))return p(t)||n>=0?Math.pow(n,t):r(new o(n,0),new o(t,0));if(h(t))return r(new o(n,0),t)}if(h(n)){if(u(t))return r(n,new o(t,0));if(h(t))return r(n,t)}if(n instanceof i)return u(t)?t=c(t):l(t)&&(t=new i(t?1:0)),t instanceof i?n.pow(t):g(f(n),t);if(t instanceof i)return u(n)?n=c(n):l(n)&&(n=new i(n?1:0)),n instanceof i?n.pow(t):g(n,f(t));if(m(n)){if(!u(t)||!p(t)||0>t)throw new TypeError("For A^b, b must be a positive integer (value is "+t+")");var d=s.size(n);if(2!=d.length)throw new Error("For A^b, A must be 2 dimensional (A has "+d.length+" dimensions)");if(d[0]!=d[1])throw new Error("For A^b, A must be square (size is "+d[0]+"x"+d[1]+")");for(var x=e.eye(d[0]).valueOf(),w=n;t>=1;)1==(1&t)&&(x=e.multiply(w,x)),t>>=1,w=e.multiply(w,w);return x}if(n instanceof a)return new a(g(n.valueOf(),t));if(l(n))return g(+n,t);if(l(t))return g(n,+t);throw new e.error.UnsupportedTypeError("pow",n,t)}}},function(e,r,n){e.exports=function(e){function r(e,r){var n=Math.pow(10,r);return Math.round(e*n)/n}var t=n(112),i=n(111),o=n(8),a=n(14),s=t.number.isNumber,u=t.number.isInteger,f=t["boolean"].isBoolean,c=o.isComplex,l=a.isCollection; -e.round=function m(n,t){if(1!=arguments.length&&2!=arguments.length)throw new e.error.ArgumentsError("round",arguments.length,1,2);if(void 0==t){if(s(n))return Math.round(n);if(c(n))return new o(Math.round(n.re),Math.round(n.im));if(n instanceof i)return n.round();if(l(n))return a.deepMap(n,m);if(f(n))return Math.round(n);throw new e.error.UnsupportedTypeError("round",n)}if(!s(t)||!u(t)){if(!(t instanceof i)){if(f(t))return m(n,+t);throw new TypeError("Number of decimals in function round must be an integer")}t=parseFloat(t.valueOf())}if(0>t||t>15)throw new Error("Number of decimals in function round must be in te range of 0-15");if(s(n))return r(n,t);if(c(n))return new o(r(n.re,t),r(n.im,t));if(n instanceof i)return n.round(t);if(l(n)||l(t))return a.deepMap2(n,t,m);if(f(n))return m(+n,t);throw new e.error.UnsupportedTypeError("round",n,t)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=n(14),a=r.number,s=r.number.isNumber,u=r["boolean"].isBoolean,f=i.isComplex,c=o.isCollection;e.sign=function l(r){if(1!=arguments.length)throw new e.error.ArgumentsError("sign",arguments.length,1);if(s(r))return a.sign(r);if(f(r)){var n=Math.sqrt(r.re*r.re+r.im*r.im);return new i(r.re/n,r.im/n)}if(r instanceof t)return new t(r.cmp(0));if(c(r))return o.deepMap(r,l);if(u(r))return a.sign(r);throw new e.error.UnsupportedTypeError("sign",r)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=n(12),a=n(14),s=r.number.isNumber,u=r.number.toNumber,f=r.number.toBigNumber,c=r["boolean"].isBoolean,l=r.string.isString,m=i.isComplex,p=o.isUnit,h=a.isCollection;e.smaller=function g(r,n){if(2!=arguments.length)throw new e.error.ArgumentsError("smaller",arguments.length,2);if(s(r)&&s(n))return n>r;if(r instanceof t)return s(n)?n=f(n):c(n)&&(n=new t(n?1:0)),n instanceof t?r.lt(n):g(u(r),n);if(n instanceof t)return s(r)?r=f(r):c(r)&&(r=new t(r?1:0)),r instanceof t?r.lt(n):g(r,u(n));if(p(r)&&p(n)){if(!r.equalBase(n))throw new Error("Cannot compare units with different base");return r.valuer;if(h(r)||h(n))return a.deepMap2(r,n,g);if(c(r))return g(+r,n);if(c(n))return g(r,+n);if(m(r)||m(n))throw new TypeError("No ordering relation is defined for complex numbers");throw new e.error.UnsupportedTypeError("smaller",r,n)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=n(12),a=n(14),s=r.number.isNumber,u=r.number.toNumber,f=r.number.toBigNumber,c=r["boolean"].isBoolean,l=r.string.isString,m=i.isComplex,p=o.isUnit,h=a.isCollection;e.smallereq=function g(r,n){if(2!=arguments.length)throw new e.error.ArgumentsError("smallereq",arguments.length,2);if(s(r)&&s(n))return n>=r;if(r instanceof t)return s(n)?n=f(n):c(n)&&(n=new t(n?1:0)),n instanceof t?r.lte(n):g(u(r),n);if(n instanceof t)return s(r)?r=f(r):c(r)&&(r=new t(r?1:0)),r instanceof t?r.lte(n):g(r,u(n));if(p(r)&&p(n)){if(!r.equalBase(n))throw new Error("Cannot compare units with different base");return r.value<=n.value}if(l(r)||l(n))return n>=r;if(h(r)||h(n))return a.deepMap2(r,n,g);if(c(r))return g(+r,n);if(c(n))return g(r,+n);if(m(r)||m(n))throw new TypeError("No ordering relation is defined for complex numbers");throw new e.error.UnsupportedTypeError("smallereq",r,n)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=n(14),a=r.number.isNumber,s=r["boolean"].isBoolean,u=i.isComplex,f=o.isCollection;e.sqrt=function c(r){if(1!=arguments.length)throw new e.error.ArgumentsError("sqrt",arguments.length,1);if(a(r))return r>=0?Math.sqrt(r):c(new i(r,0));if(u(r)){var n=Math.sqrt(r.re*r.re+r.im*r.im);return r.im>=0?new i(.5*Math.sqrt(2*(n+r.re)),.5*Math.sqrt(2*(n-r.re))):new i(.5*Math.sqrt(2*(n+r.re)),-.5*Math.sqrt(2*(n-r.re)))}if(r instanceof t)return r.sqrt();if(f(r))return o.deepMap(r,c);if(s(r))return c(+r);throw new e.error.UnsupportedTypeError("sqrt",r)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=n(14),a=r.number.isNumber,s=r["boolean"].isBoolean,u=i.isComplex,f=o.isCollection;e.square=function c(r){if(1!=arguments.length)throw new e.error.ArgumentsError("square",arguments.length,1);if(a(r))return r*r;if(u(r))return e.multiply(r,r);if(r instanceof t)return r.times(r);if(f(r))return o.deepMap(r,c);if(s(r))return r*r;throw new e.error.UnsupportedTypeError("square",r)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=(n(11),n(12)),a=n(14),s=r.number.toNumber,u=r.number.toBigNumber,f=r["boolean"].isBoolean,c=r.number.isNumber,l=i.isComplex,m=o.isUnit,p=a.isCollection;e.subtract=function h(r,n){if(2!=arguments.length)throw new e.error.ArgumentsError("subtract",arguments.length,2);if(c(r)){if(c(n))return r-n;if(l(n))return new i(r-n.re,-n.im)}else if(l(r)){if(c(n))return new i(r.re-n,r.im);if(l(n))return new i(r.re-n.re,r.im-n.im)}if(r instanceof t)return c(n)?n=u(n):f(n)&&(n=new t(n?1:0)),n instanceof t?r.minus(n):h(s(r),n);if(n instanceof t)return c(r)?r=u(r):f(r)&&(r=new t(r?1:0)),r instanceof t?r.minus(n):h(r,s(n));if(m(r)&&m(n)){if(null==r.value)throw new Error("Parameter x contains a unit with undefined value");if(null==n.value)throw new Error("Parameter y contains a unit with undefined value");if(!r.equalBase(n))throw new Error("Units do not match");var o=r.clone();return o.value-=n.value,o.fixPrefix=!1,o}if(p(r)||p(n))return a.deepMap2(r,n,h);if(f(r))return h(+r,n);if(f(n))return h(r,+n);throw new e.error.UnsupportedTypeError("subtract",r,n)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=n(12),a=n(14),s=r.number.isNumber,u=r["boolean"].isBoolean,f=i.isComplex,c=o.isUnit,l=a.isCollection;e.unary=function m(r){if(1!=arguments.length)throw new e.error.ArgumentsError("unary",arguments.length,1);if(s(r))return-r;if(f(r))return new i(-r.re,-r.im);if(r instanceof t)return r.neg();if(c(r)){var n=r.clone();return n.value=-r.value,n}if(l(r))return a.deepMap(r,m);if(u(r))return-r;throw new e.error.UnsupportedTypeError("unary",r)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=n(12),a=n(14),s=r.number.isNumber,u=r.number.toNumber,f=r.number.toBigNumber,c=r["boolean"].isBoolean,l=r.string.isString,m=i.isComplex,p=o.isUnit,h=a.isCollection;e.unequal=function g(r,n){if(2!=arguments.length)throw new e.error.ArgumentsError("unequal",arguments.length,2);if(s(r)){if(s(n))return r!=n;if(m(n))return r!=n.re||0!=n.im}if(m(r)){if(s(n))return r.re!=n||0!=r.im;if(m(n))return r.re!=n.re||r.im!=n.im}if(r instanceof t)return s(n)?n=f(n):c(n)&&(n=new t(n?1:0)),n instanceof t?!r.eq(n):g(u(r),n);if(n instanceof t)return s(r)?r=f(r):c(r)&&(r=new t(r?1:0)),r instanceof t?!r.eq(n):g(r,u(n));if(p(r)&&p(n)){if(!r.equalBase(n))throw new Error("Cannot compare units with different base");return r.value!=n.value}if(l(r)||l(n))return r!=n;if(h(r)||h(n))return a.deepMap2(r,n,g);if(c(r))return g(+r,n);if(c(n))return g(r,+n);throw new e.error.UnsupportedTypeError("unequal",r,n)}}},function(e,r,n){e.exports=function(e){function r(e,r){for(var n,t,i,o=0,a=1,s=1,u=0;r;)t=Math.floor(e/r),i=e%r,n=o,o=a-t*o,a=n,n=s,s=u-t*s,u=n,e=r,r=i;return 0>e?[-e,-a,-u]:[e,e?a:0,u]}var t=n(112),i=n(111),o=t.number.toNumber,a=t.number.isNumber,s=t["boolean"].isBoolean,u=t.number.isInteger;e.xgcd=function f(n,t){if(2==arguments.length){if(a(n)&&a(t)){if(!u(n)||!u(t))throw new Error("Parameters in function xgcd must be integer numbers");return r(n,t)}if(n instanceof i)return f(o(n),t);if(t instanceof i)return f(n,o(t));if(s(n))return f(+n,t);if(s(t))return f(n,+t);throw new e.error.UnsupportedTypeError("xgcd",n,t)}throw new SyntaxError("Function xgcd expects two arguments")}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=n(14),a=r.number.isNumber,s=r["boolean"].isBoolean,u=o.isCollection,f=i.isComplex;e.arg=function c(n){if(1!=arguments.length)throw new e.error.ArgumentsError("arg",arguments.length,1);if(a(n))return Math.atan2(0,n);if(f(n))return Math.atan2(n.im,n.re);if(u(n))return o.deepMap(n,c);if(s(n))return c(+n);if(n instanceof t)return c(r.number.toNumber(n));throw new e.error.UnsupportedTypeError("arg",n)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=n(14),a=r.object,s=r.number.isNumber,u=r["boolean"].isBoolean,f=o.isCollection,c=i.isComplex;e.conj=function l(r){if(1!=arguments.length)throw new e.error.ArgumentsError("conj",arguments.length,1);return s(r)?r:r instanceof t?new t(r):c(r)?new i(r.re,-r.im):f(r)?o.deepMap(r,l):u(r)?+r:a.clone(r)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=n(14),a=r.object,s=r.number.isNumber,u=r["boolean"].isBoolean,f=o.isCollection,c=i.isComplex;e.re=function l(r){if(1!=arguments.length)throw new e.error.ArgumentsError("re",arguments.length,1);return s(r)?r:r instanceof t?new t(r):c(r)?r.re:f(r)?o.deepMap(r,l):u(r)?+r:a.clone(r)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=n(14),a=r.number.isNumber,s=r["boolean"].isBoolean,u=o.isCollection,f=i.isComplex;e.im=function c(r){if(1!=arguments.length)throw new e.error.ArgumentsError("im",arguments.length,1);return a(r)?0:r instanceof t?new t(0):f(r)?r.im:u(r)?o.deepMap(r,c):s(r)?0:0}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(14),o=i.isCollection,a=r.number.isNumber,s=r.string.isString,u=r["boolean"].isBoolean;"function"!=typeof t.prototype.clone&&(t.prototype.clone=function(){return new t(this)}),e.bignumber=function f(r){if(arguments.length>1)throw new e.error.ArgumentsError("bignumber",arguments.length,0,1);if(r instanceof t||a(r)||s(r))return new t(r);if(u(r))return new t(+r);if(o(r))return i.deepMap(r,f);if(0==arguments.length)return new t(0);throw new e.error.UnsupportedTypeError("bignumber",r)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(14),o=i.isCollection,a=r.number.isNumber,s=r.string.isString;e["boolean"]=function u(r){if(1!=arguments.length)throw new e.error.ArgumentsError("boolean",arguments.length,0,1);if("true"===r||r===!0)return!0;if("false"===r||r===!1)return!1;if(r instanceof Boolean)return 1==r;if(a(r))return 0!==r;if(r instanceof t)return!r.isZero();if(s(r)){var n=r.toLowerCase();if("true"===n)return!0;if("false"===n)return!1;var f=Number(r);if(""!=r&&!isNaN(f))return 0!==f}if(o(r))return i.deepMap(r,u);throw new SyntaxError(r.toString()+" is no valid boolean")}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=n(14),a=o.isCollection,s=r.number.isNumber,u=r.number.toNumber,f=r.string.isString,c=i.isComplex;e.complex=function l(){switch(arguments.length){case 0:return new i(0,0);case 1:var r=arguments[0];if(s(r))return new i(r,0);if(r instanceof t)return new i(u(r),0);if(c(r))return r.clone();if(f(r)){var n=i.parse(r);if(n)return n;throw new SyntaxError('String "'+r+'" is no valid complex number')}if(a(r))return o.deepMap(r,l);throw new TypeError("Two numbers or a single string expected in function complex");case 2:var m=arguments[0],p=arguments[1];if(m instanceof t&&(m=u(m)),p instanceof t&&(p=u(p)),s(m)&&s(p))return new i(m,p);throw new TypeError("Two numbers or a single string expected in function complex");default:throw new e.error.ArgumentsError("complex",arguments.length,0,2)}}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(10),o=r.number.toNumber;e.index=function(){var e=new i,r=Array.prototype.slice.apply(arguments).map(function(e){return e instanceof t?o(e):Array.isArray(e)?e.map(function(e){return e instanceof t?o(e):e}):e});return i.apply(e,r),e}}},function(e,r,n){e.exports=function(e){var r=n(11);e.matrix=function(n){if(arguments.length>1)throw new e.error.ArgumentsError("matrix",arguments.length,0,1);return new r(n)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(14),o=i.isCollection,a=r.number.toNumber,s=r.number.isNumber,u=r["boolean"].isBoolean,f=r.string.isString;e.number=function c(r){switch(arguments.length){case 0:return 0;case 1:if(o(r))return i.deepMap(r,c);if(r instanceof t)return a(r);if(f(r)){var n=Number(r);if(isNaN(n)&&(n=Number(r.valueOf())),isNaN(n))throw new SyntaxError(r.toString()+" is no valid number");return n}if(u(r))return r+0;if(s(r))return r;throw new e.error.UnsupportedTypeError("number",r);default:throw new e.error.ArgumentsError("number",arguments.length,0,1)}}}},function(e,r,n){e.exports=function(e){var r=n(5);e.parser=function(){return new r(e)}}},function(e){e.exports=function(e){e.select=function(r){return new e.chaining.Selector(r)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(14),i=r.number,o=r.number.isNumber,a=t.isCollection;e.string=function s(r){switch(arguments.length){case 0:return"";case 1:return o(r)?i.format(r):a(r)?t.deepMap(r,s):null===r?"null":r.toString();default:throw new e.error.ArgumentsError("string",arguments.length,0,1)}}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(12),o=n(14),a=o.isCollection,s=r.number.toNumber,u=r.string.isString;e.unit=function f(r){switch(arguments.length){case 1:var n=arguments[0];if(n instanceof i)return n.clone();if(u(n)){if(i.isPlainUnit(n))return new i(null,n);var c=i.parse(n);if(c)return c;throw new SyntaxError('String "'+n+'" is no valid unit')}if(a(r))return o.deepMap(r,f);throw new TypeError("A string or a number and string expected in function unit");case 2:return arguments[0]instanceof t?new i(s(arguments[0]),arguments[1]):new i(arguments[0],arguments[1]);default:throw new e.error.ArgumentsError("unit",arguments.length,1,2)}}}},function(e,r,n){e.exports=function(e){function r(e,n,t,i){if(t>i){if(e.length!=n.length)throw new Error("Dimensions mismatch ("+e.length+" != "+n.length+")");for(var o=[],a=0;an;n++){var h=arguments[n];if(h instanceof i&&(m=!0),n==o-1&&u(h)){if(t=l,l=h,!f(l)||0>l)throw new TypeError("Dimension number must be a positive integer (dim = "+l+")");if(n>0&&l>t)throw new RangeError("Dimension out of range ("+l+" > "+t+")")}else{if(!c(h))throw new e.error.UnsupportedTypeError("concat",h);var g=a.clone(h).valueOf(),d=s.size(h.valueOf());if(p[n]=g,t=l,l=d.length-1,n>0&&l!=t)throw new RangeError("Dimension mismatch ("+t+" != "+l+")")}}if(0==p.length)throw new SyntaxError("At least one matrix expected");for(var x=p.shift();p.length;)x=r(x,p.shift(),l,0);return m?new i(x):x}}},function(e,r,n){e.exports=function(e){function r(r,n,t){if(1==n)return o.clone(r[0][0]);if(2==n)return e.subtract(e.multiply(r[0][0],r[1][1]),e.multiply(r[1][0],r[0][1]));for(var i,a=1,s=0,u=0;n>u&&!(s>=t);u++){for(var f=u;0==r[f][s];)if(f++,f==n&&(f=u,s++,s==t))return o.deepEqual(r,e.eye(n).valueOf())?e.round(a,6):0;if(f!=u){for(i=0;t>i;i++){var c=r[f][i];r[f][i]=r[u][i],r[u][i]=c}a*=-1}var l=r[u][s];for(i=0;t>i;i++)r[u][i]=r[u][i]/l;a*=l;for(var m=0;n>m;m++)if(m!=u){var p=r[m][s];for(i=0;t>i;i++)r[m][i]=r[m][i]-r[u][i]*p}s++}return o.deepEqual(r,e.eye(n).valueOf())?e.round(a,6):0}var t=n(112),i=n(11),o=t.object,a=t.string;e.det=function(n){if(1!=arguments.length)throw new e.error.ArgumentsError("det",arguments.length,1);var t;switch(n instanceof i?t=n.size():n instanceof Array?(n=new i(n),t=n.size()):t=[],t.length){case 0:return o.clone(n);case 1:if(1==t[0])return o.clone(n.valueOf()[0]);throw new RangeError("Matrix must be square (size: "+a.format(t)+")");case 2:var s=t[0],u=t[1];if(s==u)return r(n.clone().valueOf(),s,u);throw new RangeError("Matrix must be square (size: "+a.format(t)+")");default:throw new RangeError("Matrix must be two dimensional (size: "+a.format(t)+")")}}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(11),i=r.object,o=r.array.isArray,a=r.number.isNumber,s=r.number.isInteger;e.diag=function(r,n){var u,f,c,l;if(1!=arguments.length&&2!=arguments.length)throw new e.error.ArgumentsError("diag",arguments.length,1,2);if(n){if(!a(n)||!s(n))throw new TypeError("Second parameter in function diag must be an integer")}else n=0;var m,p=n>0?n:0,h=0>n?-n:0;if(r instanceof t)m=!1;else{if(!o(r))throw new TypeError("First parameter in function diag must be a Matrix or Array");r=new t(r),m=!0}var g=r.size();switch(g.length){case 1:f=r.valueOf();var d=new t,x=0;for(d.resize([f.length+h,f.length+p],x),u=d.valueOf(),l=f.length,c=0;l>c;c++)u[c+h][c+p]=i.clone(f[c]);return m?d.valueOf():d;case 2:for(f=[],u=r.valueOf(),l=Math.min(g[0]-h,g[1]-p),c=0;l>c;c++)f[c]=i.clone(u[c+h][c+p]);return m?f:new t(f);default:throw new RangeError("Matrix for function diag must be 2 dimensional")}}}},function(e,r,n){e.exports=function(e,r){var t=n(112),i=n(111),o=n(11),a=n(14),s=t.number.toNumber,u=t.number.isNumber,f=t.number.isInteger,c=Array.isArray;e.eye=function(n){var t=a.argsToArray(arguments),l=n instanceof o?!0:c(n)?!1:"matrix"===r.matrix;if(0==t.length)return l?new o:[];if(1==t.length)t[1]=t[0];else if(t.length>2)throw new e.error.ArgumentsError("eye",t.length,0,2);var m=t[0]instanceof i,p=t[0],h=t[1];if(p instanceof i&&(p=s(p)),h instanceof i&&(h=s(h)),!u(p)||!f(p)||1>p)throw new Error("Parameters in function eye must be positive integers");if(!u(h)||!f(h)||1>h)throw new Error("Parameters in function eye must be positive integers");var g=new o,d=m?new i(1):1,x=m?new i(0):0;g.resize(t.map(s),x);for(var w=e.min(t),v=g.valueOf(),y=0;w>y;y++)v[y][y]=d;return l?g:g.valueOf()}}},function(e,r,n){e.exports=function(e){function r(r,n,t){var i,o,a,s,u;if(1==n){if(s=r[0][0],0==s)throw Error("Cannot calculate inverse, determinant is zero");return[[e.divide(1,s)]]}if(2==n){var f=e.det(r);if(0==f)throw Error("Cannot calculate inverse, determinant is zero");return[[e.divide(r[1][1],f),e.divide(e.unary(r[0][1]),f)],[e.divide(e.unary(r[1][0]),f),e.divide(r[0][0],f)]]}var c=r.concat();for(i=0;n>i;i++)c[i]=c[i].concat();for(var l=e.eye(n).valueOf(),m=0;t>m;m++){for(i=m;n>i&&0==c[i][m];)i++;if(i==n||0==c[i][m])throw Error("Cannot calculate inverse, determinant is zero");i!=m&&(u=c[m],c[m]=c[i],c[i]=u,u=l[m],l[m]=l[i],l[i]=u);var p=c[m],h=l[m];for(i=0;n>i;i++){var g=c[i],d=l[i];if(i!=m){if(0!=g[m]){for(a=e.divide(e.unary(g[m]),p[m]),o=m;t>o;o++)g[o]=e.add(g[o],e.multiply(a,p[o]));for(o=0;t>o;o++)d[o]=e.add(d[o],e.multiply(a,h[o]))}}else{for(a=p[m],o=m;t>o;o++)g[o]=e.divide(g[o],a);for(o=0;t>o;o++)d[o]=e.divide(d[o],a)}}}return l}{var t=n(127),i=n(11);n(14)}e.inv=function(n){if(1!=arguments.length)throw new e.error.ArgumentsError("inv",arguments.length,1);var o=e.size(n).valueOf();switch(o.length){case 0:return e.divide(1,n);case 1:if(1==o[0])return n instanceof i?new i([e.divide(1,n.valueOf()[0])]):[e.divide(1,n[0])];throw new RangeError("Matrix must be square (size: "+t.format(o)+")");case 2:var a=o[0],s=o[1];if(a==s)return n instanceof i?new i(r(n.valueOf(),a,s)):r(n,a,s);throw new RangeError("Matrix must be square (size: "+t.format(o)+")");default:throw new RangeError("Matrix must be two dimensional (size: "+t.format(o)+")")}}}},function(e,r,n){e.exports=function(e,r){var t=n(112),i=n(111),o=n(11),a=n(14),s=t.array,u=t.number.toNumber,f=Array.isArray;e.ones=function(e){var n=a.argsToArray(arguments),t=e instanceof o?!0:f(e)?!1:"matrix"===r.matrix;if(0==n.length)return t?new o:[];var c=[],l=n[0]instanceof i?new i(1):1;return c=s.resize(c,n.map(u),l),t?new o(c):c}}},function(e,r,n){e.exports=function(e,r){function t(e,r,n){var t=[],i=e;if(n>0)for(;r>i;)t.push(i),i+=n;else if(0>n)for(;i>r;)t.push(i),i+=n;return t}function i(e,r,n){var t=[],i=e;if(n>0)for(;r>=i;)t.push(i),i+=n;else if(0>n)for(;i>=r;)t.push(i),i+=n;return t}function o(e,r,n){var t=[],i=e.clone(),o=new f(0);if(n.gt(o))for(;i.lt(r);)t.push(i),i=i.plus(n);else if(n.lt(o))for(;i.gt(r);)t.push(i),i=i.plus(n);return t}function a(e,r,n){var t=[],i=e.clone(),o=new f(0);if(n.gt(o))for(;i.lte(r);)t.push(i),i=i.plus(n);else if(n.lt(o))for(;i.gte(r);)t.push(i),i=i.plus(n);return t}function s(e){var n=e.split(":"),t=null;if("bignumber"===r.number)try{t=n.map(function(e){return new f(e)})}catch(i){return null}else{t=n.map(function(e){return Number(e)});var o=t.some(function(e){return isNaN(e)});if(o)return null}switch(t.length){case 2:return{start:t[0],end:t[1],step:1};case 3:return{start:t[0],end:t[2],step:t[1]};default:return null}}var u=n(112),f=n(111),c=n(11),l=(n(14),u["boolean"].isBoolean),m=u.string.isString,p=u.number.isNumber,h=u.number.toNumber,g=u.number.toBigNumber;e.range=function(){var n,u,d,x=Array.prototype.slice.call(arguments),w=!1;switch(l(x[x.length-1])&&(w=x.pop()?!0:!1),x.length){case 1:if(!m(x[0]))throw new TypeError("Two or three numbers or a single string expected in function range");var v=s(x[0]);if(!v)throw new SyntaxError('String "'+x[0]+'" is no valid range');n=v.start,u=v.end,d=v.step;break;case 2:n=x[0],u=x[1],d=1;break;case 3:n=x[0],u=x[1],d=x[2];break;case 4:throw new TypeError("Parameter includeEnd must be a boolean");default:throw new e.error.ArgumentsError("range",arguments.length,2,4)}if(!(p(n)||n instanceof f))throw new TypeError("Parameter start must be a number");if(!(p(u)||u instanceof f))throw new TypeError("Parameter end must be a number");if(!(p(d)||d instanceof f))throw new TypeError("Parameter step must be a number");if(n instanceof f||u instanceof f||d instanceof f){var y=!0;n instanceof f||(n=g(n)),u instanceof f||(u=g(u)),d instanceof f||(d=g(d)),n instanceof f&&u instanceof f&&d instanceof f||(y=!1,n=h(n),u=h(u),d=h(d))}var b=y?w?a:o:w?i:t,E=b(n,u,d);return"array"===r.matrix?E:new c(E)}}},function(e,r,n){e.exports=function(e,r){function t(e,r,n){if(void 0!==n){if(!c(n)||1!==n.length)throw new TypeError("Single character expected as defaultValue")}else n=" ";if(1!==r.length)throw new Error("Dimension mismatch: ("+r.length+" != 1)");var t=r[0];if(!m(t)||!p(t))throw new TypeError("Invalid size, must contain positive integers (size: "+f.format(r)+")");if(e.length>t)return e.substring(0,t);if(e.lengtho;o++)i+=n;return i}return e}var i=n(112),o=n(111),a=n(11),s=i.array,u=i.object.clone,f=i.string,c=i.string.isString,l=i.number.toNumber,m=i.number.isNumber,p=i.number.isInteger,h=s.isArray;e.resize=function(n,i,f){if(2!=arguments.length&&3!=arguments.length)throw new e.error.ArgumentsError("resize",arguments.length,2,3);var m=n instanceof a?!0:h(n)?!1:"array"!==r.matrix;if(n instanceof a&&(n=n.valueOf()),i instanceof a&&(i=i.valueOf()),i.length&&i[0]instanceof o&&(i=i.map(l)),c(n))return t(n,i,f);if(0==i.length){for(;h(n);)n=n[0];return u(n)}h(n)||(n=[n]),n=u(n);var p=s.resize(n,i,f);return m?new a(p):p}}},function(e,r,n){e.exports=function(e,r){var t=n(112),i=n(111),o=n(8),a=n(12),s=n(11),u=t.array,f=t.number.isNumber,c=t["boolean"].isBoolean,l=t.string.isString,m=o.isComplex,p=a.isUnit;e.size=function(n){if(1!=arguments.length)throw new e.error.ArgumentsError("size",arguments.length,1);var t="array"===r.matrix;if(f(n)||m(n)||p(n)||c(n)||null==n||n instanceof i)return t?[]:new s([]);if(l(n))return t?[n.length]:new s([n.length]);if(Array.isArray(n))return u.size(n);if(n instanceof s)return new s(n.size());throw new e.error.UnsupportedTypeError("size",n)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(11),i=r.object,o=r.array,a=Array.isArray;e.squeeze=function(r){if(1!=arguments.length)throw new e.error.ArgumentsError("squeeze",arguments.length,1);if(a(r))return o.squeeze(i.clone(r));if(r instanceof t){var n=o.squeeze(r.toArray());return a(n)?new t(n):n}return i.clone(r)}}},function(e,r,n){e.exports=function(e){function r(r,n){var i,o;if(l(r))return i=new s(r),o=i.subset(n),o.valueOf();if(r instanceof s)return r.subset(n);if(c(r))return t(r,n);throw new e.error.UnsupportedTypeError("subset",r)}function t(e,r){if(!(r instanceof u))throw new TypeError("Index expected");if(1!=r.size().length)throw new RangeError("Dimension mismatch ("+r.size().length+" != 1)");var n=r.range(0),t="",i=e.length;return n.forEach(function(r){f.validateIndex(r,i),t+=e.charAt(r)}),t}function i(r,n,t,i){var a;if(l(r))return a=new s(e.clone(r)),a.subset(n,t,i),a.valueOf();if(r instanceof s)return r.clone().subset(n,t,i);if(c(r))return o(r,n,t,i);throw new e.error.UnsupportedTypeError("subset",r)}function o(e,r,n,t){if(!(r instanceof u))throw new TypeError("Index expected");if(1!=r.size().length)throw new RangeError("Dimension mismatch ("+r.size().length+" != 1)");if(void 0!==t){if(!c(t)||1!==t.length)throw new TypeError("Single character expected as defaultValue")}else t=" ";var i=r.range(0),o=i.size()[0];if(o!=n.length)throw new RangeError("Dimension mismatch ("+i.size()[0]+" != "+n.length+")");for(var a=e.length,s=[],l=0;a>l;l++)s[l]=e.charAt(l);if(i.forEach(function(e,r){f.validateIndex(e),s[e]=n.charAt(r)}),s.length>a)for(l=a-1,o=s.length;o>l;l++)s[l]||(s[l]=t);return s.join("")}var a=n(112),s=n(11),u=n(10),f=a.array,c=a.string.isString,l=Array.isArray;e.subset=function(){switch(arguments.length){case 2:return r(arguments[0],arguments[1]);case 3:case 4:return i(arguments[0],arguments[1],arguments[2],arguments[3]);default:throw new e.error.ArgumentsError("subset",arguments.length,2,4)}}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(11),i=(n(14),r.object),o=r.string;e.transpose=function(r){if(1!=arguments.length)throw new e.error.ArgumentsError("transpose",arguments.length,1);var n=e.size(r).valueOf();switch(n.length){case 0:return i.clone(r);case 1:return i.clone(r);case 2:var a,s=n[1],u=n[0],f=r instanceof t,c=r.valueOf(),l=[],m=i.clone;if(0===s)throw new RangeError("Cannot transpose a 2D matrix with no rows(size: "+o.format(n)+")");for(var p=0;s>p;p++){a=l[p]=[];for(var h=0;u>h;h++)a[h]=m(c[h][p])}return f?new t(l):l;default:throw new RangeError("Matrix must be two dimensional (size: "+o.format(n)+")")}}}},function(e,r,n){e.exports=function(e,r){var t=n(112),i=n(111),o=n(11),a=n(14),s=t.array,u=t.number.toNumber,f=Array.isArray;e.zeros=function(e){var n=a.argsToArray(arguments),t=e instanceof o?!0:f(e)?!1:"matrix"===r.matrix;if(0==n.length)return t?new o:[];var c=[],l=n[0]instanceof i?new i(0):0;return c=s.resize(c,n.map(u),l),t?new o(c):c}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(14),o=r.number.isNumber,a=r["boolean"].isBoolean,s=r.number.isInteger,u=i.isCollection;e.factorial=function c(r){var n,l;if(1!=arguments.length)throw new e.error.ArgumentsError("factorial",arguments.length,1);if(o(r)){if(!s(r)||0>r)throw new TypeError("Positive integer value expected in function factorial");for(n=r-1,l=r;n>1;)l*=n,n--;return 0==l&&(l=1),l}if(r instanceof t){if(!f(r))throw new TypeError("Positive integer value expected in function factorial");var m=new t(1);for(n=r.minus(m),l=r;n.gt(m);)l=l.times(n),n=n.minus(m);return l.equals(0)&&(l=m),l}if(a(r))return 1;if(u(r))return i.deepMap(r,c);throw new e.error.UnsupportedTypeError("factorial",r)};var f=function(e){return e.round().equals(e)&&e.gte(0)}}},function(e,r,n){e.exports=function(e,r){var t=n(11),i=(n(14),{uniform:function(){return Math.random},normal:function(){return function(){for(var e,r,n=-1;0>n||n>1;)e=Math.random(),r=Math.random(),n=1/6*Math.pow(-2*Math.log(e),.5)*Math.cos(2*Math.PI*r)+.5;return n}}});e.distribution=function(n){if(!i.hasOwnProperty(n))throw new Error("unknown distribution "+n);var o=Array.prototype.slice.call(arguments,1),a=i[n].apply(this,o);return function(n){var i={random:function(n,i,a){var u,f,c;if(arguments.length>3)throw new e.error.ArgumentsError("random",arguments.length,0,3);if(1===arguments.length?Array.isArray(n)?u=n:c=n:2===arguments.length?Array.isArray(n)?u=n:(f=n,c=i):(u=n,f=i,c=a),void 0===c&&(c=1),void 0===f&&(f=0),void 0!==u){var l=s(u,f,c,o);return"array"===r.matrix?l:new t(l)}return o(f,c)},randomInt:function(n,i,o){var u,f,c;if(arguments.length>3||arguments.length<1)throw new e.error.ArgumentsError("randomInt",arguments.length,1,3);if(1===arguments.length?c=n:2===arguments.length?"[object Array]"===Object.prototype.toString.call(n)?u=n:(f=n,c=i):(u=n,f=i,c=o),void 0===f&&(f=0),void 0!==u){var l=s(u,f,c,a);return"array"===r.matrix?l:new t(l)}return a(f,c)},pickRandom:function(r){if(1!==arguments.length)throw new e.error.ArgumentsError("pickRandom",arguments.length,1);if(!Array.isArray(r))throw new e.error.UnsupportedTypeError("pickRandom",r);return r[Math.floor(Math.random()*r.length)]}},o=function(e,r){return e+n()*(r-e)},a=function(e,r){return Math.floor(e+n()*(r-e))},s=function(e,r,n,t){var i,o,a=[];if(e=e.slice(0),e.length>1)for(o=0,i=e.shift();i>o;o++)a.push(s(e,r,n,t));else for(o=0,i=e.shift();i>o;o++)a.push(t(r,n));return a};return i}(a)};var o=e.distribution("uniform");e.random=o.random,e.randomInt=o.randomInt,e.pickRandom=o.pickRandom}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=r.number.isNumber,o=r.number.isInteger,a=r.number.toBigNumber;e.permutations=function(r,n){var u,f,c=arguments.length;if(c>2)throw new e.error.ArgumentsError("permutations",arguments.length,2);if(i(r)){if(!o(r)||0>r)throw new TypeError("Positive integer value expected in function permutations");if(1==c)return e.factorial(r);if(2==c&&i(n)){if(!o(n)||0>n)throw new TypeError("Positive integer value expected in function permutations");if(n>r)throw new TypeError("second argument k must be less than or equal to first argument n");for(u=1,f=r-n+1;r>=f;f++)u*=f;return u}}if(r instanceof t){if(void 0===n&&s(r))return e.factorial(r);if(n=a(n),!(n instanceof t&&s(r)&&s(n)))throw new TypeError("Positive integer value expected in function permutations");if(n.gt(r))throw new TypeError("second argument k must be less than or equal to first argument n");for(u=new t(1),f=r.minus(n).plus(1);f.lte(r);f=f.plus(1))u=u.times(f);return u}throw new e.error.UnsupportedTypeError("permutations",r)};var s=function(e){return e.round().equals(e)&&e.gte(0)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=(n(14),r.number.isNumber),o=r.number.isInteger,a=r.number.toBigNumber;e.combinations=function(r,n){var u,f,c,l,m=arguments.length;if(2!=m)throw new e.error.ArgumentsError("combinations",arguments.length,2);if(i(r)){if(!o(r)||0>r)throw new TypeError("Positive integer value enpected in function combinations");if(n>r)throw new TypeError("k must be less than or equal to n");for(u=Math.max(n,r-n),f=1,c=1;r-u>=c;c++)f=f*(u+c)/c;return f}if(r instanceof t){if(n=a(n),!(n instanceof t&&s(r)&&s(n)))throw new TypeError("Positive integer value expected in function combinations");if(n.gt(r))throw new TypeError("k must be less than n in function combinations");for(u=r.minus(n),n.lt(u)&&(u=n),f=new t(1),c=new t(1),l=r.minus(u);c.lte(l);c=c.plus(1))f=f.times(u.plus(c)).dividedBy(c);return f}throw new e.error.UnsupportedTypeError("combinations",r)};var s=function(e){return e.round().equals(e)&&e.gte(0)}}},function(e,r,n){e.exports=function(e){function r(r,n){return e.smaller(r,n)?r:n}function t(r){var n=void 0;if(i.deepForEach(r,function(r){(void 0===n||e.smaller(r,n))&&(n=r)}),void 0===n)throw new Error("Cannot calculate min of an empty array");return n}var i=(n(11),n(14)),o=i.isCollection;e.min=function(e){if(0==arguments.length)throw new SyntaxError("Function min requires one or more parameters (0 provided)");if(o(e)){if(1==arguments.length)return t(e);if(2==arguments.length)return i.reduce(arguments[0],arguments[1],r);throw new SyntaxError("Wrong number of parameters")}return t(arguments)}}},function(e,r,n){e.exports=function(e){function r(r,n){return e.larger(r,n)?r:n}function t(r){var n=void 0;if(i.deepForEach(r,function(r){(void 0===n||e.larger(r,n))&&(n=r)}),void 0===n)throw new Error("Cannot calculate max of an empty array");return n}var i=(n(11),n(14)),o=i.isCollection;e.max=function(e){if(0==arguments.length)throw new SyntaxError("Function max requires one or more parameters (0 provided)");if(o(e)){if(1==arguments.length)return t(e);if(2==arguments.length)return i.reduce(arguments[0],arguments[1],r);throw new SyntaxError("Wrong number of parameters")}return t(arguments)}}},function(e,r,n){e.exports=function(e){function r(r,n){var t;return t=i.reduce(r,n,e.add),e.divide(t,a(r)[n])}function t(r){var n=0,t=0;if(i.deepForEach(r,function(r){n=e.add(n,r),t++}),0===t)throw new Error("Cannot calculate mean of an empty array"); -return e.divide(n,t)}var i=(n(11),n(14)),o=i.isCollection,a=n(142).size;e.mean=function(e){if(0==arguments.length)throw new SyntaxError("Function mean requires one or more parameters (0 provided)");if(o(e)){if(1==arguments.length)return t(e);if(2==arguments.length)return r(arguments[0],arguments[1]);throw new SyntaxError("Wrong number of parameters")}return t(arguments)}}},function(e,r,n){e.exports=function(e){function r(r){var n=u(r);n.sort(e.compare);var o=n.length;if(0==o)throw new Error("Cannot calculate median of an empty array");if(o%2==0){var s=n[o/2-1],f=n[o/2];if(!(a(s)||s instanceof i||s instanceof t))throw new e.error.UnsupportedTypeError("median",s);if(!(a(f)||f instanceof i||f instanceof t))throw new e.error.UnsupportedTypeError("median",f);return e.divide(e.add(s,f),2)}var c=n[(o-1)/2];if(!(a(c)||c instanceof i||c instanceof t))throw new e.error.UnsupportedTypeError("median",c);return c}var t=(n(11),n(12)),i=n(111),o=n(14),a=n(143).isNumber,s=o.isCollection,u=n(142).flatten;e.median=function(e){if(0==arguments.length)throw new SyntaxError("Function median requires one or more parameters (0 provided)");if(s(e)){if(1==arguments.length)return r(e.valueOf());throw 2==arguments.length?new Error("median(A, dim) is not yet supported"):new SyntaxError("Wrong number of parameters")}return r(Array.prototype.slice.call(arguments))}}},function(e,r,n){e.exports=function(e){function r(r){var n=void 0;if(t.deepForEach(r,function(r){n=void 0===n?r:e.multiply(n,r)}),void 0===n)throw new Error("Cannot calculate prod of an empty array");return n}var t=(n(11),n(14)),i=t.isCollection;e.prod=function(e){if(0==arguments.length)throw new SyntaxError("Function prod requires one or more parameters (0 provided)");if(i(e)){if(1==arguments.length)return r(e);throw 2==arguments.length?new Error("prod(A, dim) is not yet supported"):new SyntaxError("Wrong number of parameters")}return r(arguments)}}},function(e){e.exports=function(e){e.std=function(){if(0==arguments.length)throw new SyntaxError("Function std requires one or more parameters (0 provided)");var r=e["var"].apply(null,arguments);return e.sqrt(r)}}},function(e,r,n){e.exports=function(e){function r(r){var n=void 0;if(t.deepForEach(r,function(r){n=void 0===n?r:e.add(n,r)}),void 0===n)throw new Error("Cannot calculate sum of an empty array");return n}var t=(n(11),n(14)),i=t.isCollection;e.sum=function(e){if(0==arguments.length)throw new SyntaxError("Function sum requires one or more parameters (0 provided)");if(i(e)){if(1==arguments.length)return r(e);throw 2==arguments.length?new Error("sum(A, dim) is not yet supported"):new SyntaxError("Wrong number of parameters")}return r(arguments)}}},function(e,r,n){e.exports=function(e){function r(r,n){var o=0,a=0;if(i.deepForEach(r,function(r){o=e.add(o,r),a++}),0===a)throw new Error("Cannot calculate var of an empty array");var s=e.divide(o,a);switch(o=0,i.deepForEach(r,function(r){var n=e.subtract(r,s);o=e.add(o,e.multiply(n,n))}),n){case"uncorrected":return e.divide(o,a);case"biased":return e.divide(o,a+1);case"unbiased":var u=o instanceof t?new t(0):0;return 1==a?u:e.divide(o,a-1);default:throw new Error('Unknown normalization "'+n+'". Choose "unbiased" (default), "uncorrected", or "biased".')}}var t=(n(11),n(111)),i=n(14),o=i.isCollection,a=n(127).isString,s="unbiased";e["var"]=function(e,n){if(0==arguments.length)throw new SyntaxError("Function var requires one or more parameters (0 provided)");if(o(e)){if(1==arguments.length)return r(e,s);if(2==arguments.length){if(!a(n))throw new Error("String expected for parameter normalization");return r(e,n)}throw new SyntaxError("Wrong number of parameters")}return r(arguments,s)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=n(14),a=r.number.isNumber,s=r["boolean"].isBoolean,u=i.isComplex,f=o.isCollection;e.acos=function c(n){if(1!=arguments.length)throw new e.error.ArgumentsError("acos",arguments.length,1);if(a(n))return n>=-1&&1>=n?Math.acos(n):c(new i(n,0));if(u(n)){var l=new i(n.im*n.im-n.re*n.re+1,-2*n.re*n.im),m=e.sqrt(l),p=new i(m.re-n.im,m.im+n.re),h=e.log(p);return new i(1.5707963267948966-h.im,h.re)}if(f(n))return o.deepMap(n,c);if(s(n))return Math.acos(n);if(n instanceof t)return c(r.number.toNumber(n));throw new e.error.UnsupportedTypeError("acos",n)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=n(14),a=r.number.isNumber,s=r["boolean"].isBoolean,u=i.isComplex,f=o.isCollection;e.asin=function c(n){if(1!=arguments.length)throw new e.error.ArgumentsError("asin",arguments.length,1);if(a(n))return n>=-1&&1>=n?Math.asin(n):c(new i(n,0));if(u(n)){var l=n.re,m=n.im,p=new i(m*m-l*l+1,-2*l*m),h=e.sqrt(p),g=new i(h.re-m,h.im+l),d=e.log(g);return new i(d.im,-d.re)}if(f(n))return o.deepMap(n,c);if(s(n))return Math.asin(n);if(n instanceof t)return c(r.number.toNumber(n));throw new e.error.UnsupportedTypeError("asin",n)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=n(14),a=r.number.isNumber,s=r["boolean"].isBoolean,u=i.isComplex,f=o.isCollection;e.atan=function c(n){if(1!=arguments.length)throw new e.error.ArgumentsError("atan",arguments.length,1);if(a(n))return Math.atan(n);if(u(n)){var l=n.re,m=n.im,p=l*l+(1-m)*(1-m),h=new i((1-m*m-l*l)/p,-2*l/p),g=e.log(h);return new i(-.5*g.im,.5*g.re)}if(f(n))return o.deepMap(n,c);if(s(n))return Math.atan(n);if(n instanceof t)return c(r.number.toNumber(n));throw new e.error.UnsupportedTypeError("atan",n)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=n(14),a=r.number.toNumber,s=r.number.isNumber,u=r["boolean"].isBoolean,f=(i.isComplex,o.isCollection);e.atan2=function c(r,n){if(2!=arguments.length)throw new e.error.ArgumentsError("atan2",arguments.length,2);if(s(r)&&s(n))return Math.atan2(r,n);if(f(r)||f(n))return o.deepMap2(r,n,c);if(u(r))return c(+r,n);if(u(n))return c(r,+n);if(r instanceof t)return c(a(r),n);if(n instanceof t)return c(r,a(n));throw new e.error.UnsupportedTypeError("atan2",r,n)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=n(12),a=n(14),s=r.number.isNumber,u=r["boolean"].isBoolean,f=i.isComplex,c=o.isUnit,l=a.isCollection;e.cos=function m(n){if(1!=arguments.length)throw new e.error.ArgumentsError("cos",arguments.length,1);if(s(n))return Math.cos(n);if(f(n))return new i(.5*Math.cos(n.re)*(Math.exp(-n.im)+Math.exp(n.im)),.5*Math.sin(n.re)*(Math.exp(-n.im)-Math.exp(n.im)));if(c(n)){if(!n.hasBase(o.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cos is no angle");return Math.cos(n.value)}if(l(n))return a.deepMap(n,m);if(u(n))return Math.cos(n);if(n instanceof t)return m(r.number.toNumber(n));throw new e.error.UnsupportedTypeError("cos",n)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=n(12),a=n(14),s=r.number.isNumber,u=r["boolean"].isBoolean,f=i.isComplex,c=o.isUnit,l=a.isCollection;e.cot=function m(n){if(1!=arguments.length)throw new e.error.ArgumentsError("cot",arguments.length,1);if(s(n))return 1/Math.tan(n);if(f(n)){var p=Math.exp(-4*n.im)-2*Math.exp(-2*n.im)*Math.cos(2*n.re)+1;return new i(2*Math.exp(-2*n.im)*Math.sin(2*n.re)/p,(Math.exp(-4*n.im)-1)/p)}if(c(n)){if(!n.hasBase(o.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cot is no angle");return 1/Math.tan(n.value)}if(l(n))return a.deepMap(n,m);if(u(n))return m(+n);if(n instanceof t)return m(r.number.toNumber(n));throw new e.error.UnsupportedTypeError("cot",n)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=n(12),a=n(14),s=r.number.isNumber,u=r["boolean"].isBoolean,f=i.isComplex,c=o.isUnit,l=a.isCollection;e.csc=function m(n){if(1!=arguments.length)throw new e.error.ArgumentsError("csc",arguments.length,1);if(s(n))return 1/Math.sin(n);if(f(n)){var p=.25*(Math.exp(-2*n.im)+Math.exp(2*n.im))-.5*Math.cos(2*n.re);return new i(.5*Math.sin(n.re)*(Math.exp(-n.im)+Math.exp(n.im))/p,.5*Math.cos(n.re)*(Math.exp(-n.im)-Math.exp(n.im))/p)}if(c(n)){if(!n.hasBase(o.BASE_UNITS.ANGLE))throw new TypeError("Unit in function csc is no angle");return 1/Math.sin(n.value)}if(l(n))return a.deepMap(n,m);if(u(n))return m(+n);if(n instanceof t)return m(r.number.toNumber(n));throw new e.error.UnsupportedTypeError("csc",n)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=n(12),a=n(14),s=r.number.isNumber,u=r["boolean"].isBoolean,f=i.isComplex,c=o.isUnit,l=a.isCollection;e.sec=function m(n){if(1!=arguments.length)throw new e.error.ArgumentsError("sec",arguments.length,1);if(s(n))return 1/Math.cos(n);if(f(n)){var p=.25*(Math.exp(-2*n.im)+Math.exp(2*n.im))+.5*Math.cos(2*n.re);return new i(.5*Math.cos(n.re)*(Math.exp(-n.im)+Math.exp(n.im))/p,.5*Math.sin(n.re)*(Math.exp(n.im)-Math.exp(-n.im))/p)}if(c(n)){if(!n.hasBase(o.BASE_UNITS.ANGLE))throw new TypeError("Unit in function sec is no angle");return 1/Math.cos(n.value)}if(l(n))return a.deepMap(n,m);if(u(n))return m(+n);if(n instanceof t)return m(r.number.toNumber(n));throw new e.error.UnsupportedTypeError("sec",n)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=n(12),a=n(14),s=r.number.isNumber,u=r["boolean"].isBoolean,f=i.isComplex,c=o.isUnit,l=a.isCollection;e.sin=function m(n){if(1!=arguments.length)throw new e.error.ArgumentsError("sin",arguments.length,1);if(s(n))return Math.sin(n);if(f(n))return new i(.5*Math.sin(n.re)*(Math.exp(-n.im)+Math.exp(n.im)),.5*Math.cos(n.re)*(Math.exp(n.im)-Math.exp(-n.im)));if(c(n)){if(!n.hasBase(o.BASE_UNITS.ANGLE))throw new TypeError("Unit in function sin is no angle");return Math.sin(n.value)}if(l(n))return a.deepMap(n,m);if(u(n))return Math.sin(n);if(n instanceof t)return m(r.number.toNumber(n));throw new e.error.UnsupportedTypeError("sin",n)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(111),i=n(8),o=n(12),a=n(14),s=r.number.isNumber,u=r["boolean"].isBoolean,f=i.isComplex,c=o.isUnit,l=a.isCollection;e.tan=function m(n){if(1!=arguments.length)throw new e.error.ArgumentsError("tan",arguments.length,1);if(s(n))return Math.tan(n);if(f(n)){var p=Math.exp(-4*n.im)+2*Math.exp(-2*n.im)*Math.cos(2*n.re)+1;return new i(2*Math.exp(-2*n.im)*Math.sin(2*n.re)/p,(1-Math.exp(-4*n.im))/p)}if(c(n)){if(!n.hasBase(o.BASE_UNITS.ANGLE))throw new TypeError("Unit in function tan is no angle");return Math.tan(n.value)}if(l(n))return a.deepMap(n,m);if(u(n))return Math.tan(n);if(n instanceof t)return m(r.number.toNumber(n));throw new e.error.UnsupportedTypeError("tan",n)}}},function(e,r,n){e.exports=function(e){var r=n(112),t=n(12),i=n(14),o=r.string.isString,a=t.isUnit,s=i.isCollection;e.to=function u(r,n){if(2!=arguments.length)throw new e.error.ArgumentsError("to",arguments.length,2);if(a(r)&&(a(n)||o(n)))return r.to(n);if(s(r)||s(n))return i.deepMap2(r,n,u);throw new e.error.UnsupportedTypeError("to",r,n)}}},function(e,r,n){e.exports=function(e){var r=n(3);e.clone=function(n){if(1!=arguments.length)throw new e.error.ArgumentsError("clone",arguments.length,1);return r.clone(n)}}},function(e,r,n){e.exports=function(e){var r=n(127);e.format=function(n,t){var i=arguments.length;if(1!==i&&2!==i)throw new e.error.ArgumentsError("format",i,1,2);return r.format(n,t)}}},function(e){e.exports=function(e){e.ifElse=function(r,n,t){if(3!=arguments.length)throw new e.error.ArgumentsError("ifElse",arguments.length,3);return r?n:t}}},function(e,r,n){e.exports=function(e){function r(r,n,t){(t.override||void 0===e[r])&&(e[r]=t.wrap&&"function"==typeof n?function(){for(var r=[],t=0,i=arguments.length;i>t;t++)r[t]=arguments[t].valueOf();return n.apply(e,r)}:n,e.chaining.Selector.createProxy(r,n))}function t(e){return"function"==typeof e||s(e)||u(e)||f(e)||c(e)}var i=n(112),o=n(8),a=n(12),s=i.number.isNumber,u=i.string.isString,f=o.isComplex,c=a.isUnit;e["import"]=function l(o,a){var s=arguments.length;if(1!=s&&2!=s)throw new e.error.ArgumentsError("import",s,1,2);var f,c={override:!1,wrap:!0};if(a&&a instanceof Object&&i.object.extend(c,a),u(o)){var m=n(144)(o);l(m)}else{if("object"!=typeof o)throw new TypeError("Object or module name expected");for(f in o)if(o.hasOwnProperty(f)){var p=o[f];t(p)?r(f,p,c):l(p)}}}}},function(e,r,n){e.exports=function(e){function r(e,r){var n=[],t=function(i,o){return Array.isArray(i)?i.map(function(e,r){return n[o]=r,t(e,o+1)}):r(i,n,e)};return t(e,0)}var t=n(11).isMatrix;e.map=function(n,i){if(2!=arguments.length)throw new e.error.ArgumentsError("map",arguments.length,2);if(Array.isArray(n))return r(n,i);if(t(n))return n.map(i);throw new e.error.UnsupportedTypeError("map",n)}}},function(e,r,n){e.exports=function(e){var r=n(127),t=r.isString;e.print=function(r,n,i){var o=arguments.length;if(2!=o&&3!=o)throw new e.error.ArgumentsError("print",o,2,3);if(!t(r))throw new TypeError("String expected as first parameter in function format");if(!(n instanceof Object))throw new TypeError("Object expected as second parameter in function format");return r.replace(/\$([\w\.]+)/g,function(r,o){for(var a=o.split("."),s=n[a.shift()];a.length&&void 0!==s;){var u=a.shift();s=u?s[u]:s+"."}return void 0!==s?t(s)?s:e.format(s,i):r})}}},function(e,r,n){e.exports=function(e){var r=n(126),t=n(111),i=n(8),o=n(11),a=n(12),s=n(10),u=n(9),f=n(13);e["typeof"]=function(n){if(1!=arguments.length)throw new e.error.ArgumentsError("typeof",arguments.length,1);var c=r.type(n);if("object"===c){if(n instanceof i)return"complex";if(n instanceof t)return"bignumber";if(n instanceof o)return"matrix";if(n instanceof a)return"unit";if(n instanceof s)return"index";if(n instanceof u)return"range";if(n instanceof f)return"help";if(n instanceof e.chaining.Selector)return"selector"}return c}}},function(e,r,n){e.exports=function(e){function r(e,r){var n=[],t=function(i,o){Array.isArray(i)?i.forEach(function(e,r){n[o]=r,t(e,o+1)}):r(i,n,e)};t(e,0)}var t=n(11).isMatrix;e.forEach=function(n,i){if(2!=arguments.length)throw new e.error.ArgumentsError("forEach",arguments.length,2);if(Array.isArray(n))return r(n,i);if(t(n))return n.forEach(i);throw new e.error.UnsupportedTypeError("forEach",n)}}},function(e,r,n){var t;!function(i){"use strict";function o(e,r){var n,t,i,u,f,c,p=this;if(!(p instanceof o))return new o(e,r);if(e instanceof o){if(A=0,r===n)return p.s=e.s,p.e=e.e,void(p.c=(e=e.c)?e.slice():e);e+=""}if("string"!=typeof e&&(e=(i="number"==typeof e||"[object Number]"==Object.prototype.toString.call(e))&&0===e&&0>1/e?"-0":e+""),c=e,r===n&&T.test(e))p.s="-"==e.charAt(0)?(e=e.slice(1),-1):1;else{if(10==r)return l(e,g,d);if(e=O.call(e).replace(/^\+(?!-)/,""),p.s="-"==e.charAt(0)?(e=e.replace(/^-(?!-)/,""),-1):1,null!=r?r!=(0|r)&&b||(m=!(r>=2&&65>r))?(a(r,2),f=T.test(e)):(u="["+M.slice(0,r=0|r)+"]+",e=e.replace(/\.$/,"").replace(/^\./,"0."),(f=new RegExp("^"+u+"(?:\\."+u+")?$",37>r?"i":"").test(e))?(i&&(e.replace(/^0\.0*|\./,"").length>15&&a(c,0),i=!i),e=s(e,10,r,p.s)):"Infinity"!=e&&"NaN"!=e&&(a(c,1,r),e="NaN")):f=T.test(e),!f)return p.c=p.e=null,"Infinity"!=e&&("NaN"!=e&&a(c,3),p.s=null),void(A=0)}for((n=e.indexOf("."))>-1&&(e=e.replace(".","")),(t=e.search(/e/i))>0?(0>n&&(n=t),n+=+e.slice(t+1),e=e.substring(0,t)):0>n&&(n=e.length),t=0;"0"==e.charAt(t);t++);if(r=e.length,i&&r>15&&e.slice(t).length>15&&a(c,0),A=0,(n-=t+1)>y)p.c=p.e=null;else if(t==r||v>n)p.c=[p.e=0];else{for(;"0"==e.charAt(--r););for(p.e=n,p.c=[],n=0;r>=t;p.c[n++]=+e.charAt(t++));}}function a(e,r,n,t,i,o){if(b){var a,s=["new BigNumber","cmp","div","eq","gt","gte","lt","lte","minus","mod","plus","times","toFr"][A?0>A?-A:A:0>1/A?1:0]+"()",u=m?" out of range":" not a"+(i?" non-zero":"n")+" integer";throw u=([s+" number type has more than 15 significant digits",s+" not a base "+n+" number",s+" base"+u,s+" not a number"][r]||n+"() "+r+(o?" not a boolean or binary digit":u+(t?" or not ["+(m?" negative, positive":" integer, integer")+" ]":"")))+": "+e,m=A=0,a=new Error(u),a.name="BigNumber Error",a}}function s(e,r,n,t){function i(e,t){var i,o,a=0,s=e.length,u=[0];for(t=t||n;s>a;a++){for(o=u.length,i=0;o>i;u[i]*=t,i++);for(u[0]+=M.indexOf(e.charAt(a)),i=0;ir-1&&(null==u[i+1]&&(u[i+1]=0),u[i+1]+=u[i]/r^0,u[i]%=r)}return u.reverse()}function a(e){for(var r=0,n=e.length,t="";n>r;t+=M.charAt(e[r++]));return t}var s,f,c,l,m,p;if(37>n&&(e=e.toLowerCase()),(s=e.indexOf("."))>-1)if(s=e.length-s-1,f=i(new o(n).pow(s).toF(),10),l=e.split("."),c=i(l[1]),l=i(l[0]),p=u(c,f,c.length-f.length,t,r,1&l[l.length-1]),m=p.c,s=p.e){for(;++s;m.unshift(0));e=a(l)+"."+a(m)}else m[0]?l[s=l.length-1]M?0:M;w++f;f++){if(s!=(w=x.length))l=s>w?1:-1;else for(m=-1,l=0;++mx[m]?1:-1;break}if(!(0>l))break;for(u=w==s?r:p;w;){if(x[--w]M&&c(b,g,i,a,null!=x[0]),b.e>y?b.c=b.e=null:b.e++r&&c(e,t,10),t=0==i[0]?t+1:n?r:e.e+t+1;i.length=t)?(e.s<0&&i[0]?"-":"")+(i.length>1?(i.splice(1,0,"."),i.join("")):i[0])+(0>t?"e":"e+")+t:e.toS()}function c(e,r,n,t,i){var o=e.c,a=e.s<0,s=n/2,u=e.e+r+1,f=o[u],c=i||0>u||null!=o[u+1];if(i=4>d?(null!=f||c)&&(0==d||2==d&&!a||3==d&&a):f>s||f==s&&(4==d||c||6==d&&(1&o[u-1]||!r&&t)||7==d&&!a||8==d&&a),1>u||!o[0])return o.length=0,o.push(0),i?(o[0]=1,e.e=-r):e.e=0,e;if(o.length=u--,i)for(--n;++o[u]>n;)o[u]=0,u--||(++e.e,o.unshift(1));for(u=o.length;!o[--u];o.pop());return e}function l(e,r,n){var t=d;return d=n,e=new o(e),e.c&&c(e,r,10),d=t,e}var m,p=1e9,h=1e6,g=20,d=4,x=-7,w=21,v=-p,y=p,b=!0,E=parseInt,N=o.prototype,M="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_",A=0,T=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,O=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")},S=o(1);o.ROUND_UP=0,o.ROUND_DOWN=1,o.ROUND_CEIL=2,o.ROUND_FLOOR=3,o.ROUND_HALF_UP=4,o.ROUND_HALF_DOWN=5,o.ROUND_HALF_EVEN=6,o.ROUND_HALF_CEIL=7,o.ROUND_HALF_FLOOR=8,o.config=function(){var e,r,n=0,t={},i=arguments,o=i[0],s="config",u=function(e,r,n){return!((m=r>e||e>n)||E(e)!=e&&0!==e)},f=o&&"object"==typeof o?function(){return o.hasOwnProperty(r)?null!=(e=o[r]):void 0}:function(){return i.length>n?null!=(e=i[n++]):void 0};return f(r="DECIMAL_PLACES")&&(u(e,0,p)?g=0|e:a(e,r,s)),t[r]=g,f(r="ROUNDING_MODE")&&(u(e,0,8)?d=0|e:a(e,r,s)),t[r]=d,f(r="EXPONENTIAL_AT")&&(u(e,-p,p)?x=-(w=~~(0>e?-e:+e)):!m&&e&&u(e[0],-p,0)&&u(e[1],0,p)?(x=~~e[0],w=~~e[1]):a(e,r,s,1)),t[r]=[x,w],f(r="RANGE")&&(u(e,-p,p)&&~~e?v=-(y=~~(0>e?-e:+e)):!m&&e&&u(e[0],-p,-1)&&u(e[1],1,p)?(v=~~e[0],y=~~e[1]):a(e,r,s,1,1)),t[r]=[v,y],f(r="ERRORS")&&(e===!!e||1===e||0===e?(m=A=0,E=(b=!!e)?parseInt:parseFloat):a(e,r,s,0,0,1)),t[r]=b,t},N.abs=N.absoluteValue=function(){var e=new o(this);return e.s<0&&(e.s=1),e},N.ceil=function(){return l(this,0,2)},N.comparedTo=N.cmp=function(e,r){var n,t=this,i=t.c,a=(A=-A,e=new o(e,r)).c,s=t.s,u=e.s,f=t.e,c=e.e;if(!s||!u)return null;if(n=i&&!i[0],r=a&&!a[0],n||r)return n?r?0:-u:s;if(s!=u)return s;if(n=0>s,r=f==c,!i||!a)return r?0:!i^n?1:-1;if(!r)return f>c^n?1:-1;for(s=-1,u=(f=i.length)<(c=a.length)?f:c;++sa[s]^n?1:-1;return f==c?0:f>c^n?1:-1},N.dividedBy=N.div=function(e,r){var n=this.c,t=this.e,i=this.s,a=(A=2,e=new o(e,r)).c,s=e.e,f=e.s,c=i==f?1:-1;return(t||n&&n[0])&&(s||a&&a[0])?u(n,a,t-s,c,10):new o(i&&f&&(n?!a||n[0]!=a[0]:a)?n&&0==n[0]||!a?0*c:c/0:0/0)},N.equals=N.eq=function(e,r){return A=3,0===this.cmp(e,r)},N.floor=function(){return l(this,0,3)},N.greaterThan=N.gt=function(e,r){return A=4,this.cmp(e,r)>0},N.greaterThanOrEqualTo=N.gte=function(e,r){return A=5,1==(r=this.cmp(e,r))||0===r},N.isFinite=N.isF=function(){return!!this.c},N.isNaN=function(){return!this.s},N.isNegative=N.isNeg=function(){return this.s<0},N.isZero=N.isZ=function(){return!!this.c&&0==this.c[0]},N.lessThan=N.lt=function(e,r){return A=6,this.cmp(e,r)<0},N.lessThanOrEqualTo=N.lte=function(e,r){return A=7,-1==(r=this.cmp(e,r))||0===r},N.minus=function(e,r){var n,t,i,a,s=this,u=s.s;if(r=(A=8,e=new o(e,r)).s,!u||!r)return new o(0/0);if(u!=r)return e.s=-r,s.plus(e);var f=s.c,c=s.e,l=e.c,m=e.e;if(!c||!m){if(!f||!l)return f?(e.s=-r,e):new o(l?s:0/0);if(!f[0]||!l[0])return l[0]?(e.s=-r,e):new o(f[0]?s:3==d?-0:0)}if(f=f.slice(),u=c-m){for(n=(a=0>u)?(u=-u,f):(m=c,l),n.reverse(),r=u;r--;n.push(0));n.reverse()}else for(i=((a=f.lengthr;r++)if(f[r]!=l[r]){a=f[r]0)for(;r--;f[i++]=0);for(r=l.length;r>u;){if(f[--r]m||!f[0])&&(f[0]||(e.s=3==d?-1:1),f=[m=0]),e.c=f,e.e=m,e},N.modulo=N.mod=function(e,r){var n=this,t=n.c,i=(A=9,e=new o(e,r)).c,a=n.s,s=e.s;return r=!a||!s||i&&!i[0],r||t&&!t[0]?new o(r?0/0:n):(n.s=e.s=1,r=1==e.cmp(n),n.s=a,e.s=s,r?new o(n):(a=g,s=d,g=0,d=1,n=n.div(e),g=a,d=s,this.minus(n.times(e))))},N.negated=N.neg=function(){var e=new o(this);return e.s=-e.s||null,e},N.plus=function(e,r){var n,t=this,i=t.s;if(r=(A=10,e=new o(e,r)).s,!i||!r)return new o(0/0);if(i!=r)return e.s=-r,t.minus(e);var a=t.e,s=t.c,u=e.e,f=e.c;if(!a||!u){if(!s||!f)return new o(i/0);if(!s[0]||!f[0])return f[0]?e:new o(s[0]?t:0*i)}if(s=s.slice(),i=a-u){for(n=i>0?(u=a,f):(i=-i,s),n.reverse();i--;n.push(0));n.reverse()}for(s.length-f.length<0&&(n=f,f=s,s=n),i=f.length,r=0;i;r=(s[--i]=s[i]+f[i]+r)/10^0,s[i]%=10);for(r&&(s.unshift(r),++u>y&&(s=u=null)),i=s.length;0==s[--i];s.pop());return e.c=s,e.e=u,e},N.toPower=N.pow=function(e){var r=0*e==0?0|e:e,n=new o(this),t=new o(S);if(((m=-h>e||e>h)&&(r=1*e/0)||E(e)!=e&&0!==e&&!(r=0/0))&&!a(e,"exponent","pow")||!r)return new o(Math.pow(n.toS(),r));for(r=0>r?-r:r;1&r&&(t=t.times(n)),r>>=1,r;)n=n.times(n);return 0>e?S.div(t):t},N.round=function(e,r){return e=null==e||((m=0>e||e>p)||E(e)!=e)&&!a(e,"decimal places","round")?0:0|e,r=null==r||((m=0>r||r>8)||E(r)!=r&&0!==r)&&!a(r,"mode","round")?d:0|r,l(this,e,r)},N.squareRoot=N.sqrt=function(){var e,r,n,t,i=this,a=i.c,s=i.s,u=i.e,f=g,l=d,m=new o("0.5");if(1!==s||!a||!a[0])return new o(!s||0>s&&(!a||a[0])?0/0:a?i:1/0);for(s=Math.sqrt(i.toS()),d=1,0==s||s==1/0?(e=a.join(""),e.length+u&1||(e+="0"),r=new o(Math.sqrt(e)+""),r.c||(r.c=[1]),r.e=((u+1)/2|0)-(0>u||1&u)):r=new o(e=s.toString()),n=r.e,s=n+(g+=4),3>s&&(s=0),u=s;;)if(t=r,r=m.times(t.plus(i.div(t))),t.c.slice(0,s).join("")===r.c.slice(0,s).join("")){if(a=r.c,s-=e&&r.eu-2&&(a.length=u-2),r.times(r).eq(i)))){for(;a.length-1;s--){for(r=0,u=f+s;u>s;r=n[u]+a[s]*i[u-s-1]+r,n[u--]=r%10|0,r=r/10|0);r&&(n[u]=(n[u]+r)%10)}for(r&&++e.e,!n[0]&&n.shift(),u=n.length;!n[--u];n.pop());return e.c=e.e>y?e.e=null:e.ee||e>p)||E(e)!=e&&0!==e)&&!a(e,"decimal places","toE"))&&this.c?this.c.length-1:0|e,1)},N.toFixed=N.toF=function(e){var r,n,t,i=this;return null==e||((m=0>e||e>p)||E(e)!=e&&0!==e)&&!a(e,"decimal places","toF")||(t=i.e+(0|e)),r=x,e=w,x=-(w=1/0),t==n?n=i.toS():(n=f(i,t),i.s<0&&i.c&&(i.c[0]?n.indexOf("-")<0&&(n="-"+n):n=n.replace(/^-/,""))),x=r,w=e,n},N.toFraction=N.toFr=function(e){var r,n,t,i,s,u,f,c=i=new o(S),l=t=new o("0"),p=this,h=p.c,x=y,w=g,v=d,E=new o(S);if(!h)return p.toS();for(f=E.e=h.length-p.e-1,(null==e||(!(A=12,u=new o(e)).s||(m=u.cmp(c)<0||!u.c)||b&&u.e0)&&(e=f>0?E:c),y=1/0,u=new o(h.join("")),g=0,d=1;r=u.div(E),s=i.plus(r.times(l)),1!=s.cmp(e);)i=l,l=s,c=t.plus(r.times(s=c)),t=s,E=u.minus(r.times(s=E)),u=s;return s=e.minus(i).div(l),t=t.plus(s.times(c)),i=i.plus(s.times(l)),t.s=c.s=p.s,g=2*f,d=v,n=c.div(l).minus(p).abs().cmp(t.div(i).minus(p).abs())<1?[c.toS(),l.toS()]:[t.toS(),i.toS()],y=x,g=w,n},N.toPrecision=N.toP=function(e){return null==e||((m=1>e||e>p)||E(e)!=e)&&!a(e,"precision","toP")?this.toS():f(this,0|--e,2)},N.toString=N.toS=function(e){var r,n,t,i=this,o=i.e;if(null===o)n=i.s?"Infinity":"NaN";else{if(e===r&&(x>=o||o>=w))return f(i,i.c.length-1,1);if(n=i.c.join(""),0>o){for(;++o;n="0"+n);n="0."+n}else if(t=n.length,o>0)if(++o>t)for(o-=t;o--;n+="0");else t>o&&(n=n.slice(0,o)+"."+n.slice(o));else if(r=n.charAt(0),t>1)n=r+"."+n.slice(1);else if("0"==r)return r;if(null!=e)if((m=!(e>=2&&65>e))||e!=(0|e)&&b)a(e,"base","toS");else if(n=s(n,0|e,10,i.s),"0"==n)return n}return i.s<0?"-"+n:n},N.valueOf=function(){return this.toS()},"undefined"!=typeof e&&e.exports?e.exports=o:(t=function(){return o}.call(r,n,r,e),!(void 0!==t&&(e.exports=t)))}(this)},function(e,r,n){r.array=n(142),r["boolean"]=n(237),r.number=n(143),r.object=n(3),r.string=n(127),r.types=n(126)},function(e,r,n){function t(e){if(!(this instanceof t))throw new SyntaxError("Constructor must be called with the new operator");if(this.nodes=e||[],!a(this.nodes)||!this.nodes.every(s))throw new TypeError("Array containing Nodes expected")}var i=n(125),o=(n(3),n(127)),a=(n(14),n(11),n(112),Array.isArray),s=i.isNode;t.prototype=new i,t.prototype._compile=function(e){var r="array"!==e.math.config().matrix,n=this.nodes.map(function(r){return r._compile(e)});return(r?"math.matrix([":"[")+n.join(",")+(r?"])":"]")},t.prototype.find=function(e){var r=[];this.match(e)&&r.push(this);for(var n=this.nodes,t=0,i=n.length;i>t;t++)r=r.concat(n[t].find(e));return r},t.prototype.toString=function(){return o.format(this.nodes)},e.exports=t},function(e,r,n){function t(e,r){if(!(this instanceof t))throw new SyntaxError("Constructor must be called with the new operator");if(!o(e))throw new TypeError('String expected for parameter "name"');if(!(r instanceof i))throw new TypeError('Node expected for parameter "expr"');this.name=e,this.expr=r}var i=n(125),o=n(127).isString;t.prototype=new i,t.prototype._compile=function(e){return'scope["'+this.name+'"] = '+this.expr._compile(e)},t.prototype.find=function(e){var r=[];return this.match(e)&&r.push(this),r=r.concat(this.expr.find(e))},t.prototype.toString=function(){return this.name+" = "+this.expr.toString()},e.exports=t},function(e,r,n){function t(){if(!(this instanceof t))throw new SyntaxError("Constructor must be called with the new operator");this.params=[]}var i=n(125),o=n(237).isBoolean;t.prototype=new i,t.prototype.add=function(e,r){if(void 0===r&&(r=!0),!(e instanceof i))throw new TypeError('Node expected for parameter "expr"');if(!o(r))throw new TypeError('Boolean expected for parameter "visible"');var n=this.params.length;this.params[n]={node:e,visible:r}},t.prototype._compile=function(e){var r=this.params.map(function(r){var n=r.node._compile(e);return r.visible?"results.push("+n+");":n+";"});return"(function () {var results = [];"+r.join("")+"return results;})()"},t.prototype.find=function(e){var r=[];this.match(e)&&r.push(this);for(var n=this.params,t=0,i=n.length;i>t;t++)r=r.concat(n[t].node.find(e));return r},t.prototype.toString=function(){return this.params.map(function(e){return e.node.toString()+(e.visible?"":";")}).join("\n")},e.exports=t},function(e,r,n){function t(e,r){if(!(this instanceof t))throw new SyntaxError("Constructor must be called with the new operator");if(!a(e))throw new TypeError('String expected for parameter "type"');if(!a(r))throw new TypeError('String expected for parameter "value"');this.type=e,this.value=r}var i=n(125),o=(n(8),n(111),n(127)),a=o.isString;t.prototype=new i,t.prototype._compile=function(e){switch(this.type){case"number":return"bignumber"===e.math.config().number?'math.bignumber("'+this.value+'")':this.value.replace(/^(0*)[0-9]/,function(e,r){return e.substring(r.length)});case"string":return'"'+this.value+'"';case"complex":return"math.complex(0, "+this.value+")";case"boolean":return this.value;case"undefined":return this.value;case"null":return this.value;default:throw new TypeError('Unsupported type of constant "'+this.type+'"')}},t.prototype.toString=function(){switch(this.type){case"string":return'"'+this.value+'"';case"complex":return this.value+"i";default:return this.value}},e.exports=t},function(e,r,n){function t(e,r,n){if(!(this instanceof t))throw new SyntaxError("Constructor must be called with the new operator");if(!o(e))throw new TypeError('String expected for parameter "name"');if(!isArray(r)||!r.every(o))throw new TypeError('Array containing strings expected for parameter "args"');if(!(n instanceof i))throw new TypeError('Node expected for parameter "expr"');this.name=e,this.args=r,this.expr=n}var i=n(125),o=n(127).isString;isArray=Array.isArray,t.prototype=new i,t.prototype._compile=function(e){return'scope["'+this.name+'"] = (function (scope) { scope = Object.create(scope); var fn = function '+this.name+"("+this.args.join(",")+") { if (arguments.length != "+this.args.length+') { throw new SyntaxError("Wrong number of arguments in function '+this.name+' (" + arguments.length + " provided, '+this.args.length+' expected)"); }'+this.args.map(function(e,r){return'scope["'+e+'"] = arguments['+r+"];"}).join("")+" return "+this.expr._compile(e)+' }; fn.syntax = "'+this.name+"("+this.args.join(", ")+')"; return fn; })(scope);'},t.prototype.find=function(e){var r=[];return this.match(e)&&r.push(this),r=r.concat(this.expr.find(e))},t.prototype.toString=function(){return"function "+this.name+"("+this.args.join(", ")+") = "+this.expr.toString()},e.exports=t},function(e,r,n){function t(e,r){if(!(this instanceof t))throw new SyntaxError("Constructor must be called with the new operator");if(!(e instanceof o))throw new TypeError('Node expected for parameter "object"');if(!isArray(r)||!r.every(u))throw new TypeError('Array containing Nodes expected for parameter "ranges"');this.object=e,this.ranges=r}var i=n(143),o=n(125),a=n(121),s=n(122),u=(n(111),n(10),n(9),i.isNumber,i.toNumber,o.isNode);t.prototype=new o,t.prototype._compile=function(e){return this.compileSubset(e)},t.prototype.compileSubset=function(e,r){var n={type:s,properties:{name:"end"}},t=!1,i=this.ranges.map(function(e){var r=e.find(n).length>0;return t=r?r:t,r}),o=this.ranges.map(function(r,n){var t=i[n];return r instanceof a?t?'(function (scope) { scope = Object.create(scope); scope["end"] = size['+n+"]; var step = "+(r.step?r.step._compile(e):"1")+"; return [ "+r.start._compile(e)+" - 1, "+r.end._compile(e)+" - (step > 0 ? 0 : 2), step ];})(scope)":"(function () { var step = "+(r.step?r.step._compile(e):"1")+"; return [ "+r.start._compile(e)+" - 1, "+r.end._compile(e)+" - (step > 0 ? 0 : 2), step ];})()":t?'(function (scope) { scope = Object.create(scope); scope["end"] = size['+n+"]; return "+r._compile(e)+" - 1;})(scope)":r._compile(e)+" - 1"});return t?"(function () { var obj = "+this.object._compile(e)+"; var size = math.size(obj).valueOf(); return math.subset( obj, math.index("+o.join(", ")+") "+(r?", "+r:"")+" );})()":"math.subset("+this.object._compile(e)+",math.index("+o.join(", ")+")"+(r?", "+r:"")+")"},t.prototype.find=function(e){var r=[];this.match(e)&&r.push(this),r=r.concat(this.object.find(e));for(var n=this.ranges,t=0,i=n.length;i>t;t++)r=r.concat(n[t].find(e));return r},t.prototype.objectName=function(){return this.object.name},t.prototype.toString=function(){return this.object.toString()+"["+this.ranges.join(", ")+"]" -},e.exports=t},function(e,r,n){function t(e,r,n){if(!(this instanceof t))throw new SyntaxError("Constructor must be called with the new operator");this.op=e,this.fn=r,this.params=n}var i=n(125);t.prototype=new i,t.prototype._compile=function(e){if(!(this.fn in e.math))throw new Error("Function "+this.fn+' missing in provided namespace "math"');var r=this.params.map(function(r){return r._compile(e)});return"math."+this.fn+"("+r.join(", ")+")"},t.prototype.find=function(e){var r=[];this.match(e)&&r.push(this);var n=this.params;if(n)for(var t=0,i=n.length;i>t;t++)r=r.concat(n[t].find(e));return r},t.prototype.toString=function(){var e=this.params;switch(e.length){case 1:return"-"==this.op?"-"+e[0].toString():e[0].toString()+this.op;case 2:var r=e[0].toString();e[0]instanceof t&&(r="("+r+")");var n=e[1].toString();return e[1]instanceof t&&(n="("+n+")"),r+" "+this.op+" "+n;default:return this.op+"("+this.params.join(", ")+")"}},e.exports=t},function(e,r,n){function t(e,r){if(!(this instanceof t))throw new SyntaxError("Constructor must be called with the new operator");if(!(e instanceof o))throw new TypeError('Node expected for parameter "object"');if(!isArray(r)||!r.every(a))throw new TypeError('Array containing Nodes expected for parameter "params"');this.object=e,this.params=r}var i=n(143),o=n(125),a=(n(121),n(122),n(111),n(10),n(9),i.isNumber,i.toNumber,o.isNode);t.prototype=new o,t.prototype._compile=function(e){var r=this.params.map(function(r){return r._compile(e)});return this.object._compile(e)+"("+r.join(", ")+")"},t.prototype.find=function(e){var r=[];this.match(e)&&r.push(this),r=r.concat(this.object.find(e));for(var n=this.params,t=0,i=n.length;i>t;t++)r=r.concat(n[t].find(e));return r},t.prototype.toString=function(){return this.object.toString()+"("+this.params.join(", ")+")"},e.exports=t},function(e,r,n){function t(e){if(!(this instanceof t))throw new SyntaxError("Constructor must be called with the new operator");if(!a(e)||2!=e.length&&3!=e.length||!e.every(isNode))throw new TypeError('Expected an Array containing 2 or 3 Nodes as parameter "params"');this.start=e[0],this.end=e[1],this.step=e[2]}var i=n(143),o=n(125),a=(n(111),n(9),n(11),i.toNumber,Array.isArray);isNode=o.isNode,t.prototype=new o,t.prototype._compile=function(e){return"math.range("+this.start._compile(e)+", "+this.end._compile(e)+", "+(this.step?this.step._compile(e)+", ":"")+"true)"},t.prototype.find=function(e){var r=[];return this.match(e)&&r.push(this),r=r.concat(this.start.find(e)),this.step&&(r=r.concat(this.step.find(e))),r=r.concat(this.end.find(e))},t.prototype.toString=function(){var e=this.start.toString();return this.step&&(e+=":"+this.step.toString()),e+=":"+this.end.toString()},e.exports=t},function(e,r,n){function t(e){if(!(this instanceof t))throw new SyntaxError("Constructor must be called with the new operator");if(!s(e))throw new TypeError('String expected for parameter "name"');this.name=e}function i(e){throw new Error("Undefined symbol "+e)}var o=n(125),a=n(12),s=n(127).isString;t.prototype=new o,t.prototype._compile=function(e){return e.undef=i,e.Unit=a,'(scope["'+this.name+'"] !== undefined ? scope["'+this.name+'"] : math["'+this.name+'"] !== undefined ? math["'+this.name+'"] : '+(a.isPlainUnit(this.name)?'new Unit(null, "'+this.name+'")':'undef("'+this.name+'")')+")"},t.prototype.toString=function(){return this.name},e.exports=t},function(e,r,n){function t(e,r){if(!(this instanceof t))throw new SyntaxError("Constructor must be called with the new operator");if(!(e instanceof i))throw new TypeError('Node expected for parameter "value"');if(!o(r))throw new TypeError('String expected for parameter "unit"');this.value=e,this.unit=r}var i=n(125),o=(n(111),n(8),n(12),n(143).toNumber,n(127).isString);t.prototype=new i,t.prototype._compile=function(e){return"math.unit("+this.value._compile(e)+', "'+this.unit+'")'},t.prototype.find=function(e){var r=[];return this.match(e)&&r.push(this),r=r.concat(this.value.find(e))},t.prototype.toString=function(){return this.value+" "+this.unit},e.exports=t},function(e,r,n){function t(e,r){if(!(this instanceof t))throw new SyntaxError("Constructor must be called with the new operator");if(!(e instanceof a))throw new TypeError('Expected IndexNode for parameter "index"');if(!(r instanceof o))throw new TypeError('Expected Node for parameter "expr"');this.index=e,this.expr=r}{var i=n(143),o=n(125),a=(n(121),n(118));n(122),n(111),n(10),n(9),i.isNumber,i.toNumber}t.prototype=new o,t.prototype._compile=function(e){return'scope["'+this.index.objectName()+'"] = '+this.index.compileSubset(e,this.expr._compile(e))},t.prototype.find=function(e){var r=[];return this.match(e)&&r.push(this),r=r.concat(this.index.find(e)),r=r.concat(this.expr.find(e))},t.prototype.toString=function(){return this.index.toString()+" = "+this.expr.toString()},e.exports=t},function(e){function r(){if(!(this instanceof r))throw new SyntaxError("Constructor must be called with the new operator")}r.prototype.eval=function(){throw new Error("Node.eval is deprecated. Use Node.compile(math).eval([scope]) instead.")},r.prototype.compile=function(e){if("object"!=typeof e)throw new TypeError("Object expected for parameter math");var r={math:e},n=this._compile(r),t=Object.keys(r).map(function(e){return" var "+e+' = defs["'+e+'"];'}),i=t.join(" ")+'return { "eval": function (scope) { scope = scope || {}; return '+n+"; }};",o=new Function("defs",i);return o(r)},r.prototype._compile=function(){throw new Error("Cannot compile a Node interface")},r.prototype.find=function(e){return this.match(e)?[this]:[]},r.prototype.match=function(e){var r=!0;if(e){!e.type||this instanceof e.type||(r=!1);var n=e.properties;if(r&&n)for(var t in n)if(n.hasOwnProperty(t)&&this[t]!==n[t]){r=!1;break}}return r},r.prototype.toString=function(){return""},r.isNode=function(e){return e instanceof r},e.exports=r},function(e,r){r.type=function n(e){var n=typeof e;if("object"===n){if(null===e)return"null";if(e instanceof Boolean)return"boolean";if(e instanceof Number)return"number";if(e instanceof String)return"string";if(Array.isArray(e))return"array";if(e instanceof Date)return"date"}return n}},function(e,r,n){function t(e,n){if(Array.isArray(e)){for(var i="[",o=e.length,a=0;o>a;a++)0!=a&&(i+=", "),i+=t(e[a],n);return i+="]"}return r.format(e,n)}var i=n(143),o=n(111);r.isString=function(e){return e instanceof String||"string"==typeof e},r.endsWith=function(e,r){var n=e.length-r.length,t=e.length;return e.substring(n,t)===r},r.format=function(e,n){return i.isNumber(e)||e instanceof o?i.format(e,n):Array.isArray(e)?t(e,n):r.isString(e)?'"'+e+'"':"function"==typeof e?e.syntax?e.syntax+"":"function":e instanceof Object?"function"==typeof e.format?e.format(n):e.toString():String(e)}},function(e){e.exports={name:"e",category:"Constants",syntax:["e"],description:"Euler's number, the base of the natural logarithm. Approximately equal to 2.71828",examples:["e","e ^ 2","exp(2)","log(e)"],seealso:["exp"]}},function(e){e.exports={name:"false",category:"Constants",syntax:["false"],description:"Boolean value false",examples:["false"],seealso:["true"]}},function(e){e.exports={name:"i",category:"Constants",syntax:["i"],description:"Imaginary unit, defined as i*i=-1. A complex number is described as a + b*i, where a is the real part, and b is the imaginary part.",examples:["i","i * i","sqrt(-1)"],seealso:[]}},function(e){e.exports={name:"Infinity",category:"Constants",syntax:["Infinity"],description:"Infinity, a number which is larger than the maximum number that can be handled by a floating point number.",examples:["Infinity","1 / 0"],seealso:[]}},function(e){e.exports={name:"LN2",category:"Constants",syntax:["LN2"],description:"Returns the natural logarithm of 2, approximately equal to 0.693",examples:["LN2","log(2)"],seealso:[]}},function(e){e.exports={name:"LN10",category:"Constants",syntax:["LN10"],description:"Returns the natural logarithm of 10, approximately equal to 2.302",examples:["LN10","log(10)"],seealso:[]}},function(e){e.exports={name:"LOG2E",category:"Constants",syntax:["LOG2E"],description:"Returns the base-2 logarithm of E, approximately equal to 1.442",examples:["LOG2E","log(e, 2)"],seealso:[]}},function(e){e.exports={name:"LOG10E",category:"Constants",syntax:["LOG10E"],description:"Returns the base-10 logarithm of E, approximately equal to 0.434",examples:["LOG10E","log(e, 10)"],seealso:[]}},function(e){e.exports={name:"NaN",category:"Constants",syntax:["NaN"],description:"Not a number",examples:["NaN","0 / 0"],seealso:[]}},function(e){e.exports={name:"pi",category:"Constants",syntax:["pi"],description:"The number pi is a mathematical constant that is the ratio of a circle's circumference to its diameter, and is approximately equal to 3.14159",examples:["pi","sin(pi/2)"],seealso:["tau"]}},function(e){e.exports={name:"SQRT1_2",category:"Constants",syntax:["SQRT1_2"],description:"Returns the square root of 1/2, approximately equal to 0.707",examples:["SQRT1_2","sqrt(1/2)"],seealso:[]}},function(e){e.exports={name:"SQRT2",category:"Constants",syntax:["SQRT2"],description:"Returns the square root of 2, approximately equal to 1.414",examples:["SQRT2","sqrt(2)"],seealso:[]}},function(e){e.exports={name:"tau",category:"Constants",syntax:["pi"],description:"Tau is the ratio constant of a circle's circumference to radius, equal to 2 * pi, approximately 6.2832.",examples:["tau","2 * pi"],seealso:["pi"]}},function(e){e.exports={name:"true",category:"Constants",syntax:["true"],description:"Boolean value true",examples:["true"],seealso:["false"]}},function(e,r,n){function t(e){for(var r=[];f(e);)r.push(e.length),e=e[0];return r}function i(e,r,n){var t,o=e.length;if(o!=r[n])throw new RangeError("Dimension mismatch ("+o+" != "+r[n]+")");if(nt;t++){var s=e[t];if(!f(s))throw new RangeError("Dimension mismatch ("+(r.length-1)+" < "+r.length+")");i(e[t],r,a)}}else for(t=0;o>t;t++)if(f(e[t]))throw new RangeError("Dimension mismatch ("+(r.length+1)+" > "+r.length+")")}function o(e,r,n,t){if(!f(e))throw Error("Array expected");var i,a,s=e.length,c=r[n],l=Math.min(s,c);if(e.length=c,ni;i++)a=e[i],o(a,r,m,t);for(i=l;c>i;i++)a=[],e[i]=a,o(a,r,m,t)}else if(void 0!==t)for(i=s;c>i;i++)e[i]=u.clone(t)}var a=n(143),s=n(127),u=n(3),f=(n(126),Array.isArray);r.size=function(e){var n=t(e);return r.validate(e,n),n},r.validate=function(e,r){var n=0==r.length;if(n){if(f(e))throw new RangeError("Dimension mismatch ("+e.length+" != 0)")}else i(e,r,0)},r.validateIndex=function(e,r){if(!a.isNumber(e)||!a.isInteger(e))throw new TypeError("Index must be an integer (value: "+e+")");if(0>e)throw new RangeError("Index out of range ("+e+" < 0)");if(void 0!==r&&e>=r)throw new RangeError("Index out of range ("+e+" > "+(r-1)+")")},r.resize=function(e,r,n){if(!f(e)||!f(r))throw new TypeError("Array expected");if(0===r.length)throw new Error("Resizing to scalar is not supported");r.forEach(function(e){if(!a.isNumber(e)||!a.isInteger(e)||0>e)throw new TypeError("Invalid size, must contain positive integers (size: "+s.format(r)+")")});for(var t=1,i=e[0];f(i);)t++,i=i[0];for(;tr.length;)e=e[0],t--;return o(e,r,0,n),e},r.squeeze=function(e){for(;f(e)&&1===e.length;)e=e[0];return e},r.unsqueeze=function(e,n){for(var t=r.size(e),i=0,o=n-t.length;o>i;i++)e=[e];return e},r.flatten=function(e){for(var r=e,n=Array.isArray;n(r[0]);){for(var t=[],i=0,o=r.length;o>i;i++)t=t.concat.apply(t,r[i]);r=t}return r},r.isArray=f},function(e,r,n){function t(e){return e instanceof o?e.isZero():0===e}function i(e,r,n){var t;return e instanceof o?(t=e.abs(),t.gte(r)&&t.lt(n)):(t=Math.abs(e),t>=r&&n>t)}var o=n(111);r.isNumber=function(e){return e instanceof Number||"number"==typeof e},r.isInteger=function(e){return e==Math.round(e)},r.sign=function(e){return e>0?1:0>e?-1:0},r.format=function(e,n){if("function"==typeof n)return n(e);if(1/0===e)return"Infinity";if(e===-1/0)return"-Infinity";if(isNaN(e))return"NaN";var a="auto",s=void 0;switch(void 0!==n&&(n.notation&&(a=n.notation),r.isNumber(n)?s=n:n.precision&&(s=n.precision)),a){case"fixed":return r.toFixed(e,s);case"scientific":throw new Error('Format notation "scientific" is deprecated. Use "exponential" instead.');case"exponential":return r.toExponential(e,s);case"auto":var u=.001,f=1e5;if(n&&n.exponential)void 0!==n.exponential.lower&&(u=n.exponential.lower),void 0!==n.exponential.upper&&(f=n.exponential.upper);else if(n&&n.scientific)throw new Error("options.scientific is deprecated, use options.exponential instead.");var c=e instanceof o;if(c){var l=o.config().EXPONENTIAL_AT;o.config({EXPONENTIAL_AT:[Math.round(Math.log(u)/Math.LN10),Math.round(Math.log(f)/Math.LN10)]})}if(t(e))return"0";var m;if(i(e,u,f))if(c)m=new o(e.toPrecision(s)).toString();else{var p=s?e.toPrecision(Math.min(s,21)):e.toPrecision();m=parseFloat(p)+""}else m=r.toExponential(e,s);return c&&o.config({EXPONENTIAL_AT:l}),m.replace(/((\.\d*?)(0+))($|e)/,function(){var e=arguments[2],r=arguments[4];return"."!==e?e+r:r});default:throw new Error('Unknown notation "'+a+'". Choose "auto", "exponential", or "fixed".')}},r.toExponential=function(e,r){return void 0!==r?e.toExponential(e instanceof o?r-1:Math.min(r-1,20)):e.toExponential()},r.toFixed=function(e,r){return e.toFixed(e instanceof o?r||0:Math.min(r,20))},r.digits=function(e){return e.toExponential().replace(/e[\+\-0-9]*$/,"").replace(/^0\.0*|\./,"").length},r.toBigNumber=function(e){return r.digits(e)>15?e:new o(e)},r.toNumber=function(e){return parseFloat(e.valueOf())}},function(e,r,n){function t(e){return n(i(e))}function i(e){return o[e]||function(){throw new Error("Cannot find module '"+e+"'.")}()}var o={"./clone":103,"./clone.js":103,"./forEach":110,"./forEach.js":110,"./format":104,"./format.js":104,"./ifElse":105,"./ifElse.js":105,"./import":106,"./import.js":106,"./map":107,"./map.js":107,"./print":108,"./print.js":108,"./typeof":109,"./typeof.js":109};t.keys=function(){return Object.keys(o)},t.resolve=i,e.exports=t},function(e){e.exports={name:"abs",category:"Arithmetic",syntax:["abs(x)"],description:"Compute the absolute value.",examples:["abs(3.5)","abs(-4.2)"],seealso:["sign"]}},function(e){e.exports={name:"add",category:"Operators",syntax:["x + y","add(x, y)"],description:"Add two values.",examples:["2.1 + 3.6","ans - 3.6","3 + 2i",'"hello" + " world"',"3 cm + 2 inch"],seealso:["subtract"]}},function(e){e.exports={name:"ceil",category:"Arithmetic",syntax:["ceil(x)"],description:"Round a value towards plus infinity.If x is complex, both real and imaginary part are rounded towards plus infinity.",examples:["ceil(3.2)","ceil(3.8)","ceil(-4.2)"],seealso:["floor","fix","round"]}},function(e){e.exports={name:"compare",category:"Operators",syntax:["compare(x, y)"],description:"Compare two values. Returns 1 if x is larger than y, -1 if x is smaller than y, and 0 if x and y are equal.",examples:["compare(2, 3)","compare(3, 2)","compare(2, 2)","compare(5cm, 40mm)","compare(2, [1, 2, 3])"],seealso:["equal","unequal","smaller","smallereq","largereq"]}},function(e){e.exports={name:"cube",category:"Arithmetic",syntax:["cube(x)"],description:"Compute the cube of a value. The cube of x is x * x * x.",examples:["cube(2)","2^3","2 * 2 * 2"],seealso:["multiply","square","pow"]}},function(e){e.exports={name:"divide",category:"Operators",syntax:["x / y","divide(x, y)"],description:"Divide two values.",examples:["2 / 3","ans * 3","4.5 / 2","3 + 4 / 2","(3 + 4) / 2","18 km / 4.5"],seealso:["multiply"]}},function(e){e.exports={name:"edivide",category:"Operators",syntax:["x ./ y","edivide(x, y)"],description:"divide two values element wise.",examples:["a = [1, 2, 3; 4, 5, 6]","b = [2, 1, 1; 3, 2, 5]","a ./ b"],seealso:["multiply","emultiply","divide"]}},function(e){e.exports={name:"emultiply",category:"Operators",syntax:["x .* y","emultiply(x, y)"],description:"multiply two values element wise.",examples:["a = [1, 2, 3; 4, 5, 6]","b = [2, 1, 1; 3, 2, 5]","a .* b"],seealso:["multiply","divide","edivide"]}},function(e){e.exports={name:"epow",category:"Operators",syntax:["x .^ y","epow(x, y)"],description:"Calculates the power of x to y element wise.",examples:["a = [1, 2, 3; 4, 5, 6]","a .^ 2"],seealso:["pow"]}},function(e){e.exports={name:"equal",category:"Operators",syntax:["x == y","equal(x, y)"],description:"Check equality of two values. Returns true if the values are equal, and false if not.",examples:["2+2 == 3","2+2 == 4","a = 3.2","b = 6-2.8","a == b","50cm == 0.5m"],seealso:["unequal","smaller","larger","smallereq","largereq","compare"]}},function(e){e.exports={name:"exp",category:"Arithmetic",syntax:["exp(x)"],description:"Calculate the exponent of a value.",examples:["exp(1.3)","e ^ 1.3","log(exp(1.3))","x = 2.4","(exp(i*x) == cos(x) + i*sin(x)) # Euler's formula"],seealso:["square","multiply","log"]}},function(e){e.exports={name:"fix",category:"Arithmetic",syntax:["fix(x)"],description:"Round a value towards zero.If x is complex, both real and imaginary part are rounded towards zero.",examples:["fix(3.2)","fix(3.8)","fix(-4.2)","fix(-4.8)"],seealso:["ceil","floor","round"]}},function(e){e.exports={name:"floor",category:"Arithmetic",syntax:["floor(x)"],description:"Round a value towards minus infinity.If x is complex, both real and imaginary part are rounded towards minus infinity.",examples:["floor(3.2)","floor(3.8)","floor(-4.2)"],seealso:["ceil","fix","round"]}},function(e){e.exports={name:"gcd",category:"Arithmetic",syntax:["gcd(a, b)","gcd(a, b, c, ...)"],description:"Compute the greatest common divisor.",examples:["gcd(8, 12)","gcd(-4, 6)","gcd(25, 15, -10)"],seealso:["lcm","xgcd"]}},function(e){e.exports={name:"larger",category:"Operators",syntax:["x > y","larger(x, y)"],description:"Check if value x is larger than y. Returns true if x is larger than y, and false if not.",examples:["2 > 3","5 > 2*2","a = 3.3","b = 6-2.8","(a > b)","(b < a)","5 cm > 2 inch"],seealso:["equal","unequal","smaller","smallereq","largereq","compare"]}},function(e){e.exports={name:"largereq",category:"Operators",syntax:["x >= y","largereq(x, y)"],description:"Check if value x is larger or equal to y. Returns true if x is larger or equal to y, and false if not.",examples:["2 > 1+1","2 >= 1+1","a = 3.2","b = 6-2.8","(a > b)"],seealso:["equal","unequal","smallereq","smaller","largereq","compare"]}},function(e){e.exports={name:"lcm",category:"Arithmetic",syntax:["lcm(x, y)"],description:"Compute the least common multiple.",examples:["lcm(4, 6)","lcm(6, 21)","lcm(6, 21, 5)"],seealso:["gcd"]}},function(e){e.exports={name:"log",category:"Arithmetic",syntax:["log(x)","log(x, base)"],description:"Compute the logarithm of a value. If no base is provided, the natural logarithm of x is calculated. If base if provided, the logarithm is calculated for the specified base. log(x, base) is defined as log(x) / log(base).",examples:["log(3.5)","a = log(2.4)","exp(a)","10 ^ 3","log(1000, 10)","log(1000) / log(10)","b = logb(1024, 2)","2 ^ b"],seealso:["exp","log10"]}},function(e){e.exports={name:"log10",category:"Arithmetic",syntax:["log10(x)"],description:"Compute the 10-base logarithm of a value.",examples:["log10(1000)","10 ^ 3","log10(0.01)","log(1000) / log(10)","log(1000, 10)"],seealso:["exp","log"]}},function(e){e.exports={name:"mod",category:"Operators",syntax:["x % y","x mod y","mod(x, y)"],description:"Calculates the modulus, the remainder of an integer division.",examples:["7 % 3","11 % 2","10 mod 4","function isOdd(x) = x % 2","isOdd(2)","isOdd(3)"],seealso:[]}},function(e){e.exports={name:"multiply",category:"Operators",syntax:["x * y","multiply(x, y)"],description:"multiply two values.",examples:["2.1 * 3.6","ans / 3.6","2 * 3 + 4","2 * (3 + 4)","3 * 2.1 km"],seealso:["divide"]}},function(e){e.exports={name:"pow",category:"Operators",syntax:["x ^ y","pow(x, y)"],description:"Calculates the power of x to y, x^y.",examples:["2^3 = 8","2*2*2","1 + e ^ (pi * i)"],seealso:["unequal","smaller","larger","smallereq","largereq"]}},function(e){e.exports={name:"round",category:"Arithmetic",syntax:["round(x)","round(x, n)"],description:"round a value towards the nearest integer.If x is complex, both real and imaginary part are rounded towards the nearest integer. When n is specified, the value is rounded to n decimals.",examples:["round(3.2)","round(3.8)","round(-4.2)","round(-4.8)","round(pi, 3)","round(123.45678, 2)"],seealso:["ceil","floor","fix"]}},function(e){e.exports={name:"sign",category:"Arithmetic",syntax:["sign(x)"],description:"Compute the sign of a value. The sign of a value x is 1 when x>1, -1 when x<0, and 0 when x=0.",examples:["sign(3.5)","sign(-4.2)","sign(0)"],seealso:["abs"]}},function(e){e.exports={name:"smaller",category:"Operators",syntax:["x < y","smaller(x, y)"],description:"Check if value x is smaller than value y. Returns true if x is smaller than y, and false if not.",examples:["2 < 3","5 < 2*2","a = 3.3","b = 6-2.8","(a < b)","5 cm < 2 inch"],seealso:["equal","unequal","larger","smallereq","largereq","compare"]}},function(e){e.exports={name:"smallereq",category:"Operators",syntax:["x <= y","smallereq(x, y)"],description:"Check if value x is smaller or equal to value y. Returns true if x is smaller than y, and false if not.",examples:["2 < 1+1","2 <= 1+1","a = 3.2","b = 6-2.8","(a < b)"],seealso:["equal","unequal","larger","smaller","largereq","compare"]}},function(e){e.exports={name:"sqrt",category:"Arithmetic",syntax:["sqrt(x)"],description:"Compute the square root value. If x = y * y, then y is the square root of x.",examples:["sqrt(25)","5 * 5","sqrt(-1)"],seealso:["square","multiply"]}},function(e){e.exports={name:"square",category:"Arithmetic",syntax:["square(x)"],description:"Compute the square of a value. The square of x is x * x.",examples:["square(3)","sqrt(9)","3^2","3 * 3"],seealso:["multiply","pow","sqrt","cube"]}},function(e){e.exports={name:"subtract",category:"Operators",syntax:["x - y","subtract(x, y)"],description:"subtract two values.",examples:["5.3 - 2","ans + 2","2/3 - 1/6","2 * 3 - 3","2.1 km - 500m"],seealso:["add"]}},function(e){e.exports={name:"unary",category:"Operators",syntax:["-x","unary(x)"],description:"Inverse the sign of a value.",examples:["-4.5","-(-5.6)"],seealso:["add","subtract"]}},function(e){e.exports={name:"unequal",category:"Operators",syntax:["x != y","unequal(x, y)"],description:"Check unequality of two values. Returns true if the values are unequal, and false if they are equal.",examples:["2+2 != 3","2+2 != 4","a = 3.2","b = 6-2.8","a != b","50cm != 0.5m","5 cm != 2 inch"],seealso:["equal","smaller","larger","smallereq","largereq","compare"]}},function(e){e.exports={name:"xgcd",category:"Arithmetic",syntax:["xgcd(a, b)"],description:"Calculate the extended greatest common divisor for two values",examples:["xgcd(8, 12)","gcd(8, 12)","xgcd(36163, 21199)"],seealso:["gcd","lcm"]}},function(e){e.exports={name:"arg",category:"Complex",syntax:["arg(x)"],description:"Compute the argument of a complex value. If x = a+bi, the argument is computed as atan2(b, a).",examples:["arg(2 + 2i)","atan2(3, 2)","arg(2 - 3i)"],seealso:["re","im","conj","abs"]}},function(e){e.exports={name:"conj",category:"Complex",syntax:["conj(x)"],description:"Compute the complex conjugate of a complex value. If x = a+bi, the complex conjugate is a-bi.",examples:["conj(2 + 3i)","conj(2 - 3i)","conj(-5.2i)"],seealso:["re","im","abs","arg"]}},function(e){e.exports={name:"re",category:"Complex",syntax:["re(x)"],description:"Get the real part of a complex number.",examples:["re(2 + 3i)","im(2 + 3i)","re(-5.2i)","re(2.4)"],seealso:["im","conj","abs","arg"]}},function(e){e.exports={name:"im",category:"Complex",syntax:["im(x)"],description:"Get the imaginary part of a complex number.",examples:["im(2 + 3i)","re(2 + 3i)","im(-5.2i)","im(2.4)"],seealso:["re","conj","abs","arg"]}},function(e){e.exports={name:"bignumber",category:"Type",syntax:["bignumber(x)"],description:"Create a big number from a number or string.",examples:["0.1 + 0.2","bignumber(0.1) + bignumber(0.2)",'bignumber("7.2")','bignumber("7.2e500")',"bignumber([0.1, 0.2, 0.3])"],seealso:["boolean","complex","index","matrix","string","unit"]}},function(e){e.exports={name:"boolean",category:"Type",syntax:["x","boolean(x)"],description:"Convert a string or number into a boolean.",examples:["boolean(0)","boolean(1)","boolean(3)",'boolean("true")','boolean("false")',"boolean([1, 0, 1, 1])"],seealso:["bignumber","complex","index","matrix","number","string","unit"]}},function(e){e.exports={name:"complex",category:"Type",syntax:["complex()","complex(re, im)","complex(string)"],description:"Create a complex number.",examples:["complex()","complex(2, 3)",'complex("7 - 2i")'],seealso:["bignumber","boolean","index","matrix","number","string","unit"]}},function(e){e.exports={name:"index",category:"Type",syntax:["[start]","[start:end]","[start:step:end]","[start1, start 2, ...]","[start1:end1, start2:end2, ...]","[start1:step1:end1, start2:step2:end2, ...]"],description:"Create an index to get or replace a subset of a matrix",examples:["[]","[1, 2, 3]","A = [1, 2, 3; 4, 5, 6]","A[1, :]","A[1, 2] = 50","A[0:2, 0:2] = ones(2, 2)"],seealso:["bignumber","boolean","complex","matrix,","number","range","string","unit"]}},function(e){e.exports={name:"matrix",category:"Type",syntax:["[]","[a1, b1, ...; a2, b2, ...]","matrix()","matrix([...])"],description:"Create a matrix.",examples:["[]","[1, 2, 3]","[1, 2, 3; 4, 5, 6]","matrix()","matrix([3, 4])"],seealso:["bignumber","boolean","complex","index","number","string","unit"]}},function(e){e.exports={name:"number",category:"Type",syntax:["x","number(x)"],description:"Create a number or convert a string or boolean into a number.",examples:["2","2e3","4.05","number(2)",'number("7.2")',"number(true)","number([true, false, true, true])"],seealso:["bignumber","boolean","complex","index","matrix","string","unit"]}},function(e){e.exports={name:"string",category:"Type",syntax:['"text"',"string(x)"],description:"Create a string or convert a value to a string",examples:['"Hello World!"',"string(4.2)","string(3 + 2i)"],seealso:["bignumber","boolean","complex","index","matrix","number","unit"]}},function(e){e.exports={name:"unit",category:"Type",syntax:["value unit","unit(value, unit)","unit(string)"],description:"Create a unit.",examples:["5.5 mm","3 inch",'unit(7.1, "kilogram")','unit("23 deg")'],seealso:["bignumber","boolean","complex","index","matrix","number","string"]}},function(e){e.exports={name:"eval",category:"Expression",syntax:["eval(expression)","eval([expr1, expr2, expr3, ...])"],description:"Evaluate an expression or an array with expressions.",examples:['eval("2 + 3")','eval("sqrt(" + 4 + ")")'],seealso:[]}},function(e){e.exports={name:"help",category:"Expression",syntax:["help(object)","help(string)"],description:"Display documentation on a function or data type.",examples:["help(sqrt)",'help("complex")'],seealso:[]}},function(e){e.exports={name:"concat",category:"Matrix",syntax:["concat(a, b, c, ...)","concat(a, b, c, ..., dim)"],description:"Concatenate matrices. By default, the matrices are concatenated by the first dimension. The dimension on which to concatenate can be provided as last argument.",examples:["a = [1, 2; 5, 6]","b = [3, 4; 7, 8]","concat(a, b)","[a, b]","concat(a, b, 2)","[a; b]"],seealso:["det","diag","eye","inv","ones","range","size","squeeze","subset","transpose","zeros"]}},function(e){e.exports={name:"det",category:"Matrix",syntax:["det(x)"],description:"Calculate the determinant of a matrix",examples:["det([1, 2; 3, 4])","det([-2, 2, 3; -1, 1, 3; 2, 0, -1])"],seealso:["concat","diag","eye","inv","ones","range","size","squeeze","subset","transpose","zeros"]}},function(e){e.exports={name:"diag",category:"Matrix",syntax:["diag(x)","diag(x, k)"],description:"Create a diagonal matrix or retrieve the diagonal of a matrix. When x is a vector, a matrix with the vector values on the diagonal will be returned. When x is a matrix, a vector with the diagonal values of the matrix is returned.When k is provided, the k-th diagonal will be filled in or retrieved, if k is positive, the values are placed on the super diagonal. When k is negative, the values are placed on the sub diagonal.",examples:["diag(1:3)","diag(1:3, 1)","a = [1, 2, 3; 4, 5, 6; 7, 8, 9]","diag(a)"],seealso:["concat","det","eye","inv","ones","range","size","squeeze","subset","transpose","zeros"]}},function(e){e.exports={name:"eye",category:"Matrix",syntax:["eye(n)","eye(m, n)","eye([m, n])","eye"],description:"Returns the identity matrix with size m-by-n. The matrix has ones on the diagonal and zeros elsewhere.",examples:["eye(3)","eye(3, 5)","a = [1, 2, 3; 4, 5, 6]","eye(size(a))"],seealso:["concat","det","diag","inv","ones","range","size","squeeze","subset","transpose","zeros"]}},function(e){e.exports={name:"inv",category:"Matrix",syntax:["inv(x)"],description:"Calculate the inverse of a matrix",examples:["inv([1, 2; 3, 4])","inv(4)","1 / 4"],seealso:["concat","det","diag","eye","ones","range","size","squeeze","subset","transpose","zeros"]}},function(e){e.exports={name:"ones",category:"Matrix",syntax:["ones(m)","ones(m, n)","ones(m, n, p, ...)","ones([m])","ones([m, n])","ones([m, n, p, ...])","ones"],description:"Create a matrix containing ones.",examples:["ones(3)","ones(3, 5)","ones([2,3]) * 4.5","a = [1, 2, 3; 4, 5, 6]","ones(size(a))"],seealso:["concat","det","diag","eye","inv","range","size","squeeze","subset","transpose","zeros"]}},function(e){e.exports={name:"range",category:"Type",syntax:["start:end","start:step:end","range(start, end)","range(start, end, step)","range(string)"],description:"Create a range. Lower bound of the range is included, upper bound is excluded.",examples:["1:5","3:-1:-3","range(3, 7)","range(0, 12, 2)",'range("4:10")',"a = [1, 2, 3, 4; 5, 6, 7, 8]","a[1:2, 1:2]"],seealso:["concat","det","diag","eye","inv","ones","size","squeeze","subset","transpose","zeros"]}},function(e){e.exports={name:"resize",category:"Matrix",syntax:["resize(x, size)","resize(x, size, defaultValue)"],description:"Resize a matrix.",examples:["resize([1,2,3,4,5], [3])","resize([1,2,3], [5], 0)","resize(2, [2, 3], 0)",'resize("hello", [8], "!")'],seealso:["size","subset","squeeze"]}},function(e){e.exports={name:"size",category:"Matrix",syntax:["size(x)"],description:"Calculate the size of a matrix.",examples:["size(2.3)",'size("hello world")',"a = [1, 2; 3, 4; 5, 6]","size(a)","size(1:6)"],seealso:["concat","det","diag","eye","inv","ones","range","squeeze","subset","transpose","zeros"]}},function(e){e.exports={name:"squeeze",category:"Matrix",syntax:["squeeze(x)"],description:"Remove singleton dimensions from a matrix.",examples:["a = zeros(1,3,2)","size(squeeze(a))","b = zeros(3,1,1)","size(squeeze(b))"],seealso:["concat","det","diag","eye","inv","ones","range","size","subset","transpose","zeros"]}},function(e){e.exports={name:"subset",category:"Matrix",syntax:["value(index)","value(index) = replacement","subset(value, [index])","subset(value, [index], replacement)"],description:"Get or set a subset of a matrix or string. Indexes are one-based. Both the ranges lower-bound and upper-bound are included.",examples:["d = [1, 2; 3, 4]","e = []","e[1, 1:2] = [5, 6]","e[2, :] = [7, 8]","f = d * e","f[2, 1]","f[:, 1]"],seealso:["concat","det","diag","eye","inv","ones","range","size","squeeze","transpose","zeros"]}},function(e){e.exports={name:"transpose",category:"Matrix",syntax:["x'","transpose(x)"],description:"Transpose a matrix",examples:["a = [1, 2, 3; 4, 5, 6]","a'","transpose(a)"],seealso:["concat","det","diag","eye","inv","ones","range","size","squeeze","subset","zeros"]}},function(e){e.exports={name:"zeros",category:"Matrix",syntax:["zeros(m)","zeros(m, n)","zeros(m, n, p, ...)","zeros([m])","zeros([m, n])","zeros([m, n, p, ...])","zeros"],description:"Create a matrix containing zeros.",examples:["zeros(3)","zeros(3, 5)","a = [1, 2, 3; 4, 5, 6]","zeros(size(a))"],seealso:["concat","det","diag","eye","inv","ones","range","size","squeeze","subset","transpose"]} -},function(e){e.exports={name:"combinations",category:"Probability",syntax:["combinations(n, k)"],description:"Compute the number of combinations of n items taken k at a time",examples:["combinations(7, 5)"],seealso:["permutations","factorial"]}},function(e){e.exports={name:"distribution",category:"Probability",syntax:["distribution(name)","distribution(name, arg1, arg2, ...)"],description:'Create a distribution object of a specific type. A distribution object contains functions `random([size,] [min,] [max])`, `randomInt([size,] [min,] [max])`, and `pickRandom(array)`. Available types of distributions: "uniform", "normal". Note that the function distribution is currently not available via the expression parser.',examples:[],seealso:["random","randomInt"]}},function(e){e.exports={name:"factorial",category:"Probability",syntax:["n!","factorial(n)"],description:"Compute the factorial of a value",examples:["5!","5*4*3*2*1","3!"],seealso:[]}},function(e){e.exports={name:"permutations",category:"Probability",syntax:["permutations(n)","permutations(n, k)"],description:"Compute the number of permutations of n items taken k at a time",examples:["permutations(5)","permutations(5, 4)"],seealso:["combinations","factorial"]}},function(e){e.exports={name:"pickRandom",category:"Probability",syntax:["pickRandom(array)"],description:"Pick a random entry from a given array.",examples:["pickRandom(0:10)","pickRandom([1, 3, 1, 6])"],seealso:["distribution","random","randomInt"]}},function(e){e.exports={name:"random",category:"Probability",syntax:["random()","random(max)","random(min, max)","random(size)","random(size, max)","random(size, min, max)"],description:"Return a random number.",examples:["random()","random(10, 20)","random([2, 3])"],seealso:["distribution","pickRandom","randomInt"]}},function(e){e.exports={name:"randInt",category:"Probability",syntax:["randInt()","randInt(max)","randInt(min, max)","randInt(size)","randInt(size, max)","randInt(size, min, max)"],description:"Return a random integer number",examples:["randInt()","randInt(10, 20)","randInt([2, 3], 10)"],seealso:["distribution","pickRandom","random"]}},function(e){e.exports={name:"max",category:"Statistics",syntax:["max(a, b, c, ...)","max(A)","max(A, dim)"],description:"Compute the maximum value of a list of values.",examples:["max(2, 3, 4, 1)","max([2, 3, 4, 1])","max([2, 5; 4, 3], 0)","max([2, 5; 4, 3], 1)","max(2.7, 7.1, -4.5, 2.0, 4.1)","min(2.7, 7.1, -4.5, 2.0, 4.1)"],seealso:["mean","median","min","prod","std","sum","var"]}},function(e){e.exports={name:"mean",category:"Statistics",syntax:["mean(a, b, c, ...)","mean(A)","mean(A, dim)"],description:"Compute the arithmetic mean of a list of values.",examples:["mean(2, 3, 4, 1)","mean([2, 3, 4, 1])","mean([2, 5; 4, 3], 0)","mean([2, 5; 4, 3], 1)","mean([1.0, 2.7, 3.2, 4.0])"],seealso:["max","median","min","prod","std","sum","var"]}},function(e){e.exports={name:"median",category:"Statistics",syntax:["median(a, b, c, ...)","median(A)"],description:"Compute the median of all values. The values are sorted and the middle value is returned. In case of an even number of values, the average of the two middle values is returned.",examples:["median(4, 2, 7)","median([3, -1, 5, 7])"],seealso:["max","mean","min","prod","std","sum","var"]}},function(e){e.exports={name:"min",category:"Statistics",syntax:["min(a, b, c, ...)","min(A)","min(A, dim)"],description:"Compute the minimum value of a list of values.",examples:["min(2, 3, 4, 1)","min([2, 3, 4, 1])","min([2, 5; 4, 3], 0)","min([2, 5; 4, 3], 1)","min(2.7, 7.1, -4.5, 2.0, 4.1)","max(2.7, 7.1, -4.5, 2.0, 4.1)"],seealso:["max","mean","median","prod","std","sum","var"]}},function(e){e.exports={name:"prod",category:"Statistics",syntax:["prod(a, b, c, ...)","prod(A)"],description:"Compute the product of all values.",examples:["prod(2, 3, 4)","prod([2, 3, 4])","prod([2, 5; 4, 3])"],seealso:["max","mean","min","median","min","std","sum","var"]}},function(e){e.exports={name:"std",category:"Statistics",syntax:["std(a, b, c, ...)","std(A)","std(A, normalization)"],description:'Compute the standard deviation of all values, defined as std(A) = sqrt(var(A)). Optional parameter normalization can be "unbiased" (default), "uncorrected", or "biased".',examples:["std(2, 4, 6)","std([2, 4, 6, 8])",'std([2, 4, 6, 8], "uncorrected")','std([2, 4, 6, 8], "biased")',"std([1, 2, 3; 4, 5, 6])"],seealso:["max","mean","min","median","min","prod","sum","var"]}},function(e){e.exports={name:"sum",category:"Statistics",syntax:["sum(a, b, c, ...)","sum(A)"],description:"Compute the sum of all values.",examples:["sum(2, 3, 4, 1)","sum([2, 3, 4, 1])","sum([2, 5; 4, 3])"],seealso:["max","mean","median","min","prod","std","sum","var"]}},function(e){e.exports={name:"var",category:"Statistics",syntax:["var(a, b, c, ...)","var(A)","var(A, normalization)"],description:'Compute the variance of all values. Optional parameter normalization can be "unbiased" (default), "uncorrected", or "biased".',examples:["var(2, 4, 6)","var([2, 4, 6, 8])",'var([2, 4, 6, 8], "uncorrected")','var([2, 4, 6, 8], "biased")',"var([1, 2, 3; 4, 5, 6])"],seealso:["max","mean","min","median","min","prod","std","sum"]}},function(e){e.exports={name:"acos",category:"Trigonometry",syntax:["acos(x)"],description:"Compute the inverse cosine of a value in radians.",examples:["acos(0.5)","acos(cos(2.3))"],seealso:["cos","acos","asin"]}},function(e){e.exports={name:"asin",category:"Trigonometry",syntax:["asin(x)"],description:"Compute the inverse sine of a value in radians.",examples:["asin(0.5)","asin(sin(2.3))"],seealso:["sin","acos","asin"]}},function(e){e.exports={name:"atan",category:"Trigonometry",syntax:["atan(x)"],description:"Compute the inverse tangent of a value in radians.",examples:["atan(0.5)","atan(tan(2.3))"],seealso:["tan","acos","asin"]}},function(e){e.exports={name:"atan2",category:"Trigonometry",syntax:["atan2(y, x)"],description:"Computes the principal value of the arc tangent of y/x in radians.",examples:["atan2(2, 2) / pi","angle = 60 deg in rad","x = cos(angle)","y = sin(angle)","atan2(y, x)"],seealso:["sin","cos","tan"]}},function(e){e.exports={name:"cos",category:"Trigonometry",syntax:["cos(x)"],description:"Compute the cosine of x in radians.",examples:["cos(2)","cos(pi / 4) ^ 2","cos(180 deg)","cos(60 deg)","sin(0.2)^2 + cos(0.2)^2"],seealso:["acos","sin","tan"]}},function(e){e.exports={name:"cot",category:"Trigonometry",syntax:["cot(x)"],description:"Compute the cotangent of x in radians. Defined as 1/tan(x)",examples:["cot(2)","1 / tan(2)"],seealso:["sec","csc","tan"]}},function(e){e.exports={name:"csc",category:"Trigonometry",syntax:["csc(x)"],description:"Compute the cosecant of x in radians. Defined as 1/sin(x)",examples:["csc(2)","1 / sin(2)"],seealso:["sec","cot","sin"]}},function(e){e.exports={name:"sec",category:"Trigonometry",syntax:["sec(x)"],description:"Compute the secant of x in radians. Defined as 1/cos(x)",examples:["sec(2)","1 / cos(2)"],seealso:["cot","csc","cos"]}},function(e){e.exports={name:"sin",category:"Trigonometry",syntax:["sin(x)"],description:"Compute the sine of x in radians.",examples:["sin(2)","sin(pi / 4) ^ 2","sin(90 deg)","sin(30 deg)","sin(0.2)^2 + cos(0.2)^2"],seealso:["asin","cos","tan"]}},function(e){e.exports={name:"tan",category:"Trigonometry",syntax:["tan(x)"],description:"Compute the tangent of x in radians.",examples:["tan(0.5)","sin(0.5) / cos(0.5)","tan(pi / 4)","tan(45 deg)"],seealso:["atan","sin","cos"]}},function(e){e.exports={name:"to",category:"Units",syntax:["x to unit","to(x, unit)"],description:"Change the unit of a value.",examples:["5 inch in cm","3.2kg in g","16 bytes in bits"],seealso:[]}},function(e){e.exports={name:"clone",category:"Utils",syntax:["clone(x)"],description:"Clone a variable. Creates a copy of primitive variables,and a deep copy of matrices",examples:["clone(3.5)","clone(2 - 4i)","clone(45 deg)","clone([1, 2; 3, 4])",'clone("hello world")'],seealso:[]}},function(e){e.exports={name:"map",category:"Utils",syntax:["map(x, callback)"],description:"Create a new matrix or array with the results of the callback function executed on each entry of the matrix/array.",examples:["map([1, 2, 3], function(val) { return math.max(val, 1.5) })"],seealso:[]}},function(e){e.exports={name:"forEach",category:"Utils",syntax:["forEach(x, callback)"],description:"Iterates over all elements of a matrix/array, and executes the given callback.",examples:["forEach([1, 2, 3], function(val) { console.log(val) })"],seealso:[]}},function(e){e.exports={name:"format",category:"Utils",syntax:["format(value)","format(value, precision)"],description:"Format a value of any type as string.",examples:["format(2.3)","format(3 - 4i)","format([])","format(pi, 3)"],seealso:["print"]}},function(e){e.exports={name:"ifElse",category:"Utils",syntax:["ifElse(conditionalExpr, trueExpr, falseExpr)"],description:"Executes a ternary operation.",examples:["ifElse(10 > 0, 10, 0)"],seealso:[]}},function(e){e.exports={name:"import",category:"Utils",syntax:["import(string)"],description:"Import functions from a file.",examples:['import("numbers")','import("./mylib.js")'],seealso:[]}},function(e){e.exports={name:"typeof",category:"Utils",syntax:["typeof(x)"],description:"Get the type of a variable.",examples:["typeof(3.5)","typeof(2 - 4i)","typeof(45 deg)",'typeof("hello world")'],seealso:[]}},function(e,r){r.isBoolean=function(e){return e instanceof Boolean||"boolean"==typeof e}}])}); +!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):"object"==typeof exports?exports.mathjs=r():e.mathjs=r()}(this,function(){return function(e){function r(n){if(t[n])return t[n].exports;var i=t[n]={exports:{},id:n,loaded:!1};return e[n].call(i.exports,i,i.exports,r),i.loaded=!0,i.exports}var t={};return r.m=e,r.c=t,r.p="",r(0)}([function(e,r,t){e.exports=t(1)},function(e,r,t){function n(e){if("function"!=typeof Object.create)throw new Error("ES5 not supported by this JavaScript engine. Please load the es5-shim and es5-sham library for compatibility.");var r={},n={matrix:"matrix",number:"number",precision:20,epsilon:1e-14};r.config=function(e){if(e){if(i.deepExtend(n,e),e.precision&&r.type.BigNumber.config({precision:e.precision}),e.number&&e.number.defaultType)throw new Error("setting `number.defaultType` is deprecated. Use `number` instead.");if(e.number&&e.number.precision)throw new Error("setting `number.precision` is deprecated. Use `precision` instead.");if(e.matrix&&e.matrix.defaultType)throw new Error("setting `matrix.defaultType` is deprecated. Use `matrix` instead.");if(e.matrix&&e.matrix["default"])throw new Error("setting `matrix.default` is deprecated. Use `matrix` instead.");if(e.decimals)throw new Error("setting `decimals` is deprecated. Use `precision` instead.")}return i.clone(n)};var o=t(112).constructor();if("function"!=typeof o.prototype.clone&&(o.prototype.clone=function(){return new o(this)}),"function"==typeof o.convert)throw new Error("Cannot add function convert to BigNumber: function already exists");return o.convert=function(e){return digits(e)>15?e:new o(e)},r.error=t(4),r.type={},r.type.Complex=t(5),r.type.Range=t(6),r.type.Index=t(7),r.type.Matrix=t(8),r.type.Unit=t(9),r.type.Help=t(10),r.type.BigNumber=o,r.collection=t(11),r.expression={},r.expression.node=t(14),r.expression.parse=t(12),r.expression.Scope=function(){throw new Error("Scope is deprecated. Use a regular Object instead")},r.expression.Parser=t(13),r.expression.docs=t(15),t(17)(r,n),t(18)(r,n),t(19)(r,n),t(20)(r,n),t(21)(r,n),t(22)(r,n),t(23)(r,n),t(24)(r,n),t(25)(r,n),t(26)(r,n),t(27)(r,n),t(28)(r,n),t(29)(r,n),t(30)(r,n),t(31)(r,n),t(32)(r,n),t(33)(r,n),t(34)(r,n),t(35)(r,n),t(36)(r,n),t(37)(r,n),t(38)(r,n),t(39)(r,n),t(40)(r,n),t(41)(r,n),t(42)(r,n),t(43)(r,n),t(44)(r,n),t(45)(r,n),t(46)(r,n),t(47)(r,n),t(48)(r,n),t(49)(r,n),t(50)(r,n),t(51)(r,n),t(52)(r,n),t(53)(r,n),t(54)(r,n),t(55)(r,n),t(56)(r,n),t(57)(r,n),t(58)(r,n),t(59)(r,n),t(60)(r,n),t(61)(r,n),t(62)(r,n),t(63)(r,n),t(64)(r,n),t(65)(r,n),t(66)(r,n),t(67)(r,n),t(68)(r,n),t(69)(r,n),t(70)(r,n),t(71)(r,n),t(72)(r,n),t(73)(r,n),t(74)(r,n),t(75)(r,n),t(76)(r,n),t(77)(r,n),t(78)(r,n),t(79)(r,n),t(80)(r,n),t(81)(r,n),t(82)(r,n),t(83)(r,n),t(84)(r,n),t(85)(r,n),t(86)(r,n),t(87)(r,n),t(88)(r,n),t(89)(r,n),t(90)(r,n),t(91)(r,n),t(92)(r,n),t(93)(r,n),t(94)(r,n),t(95)(r,n),t(96)(r,n),t(97)(r,n),t(98)(r,n),t(99)(r,n),t(100)(r,n),t(101)(r,n),t(102)(r,n),t(103)(r,n),t(104)(r,n),t(105)(r,n),t(106)(r,n),t(107)(r,n),t(108)(r,n),t(109)(r,n),t(110)(r,n),t(111)(r,n),t(2)(r,n),r.chaining={},r.chaining.Selector=t(16)(r,n),r.config(e),r}var i=t(3);e.exports=n},function(e,r,t){e.exports=function(e){var r=t(5);e.pi=Math.PI,e.e=Math.E,e.tau=2*Math.PI,e.i=new r(0,1),e.Infinity=1/0,e.NaN=0/0,e["true"]=!0,e["false"]=!1,e.E=Math.E,e.LN2=Math.LN2,e.LN10=Math.LN10,e.LOG2E=Math.LOG2E,e.LOG10E=Math.LOG10E,e.PI=Math.PI,e.SQRT1_2=Math.SQRT1_2,e.SQRT2=Math.SQRT2}},function(e,r){r.clone=function t(e){var r=typeof e;if("number"===r||"string"===r||"boolean"===r||null===e||void 0===e)return e;if("function"==typeof e.clone)return e.clone();if(Array.isArray(e))return e.map(function(e){return t(e)});if(e instanceof Number)return new Number(e.valueOf());if(e instanceof String)return new String(e.valueOf());if(e instanceof Boolean)return new Boolean(e.valueOf());if(e instanceof Date)return new Date(e.valueOf());if(e instanceof RegExp)throw new TypeError("Cannot clone "+e);var n={};for(var i in e)e.hasOwnProperty(i)&&(n[i]=t(e[i]));return n},r.extend=function(e,r){for(var t in r)r.hasOwnProperty(t)&&(e[t]=r[t]);return e},r.deepExtend=function n(e,r){if(Array.isArray(r))throw new TypeError("Arrays are not supported by deepExtend");for(var t in r)if(r.hasOwnProperty(t))if(r[t]&&r[t].constructor===Object)void 0===e[t]&&(e[t]={}),e[t].constructor===Object?n(e[t],r[t]):e[t]=r[t];else{if(Array.isArray(r[t]))throw new TypeError("Arrays are not supported by deepExtend");e[t]=r[t]}return e},r.deepEqual=function(e,t){var n,i,o;if(Array.isArray(e)){if(!Array.isArray(t))return!1;if(e.length!=t.length)return!1;for(i=0,o=e.length;o>i;i++)if(!r.deepEqual(e[i],t[i]))return!1;return!0}if(e instanceof Object){if(Array.isArray(t)||!(t instanceof Object))return!1;for(n in e)if(!r.deepEqual(e[n],t[n]))return!1;for(n in t)if(!r.deepEqual(e[n],t[n]))return!1;return!0}return typeof e==typeof t&&e==t}},function(e,r,t){r.ArgumentsError=t(113),r.DimensionError=t(114),r.IndexError=t(115),r.UnsupportedTypeError=t(116)},function(e,r,t){function n(e,r){if(!(this instanceof n))throw new SyntaxError("Constructor must be called with the new operator");switch(arguments.length){case 0:this.re=0,this.im=0;break;case 1:var t=arguments[0];if("object"==typeof t){if("re"in t&&"im"in t){var i=new n(t.re,t.im);this.re=i.re,this.im=i.im;break}if("r"in t&&"phi"in t){var i=n.fromPolar(t.r,t.phi);this.re=i.re,this.im=i.im;break}}throw new SyntaxError("Object with the re and im or r and phi properties expected.");case 2:if(!h(e)||!h(r))throw new TypeError("Two numbers expected in Complex constructor");this.re=e,this.im=r;break;default:throw new SyntaxError("One, two or three arguments expected in Complex constructor")}}function i(){for(;" "==v||" "==v;)s()}function o(e){return e>="0"&&"9">=e||"."==e}function a(e){return e>="0"&&"9">=e}function s(){y++,v=w.charAt(y)}function u(e){y=e,v=w.charAt(y)}function f(){var e,r="";if(e=y,"+"==v?s():"-"==v&&(r+=v,s()),!o(v))return u(e),null;if("."==v){if(r+=v,s(),!a(v))return u(e),null}else{for(;a(v);)r+=v,s();"."==v&&(r+=v,s())}for(;a(v);)r+=v,s();if("E"==v||"e"==v){if(r+=v,s(),("+"==v||"-"==v)&&(r+=v,s()),!a(v))return u(e),null;for(;a(v);)r+=v,s()}return r}function c(){var e=w.charAt(y+1);if("I"==v||"i"==v)return s(),"1";if(!("+"!=v&&"-"!=v||"I"!=e&&"i"!=e)){var r="+"==v?"1":"-1";return s(),s(),r}return null}var l=t(117),p=t(9),m=l.number,h=l.number.isNumber,g=p.isUnit,d=l.string.isString;n.isComplex=function(e){return e instanceof n};var w,y,v;n.parse=function(e){if(w=e,y=-1,v="",!d(w))return null;s(),i();var r=f();if(r){if("I"==v||"i"==v)return s(),i(),v?null:new n(0,Number(r));i();var t=v;if("+"!=t&&"-"!=t)return i(),v?null:new n(Number(r),0);s(),i();var o=f();if(o){if("I"!=v&&"i"!=v)return null;s()}else if(o=c(),!o)return null;return"-"==t&&(o="-"==o[0]?"+"+o.substring(1):"-"+o),s(),i(),v?null:new n(Number(r),Number(o))}return(r=c())?(i(),v?null:new n(0,Number(r))):null},n.fromPolar=function(){switch(arguments.length){case 1:var e=arguments[0];if("object"==typeof e)return n.fromPolar(e.r,e.phi);throw new TypeError("Input has to be an object with r and phi keys.");case 2:var r=arguments[0],t=arguments[1];if(h(r)){if(g(t)&&t.hasBase(p.BASE_UNITS.ANGLE)&&(t=t.toNumber("rad")),h(t))return new n(r*Math.cos(t),r*Math.sin(t));throw new TypeError("Phi is not a number nor an angle unit.")}throw new TypeError("Radius r is not a number.");default:throw new SyntaxError("Wrong number of arguments in function fromPolar")}},n.prototype.toPolar=function(){return{r:Math.sqrt(this.re*this.re+this.im*this.im),phi:Math.atan2(this.im,this.re)}},n.prototype.clone=function(){return new n(this.re,this.im)},n.prototype.equals=function(e){return this.re===e.re&&this.im===e.im},n.prototype.format=function(e){var r="",t=m.format(this.re,e),n=m.format(this.im,e);return r=0==this.im?t:0==this.re?1==this.im?"i":-1==this.im?"-i":n+"i":this.im>0?1==this.im?t+" + i":t+" + "+n+"i":-1==this.im?t+" - i":t+" - "+n.substring(1)+"i"},n.prototype.toString=function(){return this.format()},e.exports=n},function(e,r,t){function n(e,r,t){if(!(this instanceof n))throw new SyntaxError("Constructor must be called with the new operator");if(null!=e&&!o.isNumber(e))throw new TypeError("Parameter start must be a number");if(null!=r&&!o.isNumber(r))throw new TypeError("Parameter end must be a number");if(null!=t&&!o.isNumber(t))throw new TypeError("Parameter step must be a number");this.start=null!=e?parseFloat(e):0,this.end=null!=r?parseFloat(r):0,this.step=null!=t?parseFloat(t):1}{var i=t(117),o=i.number,a=i.string;i.array}n.parse=function(e){if(!a.isString(e))return null;var r=e.split(":"),t=r.map(function(e){return parseFloat(e)}),i=t.some(function(e){return isNaN(e)});if(i)return null;switch(t.length){case 2:return new n(t[0],t[1]);case 3:return new n(t[0],t[2],t[1]);default:return null}},n.prototype.clone=function(){return new n(this.start,this.end,this.step)},n.isRange=function(e){return e instanceof n},n.prototype.size=function(){var e=0,r=this.start,t=this.step,n=this.end,i=n-r;return o.sign(t)==o.sign(i)?e=Math.ceil(i/t):0==i&&(e=0),isNaN(e)&&(e=0),[e]},n.prototype.min=function(){var e=this.size()[0];return e>0?this.step>0?this.start:this.start+(e-1)*this.step:void 0},n.prototype.max=function(){var e=this.size()[0];return e>0?this.step>0?this.start+(e-1)*this.step:this.start:void 0},n.prototype.forEach=function(e){var r=this.start,t=this.step,n=this.end,i=0;if(t>0)for(;n>r;)e(r,i,this),r+=t,i++;else if(0>t)for(;r>n;)e(r,i,this),r+=t,i++},n.prototype.map=function(e){var r=[];return this.forEach(function(t,n,i){r[n]=e(t,n,i)}),r},n.prototype.toArray=function(){var e=[];return this.forEach(function(r,t){e[t]=r}),e},n.prototype.valueOf=function(){return this.toArray()},n.prototype.format=function(e){var r=o.format(this.start,e);return 1!=this.step&&(r+=":"+o.format(this.step,e)),r+=":"+o.format(this.end,e)},n.prototype.toString=function(){return this.format()},e.exports=n},function(e,r,t){function n(){if(!(this instanceof n))throw new SyntaxError("Constructor must be called with the new operator");this._ranges=[];for(var e=0,r=arguments.length;r>e;e++){var t=arguments[e];if(t instanceof a)this._ranges.push(t);else if(c(t))this._ranges.push(i(t));else{if(!u(t))throw new TypeError("Ranges must be an Array, Number, or Range");this._ranges.push(i([t,t+1]))}}}function i(e){for(var r=e.length,t=0;r>t;t++)if(!u(e[t])||!f(e[t]))throw new TypeError("Index parameters must be integer numbers");switch(e.length){case 2:return new a(e[0],e[1]);case 3:return new a(e[0],e[1],e[2]);default:throw new SyntaxError("Wrong number of arguments in Index (2 or 3 expected)")}}{var o=t(117),a=t(6),s=o.number,u=s.isNumber,f=s.isInteger,c=Array.isArray;o.array.validateIndex}n.prototype.clone=function(){var e=new n;return e._ranges=o.object.clone(this._ranges),e},n.isIndex=function(e){return e instanceof n},n.create=function(e){var r=new n;return n.apply(r,e),r},n.prototype.size=function l(){for(var l=[],e=0,r=this._ranges.length;r>e;e++){var t=this._ranges[e];l[e]=t.size()[0]}return l},n.prototype.max=function(){for(var e=[],r=0,t=this._ranges.length;t>r;r++){var n=this._ranges[r];e[r]=n.max()}return e},n.prototype.min=function(){for(var e=[],r=0,t=this._ranges.length;t>r;r++){var n=this._ranges[r];e[r]=n.min()}return e},n.prototype.forEach=function(e){for(var r=0,t=this._ranges.length;t>r;r++)e(this._ranges[r],r,this)},n.prototype.range=function(e){return this._ranges[e]||null},n.prototype.isScalar=function(){for(var e=this.size(),r=0,t=e.length;t>r;r++)if(1!==e[r])return!1;return!0},n.prototype.toArray=function(){for(var e=[],r=0,t=this._ranges.length;t>r;r++){var n=this._ranges[r],i=[],o=n.start,a=n.end,s=n.step;if(s>0)for(;a>o;)i.push(o),o+=s;else if(0>s)for(;o>a;)i.push(o),o+=s;e.push(i)}return e},n.prototype.valueOf=n.prototype.toArray,n.prototype.toString=function(){for(var e=[],r=0,t=this._ranges.length;t>r;r++){var n=this._ranges[r],i=s.format(n.start);1!=n.step&&(i+=":"+s.format(n.step)),i+=":"+s.format(n.end),e.push(i)}return"["+e.join(", ")+"]"},e.exports=n},function(e,r,t){function n(e){if(!(this instanceof n))throw new SyntaxError("Constructor must be called with the new operator");if(e instanceof n)this._data=e.clone()._data;else if(d(e))this._data=f(e);else{if(null!=e)throw new TypeError("Unsupported type of data ("+c.types.type(e)+")");this._data=[]}this._size=h.size(this._data)}function i(e,r){if(!(r instanceof p))throw new TypeError("Invalid index");var t=r.isScalar();if(t)return e.get(r.min());var i=r.size();if(i.length!=e._size.length)throw new l(i.length,e._size.length);for(var a=new n(o(e._data,r,i.length,0));d(a._data)&&1==a._data.length;)a._data=a._data[0],a._size.shift();return a}function o(e,r,t,n){var i=n==t-1,a=r.range(n);return a.map(i?function(r){return w(r,e.length),e[r]}:function(i){w(i,e.length);var a=e[i];return o(a,r,t,n+1)})}function a(e,r,t,i){if(!(r instanceof p))throw new TypeError("Invalid index");var o,a=r.size(),f=r.isScalar();if(t instanceof n?(o=t.size(),t=t.valueOf()):o=h.size(t),f){if(0!=o.length)throw new TypeError("Scalar expected");e.set(r.min(),t,i)}else{if(a.lengthc;c++)t=[t],o.unshift(1);if(!g.deepEqual(a,o))throw new l(a,o);var d=r.max().map(function(e){return e+1});u(e,d,i);var w=a.length,y=0;s(e._data,r,t,w,y)}return e}function s(e,r,t,n,i){var o=i==n-1,a=r.range(i);a.forEach(o?function(r,n){w(r),e[r]=t[n]}:function(o,a){w(o),s(e[o],r,t[a],n,i+1)})}function u(e,r,t){for(var n=g.clone(e._size),i=!1;n.lengtho;o++)r[o]>n[o]&&(n[o]=r[o],i=!0);i&&e.resize(n,t)}function f(e){for(var r=0,t=e.length;t>r;r++){var i=e[r];d(i)?e[r]=f(i):i instanceof n&&(e[r]=f(i._data))}return e}var c=t(117),l=t(114),p=t(7),m=(c.number,c.string),h=c.array,g=c.object,d=Array.isArray,w=h.validateIndex;n.isMatrix=function(e){return e instanceof n},n.prototype.subset=function(e,r,t){switch(arguments.length){case 1:return i(this,e);case 2:case 3:return a(this,e,r,t);default:throw new SyntaxError("Wrong number of arguments")}},n.prototype.get=function(e){if(!d(e))throw new TypeError("Array expected");if(e.length!=this._size.length)throw new l(e.length,this._size.length);for(var r=this._data,t=0,n=e.length;n>t;t++){var i=e[t];w(i,r.length),r=r[i]}return g.clone(r)},n.prototype.set=function(e,r,t){var n,i;if(!d(e))throw new Error("Array expected");if(e.lengthn;n++){var s=e[n];w(s,a.length),a=a[s]}return s=e[e.length-1],w(s,a.length),a[s]=r,this},n.prototype.resize=function(e,r){return this._size=g.clone(e),this._data=h.resize(this._data,this._size,r),this},n.prototype.clone=function(){var e=new n;return e._data=g.clone(this._data),e._size=g.clone(this._size),e},n.prototype.size=function(){return this._size},n.prototype.map=function(e){var r=this,t=new n,i=[],o=function(t,n){return d(t)?t.map(function(e,r){return i[n]=r,o(e,n+1)}):e(t,i,r)};return t._data=o(this._data,0),t._size=g.clone(this._size),t},n.prototype.forEach=function(e){var r=this,t=[],n=function(i,o){d(i)?i.forEach(function(e,r){t[o]=r,n(e,o+1)}):e(i,t,r)};n(this._data,0)},n.prototype.toArray=function(){return g.clone(this._data)},n.prototype.valueOf=function(){return this._data},n.prototype.format=function(e){return m.format(this._data,e)},n.prototype.toString=function(){return m.format(this._data)},e.exports=n},function(e,r,t){function n(e,r){if(!(this instanceof n))throw new Error("Constructor must be called with the new operator");if(null!=e&&!y(e))throw new TypeError("First parameter in Unit constructor must be a number");if(null!=r&&(!v(r)||""==r))throw new TypeError("Second parameter in Unit constructor must be a string");if(null!=r){var t=l(r);if(!t)throw new SyntaxError('Unknown unit "'+r+'"');this.unit=t.unit,this.prefix=t.prefix}else this.unit=UNIT_NONE,this.prefix=b;null!=e?(this.value=this._normalize(e),this.fixPrefix=!1):(this.value=null,this.fixPrefix=!0)}function i(){for(;" "==h||" "==h;)s()}function o(e){return e>="0"&&"9">=e||"."==e}function a(e){return e>="0"&&"9">=e}function s(){m++,h=p.charAt(m)}function u(e){m=e,h=p.charAt(m)}function f(){var e,r="";if(e=m,"+"==h?s():"-"==h&&(r+=h,s()),!o(h))return u(e),null;if("."==h){if(r+=h,s(),!a(h))return u(e),null}else{for(;a(h);)r+=h,s();"."==h&&(r+=h,s())}for(;a(h);)r+=h,s();if("E"==h||"e"==h){if(r+=h,s(),("+"==h||"-"==h)&&(r+=h,s()),!a(h))return u(e),null;for(;a(h);)r+=h,s()}return r}function c(){var e="";for(i();h&&" "!=h&&" "!=h;)e+=h,s();return e||null}function l(e){for(var r in N)if(N.hasOwnProperty(r)&&w.endsWith(e,r)){var t=N[r],n=e.length-r.length,i=e.substring(0,n),o=t.prefixes[i];if(void 0!==o)return{unit:t,prefix:o}}return null}var p,m,h,g=t(117),d=g.number,w=g.string,y=g.number.isNumber,v=g.string.isString;n.parse=function(e){if(p=e,m=-1,h="",!v(p))return null;s(),i();var r,t=f();if(t){if(r=c(),s(),i(),h)return null;if(t&&r)try{return new n(Number(t),r)}catch(o){}}else{if(r=c(),s(),i(),h)return null;if(r)try{return new n(null,r)}catch(o){}}return null},n.isUnit=function(e){return e instanceof n},n.prototype.clone=function(){var e=new n;for(var r in this)this.hasOwnProperty(r)&&(e[r]=this[r]);return e},n.prototype._normalize=function(e){return(e+this.unit.offset)*this.unit.value*this.prefix.value},n.prototype._unnormalize=function(e,r){return void 0==r?e/this.unit.value/this.prefix.value-this.unit.offset:e/this.unit.value/r-this.unit.offset},n.isValuelessUnit=function(e){return null!=l(e)},n.prototype.hasBase=function(e){return this.unit.base===e},n.prototype.equalBase=function(e){return this.unit.base===e.unit.base},n.prototype.equals=function(e){return this.equalBase(e)&&this.value==e.value},n.prototype.to=function(e){var r;if(v(e)){if(r=new n(null,e),!this.equalBase(r))throw new Error("Units do not match");return r.value=this.value,r}if(e instanceof n){if(!this.equalBase(e))throw new Error("Units do not match");if(null!=e.value)throw new Error("Cannot convert to a unit with a value");return r=e.clone(),r.value=this.value,r.fixPrefix=!0,r}throw new Error("String or Unit expected as parameter")},n.prototype.toNumber=function(e){var r=this.to(e);return r._unnormalize(r.value,r.prefix.value)},n.prototype.toString=function(){return this.format()},n.prototype.format=function(e){var r,t;if(this.fixPrefix)r=this._unnormalize(this.value),t=null!=this.value?d.format(r,e)+" ":"",t+=this.prefix.name+this.unit.name;else{var n=this._bestPrefix();r=this._unnormalize(this.value,n.value),t=d.format(r,e)+" ",t+=n.name+this.unit.name}return t},n.prototype._bestPrefix=function(){var e=Math.abs(this.value/this.unit.value),r=b,t=Math.abs(Math.log(e/r.value)/Math.LN10-1.2),n=this.unit.prefixes;for(var i in n)if(n.hasOwnProperty(i)){var o=n[i];if(o.scientific){var a=Math.abs(Math.log(e/o.value)/Math.LN10-1.2);t>a&&(r=o,t=a)}}return r};var x={NONE:{"":{name:"",value:1,scientific:!0}},SHORT:{"":{name:"",value:1,scientific:!0},da:{name:"da",value:10,scientific:!1},h:{name:"h",value:100,scientific:!1},k:{name:"k",value:1e3,scientific:!0},M:{name:"M",value:1e6,scientific:!0},G:{name:"G",value:1e9,scientific:!0},T:{name:"T",value:1e12,scientific:!0},P:{name:"P",value:1e15,scientific:!0},E:{name:"E",value:1e18,scientific:!0},Z:{name:"Z",value:1e21,scientific:!0},Y:{name:"Y",value:1e24,scientific:!0},d:{name:"d",value:.1,scientific:!1},c:{name:"c",value:.01,scientific:!1},m:{name:"m",value:.001,scientific:!0},u:{name:"u",value:1e-6,scientific:!0},n:{name:"n",value:1e-9,scientific:!0},p:{name:"p",value:1e-12,scientific:!0},f:{name:"f",value:1e-15,scientific:!0},a:{name:"a",value:1e-18,scientific:!0},z:{name:"z",value:1e-21,scientific:!0},y:{name:"y",value:1e-24,scientific:!0}},LONG:{"":{name:"",value:1,scientific:!0},deca:{name:"deca",value:10,scientific:!1},hecto:{name:"hecto",value:100,scientific:!1},kilo:{name:"kilo",value:1e3,scientific:!0},mega:{name:"mega",value:1e6,scientific:!0},giga:{name:"giga",value:1e9,scientific:!0},tera:{name:"tera",value:1e12,scientific:!0},peta:{name:"peta",value:1e15,scientific:!0},exa:{name:"exa",value:1e18,scientific:!0},zetta:{name:"zetta",value:1e21,scientific:!0},yotta:{name:"yotta",value:1e24,scientific:!0},deci:{name:"deci",value:.1,scientific:!1},centi:{name:"centi",value:.01,scientific:!1},milli:{name:"milli",value:.001,scientific:!0},micro:{name:"micro",value:1e-6,scientific:!0},nano:{name:"nano",value:1e-9,scientific:!0},pico:{name:"pico",value:1e-12,scientific:!0},femto:{name:"femto",value:1e-15,scientific:!0},atto:{name:"atto",value:1e-18,scientific:!0},zepto:{name:"zepto",value:1e-21,scientific:!0},yocto:{name:"yocto",value:1e-24,scientific:!0}},SQUARED:{"":{name:"",value:1,scientific:!0},da:{name:"da",value:100,scientific:!1},h:{name:"h",value:1e4,scientific:!1},k:{name:"k",value:1e6,scientific:!0},M:{name:"M",value:1e12,scientific:!0},G:{name:"G",value:1e18,scientific:!0},T:{name:"T",value:1e24,scientific:!0},P:{name:"P",value:1e30,scientific:!0},E:{name:"E",value:1e36,scientific:!0},Z:{name:"Z",value:1e42,scientific:!0},Y:{name:"Y",value:1e48,scientific:!0},d:{name:"d",value:.01,scientific:!1},c:{name:"c",value:1e-4,scientific:!1},m:{name:"m",value:1e-6,scientific:!0},u:{name:"u",value:1e-12,scientific:!0},n:{name:"n",value:1e-18,scientific:!0},p:{name:"p",value:1e-24,scientific:!0},f:{name:"f",value:1e-30,scientific:!0},a:{name:"a",value:1e-36,scientific:!0},z:{name:"z",value:1e-42,scientific:!0},y:{name:"y",value:1e-42,scientific:!0}},CUBIC:{"":{name:"",value:1,scientific:!0},da:{name:"da",value:1e3,scientific:!1},h:{name:"h",value:1e6,scientific:!1},k:{name:"k",value:1e9,scientific:!0},M:{name:"M",value:1e18,scientific:!0},G:{name:"G",value:1e27,scientific:!0},T:{name:"T",value:1e36,scientific:!0},P:{name:"P",value:1e45,scientific:!0},E:{name:"E",value:1e54,scientific:!0},Z:{name:"Z",value:1e63,scientific:!0},Y:{name:"Y",value:1e72,scientific:!0},d:{name:"d",value:.001,scientific:!1},c:{name:"c",value:1e-6,scientific:!1},m:{name:"m",value:1e-9,scientific:!0},u:{name:"u",value:1e-18,scientific:!0},n:{name:"n",value:1e-27,scientific:!0},p:{name:"p",value:1e-36,scientific:!0},f:{name:"f",value:1e-45,scientific:!0},a:{name:"a",value:1e-54,scientific:!0},z:{name:"z",value:1e-63,scientific:!0},y:{name:"y",value:1e-72,scientific:!0}},BINARY_SHORT:{"":{name:"",value:1,scientific:!0},k:{name:"k",value:1024,scientific:!0},M:{name:"M",value:Math.pow(1024,2),scientific:!0},G:{name:"G",value:Math.pow(1024,3),scientific:!0},T:{name:"T",value:Math.pow(1024,4),scientific:!0},P:{name:"P",value:Math.pow(1024,5),scientific:!0},E:{name:"E",value:Math.pow(1024,6),scientific:!0},Z:{name:"Z",value:Math.pow(1024,7),scientific:!0},Y:{name:"Y",value:Math.pow(1024,8),scientific:!0},Ki:{name:"Ki",value:1024,scientific:!0},Mi:{name:"Mi",value:Math.pow(1024,2),scientific:!0},Gi:{name:"Gi",value:Math.pow(1024,3),scientific:!0},Ti:{name:"Ti",value:Math.pow(1024,4),scientific:!0},Pi:{name:"Pi",value:Math.pow(1024,5),scientific:!0},Ei:{name:"Ei",value:Math.pow(1024,6),scientific:!0},Zi:{name:"Zi",value:Math.pow(1024,7),scientific:!0},Yi:{name:"Yi",value:Math.pow(1024,8),scientific:!0}},BINARY_LONG:{"":{name:"",value:1,scientific:!0},kilo:{name:"kilo",value:1024,scientific:!0},mega:{name:"mega",value:Math.pow(1024,2),scientific:!0},giga:{name:"giga",value:Math.pow(1024,3),scientific:!0},tera:{name:"tera",value:Math.pow(1024,4),scientific:!0},peta:{name:"peta",value:Math.pow(1024,5),scientific:!0},exa:{name:"exa",value:Math.pow(1024,6),scientific:!0},zetta:{name:"zetta",value:Math.pow(1024,7),scientific:!0},yotta:{name:"yotta",value:Math.pow(1024,8),scientific:!0},kibi:{name:"kibi",value:1024,scientific:!0},mebi:{name:"mebi",value:Math.pow(1024,2),scientific:!0},gibi:{name:"gibi",value:Math.pow(1024,3),scientific:!0},tebi:{name:"tebi",value:Math.pow(1024,4),scientific:!0},pebi:{name:"pebi",value:Math.pow(1024,5),scientific:!0},exi:{name:"exi",value:Math.pow(1024,6),scientific:!0},zebi:{name:"zebi",value:Math.pow(1024,7),scientific:!0},yobi:{name:"yobi",value:Math.pow(1024,8),scientific:!0}}},b={name:"",value:1,scientific:!0},E={NONE:{},LENGTH:{},MASS:{},TIME:{},CURRENT:{},TEMPERATURE:{},LUMINOUS_INTENSITY:{},AMOUNT_OF_SUBSTANCE:{},FORCE:{},SURFACE:{},VOLUME:{},ANGLE:{},BIT:{}};BASE_UNIT_NONE={},UNIT_NONE={name:"",base:BASE_UNIT_NONE,value:1,offset:0};var N={meter:{name:"meter",base:E.LENGTH,prefixes:x.LONG,value:1,offset:0},inch:{name:"inch",base:E.LENGTH,prefixes:x.NONE,value:.0254,offset:0},foot:{name:"foot",base:E.LENGTH,prefixes:x.NONE,value:.3048,offset:0},yard:{name:"yard",base:E.LENGTH,prefixes:x.NONE,value:.9144,offset:0},mile:{name:"mile",base:E.LENGTH,prefixes:x.NONE,value:1609.344,offset:0},link:{name:"link",base:E.LENGTH,prefixes:x.NONE,value:.201168,offset:0},rod:{name:"rod",base:E.LENGTH,prefixes:x.NONE,value:5.02921,offset:0},chain:{name:"chain",base:E.LENGTH,prefixes:x.NONE,value:20.1168,offset:0},angstrom:{name:"angstrom",base:E.LENGTH,prefixes:x.NONE,value:1e-10,offset:0},m:{name:"m",base:E.LENGTH,prefixes:x.SHORT,value:1,offset:0},"in":{name:"in",base:E.LENGTH,prefixes:x.NONE,value:.0254,offset:0},ft:{name:"ft",base:E.LENGTH,prefixes:x.NONE,value:.3048,offset:0},yd:{name:"yd",base:E.LENGTH,prefixes:x.NONE,value:.9144,offset:0},mi:{name:"mi",base:E.LENGTH,prefixes:x.NONE,value:1609.344,offset:0},li:{name:"li",base:E.LENGTH,prefixes:x.NONE,value:.201168,offset:0},rd:{name:"rd",base:E.LENGTH,prefixes:x.NONE,value:5.02921,offset:0},ch:{name:"ch",base:E.LENGTH,prefixes:x.NONE,value:20.1168,offset:0},mil:{name:"mil",base:E.LENGTH,prefixes:x.NONE,value:254e-7,offset:0},m2:{name:"m2",base:E.SURFACE,prefixes:x.SQUARED,value:1,offset:0},sqin:{name:"sqin",base:E.SURFACE,prefixes:x.NONE,value:64516e-8,offset:0},sqft:{name:"sqft",base:E.SURFACE,prefixes:x.NONE,value:.09290304,offset:0},sqyd:{name:"sqyd",base:E.SURFACE,prefixes:x.NONE,value:.83612736,offset:0},sqmi:{name:"sqmi",base:E.SURFACE,prefixes:x.NONE,value:2589988.110336,offset:0},sqrd:{name:"sqrd",base:E.SURFACE,prefixes:x.NONE,value:25.29295,offset:0},sqch:{name:"sqch",base:E.SURFACE,prefixes:x.NONE,value:404.6873,offset:0},sqmil:{name:"sqmil",base:E.SURFACE,prefixes:x.NONE,value:6.4516e-10,offset:0},m3:{name:"m3",base:E.VOLUME,prefixes:x.CUBIC,value:1,offset:0},L:{name:"L",base:E.VOLUME,prefixes:x.SHORT,value:.001,offset:0},l:{name:"l",base:E.VOLUME,prefixes:x.SHORT,value:.001,offset:0},litre:{name:"litre",base:E.VOLUME,prefixes:x.LONG,value:.001,offset:0},cuin:{name:"cuin",base:E.VOLUME,prefixes:x.NONE,value:16387064e-12,offset:0},cuft:{name:"cuft",base:E.VOLUME,prefixes:x.NONE,value:.028316846592,offset:0},cuyd:{name:"cuyd",base:E.VOLUME,prefixes:x.NONE,value:.764554857984,offset:0},teaspoon:{name:"teaspoon",base:E.VOLUME,prefixes:x.NONE,value:5e-6,offset:0},tablespoon:{name:"tablespoon",base:E.VOLUME,prefixes:x.NONE,value:15e-6,offset:0},minim:{name:"minim",base:E.VOLUME,prefixes:x.NONE,value:6.161152e-8,offset:0},fluiddram:{name:"fluiddram",base:E.VOLUME,prefixes:x.NONE,value:36966911e-13,offset:0},fluidounce:{name:"fluidounce",base:E.VOLUME,prefixes:x.NONE,value:2957353e-11,offset:0},gill:{name:"gill",base:E.VOLUME,prefixes:x.NONE,value:.0001182941,offset:0},cc:{name:"cc",base:E.VOLUME,prefixes:x.NONE,value:1e-6,offset:0},cup:{name:"cup",base:E.VOLUME,prefixes:x.NONE,value:.0002365882,offset:0},pint:{name:"pint",base:E.VOLUME,prefixes:x.NONE,value:.0004731765,offset:0},quart:{name:"quart",base:E.VOLUME,prefixes:x.NONE,value:.0009463529,offset:0},gallon:{name:"gallon",base:E.VOLUME,prefixes:x.NONE,value:.003785412,offset:0},beerbarrel:{name:"beerbarrel",base:E.VOLUME,prefixes:x.NONE,value:.1173478,offset:0},oilbarrel:{name:"oilbarrel",base:E.VOLUME,prefixes:x.NONE,value:.1589873,offset:0},hogshead:{name:"hogshead",base:E.VOLUME,prefixes:x.NONE,value:.238481,offset:0},fldr:{name:"fldr",base:E.VOLUME,prefixes:x.NONE,value:36966911e-13,offset:0},floz:{name:"floz",base:E.VOLUME,prefixes:x.NONE,value:2957353e-11,offset:0},gi:{name:"gi",base:E.VOLUME,prefixes:x.NONE,value:.0001182941,offset:0},cp:{name:"cp",base:E.VOLUME,prefixes:x.NONE,value:.0002365882,offset:0},pt:{name:"pt",base:E.VOLUME,prefixes:x.NONE,value:.0004731765,offset:0},qt:{name:"qt",base:E.VOLUME,prefixes:x.NONE,value:.0009463529,offset:0},gal:{name:"gal",base:E.VOLUME,prefixes:x.NONE,value:.003785412,offset:0},bbl:{name:"bbl",base:E.VOLUME,prefixes:x.NONE,value:.1173478,offset:0},obl:{name:"obl",base:E.VOLUME,prefixes:x.NONE,value:.1589873,offset:0},g:{name:"g",base:E.MASS,prefixes:x.SHORT,value:.001,offset:0},gram:{name:"gram",base:E.MASS,prefixes:x.LONG,value:.001,offset:0},ton:{name:"ton",base:E.MASS,prefixes:x.SHORT,value:907.18474,offset:0},tonne:{name:"tonne",base:E.MASS,prefixes:x.SHORT,value:1e3,offset:0},grain:{name:"grain",base:E.MASS,prefixes:x.NONE,value:6479891e-11,offset:0},dram:{name:"dram",base:E.MASS,prefixes:x.NONE,value:.0017718451953125,offset:0},ounce:{name:"ounce",base:E.MASS,prefixes:x.NONE,value:.028349523125,offset:0},poundmass:{name:"poundmass",base:E.MASS,prefixes:x.NONE,value:.45359237,offset:0},hundredweight:{name:"hundredweight",base:E.MASS,prefixes:x.NONE,value:45.359237,offset:0},stick:{name:"stick",base:E.MASS,prefixes:x.NONE,value:.115,offset:0},gr:{name:"gr",base:E.MASS,prefixes:x.NONE,value:6479891e-11,offset:0},dr:{name:"dr",base:E.MASS,prefixes:x.NONE,value:.0017718451953125,offset:0},oz:{name:"oz",base:E.MASS,prefixes:x.NONE,value:.028349523125,offset:0},lbm:{name:"lbm",base:E.MASS,prefixes:x.NONE,value:.45359237,offset:0},cwt:{name:"cwt",base:E.MASS,prefixes:x.NONE,value:45.359237,offset:0},s:{name:"s",base:E.TIME,prefixes:x.SHORT,value:1,offset:0},min:{name:"min",base:E.TIME,prefixes:x.NONE,value:60,offset:0},h:{name:"h",base:E.TIME,prefixes:x.NONE,value:3600,offset:0},second:{name:"second",base:E.TIME,prefixes:x.LONG,value:1,offset:0},sec:{name:"sec",base:E.TIME,prefixes:x.LONG,value:1,offset:0},minute:{name:"minute",base:E.TIME,prefixes:x.NONE,value:60,offset:0},hour:{name:"hour",base:E.TIME,prefixes:x.NONE,value:3600,offset:0},day:{name:"day",base:E.TIME,prefixes:x.NONE,value:86400,offset:0},rad:{name:"rad",base:E.ANGLE,prefixes:x.NONE,value:1,offset:0},deg:{name:"deg",base:E.ANGLE,prefixes:x.NONE,value:.017453292519943295,offset:0},grad:{name:"grad",base:E.ANGLE,prefixes:x.NONE,value:.015707963267948967,offset:0},cycle:{name:"cycle",base:E.ANGLE,prefixes:x.NONE,value:6.283185307179586,offset:0},A:{name:"A",base:E.CURRENT,prefixes:x.SHORT,value:1,offset:0},ampere:{name:"ampere",base:E.CURRENT,prefixes:x.LONG,value:1,offset:0},K:{name:"K",base:E.TEMPERATURE,prefixes:x.NONE,value:1,offset:0},degC:{name:"degC",base:E.TEMPERATURE,prefixes:x.NONE,value:1,offset:273.15},degF:{name:"degF",base:E.TEMPERATURE,prefixes:x.NONE,value:1/1.8,offset:459.67},degR:{name:"degR",base:E.TEMPERATURE,prefixes:x.NONE,value:1/1.8,offset:0},kelvin:{name:"kelvin",base:E.TEMPERATURE,prefixes:x.NONE,value:1,offset:0},celsius:{name:"celsius",base:E.TEMPERATURE,prefixes:x.NONE,value:1,offset:273.15},fahrenheit:{name:"fahrenheit",base:E.TEMPERATURE,prefixes:x.NONE,value:1/1.8,offset:459.67},rankine:{name:"rankine",base:E.TEMPERATURE,prefixes:x.NONE,value:1/1.8,offset:0},mol:{name:"mol",base:E.AMOUNT_OF_SUBSTANCE,prefixes:x.NONE,value:1,offset:0},mole:{name:"mole",base:E.AMOUNT_OF_SUBSTANCE,prefixes:x.NONE,value:1,offset:0},cd:{name:"cd",base:E.LUMINOUS_INTENSITY,prefixes:x.NONE,value:1,offset:0},candela:{name:"candela",base:E.LUMINOUS_INTENSITY,prefixes:x.NONE,value:1,offset:0},N:{name:"N",base:E.FORCE,prefixes:x.SHORT,value:1,offset:0},newton:{name:"newton",base:E.FORCE,prefixes:x.LONG,value:1,offset:0},lbf:{name:"lbf",base:E.FORCE,prefixes:x.NONE,value:4.4482216152605,offset:0},poundforce:{name:"poundforce",base:E.FORCE,prefixes:x.NONE,value:4.4482216152605,offset:0},b:{name:"b",base:E.BIT,prefixes:x.BINARY_SHORT,value:1,offset:0},bits:{name:"bits",base:E.BIT,prefixes:x.BINARY_LONG,value:1,offset:0},B:{name:"B",base:E.BIT,prefixes:x.BINARY_SHORT,value:8,offset:0},bytes:{name:"bytes",base:E.BIT,prefixes:x.BINARY_LONG,value:8,offset:0}},M={meters:"meter",inches:"inch",feet:"foot",yards:"yard",miles:"mile",links:"link",rods:"rod",chains:"chain",angstroms:"angstrom",litres:"litre",teaspoons:"teaspoon",tablespoons:"tablespoon",minims:"minim",fluiddrams:"fluiddram",fluidounces:"fluidounce",gills:"gill",cups:"cup",pints:"pint",quarts:"quart",gallons:"gallon",beerbarrels:"beerbarrel",oilbarrels:"oilbarrel",hogsheads:"hogshead",grams:"gram",tons:"ton",tonnes:"tonne",grains:"grain",drams:"dram",ounces:"ounce",poundmasses:"poundmass",hundredweights:"hundredweight",sticks:"stick",seconds:"second",minutes:"minute",hours:"hour",days:"day",radians:"rad",degrees:"deg",gradients:"grad",cycles:"cycle",amperes:"ampere",moles:"mole"}; +for(var A in M)if(M.hasOwnProperty(A)){var S=N[M[A]],T=Object.create(S);T.name=A,N[A]=T}N.lt=N.l,N.liter=N.litre,N.liters=N.litres,N.lb=N.lbm,N.lbs=N.lbm,n.PREFIXES=x,n.BASE_UNITS=E,n.UNITS=N,e.exports=n},function(e,r,t){function n(e,r){if(!(this instanceof n))throw new SyntaxError("Constructor must be called with the new operator");this.math=e,this.doc=r}var i=t(117),o=i.object,a=i.string;n.isHelp=function(e){return e instanceof n},n.prototype.toString=function(){var e=this.doc||{},r="\n";if(e.name&&(r+="Name: "+e.name+"\n\n"),e.category&&(r+="Category: "+e.category+"\n\n"),e.description&&(r+="Description:\n "+e.description+"\n\n"),e.syntax&&(r+="Syntax:\n "+e.syntax.join("\n ")+"\n\n"),e.examples){var t=this.math.parser();r+="Examples:\n";for(var i=0;i=r){if(u(e[0])){for(f=i(e),a=[],o=0;ot;t++){var a=[];for(r=0;n>r;r++)a.push(e[r][t]);o.push(a)}return o}{var o=t(117),a=t(114),s=t(8),u=o.array.isArray;o.string.isString}r.argsToArray=function(e){var r;return 0==e.length?r=[]:1==e.length?(r=e[0],r instanceof s&&(r=r.valueOf()),u(r)||(r=[r])):r=Array.prototype.slice.apply(e),r},r.isCollection=function(e){return u(e)||e instanceof s},r.deepMap=function f(e,r){return e&&"function"==typeof e.map?e.map(function(e){return f(e,r)}):r(e)},r.deepMap2=function c(e,r,t){var n,i,o;if(u(e))if(u(r)){if(e.length!=r.length)throw new a(e.length,r.length);for(n=[],i=e.length,o=0;i>o;o++)n[o]=c(e[o],r[o],t)}else{if(r instanceof s)return n=c(e,r.valueOf(),t),new s(n);for(n=[],i=e.length,o=0;i>o;o++)n[o]=c(e[o],r,t)}else{if(e instanceof s)return r instanceof s?(n=c(e.valueOf(),r.valueOf(),t),new s(n)):(n=c(e.valueOf(),r,t),new s(n));if(u(r))for(n=[],i=r.length,o=0;i>o;o++)n[o]=c(e,r[o],t);else{if(r instanceof s)return n=c(e,r.valueOf(),t),new s(n);n=t(e,r)}}return n},r.reduce=function(e,r,t){return e instanceof s?new s(n(e.valueOf(),r,t)):n(e,r,t)},r.deepForEach=function l(e,r){e instanceof s&&(e=e.valueOf());for(var t=0,n=e.length;n>t;t++){var i=e[t];u(i)?l(i,r):r(i)}}},function(e,r,t){function n(e,r){if(1!=arguments.length&&2!=arguments.length)throw new SyntaxError("Wrong number of arguments: 1 or 2 expected");if(fr="object"===V(r)?r:{},D(e))return cr=e,p();if(G(e)||e instanceof H)return W.deepMap(e,function(e){if(!D(e))throw new TypeError("String expected");return cr=e,p()});throw new TypeError("String or matrix expected")}function i(){lr=0,pr=cr.charAt(0)}function o(){lr++,pr=cr.charAt(lr)}function a(){return cr.charAt(lr+1)}function s(){for(hr=ar.NULL,mr="";" "==pr||" "==pr;)o();if("#"==pr)for(;"\n"!=pr&&""!=pr;)o();if(""==pr)return void(hr=ar.DELIMITER);var e=pr+a();if(sr[e])return hr=ar.DELIMITER,mr=e,o(),void o();if(sr[pr])return hr=ar.DELIMITER,mr=pr,void o();if(!c(pr)){if(f(pr)){for(;f(pr)||l(pr);)mr+=pr,o();return void(hr=ur[mr]?ar.DELIMITER:ar.SYMBOL)}for(hr=ar.UNKNOWN;""!=pr;)mr+=pr,o();throw k('Syntax error in part "'+mr+'"')}if(hr=ar.NUMBER,"."==pr)mr+=pr,o(),l(pr)||(hr=ar.UNKNOWN);else{for(;l(pr);)mr+=pr,o();"."==pr&&(mr+=pr,o())}for(;l(pr);)mr+=pr,o();if("E"==pr||"e"==pr)for(mr+=pr,o(),("+"==pr||"-"==pr)&&(mr+=pr,o()),l(pr)||(hr=ar.UNKNOWN);l(pr);)mr+=pr,o()}function u(){for(;"\n"==mr;)s()}function f(e){return e>="a"&&"z">=e||e>="A"&&"Z">=e||"_"==e}function c(e){return e>="0"&&"9">=e||"."==e}function l(e){return e>="0"&&"9">=e}function p(){i(),s();var e=m();if(""!=mr)throw hr==ar.DELIMITER?P("Unknown operator "+mr):k('Unexpected part "'+mr+'"');return e}function m(){var e,r,t;if(""==mr)return new Q("undefined","undefined");for("\n"!=mr&&";"!=mr&&(e=h());"\n"==mr||";"==mr;)r||(r=new $,e&&(t=";"!=mr,r.add(e,t))),s(),"\n"!=mr&&";"!=mr&&""!=mr&&(e=h(),t=";"!=mr,r.add(e,t));return r?r:e}function h(){var e=g(),r="ans";return new Z(r,e)}function g(){if(hr==ar.SYMBOL&&"function"==mr)throw new Error('Deprecated keyword "function". Functions can now be assigned without it, like "f(x) = x^2".');return d()}function d(){var e,r,t,n=w();if("="==mr){if(n instanceof tr)return e=n.name,s(),t=d(),new Z(e,t);if(n instanceof K)return s(),t=d(),new or(n,t);if(n instanceof er){var i=!0;if(r=[],n.object instanceof tr?(e=n.object.name,n.params.forEach(function(e,t){e instanceof tr?r[t]=e.name:i=!1})):i=!1,i)return s(),t=d(),new J(e,r,t)}throw k("Invalid left hand side of assignment operator =")}return n}function w(){var e,r=[];if(e=":"==mr?new Q("number","1"):y(),":"==mr){for(r.push(e);":"==mr;)s(),r.push(")"==mr||"]"==mr||","==mr||""==mr?new tr("end"):y());if(3==r.length){var t=r[2];r[2]=r[1],r[1]=t}e=new rr(r)}return e}function y(){var e=v();return e}function v(){for(var e=x();"?"==mr;){s();var r=[e];if(r.push(x()),":"!=mr)throw k("False part of conditional expression expected");s(),r.push(v()),e=new nr(["?",":"],"ifElse",r)}return e}function x(){var e,r,t,n,i;for(e=b(),r={"==":"equal","!=":"unequal","<":"smaller",">":"larger","<=":"smallereq",">=":"largereq"};mr in r;)t=mr,n=r[t],s(),i=[e,b()],e=new X(t,n,i);return e}function b(){var e,r,t,n,i;for(e=E(),r={to:"to","in":"to"};mr in r;)t=mr,n=r[t],s(),i=[e,E()],e=new X(t,n,i);return e}function E(){var e,r,t,n,i;for(e=N(),r={"+":"add","-":"subtract"};mr in r;)t=mr,n=r[t],s(),i=[e,N()],e=new X(t,n,i);return e}function N(){var e,r,t,n,i;for(e=M(),r={"*":"multiply",".*":"emultiply","/":"divide","./":"edivide","%":"mod",mod:"mod"};mr in r;)t=mr,n=r[t],s(),i=[e,M()],e=new X(t,n,i);return e}function M(){var e,r;return e=A(),(hr==ar.SYMBOL||"in"==mr)&&(r=mr,s(),e=new ir(e,r)),e}function A(){var e,r,t;return"-"==mr?(e=mr,r="unary",s(),t=[A()],new X(e,r,t)):S()}function S(){var e,r,t,n;return e=T(),("^"==mr||".^"==mr)&&(r=mr,t="^"==r?"pow":"epow",s(),n=[e,S()],e=new X(r,t,n)),e}function T(){var e,r,t,n,i;for(e=O(),r={"!":"factorial","'":"transpose"};mr in r;)t=mr,n=r[t],s(),i=[e],e=new X(t,n,i);return e}function O(){var e,r=[];if(hr==ar.SYMBOL&&fr[mr]){if(e=fr[mr],s(),"("==mr){if(r=[],s(),")"!=mr)for(r.push(w());","==mr;)s(),r.push(w());if(")"!=mr)throw k("Parenthesis ) expected");s()}return new e(r)}return C()}function C(){var e,r;return hr==ar.SYMBOL||hr==ar.DELIMITER&&mr in ur?(r=mr,s(),e=new tr(r),_(e)):B()}function _(e){for(var r,t;"("==mr||"["==mr;){if(r=mr,t=[],s(),")"!=mr&&"]"!=mr)for(t.push(w());","==mr;)s(),t.push(w());if("("==r&&")"!=mr)throw k("Parenthesis ) expected");if("["==r&&"]"!=mr)throw k("Parenthesis ] expected");s(),e="("==r?new er(e,t):new K(e,t)}return e}function B(){var e,r,t;if('"'==mr){for(r="",t="";""!=pr&&('"'!=pr||"\\"==t);)r+=pr,t=pr,o();if(s(),'"'!=mr)throw k('End of string " expected');return s(),e=new Q("string",r),e=_(e)}return I()}function I(){var e,r,t,n;if("["==mr){if(s(),u(),"]"!=mr){var i=U();if(";"==mr){for(t=1,r=[i];";"==mr;)s(),u(),r[t]=U(),t++,u();if("]"!=mr)throw k("End of matrix ] expected");s(),n=r[0].nodes.length;for(var o=1;t>o;o++)if(r[o].nodes.length!=n)throw P("Column dimensions mismatch ("+r[o].nodes.length+" != "+n+")");e=new Y(r)}else{if("]"!=mr)throw k("End of matrix ] expected");s(),e=i}}else s(),e=new Y([]);return e=_(e)}return z()}function U(){for(var e=[d()],r=1;","==mr;)s(),u(),e[r]=d(),r++,u();return new Y(e)}function z(){var e,r;return hr==ar.NUMBER?(r=mr,s(),"i"==mr||"I"==mr?(s(),e=new Q("complex",r)):e=new Q("number",r),e=_(e)):q()}function q(){var e;if("("==mr){if(s(),e=d(),")"!=mr)throw k("Parenthesis ) expected");return s(),e=_(e)}return L()}function L(){throw k(""==mr?"Unexpected end of expression":"Value expected")}function j(){return lr-mr.length+1}function R(e){return e+" (char "+j()+")"}function k(e){return new SyntaxError(R(e))}function P(e){return new Error(R(e))}var F=t(117),D=F.string.isString,G=Array.isArray,V=F.types.type,H=(t(5),t(8)),W=(t(9),t(11)),Y=t(118),Z=t(119),$=t(120),Q=t(121),J=t(122),K=t(123),X=t(124),er=t(125),rr=t(126),tr=t(127),nr=t(128),ir=t(129),or=t(130),ar={NULL:0,DELIMITER:1,NUMBER:2,SYMBOL:3,UNKNOWN:4},sr={",":!0,"(":!0,")":!0,"[":!0,"]":!0,'"':!0,"\n":!0,";":!0,"+":!0,"-":!0,"*":!0,".*":!0,"/":!0,"./":!0,"%":!0,"^":!0,".^":!0,"!":!0,"'":!0,"=":!0,":":!0,"?":!0,"==":!0,"!=":!0,"<":!0,">":!0,"<=":!0,">=":!0},ur={mod:!0,to:!0,"in":!0},fr={},cr="",lr=0,pr="",mr="",hr=ar.NULL;e.exports=n},function(e,r,t){function n(e){if(!(this instanceof n))throw new SyntaxError("Constructor must be called with the new operator");if("object"!=typeof e)throw new TypeError("Object expected as parameter math");this.math=e,this.scope={}}var i=t(12);n.prototype.parse=function(e){return i(e)},n.prototype.compile=function(e){return i(e).compile(this.math)},n.prototype.eval=function(e){return i(e).compile(this.math).eval(this.scope)},n.prototype.get=function(e){return this.scope[e]},n.prototype.set=function(e,r){return this.scope[e]=r},n.prototype.remove=function(e){delete this.scope[e]},n.prototype.clear=function(){for(var e in this.scope)this.scope.hasOwnProperty(e)&&delete this.scope[e]},e.exports=n},function(e,r,t){r.ArrayNode=t(118),r.AssignmentNode=t(119),r.BlockNode=t(120),r.ConstantNode=t(121),r.IndexNode=t(123),r.FunctionNode=t(122),r.Node=t(131),r.OperatorNode=t(124),r.ParamsNode=t(125),r.RangeNode=t(126),r.SymbolNode=t(127),r.TernaryNode=t(128),r.UnitNode=t(129),r.UpdateNode=t(130)},function(e,r,t){r.e=t(133),r.E=t(133),r["false"]=t(134),r.i=t(135),r.Infinity=t(136),r.LN2=t(137),r.LN10=t(138),r.LOG2E=t(139),r.LOG10E=t(140),r.NaN=t(141),r.pi=t(142),r.PI=t(142),r.SQRT1_2=t(143),r.SQRT2=t(144),r.tau=t(145),r["true"]=t(146),r.abs=t(151),r.add=t(152),r.ceil=t(153),r.compare=t(154),r.cube=t(155),r.divide=t(156),r.edivide=t(157),r.emultiply=t(158),r.epow=t(159),r.equal=t(160),r.exp=t(161),r.fix=t(162),r.floor=t(163),r.gcd=t(164),r.larger=t(165),r.largereq=t(166),r.lcm=t(167),r.log=t(168),r.log10=t(169),r.mod=t(170),r.multiply=t(171),r.norm=t(172),r.pow=t(173),r.round=t(174),r.sign=t(175),r.smaller=t(176),r.smallereq=t(177),r.sqrt=t(178),r.square=t(179),r.subtract=t(180),r.unary=t(181),r.unequal=t(182),r.xgcd=t(183),r.arg=t(184),r.conj=t(185),r.re=t(186),r.im=t(187),r.bignumber=t(188),r["boolean"]=t(189),r.complex=t(190),r.index=t(191),r.matrix=t(192),r.number=t(193),r.string=t(194),r.unit=t(195),r.eval=t(196),r.help=t(197),r.concat=t(198),r.det=t(199),r.diag=t(200),r.eye=t(201),r.inv=t(202),r.ones=t(203),r.range=t(204),r.resize=t(205),r.size=t(206),r.squeeze=t(207),r.subset=t(208),r.transpose=t(209),r.zeros=t(210),r.combinations=t(211),r.distribution=t(212),r.factorial=t(213),r.permutations=t(214),r.pickRandom=t(215),r.random=t(216),r.randomInt=t(217),r.max=t(218),r.mean=t(219),r.median=t(220),r.min=t(221),r.prod=t(222),r.std=t(223),r.sum=t(224),r["var"]=t(225),r.acos=t(226),r.asin=t(227),r.atan=t(228),r.atan2=t(229),r.cos=t(230),r.cot=t(231),r.csc=t(232),r.sec=t(233),r.sin=t(234),r.tan=t(235),r.to=t(236),r.clone=t(237),r.map=t(238),r.forEach=t(239),r.format=t(240),r.ifElse=t(241),r["import"]=t(242),r["typeof"]=t(243)},function(e,r,t){e.exports=function(e){function r(e){if(!(this instanceof r))throw new SyntaxError("Constructor must be called with the new operator");this.value=e instanceof r?e.value:e}function n(e,t){var n=Array.prototype.slice;r.prototype[e]="function"==typeof t?function(){var e=[this.value].concat(n.call(arguments,0));return new r(t.apply(this,e))}:new r(t)}var i=t(132);r.prototype.done=function(){return this.value},r.prototype.valueOf=function(){return this.value},r.prototype.toString=function(){return i.format(this.value)},r.createProxy=n;for(var o in e)e.hasOwnProperty(o)&&n(o,e[o]);return r}},function(e,r,t){e.exports=function(e){var r=t(117),n=t(12),i=t(11),o=r.string.isString,a=i.isCollection;e.compile=function(r){if(1!=arguments.length)throw new e.error.ArgumentsError("compile",arguments.length,1);if(o(r))return n(r).compile(e);if(a(r))return i.deepMap(r,function(r){return n(r).compile(e)});throw new TypeError("String, array, or matrix expected")}}},function(e,r,t){e.exports=function(e){var r=t(117),n=t(12),i=t(11),o=r.string.isString,a=i.isCollection;e.eval=function(r,t){if(1!=arguments.length&&2!=arguments.length)throw new e.error.ArgumentsError("eval",arguments.length,1,2);if(t=t||{},o(r))return n(r).compile(e).eval(t);if(a(r))return i.deepMap(r,function(r){return n(r).compile(e).eval(t)});throw new TypeError("String, array, or matrix expected")}}},function(e,r,t){e.exports=function(e){var r=t(10);e.help=function(t){if(1!=arguments.length)throw new SyntaxError("Wrong number of arguments in function help ("+arguments.length+" provided, 1 expected)");var n=null;if(t instanceof String||"string"==typeof t)n=t;else{var i;for(i in e)if(e.hasOwnProperty(i)&&t===e[i]){n=i;break}}var o=e.expression.docs[n];if(!n||!o)throw new Error('No documentation found on "'+n+'"');return new r(e,o)}}},function(e,r,t){e.exports=function(e){var r=t(12);e.parse=function(){return r.apply(r,arguments)}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(5),o=(t(8),t(11)),a=r.number.isNumber,s=r["boolean"].isBoolean,u=i.isComplex,f=o.isCollection;e.abs=function c(r){if(1!=arguments.length)throw new e.error.ArgumentsError("abs",arguments.length,1);if(a(r))return Math.abs(r);if(u(r))return Math.sqrt(r.re*r.re+r.im*r.im);if(r instanceof n)return r.abs();if(f(r))return o.deepMap(r,c);if(s(r))return Math.abs(r);throw new e.error.UnsupportedTypeError("abs",e["typeof"](r))}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(5),o=(t(8),t(9)),a=t(11),s=r["boolean"].isBoolean,u=r.number.isNumber,f=r.string.isString,c=i.isComplex,l=o.isUnit,p=a.isCollection;e.add=function m(r,t){if(2!=arguments.length)throw new e.error.ArgumentsError("add",arguments.length,2);if(u(r)){if(u(t))return r+t;if(c(t))return new i(r+t.re,t.im)}if(c(r)){if(c(t))return new i(r.re+t.re,r.im+t.im);if(u(t))return new i(r.re+t,r.im)}if(l(r)&&l(t)){if(null==r.value)throw new Error("Parameter x contains a unit with undefined value");if(null==t.value)throw new Error("Parameter y contains a unit with undefined value");if(!r.equalBase(t))throw new Error("Units do not match");var o=r.clone();return o.value+=t.value,o.fixPrefix=!1,o}if(r instanceof n)return u(t)?t=n.convert(t):s(t)&&(t=new n(t?1:0)),t instanceof n?r.plus(t):m(r.toNumber(),t);if(t instanceof n)return u(r)?r=n.convert(r):s(r)&&(r=new n(r?1:0)),r instanceof n?r.plus(t):m(r,t.toNumber());if(f(r)||f(t))return r+t;if(p(r)||p(t))return a.deepMap2(r,t,m);if(s(r))return m(+r,t);if(s(t))return m(r,+t);throw new e.error.UnsupportedTypeError("add",e["typeof"](r),e["typeof"](t))}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(5),o=t(11),a=r.number.isNumber,s=r["boolean"].isBoolean,u=o.isCollection,f=i.isComplex;e.ceil=function c(r){if(1!=arguments.length)throw new e.error.ArgumentsError("ceil",arguments.length,1);if(a(r))return Math.ceil(r);if(f(r))return new i(Math.ceil(r.re),Math.ceil(r.im));if(r instanceof n)return r.ceil();if(u(r))return o.deepMap(r,c);if(s(r))return Math.ceil(r);throw new e.error.UnsupportedTypeError("ceil",e["typeof"](r))}}},function(e,r,t){e.exports=function(e,r){var n=t(117),i=e.type.BigNumber,o=t(5),a=t(9),s=t(11),u=n.number.isNumber,f=n.number.nearlyEqual,c=n["boolean"].isBoolean,l=n.string.isString,p=o.isComplex,m=a.isUnit,h=s.isCollection;e.compare=function g(t,n){if(2!=arguments.length)throw new e.error.ArgumentsError("compare",arguments.length,2);if(u(t)&&u(n))return f(t,n,r.epsilon)?0:t>n?1:-1;if(t instanceof i)return u(n)?n=i.convert(n):c(n)&&(n=new i(n?1:0)),n instanceof i?new i(t.cmp(n)):g(t.toNumber(),n);if(n instanceof i)return u(t)?t=i.convert(t):c(t)&&(t=new i(t?1:0)),t instanceof i?new i(t.cmp(n)):g(t,n.toNumber());if(m(t)&&m(n)){if(!t.equalBase(n))throw new Error("Cannot compare units with different base");return t.value>n.value?1:t.valuen?1:n>t?-1:0;if(c(t))return g(+t,n);if(c(n))return g(t,+n);if(p(t)||p(n))throw new TypeError("No ordering relation is defined for complex numbers");throw new e.error.UnsupportedTypeError("compare",e["typeof"](t),e["typeof"](n))}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(5),o=t(11),a=r.number.isNumber,s=r["boolean"].isBoolean,u=i.isComplex,f=o.isCollection;e.cube=function c(r){if(1!=arguments.length)throw new e.error.ArgumentsError("cube",arguments.length,1);if(a(r))return r*r*r;if(u(r))return e.multiply(e.multiply(r,r),r);if(r instanceof n)return r.times(r).times(r);if(f(r))return o.deepMap(r,c);if(s(r))return c(+r);throw new e.error.UnsupportedTypeError("cube",e["typeof"](r))}}},function(e,r,t){e.exports=function(e){function r(e,r){var t=r.re*r.re+r.im*r.im;return 0!=t?new o((e.re*r.re+e.im*r.im)/t,(e.im*r.re-e.re*r.im)/t):new o(0!=e.re?e.re/0:0,0!=e.im?e.im/0:0)}var n=t(117),i=e.type.BigNumber,o=t(5),a=(t(8),t(9)),s=t(11),u=n.number.isNumber,f=n["boolean"].isBoolean,c=o.isComplex,l=a.isUnit,p=s.isCollection;e.divide=function m(t,n){if(2!=arguments.length)throw new e.error.ArgumentsError("divide",arguments.length,2);if(u(t)){if(u(n))return t/n;if(c(n))return r(new o(t,0),n)}if(c(t)){if(c(n))return r(t,n);if(u(n))return r(t,new o(n,0))}if(t instanceof i)return u(n)?n=i.convert(n):f(n)&&(n=new i(n?1:0)),n instanceof i?t.div(n):m(t.toNumber(),n);if(n instanceof i)return u(t)?t=i.convert(t):f(t)&&(t=new i(t?1:0)),t instanceof i?t.div(n):m(t,n.toNumber());if(l(t)&&u(n)){var a=t.clone();return a.value/=n,a}if(p(t))return p(n)?e.multiply(t,e.inv(n)):s.deepMap2(t,n,m);if(p(n))return e.multiply(t,e.inv(n));if(f(t))return m(+t,n);if(f(n))return m(t,+n);throw new e.error.UnsupportedTypeError("divide",e["typeof"](t),e["typeof"](n))}}},function(e,r,t){e.exports=function(e){var r=t(11);e.edivide=function(t,n){if(2!=arguments.length)throw new e.error.ArgumentsError("edivide",arguments.length,2);return r.deepMap2(t,n,e.divide)}}},function(e,r,t){e.exports=function(e){var r=(t(117),t(11));e.emultiply=function(t,n){if(2!=arguments.length)throw new e.error.ArgumentsError("emultiply",arguments.length,2);return r.deepMap2(t,n,e.multiply)}}},function(e,r,t){e.exports=function(e){var r=(t(117),t(11));e.epow=function(t,n){if(2!=arguments.length)throw new e.error.ArgumentsError("epow",arguments.length,2);return r.deepMap2(t,n,e.pow)}}},function(e,r,t){e.exports=function(e,r){var n=t(117),i=e.type.BigNumber,o=t(5),a=t(9),s=t(11),u=n.number.isNumber,f=n.number.nearlyEqual,c=n["boolean"].isBoolean,l=n.string.isString,p=o.isComplex,m=a.isUnit,h=s.isCollection;e.equal=function g(t,n){if(2!=arguments.length)throw new e.error.ArgumentsError("equal",arguments.length,2);if(u(t)){if(u(n))return f(t,n,r.epsilon);if(p(n))return f(t,n.re,r.epsilon)&&f(n.im,0,r.epsilon)}if(p(t)){if(u(n))return f(t.re,n,r.epsilon)&&f(t.im,0,r.epsilon);if(p(n))return f(t.re,n.re,r.epsilon)&&f(t.im,n.im,r.epsilon)}if(t instanceof i)return u(n)?n=i.convert(n):c(n)&&(n=new i(n?1:0)),n instanceof i?t.eq(n):g(t.toNumber(),n);if(n instanceof i)return u(t)?t=i.convert(t):c(t)&&(t=new i(t?1:0)),t instanceof i?t.eq(n):g(t,n.toNumber());if(m(t)&&m(n)){if(!t.equalBase(n))throw new Error("Cannot compare units with different base");return t.value==n.value}if(h(t)||h(n))return s.deepMap2(t,n,g);if(l(t)||l(n))return t==n;if(c(t))return g(+t,n);if(c(n))return g(t,+n);throw new e.error.UnsupportedTypeError("equal",e["typeof"](t),e["typeof"](n))}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(5),o=(t(8),t(11)),a=r.number.isNumber,s=r["boolean"].isBoolean,u=i.isComplex,f=o.isCollection;e.exp=function c(r){if(1!=arguments.length)throw new e.error.ArgumentsError("exp",arguments.length,1);if(a(r))return Math.exp(r);if(u(r)){var t=Math.exp(r.re);return new i(t*Math.cos(r.im),t*Math.sin(r.im))}if(r instanceof n)return r.exp();if(f(r))return o.deepMap(r,c);if(s(r))return Math.exp(r);throw new e.error.UnsupportedTypeError("exp",e["typeof"](r))}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(5),o=t(11),a=r.number.isNumber,s=r["boolean"].isBoolean,u=i.isComplex,f=o.isCollection;e.fix=function c(r){if(1!=arguments.length)throw new e.error.ArgumentsError("fix",arguments.length,1);if(a(r))return r>0?Math.floor(r):Math.ceil(r);if(u(r))return new i(r.re>0?Math.floor(r.re):Math.ceil(r.re),r.im>0?Math.floor(r.im):Math.ceil(r.im));if(r instanceof n)return r.isNegative()?r.ceil():r.floor();if(f(r))return o.deepMap(r,c);if(s(r))return c(+r);throw new e.error.UnsupportedTypeError("fix",e["typeof"](r))}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(5),o=t(11),a=r.number.isNumber,s=r["boolean"].isBoolean,u=i.isComplex,f=o.isCollection;e.floor=function c(r){if(1!=arguments.length)throw new e.error.ArgumentsError("floor",arguments.length,1);if(a(r))return Math.floor(r);if(u(r))return new i(Math.floor(r.re),Math.floor(r.im));if(r instanceof n)return r.floor();if(f(r))return o.deepMap(r,c);if(s(r))return c(+r);throw new e.error.UnsupportedTypeError("floor",e["typeof"](r))}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(11),o=r.number.isNumber,a=r["boolean"].isBoolean,s=r.number.isInteger,u=i.isCollection;e.gcd=function f(){var r,t=arguments[0],c=arguments[1];if(2==arguments.length){if(o(t)&&o(c)){if(!s(t)||!s(c))throw new Error("Parameters in function gcd must be integer numbers");for(;0!=c;)r=t%c,t=c,c=r;return 0>t?-t:t}if(u(t)||u(c))return i.deepMap2(t,c,f);if(t instanceof n)return f(t.toNumber(),c);if(c instanceof n)return f(t,c.toNumber());if(a(t))return f(+t,c);if(a(c))return f(t,+c);throw new e.error.UnsupportedTypeError("gcd",e["typeof"](t),e["typeof"](c))}if(arguments.length>2){for(var l=1;ln;if(t instanceof i)return u(n)?n=i.convert(n):c(n)&&(n=new i(n?1:0)),n instanceof i?t.gt(n):g(t.toNumber(),n);if(n instanceof i)return u(t)?t=i.convert(t):c(t)&&(t=new i(t?1:0)),t instanceof i?t.gt(n):g(t,n.toNumber());if(m(t)&&m(n)){if(!t.equalBase(n))throw new Error("Cannot compare units with different base");return t.value>n.value}if(h(t)||h(n))return s.deepMap2(t,n,g);if(l(t)||l(n))return t>n;if(c(t))return g(+t,n);if(c(n))return g(t,+n);if(p(t)||p(n))throw new TypeError("No ordering relation is defined for complex numbers");throw new e.error.UnsupportedTypeError("larger",e["typeof"](t),e["typeof"](n))}}},function(e,r,t){e.exports=function(e,r){var n=t(117),i=e.type.BigNumber,o=t(5),a=t(9),s=t(11),u=n.number.isNumber,f=n.number.nearlyEqual,c=n["boolean"].isBoolean,l=n.string.isString,p=o.isComplex,m=a.isUnit,h=s.isCollection;e.largereq=function g(t,n){if(2!=arguments.length)throw new e.error.ArgumentsError("largereq",arguments.length,2);if(u(t)&&u(n))return f(t,n,r.epsilon)||t>n;if(t instanceof i)return u(n)?n=i.convert(n):c(n)&&(n=new i(n?1:0)),n instanceof i?t.gte(n):g(t.toNumber(),n);if(n instanceof i)return u(t)?t=i.convert(t):c(t)&&(t=new i(t?1:0)),t instanceof i?t.gte(n):g(t,n.toNumber());if(m(t)&&m(n)){if(!t.equalBase(n))throw new Error("Cannot compare units with different base");return t.value>=n.value}if(h(t)||h(n))return s.deepMap2(t,n,g);if(l(t)||l(n))return t>=n;if(c(t))return g(+t,n);if(c(n))return g(t,+n);if(p(t)||p(n))throw new TypeError("No ordering relation is defined for complex numbers");throw new e.error.UnsupportedTypeError("largereq",e["typeof"](t),e["typeof"](n))}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(11),o=r.number.isNumber,a=r["boolean"].isBoolean,s=r.number.isInteger,u=i.isCollection;e.lcm=function f(){var r,t=arguments[0],c=arguments[1];if(2==arguments.length){if(o(t)&&o(c)){if(!s(t)||!s(c))throw new Error("Parameters in function lcm must be integer numbers");if(0==t||0==c)return 0;for(var l=t*c;0!=c;)r=c,c=t%r,t=r;return Math.abs(l/t)}if(u(t)||u(c))return i.deepMap2(t,c,f);if(a(t))return f(+t,c);if(a(c))return f(t,+c);if(t instanceof n)return f(t.toNumber(),c);if(c instanceof n)return f(t,c.toNumber());throw new e.error.UnsupportedTypeError("lcm",e["typeof"](t),e["typeof"](c))}if(arguments.length>2){for(var p=1;p=0?Math.log(r):c(new i(r,0));if(u(r))return new i(Math.log(Math.sqrt(r.re*r.re+r.im*r.im)),Math.atan2(r.im,r.re));if(r instanceof n)return r.ln();if(f(r))return o.deepMap(r,c);if(s(r))return c(+r);throw new e.error.UnsupportedTypeError("log",e["typeof"](r))}if(2==arguments.length)return e.divide(c(r),c(t));throw new e.error.ArgumentsError("log",arguments.length,1,2)}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(5),o=t(11),a=r.number.isNumber,s=r["boolean"].isBoolean,u=i.isComplex,f=o.isCollection;e.log10=function c(r){if(1!=arguments.length)throw new e.error.ArgumentsError("log10",arguments.length,1);if(a(r))return r>=0?Math.log(r)/Math.LN10:c(new i(r,0));if(r instanceof n)return r.log();if(u(r))return new i(Math.log(Math.sqrt(r.re*r.re+r.im*r.im))/Math.LN10,Math.atan2(r.im,r.re)/Math.LN10);if(f(r))return o.deepMap(r,c);if(s(r))return c(+r);throw new e.error.UnsupportedTypeError("log10",e["typeof"](r))}}},function(e,r,t){e.exports=function(e){function r(e,r){if(r>0)return e>0?e%r:0==e?0:e-r*Math.floor(e/r);if(0==r)return e;throw new Error("Cannot calculate mod for a negative divisor")}var n=t(117),i=e.type.BigNumber,o=t(11),a=n.number.isNumber,s=n["boolean"].isBoolean,u=o.isCollection;e.mod=function f(t,n){if(2!=arguments.length)throw new e.error.ArgumentsError("mod",arguments.length,2);if(a(t)&&a(n))return r(t,n);if(t instanceof i)return a(n)?n=i.convert(n):s(n)&&(n=new i(n?1:0)),n instanceof i?n.isZero()?t:t.mod(n):f(t.toNumber(),n);if(n instanceof i)return a(t)?t=i.convert(t):s(t)&&(t=new i(t?1:0)),t instanceof i?n.isZero()?t:t.mod(n):f(t,n.toNumber());if(u(t)||u(n))return o.deepMap2(t,n,f);if(s(t))return f(+t,n);if(s(n))return f(t,+n);throw new e.error.UnsupportedTypeError("mod",e["typeof"](t),e["typeof"](n))}}},function(e,r,t){e.exports=function(e){function r(r,t){for(var n=[],i=r.length,o=t[0].length,a=r[0].length,s=0;i>s;s++){n[s]=[];for(var u=0;o>u;u++){for(var f=null,c=0;a>c;c++){var l=e.multiply(r[s][c],t[c][u]);f=null===f?l:e.add(f,l)}n[s][u]=f}}return n}function n(r,t){for(var n=[],i=t.length,o=t[0].length,a=0;o>a;a++){for(var s=null,u=0;i>u;u++){var f=e.multiply(r[u],t[u][a]);s=0===u?f:e.add(s,f)}n[a]=s}return n}function i(r,t){for(var n=[],i=r.length,o=r[0].length,a=0;i>a;a++){for(var s=null,u=0;o>u;u++){var f=e.multiply(r[a][u],t[u]);s=0===u?f:e.add(s,f)}n[a]=s}return n}function o(r,t){var n=r.length;if(!n)throw new Error("Cannot multiply two empty vectors");for(var i=0,o=0;n>o;o++)i=e.add(i,e.multiply(r[o],t[o]));return i}function a(e,r){return 0==e.im?0==r.im?new f(e.re*r.re,0):0==r.re?new f(0,e.re*r.im):new f(e.re*r.re,e.re*r.im):0==e.re?0==r.im?new f(0,e.im*r.re):0==r.re?new f(-e.im*r.im,0):new f(-e.im*r.im,e.im*r.re):0==r.im?new f(e.re*r.re,e.im*r.re):0==r.re?new f(-e.im*r.im,e.re*r.im):new f(e.re*r.re-e.im*r.im,e.re*r.im+e.im*r.re)}var s=t(117),u=e.type.BigNumber,f=t(5),c=t(8),l=t(9),p=t(11),m=s.array,h=s.number.isNumber,g=s["boolean"].isBoolean,d=f.isComplex,w=Array.isArray,y=l.isUnit;e.multiply=function v(t,s){var l;if(2!=arguments.length)throw new e.error.ArgumentsError("multiply",arguments.length,2);if(h(t)){if(h(s))return t*s;if(d(s))return a(new f(t,0),s);if(y(s))return l=s.clone(),l.value*=t,l}if(d(t)){if(h(s))return a(t,new f(s,0));if(d(s))return a(t,s)}if(t instanceof u)return h(s)?s=u.convert(s):g(s)&&(s=new u(s?1:0)),s instanceof u?t.times(s):v(t.toNumber(),s);if(s instanceof u)return h(t)?t=u.convert(t):g(t)&&(t=new u(t?1:0)),t instanceof u?t.times(s):v(t,s.toNumber());if(y(t)&&h(s))return l=t.clone(),l.value*=s,l;if(w(t)){if(w(s)){var x=m.size(t),b=m.size(s);if(1==x.length){if(1==b.length){if(x[0]!=b[0])throw new RangeError("Dimension mismatch in multiplication. Length of A must match length of B (A is "+x[0]+", B is "+b[0]+x[0]+" != "+b[0]+")");return o(t,s)}if(2==b.length){if(x[0]!=b[0])throw new RangeError("Dimension mismatch in multiplication. Length of A must match rows of B (A is "+x[0]+", B is "+b[0]+"x"+b[1]+", "+x[0]+" != "+b[0]+")");return n(t,s)}throw new Error("Can only multiply a 1 or 2 dimensional matrix (B has "+b.length+" dimensions)")}if(2==x.length){if(1==b.length){if(x[1]!=b[0])throw new RangeError("Dimension mismatch in multiplication. Columns of A must match length of B (A is "+x[0]+"x"+x[0]+", B is "+b[0]+", "+x[1]+" != "+b[0]+")");return i(t,s)}if(2==b.length){if(x[1]!=b[0])throw new RangeError("Dimension mismatch in multiplication. Columns of A must match rows of B (A is "+x[0]+"x"+x[1]+", B is "+b[0]+"x"+b[1]+", "+x[1]+" != "+b[0]+")");return r(t,s)}throw new Error("Can only multiply a 1 or 2 dimensional matrix (B has "+b.length+" dimensions)")}throw new Error("Can only multiply a 1 or 2 dimensional matrix (A has "+x.length+" dimensions)")}return s instanceof c?new c(v(t,s.valueOf())):p.deepMap2(t,s,v)}if(t instanceof c)return new c(s instanceof c?v(t.valueOf(),s.valueOf()):v(t.valueOf(),s));if(w(s))return p.deepMap2(t,s,v);if(s instanceof c)return new c(p.deepMap2(t,s.valueOf(),v));if(g(t))return v(+t,s);if(g(s))return v(t,+s);throw new e.error.UnsupportedTypeError("multiply",e["typeof"](t),e["typeof"](s))}}},function(e,r,t){e.exports=function(e){{var r=t(117),n=t(147),i=e.type.BigNumber,o=t(5),a=t(8),s=t(11),u=r.number.isNumber,f=r["boolean"].isBoolean,c=o.isComplex;s.isCollection}e.norm=function l(r,t){if(arguments.length<1||arguments.length>2)throw new e.error.ArgumentsError("abs",arguments.length,1,2);if(u(r))return Math.abs(r);if(c(r))return Math.sqrt(r.re*r.re+r.im*r.im);if(r instanceof i)return r.abs();if(f(r))return Math.abs(r);if(isArray(r)){var o=n.size(r);if(t=t||2,1==o.length){if(t===Number.POSITIVE_INFINITY||"inf"===t){var s;return e.forEach(r,function(r){var t=e.abs(r);(!s||e.larger(t,s))&&(s=t)}),s}if(t===Number.NEGATIVE_INFINITY||"-inf"===t){var s;return e.forEach(r,function(r){var t=e.abs(r);(!s||e.smaller(t,s))&&(s=t)}),s}if("fro"===t)return l(r);if(u(t)&&!isNaN(t)){if(!e.equal(t,0)){var s=0;return e.forEach(r,function(r){s=e.add(e.pow(e.abs(r),t),s)}),e.pow(s,1/t)}return Number.POSITIVE_INFINITY}throw new Error("Unsupported parameter value")}if(2==o.length){if(1==t){for(var p=[],m=0;m=0?Math.pow(t,n):r(new o(t,0),new o(n,0));if(p(n))return r(new o(t,0),n)}if(p(t)){if(u(n))return r(t,new o(n,0));if(p(n))return r(t,n)}if(t instanceof i)return u(n)?n=i.convert(n):f(n)&&(n=new i(n?1:0)),n instanceof i?t.pow(n):m(t.toNumber(),n);if(n instanceof i)return u(t)?t=i.convert(t):f(t)&&(t=new i(t?1:0)),t instanceof i?t.pow(n):m(t,n.toNumber());if(c(t)){if(!u(n)||!l(n)||0>n)throw new TypeError("For A^b, b must be a positive integer (value is "+n+")");var h=s.size(t);if(2!=h.length)throw new Error("For A^b, A must be 2 dimensional (A has "+h.length+" dimensions)");if(h[0]!=h[1])throw new Error("For A^b, A must be square (size is "+h[0]+"x"+h[1]+")");for(var g=e.eye(h[0]).valueOf(),d=t;n>=1;)1==(1&n)&&(g=e.multiply(d,g)),n>>=1,d=e.multiply(d,d);return g}if(t instanceof a)return new a(m(t.valueOf(),n));if(f(t))return m(+t,n);if(f(n))return m(t,+n);throw new e.error.UnsupportedTypeError("pow",e["typeof"](t),e["typeof"](n))}}},function(e,r,t){e.exports=function(e){function r(e,r){var t=Math.pow(10,r);return Math.round(e*t)/t}var n=t(117),i=e.type.BigNumber,o=t(5),a=t(11),s=n.number.isNumber,u=n.number.isInteger,f=n["boolean"].isBoolean,c=o.isComplex,l=a.isCollection;e.round=function p(t,n){if(1!=arguments.length&&2!=arguments.length)throw new e.error.ArgumentsError("round",arguments.length,1,2);if(void 0==n){if(s(t))return Math.round(t);if(c(t))return new o(Math.round(t.re),Math.round(t.im));if(t instanceof i)return t.toDecimalPlaces(0);if(l(t))return a.deepMap(t,p);if(f(t))return Math.round(t);throw new e.error.UnsupportedTypeError("round",e["typeof"](t))}if(!s(n)||!u(n)){if(!(n instanceof i)){if(f(n))return p(t,+n);throw new TypeError("Number of decimals in function round must be an integer")}n=parseFloat(n.valueOf())}if(0>n||n>15)throw new Error("Number of decimals in function round must be in te range of 0-15");if(s(t))return r(t,n);if(c(t))return new o(r(t.re,n),r(t.im,n));if(t instanceof i)return t.toDecimalPlaces(n);if(l(t)||l(n))return a.deepMap2(t,n,p);if(f(t))return p(+t,n);throw new e.error.UnsupportedTypeError("round",e["typeof"](t),e["typeof"](n))}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(5),o=t(11),a=r.number,s=r.number.isNumber,u=r["boolean"].isBoolean,f=i.isComplex,c=o.isCollection;e.sign=function l(r){if(1!=arguments.length)throw new e.error.ArgumentsError("sign",arguments.length,1);if(s(r))return a.sign(r);if(f(r)){var t=Math.sqrt(r.re*r.re+r.im*r.im);return new i(r.re/t,r.im/t)}if(r instanceof n)return new n(r.cmp(0));if(c(r))return o.deepMap(r,l);if(u(r))return a.sign(r);throw new e.error.UnsupportedTypeError("sign",e["typeof"](r))}}},function(e,r,t){e.exports=function(e,r){var n=t(117),i=e.type.BigNumber,o=t(5),a=t(9),s=t(11),u=n.number.isNumber,f=n.number.nearlyEqual,c=n["boolean"].isBoolean,l=n.string.isString,p=o.isComplex,m=a.isUnit,h=s.isCollection;e.smaller=function g(t,n){if(2!=arguments.length)throw new e.error.ArgumentsError("smaller",arguments.length,2);if(u(t)&&u(n))return!f(t,n,r.epsilon)&&n>t;if(t instanceof i)return u(n)?n=i.convert(n):c(n)&&(n=new i(n?1:0)),n instanceof i?t.lt(n):g(t.toNumber(),n);if(n instanceof i)return u(t)?t=i.convert(t):c(t)&&(t=new i(t?1:0)),t instanceof i?t.lt(n):g(t,n.toNumber());if(m(t)&&m(n)){if(!t.equalBase(n))throw new Error("Cannot compare units with different base");return t.valuet;if(c(t))return g(+t,n);if(c(n))return g(t,+n);if(p(t)||p(n))throw new TypeError("No ordering relation is defined for complex numbers");throw new e.error.UnsupportedTypeError("smaller",e["typeof"](t),e["typeof"](n))}}},function(e,r,t){e.exports=function(e,r){var n=t(117),i=e.type.BigNumber,o=t(5),a=t(9),s=t(11),u=n.number.isNumber,f=n.number.nearlyEqual,c=n["boolean"].isBoolean,l=n.string.isString,p=o.isComplex,m=a.isUnit,h=s.isCollection;e.smallereq=function g(t,n){if(2!=arguments.length)throw new e.error.ArgumentsError("smallereq",arguments.length,2);if(u(t)&&u(n))return f(t,n,r.epsilon)||n>t;if(t instanceof i)return u(n)?n=i.convert(n):c(n)&&(n=new i(n?1:0)),n instanceof i?t.lte(n):g(t.toNumber(),n);if(n instanceof i)return u(t)?t=i.convert(t):c(t)&&(t=new i(t?1:0)),t instanceof i?t.lte(n):g(t,n.toNumber());if(m(t)&&m(n)){if(!t.equalBase(n))throw new Error("Cannot compare units with different base");return t.value<=n.value}if(h(t)||h(n))return s.deepMap2(t,n,g);if(l(t)||l(n))return n>=t;if(c(t))return g(+t,n);if(c(n))return g(t,+n);if(p(t)||p(n))throw new TypeError("No ordering relation is defined for complex numbers");throw new e.error.UnsupportedTypeError("smallereq",e["typeof"](t),e["typeof"](n))}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(5),o=t(11),a=r.number.isNumber,s=r["boolean"].isBoolean,u=i.isComplex,f=o.isCollection;e.sqrt=function c(r){if(1!=arguments.length)throw new e.error.ArgumentsError("sqrt",arguments.length,1);if(a(r))return r>=0?Math.sqrt(r):c(new i(r,0));if(u(r)){var t=Math.sqrt(r.re*r.re+r.im*r.im);return r.im>=0?new i(.5*Math.sqrt(2*(t+r.re)),.5*Math.sqrt(2*(t-r.re))):new i(.5*Math.sqrt(2*(t+r.re)),-.5*Math.sqrt(2*(t-r.re)))}if(r instanceof n)return r.sqrt();if(f(r))return o.deepMap(r,c);if(s(r))return c(+r);throw new e.error.UnsupportedTypeError("sqrt",e["typeof"](r))}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(5),o=t(11),a=r.number.isNumber,s=r["boolean"].isBoolean,u=i.isComplex,f=o.isCollection;e.square=function c(r){if(1!=arguments.length)throw new e.error.ArgumentsError("square",arguments.length,1);if(a(r))return r*r;if(u(r))return e.multiply(r,r);if(r instanceof n)return r.times(r);if(f(r))return o.deepMap(r,c);if(s(r))return r*r;throw new e.error.UnsupportedTypeError("square",e["typeof"](r))}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(5),o=(t(8),t(9)),a=t(11),s=r["boolean"].isBoolean,u=r.number.isNumber,f=i.isComplex,c=o.isUnit,l=a.isCollection;e.subtract=function p(r,t){if(2!=arguments.length)throw new e.error.ArgumentsError("subtract",arguments.length,2);if(u(r)){if(u(t))return r-t;if(f(t))return new i(r-t.re,-t.im)}else if(f(r)){if(u(t))return new i(r.re-t,r.im);if(f(t))return new i(r.re-t.re,r.im-t.im)}if(r instanceof n)return u(t)?t=n.convert(t):s(t)&&(t=new n(t?1:0)),t instanceof n?r.minus(t):p(r.toNumber(),t);if(t instanceof n)return u(r)?r=n.convert(r):s(r)&&(r=new n(r?1:0)),r instanceof n?r.minus(t):p(r,t.toNumber());if(c(r)&&c(t)){if(null==r.value)throw new Error("Parameter x contains a unit with undefined value");if(null==t.value)throw new Error("Parameter y contains a unit with undefined value");if(!r.equalBase(t))throw new Error("Units do not match");var o=r.clone();return o.value-=t.value,o.fixPrefix=!1,o}if(l(r)||l(t))return a.deepMap2(r,t,p);if(s(r))return p(+r,t);if(s(t))return p(r,+t);throw new e.error.UnsupportedTypeError("subtract",e["typeof"](r),e["typeof"](t))}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(5),o=t(9),a=t(11),s=r.number.isNumber,u=r["boolean"].isBoolean,f=i.isComplex,c=o.isUnit,l=a.isCollection;e.unary=function p(r){if(1!=arguments.length)throw new e.error.ArgumentsError("unary",arguments.length,1);if(s(r))return-r;if(f(r))return new i(-r.re,-r.im);if(r instanceof n)return r.neg();if(c(r)){var t=r.clone();return t.value=-r.value,t}if(l(r))return a.deepMap(r,p);if(u(r))return-r;throw new e.error.UnsupportedTypeError("unary",e["typeof"](r))}}},function(e,r,t){e.exports=function(e,r){var n=t(117),i=e.type.BigNumber,o=t(5),a=t(9),s=t(11),u=n.number.isNumber,f=n.number.nearlyEqual,c=n["boolean"].isBoolean,l=n.string.isString,p=o.isComplex,m=a.isUnit,h=s.isCollection;e.unequal=function g(t,n){if(2!=arguments.length)throw new e.error.ArgumentsError("unequal",arguments.length,2);if(u(t)){if(u(n))return!f(t,n,r.epsilon);if(p(n))return!f(t,n.re,r.epsilon)||!f(n.im,0,r.epsilon)}if(p(t)){if(u(n))return!f(t.re,n,r.epsilon)||!f(t.im,0,r.epsilon);if(p(n))return!f(t.re,n.re,r.epsilon)||!f(t.im,n.im,r.epsilon)}if(t instanceof i)return u(n)?n=i.convert(n):c(n)&&(n=new i(n?1:0)),n instanceof i?!t.eq(n):g(t.toNumber(),n);if(n instanceof i)return u(t)?t=i.convert(t):c(t)&&(t=new i(t?1:0)),t instanceof i?!t.eq(n):g(t,n.toNumber());if(m(t)&&m(n)){if(!t.equalBase(n))throw new Error("Cannot compare units with different base");return t.value!=n.value}if(h(t)||h(n))return s.deepMap2(t,n,g);if(l(t)||l(n))return t!=n;if(c(t))return g(+t,n);if(c(n))return g(t,+n);throw new e.error.UnsupportedTypeError("unequal",e["typeof"](t),e["typeof"](n))}}},function(e,r,t){e.exports=function(e){function r(e,r){for(var t,n,i,o=0,a=1,s=1,u=0;r;)n=Math.floor(e/r),i=e%r,t=o,o=a-n*o,a=t,t=s,s=u-n*s,u=t,e=r,r=i;return 0>e?[-e,-a,-u]:[e,e?a:0,u]}var n=t(117),i=e.type.BigNumber,o=n.number.isNumber,a=n["boolean"].isBoolean,s=n.number.isInteger;e.xgcd=function u(t,n){if(2==arguments.length){if(o(t)&&o(n)){if(!s(t)||!s(n))throw new Error("Parameters in function xgcd must be integer numbers");return r(t,n)}if(t instanceof i)return u(t.toNumber(),n);if(n instanceof i)return u(t,n.toNumber());if(a(t))return u(+t,n);if(a(n))return u(t,+n);throw new e.error.UnsupportedTypeError("xgcd",e["typeof"](t),e["typeof"](n))}throw new SyntaxError("Function xgcd expects two arguments")}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(5),o=t(11),a=r.number.isNumber,s=r["boolean"].isBoolean,u=o.isCollection,f=i.isComplex;e.arg=function c(r){if(1!=arguments.length)throw new e.error.ArgumentsError("arg",arguments.length,1);if(a(r))return Math.atan2(0,r);if(f(r))return Math.atan2(r.im,r.re);if(u(r))return o.deepMap(r,c);if(s(r))return c(+r);if(r instanceof n)return c(r.toNumber());throw new e.error.UnsupportedTypeError("arg",e["typeof"](r))}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(5),o=t(11),a=r.object,s=r.number.isNumber,u=r["boolean"].isBoolean,f=o.isCollection,c=i.isComplex;e.conj=function l(r){if(1!=arguments.length)throw new e.error.ArgumentsError("conj",arguments.length,1);return s(r)?r:r instanceof n?new n(r):c(r)?new i(r.re,-r.im):f(r)?o.deepMap(r,l):u(r)?+r:a.clone(r)}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(5),o=t(11),a=r.object,s=r.number.isNumber,u=r["boolean"].isBoolean,f=o.isCollection,c=i.isComplex;e.re=function l(r){if(1!=arguments.length)throw new e.error.ArgumentsError("re",arguments.length,1);return s(r)?r:r instanceof n?new n(r):c(r)?r.re:f(r)?o.deepMap(r,l):u(r)?+r:a.clone(r)}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(5),o=t(11),a=r.number.isNumber,s=r["boolean"].isBoolean,u=o.isCollection,f=i.isComplex;e.im=function c(r){if(1!=arguments.length)throw new e.error.ArgumentsError("im",arguments.length,1);return a(r)?0:r instanceof n?new n(0):f(r)?r.im:u(r)?o.deepMap(r,c):s(r)?0:0}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(11),o=i.isCollection,a=r.number.isNumber,s=r.string.isString,u=r["boolean"].isBoolean;e.bignumber=function f(r){if(arguments.length>1)throw new e.error.ArgumentsError("bignumber",arguments.length,0,1);if(r instanceof n||a(r)||s(r))return new n(r);if(u(r))return new n(+r);if(o(r))return i.deepMap(r,f);if(0==arguments.length)return new n(0);throw new e.error.UnsupportedTypeError("bignumber",e["typeof"](r))}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(11),o=i.isCollection,a=r.number.isNumber,s=r.string.isString;e["boolean"]=function u(r){if(1!=arguments.length)throw new e.error.ArgumentsError("boolean",arguments.length,0,1);if("true"===r||r===!0)return!0;if("false"===r||r===!1)return!1;if(r instanceof Boolean)return 1==r;if(a(r))return 0!==r;if(r instanceof n)return!r.isZero();if(s(r)){var t=r.toLowerCase();if("true"===t)return!0;if("false"===t)return!1;var f=Number(r);if(""!=r&&!isNaN(f))return 0!==f}if(o(r))return i.deepMap(r,u);throw new SyntaxError(r.toString()+" is no valid boolean")}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(5),o=t(11),a=o.isCollection,s=r.number.isNumber,u=r.string.isString,f=i.isComplex;e.complex=function c(){switch(arguments.length){case 0:return new i(0,0);case 1:var r=arguments[0];if(s(r))return new i(r,0);if(r instanceof n)return new i(r.toNumber(),0);if(f(r))return r.clone();if(u(r)){var t=i.parse(r);if(t)return t;throw new SyntaxError('String "'+r+'" is no valid complex number')}if(a(r))return o.deepMap(r,c);if("object"==typeof r){if("re"in r&&"im"in r)return new i(r.re,r.im);if("r"in r&&"phi"in r)return i.fromPolar(r.r,r.phi)}throw new TypeError("Two numbers, single string or an fitting object expected in function complex");case 2:var l=arguments[0],p=arguments[1];if(l instanceof n&&(l=l.toNumber()),p instanceof n&&(p=p.toNumber()),s(l)&&s(p))return new i(l,p);throw new TypeError("Two numbers or a single string expected in function complex");default:throw new e.error.ArgumentsError("complex",arguments.length,0,2)}}}},function(e,r,t){e.exports=function(e){var r=(t(117),e.type.BigNumber),n=t(7);e.index=function(){var e=new n,t=Array.prototype.slice.apply(arguments).map(function(e){return e instanceof r?e.toNumber():Array.isArray(e)?e.map(function(e){return e instanceof r?e.toNumber():e}):e});return n.apply(e,t),e}}},function(e,r,t){e.exports=function(e){var r=(t(117),t(8));e.matrix=function(t){if(arguments.length>1)throw new e.error.ArgumentsError("matrix",arguments.length,0,1);return new r(t)}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(11),o=i.isCollection,a=r.number.isNumber,s=r["boolean"].isBoolean,u=r.string.isString;e.number=function f(r){switch(arguments.length){case 0:return 0;case 1:if(o(r))return i.deepMap(r,f);if(r instanceof n)return r.toNumber();if(u(r)){var t=Number(r);if(isNaN(t)&&(t=Number(r.valueOf())),isNaN(t))throw new SyntaxError(r.toString()+" is no valid number");return t}if(s(r))return r+0;if(a(r))return r;throw new e.error.UnsupportedTypeError("number",e["typeof"](r));default:throw new e.error.ArgumentsError("number",arguments.length,0,1)}}}},function(e,r,t){e.exports=function(e){var r=t(13);e.parser=function(){return new r(e)}}},function(e){e.exports=function(e){e.select=function(r){return new e.chaining.Selector(r)}}},function(e,r,t){e.exports=function(e){var r=t(117),n=t(11),i=r.number,o=r.number.isNumber,a=n.isCollection;e.string=function s(r){switch(arguments.length){case 0:return"";case 1:return o(r)?i.format(r):a(r)?n.deepMap(r,s):null===r?"null":r.toString();default:throw new e.error.ArgumentsError("string",arguments.length,0,1)}}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(9),o=t(11),a=o.isCollection,s=r.string.isString;e.unit=function u(r){switch(arguments.length){case 1:var t=arguments[0];if(t instanceof i)return t.clone();if(s(t)){if(i.isValuelessUnit(t))return new i(null,t);var f=i.parse(t);if(f)return f;throw new SyntaxError('String "'+t+'" is no valid unit')}if(a(r))return o.deepMap(r,u);throw new TypeError("A string or a number and string expected in function unit");case 2:return arguments[0]instanceof n?new i(arguments[0].toNumber(),arguments[1]):new i(arguments[0],arguments[1]);default:throw new e.error.ArgumentsError("unit",arguments.length,1,2)}}}},function(e,r,t){e.exports=function(e){function r(t,n,i,o){if(i>o){if(t.length!=n.length)throw new e.error.DimensionError(t.length,n.length);for(var a=[],s=0;st;t++){var h=arguments[t];if(h instanceof i&&(p=!0),t==o-1&&u(h)){if(n=l,l=h,!f(l)||0>l)throw new TypeError("Dimension number must be a positive integer (dim = "+l+")");if(t>0&&l>n)throw new e.error.DimensionError(l,n,">")}else{if(!c(h))throw new e.error.UnsupportedTypeError("concat",e["typeof"](h));var g=a.clone(h).valueOf(),d=s.size(h.valueOf());if(m[t]=g,n=l,l=d.length-1,t>0&&l!=n)throw new e.error.DimensionError(l,n)}}if(0==m.length)throw new SyntaxError("At least one matrix expected");for(var w=m.shift();m.length;)w=r(w,m.shift(),l,0);return p?new i(w):w}}},function(e,r,t){e.exports=function(e){function r(r,t){function n(r){var t,n,i=new Array(r.length),o=0;for(t=1;tn;n++)i[t][n]=0;for(n=t+1;na;a++)i=e.multiply(n(i),r);return t%2==0?e.unary(i[0][0]):i[0][0]}var n=t(117),i=t(8),o=n.object,a=n.string;e.det=function(t){if(1!=arguments.length)throw new e.error.ArgumentsError("det",arguments.length,1);var n;switch(t instanceof i?n=t.size():t instanceof Array?(t=new i(t),n=t.size()):n=[],n.length){case 0:return o.clone(t);case 1:if(1==n[0])return o.clone(t.valueOf()[0]);throw new RangeError("Matrix must be square (size: "+a.format(n)+")");case 2:var s=n[0],u=n[1];if(s==u)return r(t.clone().valueOf(),s,u);throw new RangeError("Matrix must be square (size: "+a.format(n)+")");default:throw new RangeError("Matrix must be two dimensional (size: "+a.format(n)+")")}}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(8),o=r.object,a=r.array.isArray,s=r.number.isNumber,u=r.number.isInteger;e.diag=function(r,t){var f,c,l,p;if(1!=arguments.length&&2!=arguments.length)throw new e.error.ArgumentsError("diag",arguments.length,1,2);if(t){if(t instanceof n&&(t=t.toNumber()),!s(t)||!u(t))throw new TypeError("Second parameter in function diag must be an integer")}else t=0;var m,h=t>0?t:0,g=0>t?-t:0;if(r instanceof i)m=!1;else{if(!a(r))throw new TypeError("First parameter in function diag must be a Matrix or Array");r=new i(r),m=!0}var d=r.size();switch(d.length){case 1:c=r.valueOf();var w=new i,y=c[0]instanceof n?new n(0):0;for(w.resize([c.length+g,c.length+h],y),f=w.valueOf(),p=c.length,l=0;p>l;l++)f[l+g][l+h]=o.clone(c[l]);return m?w.valueOf():w;case 2:for(c=[],f=r.valueOf(),p=Math.min(d[0]-g,d[1]-h),l=0;p>l;l++)c[l]=o.clone(f[l+g][l+h]);return m?c:new i(c);default:throw new RangeError("Matrix for function diag must be 2 dimensional")}}}},function(e,r,t){e.exports=function(e,r){var n=t(117),i=e.type.BigNumber,o=t(8),a=t(11),s=n.number.isNumber,u=n.number.isInteger,f=Array.isArray;e.eye=function(t){var n=a.argsToArray(arguments),c=t instanceof o?!0:f(t)?!1:"matrix"===r.matrix;if(0==n.length)return c?new o:[];if(1==n.length)n[1]=n[0];else if(n.length>2)throw new e.error.ArgumentsError("eye",n.length,0,2);var l=n[0],p=n[1];if(l instanceof i&&(l=l.toNumber()),p instanceof i&&(p=p.toNumber()),!s(l)||!u(l)||1>l)throw new Error("Parameters in function eye must be positive integers");if(!s(p)||!u(p)||1>p)throw new Error("Parameters in function eye must be positive integers");var m=!1;n=n.map(function(e){return e instanceof i?(m=!0,e.toNumber()):e});var h=new o,g=m?new i(1):1,d=m?new i(0):0;h.resize(n,d);for(var w=e.min(n),y=h.valueOf(),v=0;w>v;v++)y[v][v]=g;return c?h:h.valueOf()}}},function(e,r,t){e.exports=function(e){function r(r,t,n){var i,o,a,s,u;if(1==t){if(s=r[0][0],0==s)throw Error("Cannot calculate inverse, determinant is zero");return[[e.divide(1,s)]]}if(2==t){var f=e.det(r);if(0==f)throw Error("Cannot calculate inverse, determinant is zero");return[[e.divide(r[1][1],f),e.divide(e.unary(r[0][1]),f)],[e.divide(e.unary(r[1][0]),f),e.divide(r[0][0],f)]]}var c=r.concat();for(i=0;t>i;i++)c[i]=c[i].concat();for(var l=e.eye(t).valueOf(),p=0;n>p;p++){for(i=p;t>i&&0==c[i][p];)i++;if(i==t||0==c[i][p])throw Error("Cannot calculate inverse, determinant is zero");i!=p&&(u=c[p],c[p]=c[i],c[i]=u,u=l[p],l[p]=l[i],l[i]=u);var m=c[p],h=l[p];for(i=0;t>i;i++){var g=c[i],d=l[i];if(i!=p){if(0!=g[p]){for(a=e.divide(e.unary(g[p]),m[p]),o=p;n>o;o++)g[o]=e.add(g[o],e.multiply(a,m[o]));for(o=0;n>o;o++)d[o]=e.add(d[o],e.multiply(a,h[o]))}}else{for(a=m[p],o=p;n>o;o++)g[o]=e.divide(g[o],a);for(o=0;n>o;o++)d[o]=e.divide(d[o],a)}}}return l}{var n=t(117),i=n.string,o=t(8);t(11)}e.inv=function(t){if(1!=arguments.length)throw new e.error.ArgumentsError("inv",arguments.length,1);var n=e.size(t).valueOf();switch(n.length){case 0:return e.divide(1,t);case 1:if(1==n[0])return t instanceof o?new o([e.divide(1,t.valueOf()[0])]):[e.divide(1,t[0])];throw new RangeError("Matrix must be square (size: "+i.format(n)+")");case 2:var a=n[0],s=n[1];if(a==s)return t instanceof o?new o(r(t.valueOf(),a,s)):r(t,a,s);throw new RangeError("Matrix must be square (size: "+i.format(n)+")");default:throw new RangeError("Matrix must be two dimensional (size: "+i.format(n)+")")}}}},function(e,r,t){e.exports=function(e,r){var n=t(117),i=e.type.BigNumber,o=t(8),a=t(11),s=n.array,u=Array.isArray;e.ones=function(e){var t=a.argsToArray(arguments),n=e instanceof o?!0:u(e)?!1:"matrix"===r.matrix;if(0==t.length)return n?new o:[];var f=!1;t=t.map(function(e){return e instanceof i?(f=!0,e.toNumber()):e});var c=[],l=f?new i(1):1;return c=s.resize(c,t,l),n?new o(c):c}}},function(e,r,t){e.exports=function(e,r){function n(e,r,t){var n=[],i=e;if(t>0)for(;r>i;)n.push(i),i+=t;else if(0>t)for(;i>r;)n.push(i),i+=t;return n}function i(e,r,t){var n=[],i=e;if(t>0)for(;r>=i;)n.push(i),i+=t;else if(0>t)for(;i>=r;)n.push(i),i+=t;return n}function o(e,r,t){var n=[],i=e.clone(),o=new f(0);if(t.gt(o))for(;i.lt(r);)n.push(i),i=i.plus(t);else if(t.lt(o))for(;i.gt(r);)n.push(i),i=i.plus(t);return n}function a(e,r,t){var n=[],i=e.clone(),o=new f(0);if(t.gt(o))for(;i.lte(r);)n.push(i),i=i.plus(t);else if(t.lt(o))for(;i.gte(r);)n.push(i),i=i.plus(t);return n}function s(e){var t=e.split(":"),n=null;if("bignumber"===r.number)try{n=t.map(function(e){return new f(e)})}catch(i){return null}else{n=t.map(function(e){return Number(e)});var o=n.some(function(e){return isNaN(e)});if(o)return null}switch(n.length){case 2:return{start:n[0],end:n[1],step:1};case 3:return{start:n[0],end:n[2],step:n[1]};default:return null}}var u=t(117),f=e.type.BigNumber,c=t(8),l=(t(11),u["boolean"].isBoolean),p=u.string.isString,m=u.number.isNumber;e.range=function(){var t,u,h,g=Array.prototype.slice.call(arguments),d=!1;switch(l(g[g.length-1])&&(d=g.pop()?!0:!1),g.length){case 1:if(!p(g[0]))throw new TypeError("Two or three numbers or a single string expected in function range");var w=s(g[0]);if(!w)throw new SyntaxError('String "'+g[0]+'" is no valid range');t=w.start,u=w.end,h=w.step;break;case 2:t=g[0],u=g[1],h=1;break;case 3:t=g[0],u=g[1],h=g[2];break;case 4:throw new TypeError("Parameter includeEnd must be a boolean");default:throw new e.error.ArgumentsError("range",arguments.length,2,4)}if(!(m(t)||t instanceof f))throw new TypeError("Parameter start must be a number");if(!(m(u)||u instanceof f))throw new TypeError("Parameter end must be a number");if(!(m(h)||h instanceof f))throw new TypeError("Parameter step must be a number");if(t instanceof f||u instanceof f||h instanceof f){var y=!0;t instanceof f||(t=f.convert(t)),u instanceof f||(u=f.convert(u)),h instanceof f||(h=f.convert(h)),t instanceof f&&u instanceof f&&h instanceof f||(y=!1,t instanceof f&&(t=t.toNumber()),u instanceof f&&(u=u.toNumber()),h instanceof f&&(h=h.toNumber()))}var v=y?d?a:o:d?i:n,x=v(t,u,h);return"array"===r.matrix?x:new c(x)}}},function(e,r,t){e.exports=function(e,r){function n(r,t,n){if(void 0!==n){if(!c(n)||1!==n.length)throw new TypeError("Single character expected as defaultValue")}else n=" ";if(1!==t.length)throw new e.error.DimensionError(t.length,1);var i=t[0];if(!l(i)||!p(i))throw new TypeError("Invalid size, must contain positive integers (size: "+f.format(t)+")");if(r.length>i)return r.substring(0,i);if(r.lengtha;a++)o+=n;return o}return r}var i=t(117),o=e.type.BigNumber,a=t(8),s=i.array,u=i.object.clone,f=i.string,c=i.string.isString,l=i.number.isNumber,p=i.number.isInteger,m=s.isArray;e.resize=function(t,i,f){if(2!=arguments.length&&3!=arguments.length)throw new e.error.ArgumentsError("resize",arguments.length,2,3);var l=t instanceof a?!0:m(t)?!1:"array"!==r.matrix;if(t instanceof a&&(t=t.valueOf()),i instanceof a&&(i=i.valueOf()),i.length&&i[0]instanceof o&&(i=i.map(function(e){return e instanceof o?e.toNumber():e})),c(t))return n(t,i,f);if(0==i.length){for(;m(t);)t=t[0];return u(t)}m(t)||(t=[t]),t=u(t);var p=s.resize(t,i,f);return l?new a(p):p}}},function(e,r,t){e.exports=function(e,r){var n=t(117),i=e.type.BigNumber,o=t(5),a=t(9),s=t(8),u=n.array,f=n.number.isNumber,c=n["boolean"].isBoolean,l=n.string.isString,p=o.isComplex,m=a.isUnit;e.size=function(t){if(1!=arguments.length)throw new e.error.ArgumentsError("size",arguments.length,1);var n="array"===r.matrix;if(f(t)||p(t)||m(t)||c(t)||null==t||t instanceof i)return n?[]:new s([]);if(l(t))return n?[t.length]:new s([t.length]);if(Array.isArray(t))return u.size(t);if(t instanceof s)return new s(t.size());throw new e.error.UnsupportedTypeError("size",e["typeof"](t))}}},function(e,r,t){e.exports=function(e){var r=t(117),n=t(8),i=r.object,o=r.array,a=Array.isArray;e.squeeze=function(r){if(1!=arguments.length)throw new e.error.ArgumentsError("squeeze",arguments.length,1);if(a(r))return o.squeeze(i.clone(r));if(r instanceof n){var t=o.squeeze(r.toArray());return a(t)?new n(t):t}return i.clone(r)}}},function(e,r,t){e.exports=function(e){function r(r,t){var i,o;if(l(r))return i=new s(r),o=i.subset(t),o.valueOf();if(r instanceof s)return r.subset(t);if(c(r))return n(r,t);throw new e.error.UnsupportedTypeError("subset",e["typeof"](r))}function n(r,t){if(!(t instanceof u))throw new TypeError("Index expected");if(1!=t.size().length)throw new e.error.DimensionError(t.size().length,1);var n=t.range(0),i="",o=r.length;return n.forEach(function(e){f.validateIndex(e,o),i+=r.charAt(e)}),i}function i(r,t,n,i){var a;if(l(r))return a=new s(e.clone(r)),a.subset(t,n,i),a.valueOf();if(r instanceof s)return r.clone().subset(t,n,i);if(c(r))return o(r,t,n,i);throw new e.error.UnsupportedTypeError("subset",e["typeof"](r))}function o(r,t,n,i){if(!(t instanceof u))throw new TypeError("Index expected");if(1!=t.size().length)throw new e.error.DimensionError(t.size().length,1);if(void 0!==i){if(!c(i)||1!==i.length)throw new TypeError("Single character expected as defaultValue")}else i=" ";var o=t.range(0),a=o.size()[0];if(a!=n.length)throw new e.error.DimensionError(o.size()[0],n.length);for(var s=r.length,l=[],p=0;s>p;p++)l[p]=r.charAt(p);if(o.forEach(function(e,r){f.validateIndex(e),l[e]=n.charAt(r)}),l.length>s)for(p=s-1,a=l.length;a>p;p++)l[p]||(l[p]=i);return l.join("")}var a=t(117),s=t(8),u=t(7),f=a.array,c=a.string.isString,l=Array.isArray;e.subset=function(){switch(arguments.length){case 2:return r(arguments[0],arguments[1]);case 3:case 4:return i(arguments[0],arguments[1],arguments[2],arguments[3]);default:throw new e.error.ArgumentsError("subset",arguments.length,2,4)}}}},function(e,r,t){e.exports=function(e){var r=t(117),n=t(8),i=(t(11),r.object),o=r.string;e.transpose=function(r){if(1!=arguments.length)throw new e.error.ArgumentsError("transpose",arguments.length,1);var t=e.size(r).valueOf();switch(t.length){case 0:return i.clone(r);case 1:return i.clone(r);case 2:var a,s=t[1],u=t[0],f=r instanceof n,c=r.valueOf(),l=[],p=i.clone;if(0===s)throw new RangeError("Cannot transpose a 2D matrix with no rows(size: "+o.format(t)+")");for(var m=0;s>m;m++){a=l[m]=[];for(var h=0;u>h;h++)a[h]=p(c[h][m])}return f?new n(l):l;default:throw new RangeError("Matrix must be two dimensional (size: "+o.format(t)+")")}}}},function(e,r,t){e.exports=function(e,r){var n=t(117),i=e.type.BigNumber,o=t(8),a=t(11),s=n.array,u=Array.isArray;e.zeros=function(e){var t=a.argsToArray(arguments),n=e instanceof o?!0:u(e)?!1:"matrix"===r.matrix;if(0==t.length)return n?new o:[];var f=!1;t=t.map(function(e){return e instanceof i?(f=!0,e.toNumber()):e});var c=[],l=f?new i(0):0;return c=s.resize(c,t,l),n?new o(c):c}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(11),o=r.number.isNumber,a=r["boolean"].isBoolean,s=r.number.isInteger,u=i.isCollection;e.factorial=function c(r){var t,l;if(1!=arguments.length)throw new e.error.ArgumentsError("factorial",arguments.length,1);if(o(r)){if(!s(r)||0>r)throw new TypeError("Positive integer value expected in function factorial");for(t=r-1,l=r;t>1;)l*=t,t--;return 0==l&&(l=1),l}if(r instanceof n){if(!f(r))throw new TypeError("Positive integer value expected in function factorial");var p=new n(1);for(t=r.minus(p),l=r;t.gt(p);)l=l.times(t),t=t.minus(p);return l.equals(0)&&(l=p),l}if(a(r))return 1;if(u(r))return i.deepMap(r,c);throw new e.error.UnsupportedTypeError("factorial",e["typeof"](r))};var f=function(e){return e.isInteger()&&e.gte(0)}}},function(e,r,t){e.exports=function(e,r){var n=t(8),i=(t(11),{uniform:function(){return Math.random},normal:function(){return function(){for(var e,r,t=-1;0>t||t>1;)e=Math.random(),r=Math.random(),t=1/6*Math.pow(-2*Math.log(e),.5)*Math.cos(2*Math.PI*r)+.5;return t}}});e.distribution=function(t){if(!i.hasOwnProperty(t))throw new Error("unknown distribution "+t);var o=Array.prototype.slice.call(arguments,1),a=i[t].apply(this,o);return function(t){var i={random:function(t,i,a){var u,f,c;if(arguments.length>3)throw new e.error.ArgumentsError("random",arguments.length,0,3);if(1===arguments.length?Array.isArray(t)?u=t:c=t:2===arguments.length?Array.isArray(t)?u=t:(f=t,c=i):(u=t,f=i,c=a),void 0===c&&(c=1),void 0===f&&(f=0),void 0!==u){var l=s(u,f,c,o);return"array"===r.matrix?l:new n(l)}return o(f,c)},randomInt:function(t,i,o){var u,f,c;if(arguments.length>3||arguments.length<1)throw new e.error.ArgumentsError("randomInt",arguments.length,1,3);if(1===arguments.length?c=t:2===arguments.length?"[object Array]"===Object.prototype.toString.call(t)?u=t:(f=t,c=i):(u=t,f=i,c=o),void 0===f&&(f=0),void 0!==u){var l=s(u,f,c,a);return"array"===r.matrix?l:new n(l)}return a(f,c)},pickRandom:function(r){if(1!==arguments.length)throw new e.error.ArgumentsError("pickRandom",arguments.length,1);if(!Array.isArray(r))throw new e.error.UnsupportedTypeError("pickRandom",e["typeof"](r));return r[Math.floor(Math.random()*r.length)]}},o=function(e,r){return e+t()*(r-e)},a=function(e,r){return Math.floor(e+t()*(r-e))},s=function(e,r,t,n){var i,o,a=[];if(e=e.slice(0),e.length>1)for(o=0,i=e.shift();i>o;o++)a.push(s(e,r,t,n));else for(o=0,i=e.shift();i>o;o++)a.push(n(r,t));return a};return i}(a)};var o=e.distribution("uniform");e.random=o.random,e.randomInt=o.randomInt,e.pickRandom=o.pickRandom}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=r.number.isNumber,o=r.number.isInteger;e.permutations=function(r,t){var s,u,f=arguments.length;if(f>2)throw new e.error.ArgumentsError("permutations",arguments.length,2);if(i(r)){if(!o(r)||0>r)throw new TypeError("Positive integer value expected in function permutations");if(1==f)return e.factorial(r);if(2==f&&i(t)){if(!o(t)||0>t)throw new TypeError("Positive integer value expected in function permutations");if(t>r)throw new TypeError("second argument k must be less than or equal to first argument n");for(s=1,u=r-t+1;r>=u;u++)s*=u;return s}}if(r instanceof n){if(void 0===t&&a(r))return e.factorial(r);if(t=n.convert(t),!(t instanceof n&&a(r)&&a(t)))throw new TypeError("Positive integer value expected in function permutations");if(t.gt(r))throw new TypeError("second argument k must be less than or equal to first argument n");for(s=new n(1),u=r.minus(t).plus(1);u.lte(r);u=u.plus(1))s=s.times(u);return s}throw new e.error.UnsupportedTypeError("permutations",e["typeof"](r))};var a=function(e){return e.isInteger()&&e.gte(0)}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=(t(11),r.number.isNumber),o=r.number.isInteger;e.combinations=function(r,t){var s,u,f,c,l=arguments.length; +if(2!=l)throw new e.error.ArgumentsError("combinations",arguments.length,2);if(i(r)){if(!o(r)||0>r)throw new TypeError("Positive integer value enpected in function combinations");if(t>r)throw new TypeError("k must be less than or equal to n");for(s=Math.max(t,r-t),u=1,f=1;r-s>=f;f++)u=u*(s+f)/f;return u}if(r instanceof n){if(t=n.convert(t),!(t instanceof n&&a(r)&&a(t)))throw new TypeError("Positive integer value expected in function combinations");if(t.gt(r))throw new TypeError("k must be less than n in function combinations");for(s=r.minus(t),t.lt(s)&&(s=t),u=new n(1),f=new n(1),c=r.minus(s);f.lte(c);f=f.plus(1))u=u.times(s.plus(f)).dividedBy(f);return u}throw new e.error.UnsupportedTypeError("combinations",e["typeof"](r))};var a=function(e){return e.isInteger()&&e.gte(0)}}},function(e,r,t){e.exports=function(e){function r(r,t){return e.smaller(r,t)?r:t}function n(r){var t=void 0;if(i.deepForEach(r,function(r){(void 0===t||e.smaller(r,t))&&(t=r)}),void 0===t)throw new Error("Cannot calculate min of an empty array");return t}var i=(t(8),t(11)),o=i.isCollection;e.min=function(e){if(0==arguments.length)throw new SyntaxError("Function min requires one or more parameters (0 provided)");if(o(e)){if(1==arguments.length)return n(e);if(2==arguments.length)return i.reduce(arguments[0],arguments[1],r);throw new SyntaxError("Wrong number of parameters")}return n(arguments)}}},function(e,r,t){e.exports=function(e){function r(r,t){return e.larger(r,t)?r:t}function n(r){var t=void 0;if(i.deepForEach(r,function(r){(void 0===t||e.larger(r,t))&&(t=r)}),void 0===t)throw new Error("Cannot calculate max of an empty array");return t}var i=(t(8),t(11)),o=i.isCollection;e.max=function(e){if(0==arguments.length)throw new SyntaxError("Function max requires one or more parameters (0 provided)");if(o(e)){if(1==arguments.length)return n(e);if(2==arguments.length)return i.reduce(arguments[0],arguments[1],r);throw new SyntaxError("Wrong number of parameters")}return n(arguments)}}},function(e,r,t){e.exports=function(e){function r(r,t){var n;return n=i.reduce(r,t,e.add),e.divide(n,a(r)[t])}function n(r){var t=0,n=0;if(i.deepForEach(r,function(r){t=e.add(t,r),n++}),0===n)throw new Error("Cannot calculate mean of an empty array");return e.divide(t,n)}var i=(t(8),t(11)),o=i.isCollection,a=t(147).size;e.mean=function(e){if(0==arguments.length)throw new SyntaxError("Function mean requires one or more parameters (0 provided)");if(o(e)){if(1==arguments.length)return n(e);if(2==arguments.length)return r(arguments[0],arguments[1]);throw new SyntaxError("Wrong number of parameters")}return n(arguments)}}},function(e,r,t){e.exports=function(e){function r(r){var t=u(r);t.sort(e.compare);var o=t.length;if(0==o)throw new Error("Cannot calculate median of an empty array");if(o%2==0){var s=t[o/2-1],f=t[o/2];if(!(a(s)||s instanceof i||s instanceof n))throw new e.error.UnsupportedTypeError("median",e["typeof"](s));if(!(a(f)||f instanceof i||f instanceof n))throw new e.error.UnsupportedTypeError("median",e["typeof"](f));return e.divide(e.add(s,f),2)}var c=t[(o-1)/2];if(!(a(c)||c instanceof i||c instanceof n))throw new e.error.UnsupportedTypeError("median",e["typeof"](c));return c}var n=(t(8),t(9)),i=e.type.BigNumber,o=t(11),a=t(148).isNumber,s=o.isCollection,u=t(147).flatten;e.median=function(e){if(0==arguments.length)throw new SyntaxError("Function median requires one or more parameters (0 provided)");if(s(e)){if(1==arguments.length)return r(e.valueOf());throw 2==arguments.length?new Error("median(A, dim) is not yet supported"):new SyntaxError("Wrong number of parameters")}return r(Array.prototype.slice.call(arguments))}}},function(e,r,t){e.exports=function(e){function r(r){var t=void 0;if(n.deepForEach(r,function(r){t=void 0===t?r:e.multiply(t,r)}),void 0===t)throw new Error("Cannot calculate prod of an empty array");return t}var n=(t(8),t(11)),i=n.isCollection;e.prod=function(e){if(0==arguments.length)throw new SyntaxError("Function prod requires one or more parameters (0 provided)");if(i(e)){if(1==arguments.length)return r(e);throw 2==arguments.length?new Error("prod(A, dim) is not yet supported"):new SyntaxError("Wrong number of parameters")}return r(arguments)}}},function(e){e.exports=function(e){e.std=function(){if(0==arguments.length)throw new SyntaxError("Function std requires one or more parameters (0 provided)");var r=e["var"].apply(null,arguments);return e.sqrt(r)}}},function(e,r,t){e.exports=function(e){function r(r){var t=void 0;if(n.deepForEach(r,function(r){t=void 0===t?r:e.add(t,r)}),void 0===t)throw new Error("Cannot calculate sum of an empty array");return t}var n=(t(8),t(11)),i=n.isCollection;e.sum=function(e){if(0==arguments.length)throw new SyntaxError("Function sum requires one or more parameters (0 provided)");if(i(e)){if(1==arguments.length)return r(e);throw 2==arguments.length?new Error("sum(A, dim) is not yet supported"):new SyntaxError("Wrong number of parameters")}return r(arguments)}}},function(e,r,t){e.exports=function(e){function r(r,t){var o=0,a=0;if(i.deepForEach(r,function(r){o=e.add(o,r),a++}),0===a)throw new Error("Cannot calculate var of an empty array");var s=e.divide(o,a);switch(o=0,i.deepForEach(r,function(r){var t=e.subtract(r,s);o=e.add(o,e.multiply(t,t))}),t){case"uncorrected":return e.divide(o,a);case"biased":return e.divide(o,a+1);case"unbiased":var u=o instanceof n?new n(0):0;return 1==a?u:e.divide(o,a-1);default:throw new Error('Unknown normalization "'+t+'". Choose "unbiased" (default), "uncorrected", or "biased".')}}var n=(t(8),e.type.BigNumber),i=t(11),o=i.isCollection,a=t(132).isString,s="unbiased";e["var"]=function(e,t){if(0==arguments.length)throw new SyntaxError("Function var requires one or more parameters (0 provided)");if(o(e)){if(1==arguments.length)return r(e,s);if(2==arguments.length){if(!a(t))throw new Error("String expected for parameter normalization");return r(e,t)}throw new SyntaxError("Wrong number of parameters")}return r(arguments,s)}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(5),o=t(11),a=r.number.isNumber,s=r["boolean"].isBoolean,u=i.isComplex,f=o.isCollection;e.acos=function c(r){if(1!=arguments.length)throw new e.error.ArgumentsError("acos",arguments.length,1);if(a(r))return r>=-1&&1>=r?Math.acos(r):c(new i(r,0));if(u(r)){var t=new i(r.im*r.im-r.re*r.re+1,-2*r.re*r.im),l=e.sqrt(t),p=new i(l.re-r.im,l.im+r.re),m=e.log(p);return new i(1.5707963267948966-m.im,m.re)}if(f(r))return o.deepMap(r,c);if(s(r))return Math.acos(r);if(r instanceof n)return c(r.toNumber());throw new e.error.UnsupportedTypeError("acos",e["typeof"](r))}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(5),o=t(11),a=r.number.isNumber,s=r["boolean"].isBoolean,u=i.isComplex,f=o.isCollection;e.asin=function c(r){if(1!=arguments.length)throw new e.error.ArgumentsError("asin",arguments.length,1);if(a(r))return r>=-1&&1>=r?Math.asin(r):c(new i(r,0));if(u(r)){var t=r.re,l=r.im,p=new i(l*l-t*t+1,-2*t*l),m=e.sqrt(p),h=new i(m.re-l,m.im+t),g=e.log(h);return new i(g.im,-g.re)}if(f(r))return o.deepMap(r,c);if(s(r))return Math.asin(r);if(r instanceof n)return c(r.toNumber());throw new e.error.UnsupportedTypeError("asin",e["typeof"](r))}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(5),o=t(11),a=r.number.isNumber,s=r["boolean"].isBoolean,u=i.isComplex,f=o.isCollection;e.atan=function c(r){if(1!=arguments.length)throw new e.error.ArgumentsError("atan",arguments.length,1);if(a(r))return Math.atan(r);if(u(r)){var t=r.re,l=r.im,p=t*t+(1-l)*(1-l),m=new i((1-l*l-t*t)/p,-2*t/p),h=e.log(m);return new i(-.5*h.im,.5*h.re)}if(f(r))return o.deepMap(r,c);if(s(r))return Math.atan(r);if(r instanceof n)return c(r.toNumber());throw new e.error.UnsupportedTypeError("atan",e["typeof"](r))}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(5),o=t(11),a=r.number.isNumber,s=r["boolean"].isBoolean,u=(i.isComplex,o.isCollection);e.atan2=function f(r,t){if(2!=arguments.length)throw new e.error.ArgumentsError("atan2",arguments.length,2);if(a(r)&&a(t))return Math.atan2(r,t);if(u(r)||u(t))return o.deepMap2(r,t,f);if(s(r))return f(+r,t);if(s(t))return f(r,+t);if(r instanceof n)return f(r.toNumber(),t);if(t instanceof n)return f(r,t.toNumber());throw new e.error.UnsupportedTypeError("atan2",e["typeof"](r),e["typeof"](t))}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(5),o=t(9),a=t(11),s=r.number.isNumber,u=r["boolean"].isBoolean,f=i.isComplex,c=o.isUnit,l=a.isCollection;e.cos=function p(r){if(1!=arguments.length)throw new e.error.ArgumentsError("cos",arguments.length,1);if(s(r))return Math.cos(r);if(f(r))return new i(.5*Math.cos(r.re)*(Math.exp(-r.im)+Math.exp(r.im)),.5*Math.sin(r.re)*(Math.exp(-r.im)-Math.exp(r.im)));if(c(r)){if(!r.hasBase(o.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cos is no angle");return Math.cos(r.value)}if(l(r))return a.deepMap(r,p);if(u(r))return Math.cos(r);if(r instanceof n)return p(r.toNumber());throw new e.error.UnsupportedTypeError("cos",e["typeof"](r))}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(5),o=t(9),a=t(11),s=r.number.isNumber,u=r["boolean"].isBoolean,f=i.isComplex,c=o.isUnit,l=a.isCollection;e.cot=function p(r){if(1!=arguments.length)throw new e.error.ArgumentsError("cot",arguments.length,1);if(s(r))return 1/Math.tan(r);if(f(r)){var t=Math.exp(-4*r.im)-2*Math.exp(-2*r.im)*Math.cos(2*r.re)+1;return new i(2*Math.exp(-2*r.im)*Math.sin(2*r.re)/t,(Math.exp(-4*r.im)-1)/t)}if(c(r)){if(!r.hasBase(o.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cot is no angle");return 1/Math.tan(r.value)}if(l(r))return a.deepMap(r,p);if(u(r))return p(+r);if(r instanceof n)return p(r.toNumber());throw new e.error.UnsupportedTypeError("cot",e["typeof"](r))}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(5),o=t(9),a=t(11),s=r.number.isNumber,u=r["boolean"].isBoolean,f=i.isComplex,c=o.isUnit,l=a.isCollection;e.csc=function p(r){if(1!=arguments.length)throw new e.error.ArgumentsError("csc",arguments.length,1);if(s(r))return 1/Math.sin(r);if(f(r)){var t=.25*(Math.exp(-2*r.im)+Math.exp(2*r.im))-.5*Math.cos(2*r.re);return new i(.5*Math.sin(r.re)*(Math.exp(-r.im)+Math.exp(r.im))/t,.5*Math.cos(r.re)*(Math.exp(-r.im)-Math.exp(r.im))/t)}if(c(r)){if(!r.hasBase(o.BASE_UNITS.ANGLE))throw new TypeError("Unit in function csc is no angle");return 1/Math.sin(r.value)}if(l(r))return a.deepMap(r,p);if(u(r))return p(+r);if(r instanceof n)return p(r.toNumber());throw new e.error.UnsupportedTypeError("csc",e["typeof"](r))}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(5),o=t(9),a=t(11),s=r.number.isNumber,u=r["boolean"].isBoolean,f=i.isComplex,c=o.isUnit,l=a.isCollection;e.sec=function p(r){if(1!=arguments.length)throw new e.error.ArgumentsError("sec",arguments.length,1);if(s(r))return 1/Math.cos(r);if(f(r)){var t=.25*(Math.exp(-2*r.im)+Math.exp(2*r.im))+.5*Math.cos(2*r.re);return new i(.5*Math.cos(r.re)*(Math.exp(-r.im)+Math.exp(r.im))/t,.5*Math.sin(r.re)*(Math.exp(r.im)-Math.exp(-r.im))/t)}if(c(r)){if(!r.hasBase(o.BASE_UNITS.ANGLE))throw new TypeError("Unit in function sec is no angle");return 1/Math.cos(r.value)}if(l(r))return a.deepMap(r,p);if(u(r))return p(+r);if(r instanceof n)return p(r.toNumber());throw new e.error.UnsupportedTypeError("sec",e["typeof"](r))}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(5),o=t(9),a=t(11),s=r.number.isNumber,u=r["boolean"].isBoolean,f=i.isComplex,c=o.isUnit,l=a.isCollection;e.sin=function p(r){if(1!=arguments.length)throw new e.error.ArgumentsError("sin",arguments.length,1);if(s(r))return Math.sin(r);if(f(r))return new i(.5*Math.sin(r.re)*(Math.exp(-r.im)+Math.exp(r.im)),.5*Math.cos(r.re)*(Math.exp(r.im)-Math.exp(-r.im)));if(c(r)){if(!r.hasBase(o.BASE_UNITS.ANGLE))throw new TypeError("Unit in function sin is no angle");return Math.sin(r.value)}if(l(r))return a.deepMap(r,p);if(u(r))return Math.sin(r);if(r instanceof n)return p(r.toNumber());throw new e.error.UnsupportedTypeError("sin",e["typeof"](r))}}},function(e,r,t){e.exports=function(e){var r=t(117),n=e.type.BigNumber,i=t(5),o=t(9),a=t(11),s=r.number.isNumber,u=r["boolean"].isBoolean,f=i.isComplex,c=o.isUnit,l=a.isCollection;e.tan=function p(r){if(1!=arguments.length)throw new e.error.ArgumentsError("tan",arguments.length,1);if(s(r))return Math.tan(r);if(f(r)){var t=Math.exp(-4*r.im)+2*Math.exp(-2*r.im)*Math.cos(2*r.re)+1;return new i(2*Math.exp(-2*r.im)*Math.sin(2*r.re)/t,(1-Math.exp(-4*r.im))/t)}if(c(r)){if(!r.hasBase(o.BASE_UNITS.ANGLE))throw new TypeError("Unit in function tan is no angle");return Math.tan(r.value)}if(l(r))return a.deepMap(r,p);if(u(r))return Math.tan(r);if(r instanceof n)return p(r.toNumber());throw new e.error.UnsupportedTypeError("tan",e["typeof"](r))}}},function(e,r,t){e.exports=function(e){var r=t(117),n=t(9),i=t(11),o=r.string.isString,a=n.isUnit,s=i.isCollection;e.to=function u(r,t){if(2!=arguments.length)throw new e.error.ArgumentsError("to",arguments.length,2);if(a(r)&&(a(t)||o(t)))return r.to(t);if(s(r)||s(t))return i.deepMap2(r,t,u);throw new e.error.UnsupportedTypeError("to",e["typeof"](r),e["typeof"](t))}}},function(e,r,t){e.exports=function(e){var r=t(117),n=r.object;e.clone=function(r){if(1!=arguments.length)throw new e.error.ArgumentsError("clone",arguments.length,1);return n.clone(r)}}},function(e,r,t){e.exports=function(e){var r=t(117),n=r.string;e.format=function(r,t){var i=arguments.length;if(1!==i&&2!==i)throw new e.error.ArgumentsError("format",i,1,2);return n.format(r,t)}}},function(e,r,t){e.exports=function(e){function r(r,t,n){var i=r instanceof o||t instanceof o||n instanceof o;if(r instanceof o||(r=new o(r)),g(t)&&(t instanceof o||(t=new o(t)),!f(r.size(),t.size())))throw new RangeError("Dimension mismatch (["+r.size().join(", ")+"] != ["+t.size().join(", ")+"])");if(g(n)&&(n instanceof o||(n=new o(n)),!f(r.size(),n.size())))throw new e.error.DimensionError(r.size(),n.size());var a=t instanceof o,s=n instanceof o,u=r.map(function(r,i){return e.ifElse(r,a?t.get(i):t,s?n.get(i):n)});return i?u:u.valueOf()}var n=t(117),i=e.type.BigNumber,o=t(8),a=t(5),s=t(9),u=t(11),f=n.object.deepEqual,c=n.number.isNumber,l=n.string.isString,p=n["boolean"].isBoolean,m=a.isComplex,h=s.isUnit,g=u.isCollection;e.ifElse=function(t,n,o){if(3!=arguments.length)throw new e.error.ArgumentsError("ifElse",arguments.length,3);if(c(t)||p(t))return t?n:o;if(t instanceof i)return t.isZero()?o:n;if(l(t))return t?n:o;if(m(t))return t.re||t.im?n:o;if(h(t))return t.value?n:o;if(null===t||void 0===t)return o;if(g(t))return r(t,n,o);throw new e.error.UnsupportedTypeError("ifElse",e["typeof"](t))}}},function(e,r,t){e.exports=function(e){function r(r,t,n){(n.override||void 0===e[r])&&(e[r]=n.wrap&&"function"==typeof t?function(){for(var r=[],n=0,i=arguments.length;i>n;n++)r[n]=arguments[n].valueOf();return t.apply(e,r)}:t,e.chaining.Selector.createProxy(r,t))}function n(e){return"function"==typeof e||s(e)||u(e)||f(e)||c(e)}var i=t(117),o=t(5),a=t(9),s=i.number.isNumber,u=i.string.isString,f=o.isComplex,c=a.isUnit;e["import"]=function l(o,a){var s=arguments.length;if(1!=s&&2!=s)throw new e.error.ArgumentsError("import",s,1,2);var f,c={override:!1,wrap:!0};if(a&&a instanceof Object&&i.object.extend(c,a),u(o)){var p=t(149)(o);l(p)}else{if("object"!=typeof o)throw new TypeError("Object or module name expected");for(f in o)if(o.hasOwnProperty(f)){var m=o[f];n(m)?r(f,m,c):l(m)}}}}},function(e,r,t){e.exports=function(e){function r(e,r){var t=[],n=function(i,o){return Array.isArray(i)?i.map(function(e,r){return t[o]=r,n(e,o+1)}):r(i,t,e)};return n(e,0)}var n=t(8).isMatrix;e.map=function(t,i){if(2!=arguments.length)throw new e.error.ArgumentsError("map",arguments.length,2);if(Array.isArray(t))return r(t,i);if(n(t))return t.map(i);throw new e.error.UnsupportedTypeError("map",e["typeof"](t))}}},function(e,r,t){e.exports=function(e){var r=t(117),n=r.string.isString;e.print=function(r,t,i){var o=arguments.length;if(2!=o&&3!=o)throw new e.error.ArgumentsError("print",o,2,3);if(!n(r))throw new TypeError("String expected as first parameter in function format");if(!(t instanceof Object))throw new TypeError("Object expected as second parameter in function format");return r.replace(/\$([\w\.]+)/g,function(r,o){for(var a=o.split("."),s=t[a.shift()];a.length&&void 0!==s;){var u=a.shift();s=u?s[u]:s+"."}return void 0!==s?n(s)?s:e.format(s,i):r})}}},function(e,r,t){e.exports=function(e){var r=t(150),n=t(5),i=t(8),o=t(9),a=t(7),s=t(6),u=t(10);e["typeof"]=function(t){if(1!=arguments.length)throw new e.error.ArgumentsError("typeof",arguments.length,1);var f=r.type(t);if("object"===f){if(t instanceof n)return"complex";if(t instanceof i)return"matrix";if(t instanceof o)return"unit";if(t instanceof a)return"index";if(t instanceof s)return"range";if(t instanceof u)return"help";if(t instanceof e.type.BigNumber)return"bignumber";if(t instanceof e.chaining.Selector)return"selector"}return f}}},function(e,r,t){e.exports=function(e){function r(e,r){var t=[],n=function(i,o){Array.isArray(i)?i.forEach(function(e,r){t[o]=r,n(e,o+1)}):r(i,t,e)};n(e,0)}var n=t(8).isMatrix;e.forEach=function(t,i){if(2!=arguments.length)throw new e.error.ArgumentsError("forEach",arguments.length,2);if(Array.isArray(t))return r(t,i);if(n(t))return t.forEach(i);throw new e.error.UnsupportedTypeError("forEach",e["typeof"](t))}}},function(e,r,t){var n;(function(e){!function(i){"use strict";function o(e,r,t,n){return!((!(!n&&t>3&&4==e[r]||(n||4>t)&&9==e[r])||9!=e[r+1]||9!=e[r+2]||9!=e[r+3]||null==n&&9!=e[r+4])&&(null!=n||5!=e[r]&&e[r]||e[r+1]||e[r+2]||e[r+3]||e[r+4]))}function a(e,r,t){var n=e.constructor;return null==r||((y=0>r||r>8)||0!==r&&(n.errors?parseInt:parseFloat)(r)!=r)&&!l(n,"rounding mode",r,t,0)?n.rounding:0|r}function s(e,r,t,n){var i=e.constructor;return!(y=(n||0)>r||r>=A+1)&&(0===r||(i.errors?parseInt:parseFloat)(r)==r)||l(i,"argument",r,t,0)}function u(e,r,t,n,i,o){var a=e.constructor,s=e.e-r.e,u=e.s==r.s?1:-1,f=e.c,c=r.c;if(!(f&&f[0]&&c&&c[0]))return new a(e.s&&r.s&&(f?!c||f[0]!=c[0]:c)?f&&0==f[0]||!c?0*u:u/0:0/0);var l,p,m,g,d,w,y=c.slice(),v=w=c.length,x=f.length,b=f.slice(0,w),E=b.length,N=new a(u),M=N.c=[];for(p=u=0;c[p]==(f[p]||0);p++);if(c[p]>(f[p]||0)&&(s--,u=1),N.e=s,null==t?(t=a.precision,n=a.rounding):i&&(t+=s+1),o=o||10,t>=0){for(u+=t;E++m;m++){if(w!=(E=b.length))l=w>E?1:-1;else for(g=-1,l=0;++gb[g]?1:-1;break}if(!(0>l))break;for(d=E==w?c:y;E;){if(b[--E]1&&M.shift(),t>=p&&(t=null)}return h(N,t,n,null!=b[0],o)}function f(e,r){var t,n,i,a,s,f,c,l=0,p=0,m=0,g=e.constructor,d=g.ONE,w=g.rounding,y=g.precision;if(!e.c||!e.c[0]||e.e>17)return new g(e.c?e.c[0]?e.s<0?0:1/0:d:e.s?e.s<0?0:e:0/0);for(null==r?(b=!1,s=y):s=r,c=new g(.03125);e.e>-2;)e=e.times(c),m+=5;for(n=Math.log(Math.pow(2,m))/Math.LN10*2+5|0,s+=n,t=a=f=new g(d),g.precision=s;;){if(a=h(a.times(e),s,1),t=t.times(++p),c=f.plus(u(a,t,s,1)),c.c.slice(0,s).join("")===f.c.slice(0,s).join("")){for(i=m;i--;)f=h(f.times(f),s,1);if(null!=r)return g.precision=y,f;if(!(3>l&&o(f.c,s-n,w,l)))return h(f,g.precision=y,w,b=!0);g.precision=s+=10,t=a=c=new g(d),p=0,l++}f=c}}function c(e,r,t,n){var i=e.constructor,o=(e=new i(e)).e,a=e.c;if(!a)return e.toString();for(a.length>++r&&h(e,r,t),o=n?r:r+e.e-o;a.length=r||o<=i.toExpNeg)?(e.s<0&&a[0]?"-":"")+(a.length>1?a[0]+"."+a.slice(1).join(""):a[0])+(0>o?"e":"e+")+o:e.toString()}function l(e,r,t,n,i){if(e.errors){var o=new Error((n||["new Decimal","cmp","div","eq","gt","gte","lt","lte","minus","mod","plus","times","toFraction","pow","random","log","sqrt","toNearest","divToInt"][x?0>x?-x:x:0>1/x?1:0])+"() "+(["number type has more than 15 significant digits","LN10 out of digits"][r]||r+([y?" out of range":" not an integer"," not a boolean or binary digit"][i]||""))+": "+t);throw o.name="Decimal Error",y=x=0,o}}function p(e,r,t){var n=new e(e.ONE);for(b=!1;1&t&&(n=n.times(r)),t>>=1,t;)r=r.times(r);return b=!0,n}function m(e,r){var t,n,i,a,s,f,c,p,g,d=1,w=10,y=e,v=y.c,x=y.constructor,E=x.ONE,N=x.rounding,M=x.precision;if(y.s<0||!v||!v[0]||!y.e&&1==v[0]&&1==v.length)return new x(v&&!v[0]?-1/0:1!=y.s?0/0:v?0:y);if(null==r?(b=!1,s=M):s=r,x.precision=s+=w,!(Math.abs(n=y.e)<15e14))return y=new x(y),y.e=0,s+2>T.length&&l(x,1,s+2,"ln"),y=m(y,s-w).plus(new x(T.slice(0,s+2)).times(n+"")),x.precision=M,null==r?h(y,M,N,b=!0):y;for(;v[0]<7&&1!=v[0]||1==v[0]&&v[1]>3;)y=y.times(e),v=y.c,d++;for(n=y.e,v[0]>1?(1==d?y=new x("0."+v.join("")):y.e=-1,n++):y=new x("1."+v.slice(1).join("")),p=y,f=i=y=u(y.minus(E),y.plus(E),s,1),g=h(y.times(y),s,1),t=3;;){if(i=h(i.times(g),s,1),c=f.plus(u(i,new x(t),s,1)),c.c.slice(0,s).join("")===f.c.slice(0,s).join("")){if(f=f.times(2),0!==n&&(s+2>T.length&&l(x,1,s+2,"ln"),f=f.plus(new x(T.slice(0,s+2)).times(n+""))),f=u(f,new x(d),s,1),null!=r)return x.precision=M,f;if(!o(f.c,s-w,N,a))return h(f,x.precision=M,N,b=!0);x.precision=s+=w,c=i=y=u(p.minus(E),p.plus(E),s,1),g=h(y.times(y),s,1),t=a=1}f=c,t+=2}}function h(e,r,t,n,i){var o,a,s,u,f=e.constructor;if(r!=o){if(!(u=e.c))return e;if(s=e.s<0,a=(i=i||10)/2,o=u[r],n=n||0>r||null!=u[r+1],n=4>t?(null!=o||n)&&(0==t||2==t&&!s||3==t&&s):o>a||o==a&&(4==t||n||6==t&&1&u[r-1]||7==t&&!s||8==t&&s),1>r||!u[0])return u.length=0,n?(r=r-e.e-1,u[0]=1,e.e=-r||0):u[0]=e.e=0,e;if(u.length>r&&(u.length=r),r--,n){for(o=r;null==u[o];u[o--]=0);for(--i;++u[r]>i;)u[r]=0,r--||(++e.e,u.unshift(1))}for(r=u.length;!u[--r];u.pop());}return b&&(e.e>f.maxE?e.c=e.e=null:e.ea,!i||!o)return u==f?0:!i^t?1:-1;if(u!=f)return u>f^t?1:-1;for(a=-1,s=(u=i.length)<(f=o.length)?u:f;++ao[a]^t?1:-1;return u==f?0:u>f^t?1:-1},N.decimalPlaces=N.dp=function(){var e=this;return e.c?Math.max(e.c.length-e.e-1,0):null},N.dividedBy=N.div=function(e,r){return x=2,u(this,new this.constructor(e,r))},N.dividedToIntegerBy=N.divToInt=function(e,r){var t=this,n=t.constructor;return x=18,h(u(t,new n(e,r),0,1,1),n.precision,n.rounding)},N.equals=N.eq=function(e,r){return x=3,0===this.cmp(e,r)},N.exponential=N.exp=function(){return f(this)},N.floor=function(){return h(new this.constructor(this),this.e+1,3)},N.greaterThan=N.gt=function(e,r){return x=4,this.cmp(e,r)>0},N.greaterThanOrEqualTo=N.gte=function(e,r){return x=5,r=this.cmp(e,r),1==r||0===r},N.isFinite=function(){return!!this.c},N.isInteger=N.isInt=function(){return!!this.c&&this.e>this.c.length-2},N.isNaN=function(){return!this.s},N.isNegative=N.isNeg=function(){return this.s<0},N.isZero=function(){return!!this.c&&0==this.c[0]},N.lessThan=N.lt=function(e,r){return x=6,this.cmp(e,r)<0},N.lessThanOrEqualTo=N.lte=function(e,r){return x=7,r=this.cmp(e,r),-1==r||0===r},N.logarithm=N.log=function(e,r){var t,n,i,a,s,f,c,p,g,d=this,w=d.constructor,y=w.precision,v=w.rounding,E=5;if(null==e)e=new w(10),t=!0;else{if(x=15,e=new w(e,r),n=e.c,e.s<0||!n||!n[0]||!e.e&&1==n[0]&&1==n.length)return new w(0/0);t=e.eq(10)}if(n=d.c,d.s<0||!n||!n[0]||!d.e&&1==n[0]&&1==n.length)return new w(n&&!n[0]?-1/0:1!=d.s?0/0:n?0:1/0);if(s=t&&(1!=n[0]||n.length>1)||(1&e.c[e.c.length-1])!=(1&n[n.length-1])||0,b=!1,c=y+E,p=c+10,f=m(d,c),t?(p>T.length&&l(w,1,p,"log"),i=new w(T.slice(0,p))):i=m(e,c),g=u(f,i,c,1),o(g.c,a=y,v))do if(c+=10,f=m(d,c),t?(p=c+10,p>T.length&&l(w,1,p,"log"),i=new w(T.slice(0,p))):i=m(e,c),g=u(f,i,c,1),!s){for(n=g.c;9==n[++a];);a==y+E+10&&(g=h(g,y+1,0));break}while(o(g.c,a+=10,v));return b=!0,h(g,y,v)},N.minus=function(e,r){var t,n,i,o,a=this,s=a.constructor,u=a.s;if(x=8,e=new s(e,r),r=e.s,!u||!r)return new s(0/0);if(u!=r)return e.s=-r,a.plus(e);var f=a.c,c=a.e,l=e.c,p=e.e,m=s.precision,g=s.rounding;if(!c||!p){if(!f||!l)return f?(e.s=-r,e):new s(l?a:0/0);if(!f[0]||!l[0])return a=l[0]?(e.s=-r,e):new s(f[0]?a:3==g?-0:0),b?h(a,m,g):a}if(f=f.slice(),n=f.length,u=c-p){for((o=0>u)?(u=-u,t=f,n=l.length):(p=c,t=l),m>n&&(n=m),u>(n+=2)&&(u=n,t.length=1),t.reverse(),r=u;r--;t.push(0));t.reverse()}else for((o=n<(i=l.length))&&(i=n),u=r=0;i>r;r++)if(f[r]!=l[r]){o=f[r]0)for(;r--;f[i++]=0);for(r=l.length;r>u;){if(f[--r]o?(o=-o,t=s,r=f.length):(u=a,t=f,r=s.length),c>r&&(r=c),o>++r&&(o=r,t.length=1),t.reverse();o--;t.push(0));t.reverse()}for(s.length-f.length<0&&(t=f,f=s,s=t),o=f.length,r=0;o;s[o]%=10)r=(s[--o]=s[o]+f[o]+r)/10|0;for(r&&(s.unshift(r),++u),o=s.length;0==s[--o];s.pop());return e.c=s,e.e=u,b?h(e,c,l):e},N.precision=N.sd=function(e){var r=this;return null!=e&&e!==!!e&&1!==e&&0!==e&&l(r.constructor,"argument",e,"precision",1),r.c?e?Math.max(r.e+1,r.c.length):r.c.length:null},N.round=function(){var e=this,r=e.constructor;return h(new r(e),e.e+1,r.rounding)},N.squareRoot=N.sqrt=function(){var e,r,t,n,i,o=this,a=o.c,s=o.s,f=o.e,c=o.constructor,l=new c(.5);if(1!==s||!a||!a[0])return new c(!s||0>s&&(!a||a[0])?0/0:a?o:1/0);for(b=!1,s=Math.sqrt(+o),0==s||s==1/0?(e=a.join(""),(e.length+f)%2==0&&(e+="0"),t=new c(Math.sqrt(e)+""),t.c||(t.c=[1]),t.e=Math.floor((f+1)/2)-(0>f||f%2)):t=new c(s.toString()),r=(f=c.precision)+3;;)if(i=t,t=l.times(i.plus(u(o,i,r+2,1))),i.c.slice(0,r).join("")===t.c.slice(0,r).join("")){if(a=t.c,9!=a[r-3]&&(n||4!=a[r-3])||9!=a[r-2]||9!=a[r-1]||9!=a[r]){if(!(a[r-3]&&5!=a[r-3]||a[r-2]||a[r-1]||a[r]||(a.length>f+1&&(a.length=f+1),t.times(t).eq(o)))){for(;a.lengthf&&(t=o,o=a,a=t,u=f,f=r,r=u),u=f+r,t=[];u--;t.push(0));for(s=r-1;s>-1;s--){for(r=0,u=f+s;u>s;r=r/10|0)r=t[u]+a[s]*o[u-s-1]+r,t[u--]=r%10|0;r&&(t[u]=(t[u]+r)%10)}for(r&&++e.e,t[0]||t.shift(),u=t.length;!t[--u];t.pop());return e.c=t,b?h(e,i.precision,i.rounding):e},N.toDecimalPlaces=N.toDP=function(e,r){var t=this;return t=new t.constructor(t),null!=e&&s(t,e,"toDP")?h(t,(0|e)+t.e+1,a(t,r,"toDP")):t},N.toExponential=function(e,r){var t=this;return c(t,null!=e&&s(t,e,"toExponential")||!t.c?0|e:t.c.length-1,null!=e&&a(t,r,"toExponential"),1)},N.toFixed=function(e,r){var t,n=this,i=n.constructor,o=i.toExpNeg,u=i.toExpPos;return null!=e&&(e=s(n,e,t="toFixed",-A)?n.e+(0|e):null,r=a(n,r,t)),i.toExpNeg=-(i.toExpPos=1/0),null==e?t=n.toString():(t=c(n,e,r),n.s<0&&n.c&&(n.c[0]?t.indexOf("-")<0&&(t="-"+t):t=t.replace("-",""))),i.toExpNeg=o,i.toExpPos=u,t},N.toFormat=function(e,r,t){var n=this.toFixed(r).split(".");return n[0].replace(/\B(?=(\d{3})+$)/g,null==e?",":e+"")+(n[1]?"."+(t?n[1].replace(/\d{5}\B/g,"$&"+t):n[1]):"")},N.toFraction=function(e){var r,t,n,i,o,a,s,f=this,c=f.constructor,p=r=new c(c.ONE),m=a=new c(0),h=f.c,g=new c(c.ONE),d=c.precision;if(!h)return f.toString();for(n=g.e=h.length-f.e-1,(null==e||(!(x=12,o=new c(e)).s||(y=o.cmp(p)<0||!o.c)||c.errors&&o.e0)&&(e=n>0?g:p),b=!1,o=new c(h.join("")),c.precision=h.length;s=u(o,g,0,1,1),t=r.plus(s.times(m)),1!=t.cmp(e);)r=m,m=t,p=a.plus(s.times(t=p)),a=t,g=o.minus(s.times(t=g)),o=t;return t=u(e.minus(r),m,0,1,1),a=a.plus(t.times(p)),r=r.plus(t.times(m)),a.s=p.s=f.s,n*=2,i=u(p,m,n,1,1).minus(f).abs().cmp(u(a,r,n,1,1).minus(f).abs())<1?[p.toString(),m.toString()]:[a.toString(),r.toString()],b=!0,c.precision=d,i},N.toNearest=function(e,r){var t=this,n=t.constructor;return t=new n(t),null==e?(e=new n(n.ONE),r=n.rounding):(x=17,e=new n(e),r=a(t,r,"toNearest")),e.c?t.c&&(b=!1,4>r&&(r=[4,5,7,8][r]),1==e.c[0]&&1==e.c.length?(t.e-=e.e,h(t,t.e+1,r),t.c[0]&&(t.e+=e.e)):e.c[0]?t=u(t,e,0,r,1).times(e):t.c=[t.e=0],b=!0,h(t)):t.s&&(e.s&&(e.s=t.s),t=e),t},N.toNumber=function(){var e=this;return+e||(0|e)*e.s},N.toPower=N.pow=function(e,r){var t,n,i,a,s=this,u=s.constructor,c=s.s,l=(x=13,+(e=new u(e,r))),g=0>l?-l:l,d=u.precision,w=u.rounding;if(!s.c||!e.c||(i=!s.c[0])||!e.c[0])return new u(Math.pow(i?0*c:+s,l));if(s=new u(s),t=s.c.length,!s.e&&s.c[0]==s.s&&1==t)return s;if(r=e.c.length-1,e.e||e.c[0]!=e.s||r)if(i=e.e>=r,!i&&0>c)a=new u(0/0);else{if(i&&S>t*g){if(a=p(u,s,g),e.s<0)return u.ONE.div(a)}else{if(c=0>c&&1&e.c[Math.max(e.e,r)]?-1:1,r=Math.pow(+s,l),n=0!=r&&isFinite(r)?new u(r+"").e:Math.floor(l*(Math.log("0."+s.c.join(""))/Math.LN10+s.e+1)),n>u.maxE+1||n0?c/0:0);if(b=!1,u.rounding=s.s=1,g=Math.min(12,(n+"").length),a=f(e.times(m(s,d+g)),d),a=h(a,d+5,1),o(a.c,d,w)){for(n=d+10,a=h(f(e.times(m(s,n+g)),n),n+5,1),g=d;9==a.c[++g];);g==d+15&&(a=h(a,d+1,0))}a.s=c,b=!0,u.rounding=w}a=h(a,d,w)}else a=h(s,d,w);return a},N.toPrecision=function(e,r){return null!=e&&s(this,e,"toPrecision",1)?c(this,0|--e,a(this,r,"toPrecision"),2):this.toString()},N.toSignificantDigits=N.toSD=function(e,r){var t=this,n=t.constructor;return t=new n(t),null!=e&&s(t,e,"toSD",1)?h(t,0|e,a(t,r,"toSD")):h(t,n.precision,n.rounding)},N.toString=function(e){var r,t,n,i=this,o=i.constructor,a=i.e;if(null===a)t=i.s?"Infinity":"NaN";else{if(e===r&&(a<=o.toExpNeg||a>=o.toExpPos))return c(i,i.c.length-1,o.rounding,1);if(t=i.c.join(""),0>a){for(;++a;t="0"+t);t="0."+t}else if(n=t.length,a>0)if(++a>n)for(a-=n;a--;t+="0");else n>a&&(t=t.slice(0,a)+"."+t.slice(a)); +else if(r=t.charAt(0),n>1)t=r+"."+t.slice(1);else if("0"==r)return r;if(null!=e)if((y=!(e>=2&&65>e))||e!=(0|e)&&o.errors)l(o,"base",e,"toString",0);else if(t=g(o,t,0|e,10,i.s),"0"==t)return t}return i.s<0?"-"+t:t},N.truncated=N.trunc=function(){return h(new this.constructor(this),this.e+1,1)},N.valueOf=N.toJSON=function(){return this.toString()},g=function(){function e(e,r,t){for(var n,i,o=[0],a=0,s=e.length;s>a;){for(i=o.length;i--;o[i]*=r);for(o[n=0]+=E.indexOf(e.charAt(a++));nt-1&&(null==o[n+1]&&(o[n+1]=0),o[n+1]+=o[n]/t|0,o[n]%=t)}return o.reverse()}return function(r,t,n,i,o){var a,s,f,c=t.indexOf("."),l=new r(i);for(37>i&&(t=t.toLowerCase()),0>c?(a=new r(l),f=[1]):(a=p(r,l,t.length-c-1),f=e(a.toFixed(),10,n),t=t.replace(".","")),l.c=f,l.e=f.length,s=e(t,i,n),a.c=s,a.e=s.length,a.s=o,a=u(a,l,r.precision,r.rounding,0,n),s=a.c,c=s.length;c--;)s[c]=E.charAt(s[c]);return a.s=1,a.toFixed()}}(),w=function(){function e(e){var r,t,n,i=this,o="config",a=i.errors?parseInt:parseFloat;return e==t||"object"!=typeof e&&!l(i,"object expected",e,o)?i:((n=e[r="precision"])!=t&&((y=1>n||n>A)||a(n)!=n?l(i,r,n,o,0):i[r]=0|n),(n=e[r="rounding"])!=t&&((y=0>n||n>8)||a(n)!=n?l(i,r,n,o,0):i[r]=0|n),(n=e[r="toExpNeg"])!=t&&((y=-M>n||n>0)||a(n)!=n?l(i,r,n,o,0):i[r]=Math.floor(n)),(n=e[r="toExpPos"])!=t&&((y=0>n||n>M)||a(n)!=n?l(i,r,n,o,0):i[r]=Math.floor(n)),(n=e[r="minE"])!=t&&((y=-M>n||n>0)||a(n)!=n?l(i,r,n,o,0):i[r]=Math.floor(n)),(n=e[r="maxE"])!=t&&((y=0>n||n>M)||a(n)!=n?l(i,r,n,o,0):i[r]=Math.floor(n)),(n=e[r="errors"])!=t&&(n===!!n||1===n||0===n?(y=x=0,i[r]=!!n):l(i,r,n,o,1)),(n=e[r="crypto"])!=t&&(n===!!n||1===n||0===n?i[r]=!(!n||!d||"object"!=typeof d):l(i,r,n,o,1)),(n=e[r="modulo"])!=t&&((y=0>n||n>9)||a(n)!=n?l(i,r,n,o,0):i[r]=0|n),i)}function r(e){return new this(e).exp()}function t(e){return new this(e).ln()}function n(e,r){return new this(e).log(r)}function o(e,r,t){var n,i,o=0;for("[object Array]"==v.call(r[0])&&(r=r[0]),n=new e(r[0]);++o1/i?"-0":i+""),c=i,o==s&&e.test(i))n.s="-"==i.charAt(0)?(i=i.slice(1),-1):1;else{if(10==o)return h(new t(i),t.precision,t.rounding);if(i=r.call(i).replace(/^\+(?!-)/,""),n.s="-"==i.charAt(0)?(i=i.replace(/^-(?!-)/,""),-1):1,o!=s?o!=(0|o)&&t.errors||(y=!(o>=2&&65>o))?(l(t,"base",o,0,0),p=e.test(i)):(a="["+E.slice(0,o=0|o)+"]+",i=i.replace(/\.$/,"").replace(/^\./,"0."),(p=new RegExp("^"+a+"(?:\\."+a+")?$",37>o?"i":"").test(i))?(f&&(i.replace(/^0\.0*|\./,"").length>15&&l(t,0,c),f=!f),i=g(t,i,10,o,n.s)):"Infinity"!=i&&"NaN"!=i&&(l(t,"not a base "+o+" number",c),i="NaN")):p=e.test(i),!p)return n.c=n.e=null,"Infinity"!=i&&("NaN"!=i&&l(t,"not a number",c),n.s=null),x=0,n}for((s=i.indexOf("."))>-1&&(i=i.replace(".","")),(u=i.search(/e/i))>0?(0>s&&(s=u),s+=+i.slice(u+1),i=i.substring(0,u)):0>s&&(s=i.length),u=0;"0"==i.charAt(u);u++);if(u==(o=i.length))n.c=[n.e=0];else{for(f&&o>15&&i.slice(u).length>15&&l(t,0,c);"0"==i.charAt(--o););for(n.e=s-u-1,n.c=[],s=0;o>=u;n.c[s++]=+i.charAt(u++));b&&(n.e>t.maxE?n.c=n.e=null:n.e(256/e|0)*e-1?r(e):t%e+""):(t=d.getRandomValues(new i.Uint32Array(1))[0],t>=4e9?r(e):(t+1e9+"").slice(1))}function t(e){var r,n,i=d.randomBytes;return e?(n=i(1)[0],n>(256/e|0)*e-1?t(e):n%e+""):(r=i(8),r[0]=67,r[1]=15&r[1]|48,n=r.readDoubleBE(0),n>9003599627370495?t(e):(n-0xc72815b398000+"").slice(2))}return function(n,i){var o,a,u,f,c,p,m,h,g=this,w=new g(0),y=e;if(p=n==a||!(x=14,n=new g(n)).c&&!l(g,"limit must be finite",n,"random"))n=new g(g.ONE);else if(!n.c[0])return w;g.crypto&&(d.getRandomValues?y=r:d.randomBytes&&(y=t)),a=n.e,c=(o=n.c).length;do{u=0,h=y(o[0]+1)+y();do f=o[u],m=h.charAt(u++);while(f==m)}while(m>f||u>c||""==m);for(u=0;"0"==h.charAt(u);u++,a--);for(p?i=g.precision:null!=i&&s(n,i,"random",1)?i|=0:i=a+1,i+=u;h.length0)for(w.c=[];i>u;w.c.push(+h.charAt(u++)));else w.c=[a=0];return w.e=a,w.s=n.s,w}}();return p()}(),"undefined"!=typeof e&&e&&e.exports?(e.exports=w,d=t(246)):(d=i.crypto,n=function(){return w}.call(r,t,r,e),!(void 0!==n&&(e.exports=n)))}(this)}).call(r,t(247)(e))},function(e){function r(e,t,n,i){if(!(this instanceof r))throw new SyntaxError("Constructor must be called with the new operator");this.fn=e,this.count=t,this.min=n,this.max=i,this.message="Wrong number of arguments in function "+e+" ("+t+" provided, "+n+(void 0!=i?"-"+i:"")+" expected)",this.stack=(new Error).stack}r.prototype=new Error,r.prototype.constructor=Error,r.prototype.name="ArgumentsError",e.exports=r},function(e){function r(e,t,n){if(!(this instanceof r))throw new SyntaxError("Constructor must be called with the new operator");this.actual=e,this.expected=t,this.relation=n,this.message="Dimension mismatch ("+(Array.isArray(e)?"["+e.join(", ")+"]":e)+" "+(this.relation||"!=")+" "+(Array.isArray(t)?"["+t.join(", ")+"]":t)+")",this.stack=(new Error).stack}r.prototype=new RangeError,r.prototype.constructor=RangeError,r.prototype.name="DimensionError",e.exports=r},function(e){function r(e,t,n){if(!(this instanceof r))throw new SyntaxError("Constructor must be called with the new operator");this.index=e,arguments.length<3?(this.min=0,this.max=t):(this.min=t,this.max=n),this.message=void 0!==this.min&&this.index=this.max?"Index out of range ("+this.index+" > "+(this.max-1)+")":"Index out of range ("+this.index+")",this.stack=(new Error).stack}r.prototype=new RangeError,r.prototype.constructor=RangeError,r.prototype.name="IndexError",e.exports=r},function(e){function r(e){if(!(this instanceof r))throw new SyntaxError("Constructor must be called with the new operator");this.fn=e,this.types=Array.prototype.splice.call(arguments,1),this.message=e?0==this.types.length?"Unsupported type of argument in function "+e:"Function "+e+"("+this.types.join(", ")+") not supported":"Unsupported type of argument",this.stack=(new Error).stack}r.prototype=new TypeError,r.prototype.constructor=TypeError,r.prototype.name="UnsupportedTypeError",e.exports=r},function(e,r,t){r.array=t(147),r["boolean"]=t(244),r.number=t(148),r.bignumber=t(245),r.object=t(3),r.string=t(132),r.types=t(150)},function(e,r,t){function n(e){if(!(this instanceof n))throw new SyntaxError("Constructor must be called with the new operator");if(this.nodes=e||[],!a(this.nodes)||!this.nodes.every(s))throw new TypeError("Array containing Nodes expected")}var i=t(131),o=(t(3),t(132)),a=(t(11),t(117),Array.isArray),s=i.isNode;n.prototype=new i,n.prototype._compile=function(e){var r="array"!==e.math.config().matrix,t=this.nodes.map(function(r){return r._compile(e)});return(r?"math.matrix([":"[")+t.join(",")+(r?"])":"]")},n.prototype.find=function(e){var r=[];this.match(e)&&r.push(this);for(var t=this.nodes,n=0,i=t.length;i>n;n++)r=r.concat(t[n].find(e));return r},n.prototype.toString=function(){return o.format(this.nodes)},e.exports=n},function(e,r,t){function n(e,r){if(!(this instanceof n))throw new SyntaxError("Constructor must be called with the new operator");if(!o(e))throw new TypeError('String expected for parameter "name"');if(!(r instanceof i))throw new TypeError('Node expected for parameter "expr"');this.name=e,this.expr=r}var i=t(131),o=t(132).isString;n.prototype=new i,n.prototype._compile=function(e){return'scope["'+this.name+'"] = '+this.expr._compile(e)},n.prototype.find=function(e){var r=[];return this.match(e)&&r.push(this),r=r.concat(this.expr.find(e))},n.prototype.toString=function(){return this.name+" = "+this.expr.toString()},e.exports=n},function(e,r,t){function n(){if(!(this instanceof n))throw new SyntaxError("Constructor must be called with the new operator");this.params=[]}var i=t(131),o=t(244).isBoolean;n.prototype=new i,n.prototype.add=function(e,r){if(void 0===r&&(r=!0),!(e instanceof i))throw new TypeError('Node expected for parameter "expr"');if(!o(r))throw new TypeError('Boolean expected for parameter "visible"');var t=this.params.length;this.params[t]={node:e,visible:r}},n.prototype._compile=function(e){var r=this.params.map(function(r){var t=r.node._compile(e);return r.visible?"results.push("+t+");":t+";"});return"(function () {var results = [];"+r.join("")+"return results;})()"},n.prototype.find=function(e){var r=[];this.match(e)&&r.push(this);for(var t=this.params,n=0,i=t.length;i>n;n++)r=r.concat(t[n].node.find(e));return r},n.prototype.toString=function(){return this.params.map(function(e){return e.node.toString()+(e.visible?"":";")}).join("\n")},e.exports=n},function(e,r,t){function n(e,r){if(!(this instanceof n))throw new SyntaxError("Constructor must be called with the new operator");if(!a(e))throw new TypeError('String expected for parameter "type"');if(!a(r))throw new TypeError('String expected for parameter "value"');this.type=e,this.value=r}var i=t(131),o=t(132),a=o.isString;n.prototype=new i,n.prototype._compile=function(e){switch(this.type){case"number":return"bignumber"===e.math.config().number?'math.bignumber("'+this.value+'")':this.value.replace(/^(0*)[0-9]/,function(e,r){return e.substring(r.length)});case"string":return'"'+this.value+'"';case"complex":return"math.complex(0, "+this.value+")";case"boolean":return this.value;case"undefined":return this.value;case"null":return this.value;default:throw new TypeError('Unsupported type of constant "'+this.type+'"')}},n.prototype.toString=function(){switch(this.type){case"string":return'"'+this.value+'"';case"complex":return this.value+"i";default:return this.value}},e.exports=n},function(e,r,t){function n(e,r,t){if(!(this instanceof n))throw new SyntaxError("Constructor must be called with the new operator");if(!o(e))throw new TypeError('String expected for parameter "name"');if(!isArray(r)||!r.every(o))throw new TypeError('Array containing strings expected for parameter "args"');if(!(t instanceof i))throw new TypeError('Node expected for parameter "expr"');this.name=e,this.args=r,this.expr=t}var i=t(131),o=t(132).isString;isArray=Array.isArray,n.prototype=new i,n.prototype._compile=function(e){return'scope["'+this.name+'"] = (function (scope) { scope = Object.create(scope); var fn = function '+this.name+"("+this.args.join(",")+") { if (arguments.length != "+this.args.length+') { throw new SyntaxError("Wrong number of arguments in function '+this.name+' (" + arguments.length + " provided, '+this.args.length+' expected)"); }'+this.args.map(function(e,r){return'scope["'+e+'"] = arguments['+r+"];"}).join("")+" return "+this.expr._compile(e)+' }; fn.syntax = "'+this.name+"("+this.args.join(", ")+')"; return fn; })(scope);'},n.prototype.find=function(e){var r=[];return this.match(e)&&r.push(this),r=r.concat(this.expr.find(e))},n.prototype.toString=function(){return"function "+this.name+"("+this.args.join(", ")+") = "+this.expr.toString()},e.exports=n},function(e,r,t){function n(e,r){if(!(this instanceof n))throw new SyntaxError("Constructor must be called with the new operator");if(!(e instanceof i))throw new TypeError('Node expected for parameter "object"');if(!isArray(r)||!r.every(s))throw new TypeError('Array containing Nodes expected for parameter "ranges"');this.object=e,this.ranges=r}var i=t(131),o=t(126),a=t(127),s=i.isNode;n.prototype=new i,n.prototype._compile=function(e){return this.compileSubset(e)},n.prototype.compileSubset=function(e,r){var t={type:a,properties:{name:"end"}},n=!1,i=this.ranges.map(function(e){var r=e.find(t).length>0;return n=r?r:n,r}),s=this.ranges.map(function(r,t){var n=i[t];return r instanceof o?n?'(function (scope) { scope = Object.create(scope); scope["end"] = size['+t+"]; var step = "+(r.step?r.step._compile(e):"1")+"; return [ "+r.start._compile(e)+" - 1, "+r.end._compile(e)+" - (step > 0 ? 0 : 2), step ];})(scope)":"(function () { var step = "+(r.step?r.step._compile(e):"1")+"; return [ "+r.start._compile(e)+" - 1, "+r.end._compile(e)+" - (step > 0 ? 0 : 2), step ];})()":n?'(function (scope) { scope = Object.create(scope); scope["end"] = size['+t+"]; return "+r._compile(e)+" - 1;})(scope)":r._compile(e)+" - 1"});return n?"(function () { var obj = "+this.object._compile(e)+"; var size = math.size(obj).valueOf(); return math.subset( obj, math.index("+s.join(", ")+") "+(r?", "+r:"")+" );})()":"math.subset("+this.object._compile(e)+",math.index("+s.join(", ")+")"+(r?", "+r:"")+")"},n.prototype.find=function(e){var r=[];this.match(e)&&r.push(this),r=r.concat(this.object.find(e));for(var t=this.ranges,n=0,i=t.length;i>n;n++)r=r.concat(t[n].find(e));return r},n.prototype.objectName=function(){return this.object.name},n.prototype.toString=function(){return this.object.toString()+"["+this.ranges.join(", ")+"]"},e.exports=n},function(e,r,t){function n(e,r,t){if(!(this instanceof n))throw new SyntaxError("Constructor must be called with the new operator");this.op=e,this.fn=r,this.params=t}var i=t(131);n.prototype=new i,n.prototype._compile=function(e){if(!(this.fn in e.math))throw new Error("Function "+this.fn+' missing in provided namespace "math"');var r=this.params.map(function(r){return r._compile(e)});return"math."+this.fn+"("+r.join(", ")+")"},n.prototype.find=function(e){var r=[];this.match(e)&&r.push(this);var t=this.params;if(t)for(var n=0,i=t.length;i>n;n++)r=r.concat(t[n].find(e));return r},n.prototype.toString=function(){var e=this.params;switch(e.length){case 1:return"-"==this.op?"-"+e[0].toString():e[0].toString()+this.op;case 2:var r=e[0].toString();e[0]instanceof n&&(r="("+r+")");var t=e[1].toString();return e[1]instanceof n&&(t="("+t+")"),r+" "+this.op+" "+t;default:return this.op+"("+this.params.join(", ")+")"}},e.exports=n},function(e,r,t){function n(e,r){if(!(this instanceof n))throw new SyntaxError("Constructor must be called with the new operator");if(!(e instanceof i))throw new TypeError('Node expected for parameter "object"');if(!isArray(r)||!r.every(o))throw new TypeError('Array containing Nodes expected for parameter "params"');this.object=e,this.params=r}var i=t(131),o=i.isNode;n.prototype=new i,n.prototype._compile=function(e){var r=this.params.map(function(r){return r._compile(e)});return this.object._compile(e)+"("+r.join(", ")+")"},n.prototype.find=function(e){var r=[];this.match(e)&&r.push(this),r=r.concat(this.object.find(e));for(var t=this.params,n=0,i=t.length;i>n;n++)r=r.concat(t[n].find(e));return r},n.prototype.toString=function(){return this.object.toString()+"("+this.params.join(", ")+")"},e.exports=n},function(e,r,t){function n(e){if(!(this instanceof n))throw new SyntaxError("Constructor must be called with the new operator");if(!Array.isArray(e)||2!=e.length&&3!=e.length||!e.every(o))throw new TypeError('Expected an Array containing 2 or 3 Nodes as parameter "params"');this.start=e[0],this.end=e[1],this.step=e[2]}var i=t(131),o=i.isNode;n.prototype=new i,n.prototype._compile=function(e){return"math.range("+this.start._compile(e)+", "+this.end._compile(e)+", "+(this.step?this.step._compile(e)+", ":"")+"true)"},n.prototype.find=function(e){var r=[];return this.match(e)&&r.push(this),r=r.concat(this.start.find(e)),this.step&&(r=r.concat(this.step.find(e))),r=r.concat(this.end.find(e))},n.prototype.toString=function(){var e=this.start.toString();return this.step&&(e+=":"+this.step.toString()),e+=":"+this.end.toString()},e.exports=n},function(e,r,t){function n(e){if(!(this instanceof n))throw new SyntaxError("Constructor must be called with the new operator");if(!s(e))throw new TypeError('String expected for parameter "name"');this.name=e}function i(e){throw new Error("Undefined symbol "+e)}var o=t(131),a=t(9),s=t(132).isString;n.prototype=new o,n.prototype._compile=function(e){return e.undef=i,e.Unit=a,'(scope["'+this.name+'"] !== undefined ? scope["'+this.name+'"] : math["'+this.name+'"] !== undefined ? math["'+this.name+'"] : '+(a.isValuelessUnit(this.name)?'new Unit(null, "'+this.name+'")':'undef("'+this.name+'")')+")"},n.prototype.toString=function(){return this.name},e.exports=n},function(e,r,t){function n(e,r,t){if(!(this instanceof n))throw new SyntaxError("Constructor must be called with the new operator");this.ops=e,this.fn=r,this.params=t}var i=t(124);n.prototype=new i,n.prototype.toString=function(){return this.params[0]+" "+this.ops[0]+" "+this.params[1]+" "+this.ops[1]+" "+this.params[2]},e.exports=n},function(e,r,t){function n(e,r){if(!(this instanceof n))throw new SyntaxError("Constructor must be called with the new operator");if(!(e instanceof i))throw new TypeError('Node expected for parameter "value"');if(!o(r))throw new TypeError('String expected for parameter "unit"');this.value=e,this.unit=r}var i=t(131),o=(t(9),t(132).isString);n.prototype=new i,n.prototype._compile=function(e){return"math.unit("+this.value._compile(e)+', "'+this.unit+'")'},n.prototype.find=function(e){var r=[];return this.match(e)&&r.push(this),r=r.concat(this.value.find(e))},n.prototype.toString=function(){return this.value+" "+this.unit},e.exports=n},function(e,r,t){function n(e,r){if(!(this instanceof n))throw new SyntaxError("Constructor must be called with the new operator");if(!(e instanceof o))throw new TypeError('Expected IndexNode for parameter "index"');if(!(r instanceof i))throw new TypeError('Expected Node for parameter "expr"');this.index=e,this.expr=r}var i=t(131),o=t(123);n.prototype=new i,n.prototype._compile=function(e){return'scope["'+this.index.objectName()+'"] = '+this.index.compileSubset(e,this.expr._compile(e))},n.prototype.find=function(e){var r=[];return this.match(e)&&r.push(this),r=r.concat(this.index.find(e)),r=r.concat(this.expr.find(e))},n.prototype.toString=function(){return this.index.toString()+" = "+this.expr.toString()},e.exports=n},function(e,r,t){function n(){if(!(this instanceof n))throw new SyntaxError("Constructor must be called with the new operator")}var i=t(4);n.prototype.eval=function(){throw new Error("Node.eval is deprecated. Use Node.compile(math).eval([scope]) instead.")},n.prototype.compile=function(e){if("object"!=typeof e)throw new TypeError("Object expected for parameter math");var r={math:e,error:i},t=this._compile(r),n=Object.keys(r).map(function(e){return" var "+e+' = defs["'+e+'"];'}),o=n.join(" ")+'return { "eval": function (scope) { try { scope = scope || {}; return '+t+"; } catch (err) { if (err instanceof defs.error.IndexError) { err = new defs.error.IndexError(err.index + 1, err.min + 1, err.max + 1); } throw err; } }};",a=new Function("defs",o);return a(r)},n.prototype._compile=function(){throw new Error("Cannot compile a Node interface")},n.prototype.find=function(e){return this.match(e)?[this]:[]},n.prototype.match=function(e){var r=!0;if(e){!e.type||this instanceof e.type||(r=!1);var t=e.properties;if(r&&t)for(var n in t)if(t.hasOwnProperty(n)&&this[n]!==t[n]){r=!1;break}}return r},n.prototype.toString=function(){return""},n.isNode=function(e){return e instanceof n},e.exports=n},function(e,r,t){function n(e,t){if(Array.isArray(e)){for(var i="[",o=e.length,a=0;o>a;a++)0!=a&&(i+=", "),i+=n(e[a],t);return i+="]"}return r.format(e,t)}var i=t(148),o=t(245),a=t(112);r.isString=function(e){return e instanceof String||"string"==typeof e},r.endsWith=function(e,r){var t=e.length-r.length,n=e.length;return e.substring(t,n)===r},r.format=function(e,t){return i.isNumber(e)?i.format(e,t):e instanceof a?o.format(e,t):Array.isArray(e)?n(e,t):r.isString(e)?'"'+e+'"':"function"==typeof e?e.syntax?e.syntax+"":"function":e instanceof Object?"function"==typeof e.format?e.format(t):e.toString():String(e)}},function(e){e.exports={name:"e",category:"Constants",syntax:["e"],description:"Euler's number, the base of the natural logarithm. Approximately equal to 2.71828",examples:["e","e ^ 2","exp(2)","log(e)"],seealso:["exp"]}},function(e){e.exports={name:"false",category:"Constants",syntax:["false"],description:"Boolean value false",examples:["false"],seealso:["true"]}},function(e){e.exports={name:"i",category:"Constants",syntax:["i"],description:"Imaginary unit, defined as i*i=-1. A complex number is described as a + b*i, where a is the real part, and b is the imaginary part.",examples:["i","i * i","sqrt(-1)"],seealso:[]}},function(e){e.exports={name:"Infinity",category:"Constants",syntax:["Infinity"],description:"Infinity, a number which is larger than the maximum number that can be handled by a floating point number.",examples:["Infinity","1 / 0"],seealso:[]}},function(e){e.exports={name:"LN2",category:"Constants",syntax:["LN2"],description:"Returns the natural logarithm of 2, approximately equal to 0.693",examples:["LN2","log(2)"],seealso:[]}},function(e){e.exports={name:"LN10",category:"Constants",syntax:["LN10"],description:"Returns the natural logarithm of 10, approximately equal to 2.302",examples:["LN10","log(10)"],seealso:[]}},function(e){e.exports={name:"LOG2E",category:"Constants",syntax:["LOG2E"],description:"Returns the base-2 logarithm of E, approximately equal to 1.442",examples:["LOG2E","log(e, 2)"],seealso:[]}},function(e){e.exports={name:"LOG10E",category:"Constants",syntax:["LOG10E"],description:"Returns the base-10 logarithm of E, approximately equal to 0.434",examples:["LOG10E","log(e, 10)"],seealso:[]}},function(e){e.exports={name:"NaN",category:"Constants",syntax:["NaN"],description:"Not a number",examples:["NaN","0 / 0"],seealso:[]}},function(e){e.exports={name:"pi",category:"Constants",syntax:["pi"],description:"The number pi is a mathematical constant that is the ratio of a circle's circumference to its diameter, and is approximately equal to 3.14159",examples:["pi","sin(pi/2)"],seealso:["tau"]}},function(e){e.exports={name:"SQRT1_2",category:"Constants",syntax:["SQRT1_2"],description:"Returns the square root of 1/2, approximately equal to 0.707",examples:["SQRT1_2","sqrt(1/2)"],seealso:[]}},function(e){e.exports={name:"SQRT2",category:"Constants",syntax:["SQRT2"],description:"Returns the square root of 2, approximately equal to 1.414",examples:["SQRT2","sqrt(2)"],seealso:[]}},function(e){e.exports={name:"tau",category:"Constants",syntax:["pi"],description:"Tau is the ratio constant of a circle's circumference to radius, equal to 2 * pi, approximately 6.2832.",examples:["tau","2 * pi"],seealso:["pi"]}},function(e){e.exports={name:"true",category:"Constants",syntax:["true"],description:"Boolean value true",examples:["true"],seealso:["false"]}},function(e,r,t){function n(e){for(var r=[];l(e);)r.push(e.length),e=e[0];return r}function i(e,r,t){var n,o=e.length;if(o!=r[t])throw new f(o,r[t]);if(tn;n++){var s=e[n];if(!l(s))throw new f(r.length-1,r.length,"<");i(e[n],r,a)}}else for(n=0;o>n;n++)if(l(e[n]))throw new f(r.length+1,r.length,">")}function o(e,r,t,n){if(!l(e))throw Error("Array expected");var i,a,s=e.length,f=r[t],c=Math.min(s,f);if(e.length=f,ti;i++)a=e[i],o(a,r,p,n);for(i=c;f>i;i++)a=[],e[i]=a,o(a,r,p,n)}else if(void 0!==n)for(i=s;f>i;i++)e[i]=u.clone(n)}var a=t(148),s=t(132),u=t(3),f=(t(150),t(114)),c=t(115),l=Array.isArray;r.size=function(e){var t=n(e);return r.validate(e,t),t},r.validate=function(e,r){var t=0==r.length;if(t){if(l(e))throw new f(e.length,0)}else i(e,r,0)},r.validateIndex=function(e,r){if(!a.isNumber(e)||!a.isInteger(e))throw new TypeError("Index must be an integer (value: "+e+")");if(0>e)throw new c(e);if(void 0!==r&&e>=r)throw new c(e,r)},r.resize=function(e,r,t){if(!l(e)||!l(r))throw new TypeError("Array expected");if(0===r.length)throw new Error("Resizing to scalar is not supported");r.forEach(function(e){if(!a.isNumber(e)||!a.isInteger(e)||0>e)throw new TypeError("Invalid size, must contain positive integers (size: "+s.format(r)+")")});for(var n=1,i=e[0];l(i);)n++,i=i[0];for(;nr.length;)e=e[0],n--;return o(e,r,0,t),e},r.squeeze=function(e){for(;l(e)&&1===e.length;)e=e[0];return e},r.unsqueeze=function(e,t){for(var n=r.size(e),i=0,o=t-n.length;o>i;i++)e=[e];return e},r.flatten=function(e){for(var r=e,t=Array.isArray;t(r[0]);){for(var n=[],i=0,o=r.length;o>i;i++)n=n.concat.apply(n,r[i]);r=n}return r},r.isArray=l},function(e,r){r.isNumber=function(e){return e instanceof Number||"number"==typeof e},r.isInteger=function(e){return e==Math.round(e)},r.sign=function(e){return e>0?1:0>e?-1:0},r.format=function(e,t){if("function"==typeof t)return t(e);if(1/0===e)return"Infinity";if(e===-1/0)return"-Infinity";if(isNaN(e))return"NaN";var n="auto",i=void 0;switch(void 0!==t&&(t.notation&&(n=t.notation),r.isNumber(t)?i=t:t.precision&&(i=t.precision)),n){case"fixed":return r.toFixed(e,i);case"exponential":return r.toExponential(e,i);case"auto":var o=.001,a=1e5;if(t&&t.exponential&&(void 0!==t.exponential.lower&&(o=t.exponential.lower),void 0!==t.exponential.upper&&(a=t.exponential.upper)),0===e)return"0";var s,u=Math.abs(e);if(u>=o&&a>u){var f=i?e.toPrecision(Math.min(i,21)):e.toPrecision();s=parseFloat(f)+""}else s=r.toExponential(e,i);return s.replace(/((\.\d*?)(0+))($|e)/,function(){var e=arguments[2],r=arguments[4];return"."!==e?e+r:r});default:throw new Error('Unknown notation "'+n+'". Choose "auto", "exponential", or "fixed".')}},r.toExponential=function(e,r){return void 0!==r?e.toExponential(Math.min(r-1,20)):e.toExponential()},r.toFixed=function(e,r){return e.toFixed(Math.min(r,20))},r.digits=function(e){return e.toExponential().replace(/e.*$/,"").replace(/^0\.?0*|\./,"").length},r.DBL_EPSILON=Number.EPSILON||2.220446049250313e-16,r.nearlyEqual=function(e,t,n){if(null==n)return e==t;if(e==t)return!0;if(isNaN(e)||isNaN(t))return!1;if(isFinite(e)&&isFinite(t)){var i=Math.abs(e-t);return i y","larger(x, y)"],description:"Check if value x is larger than y. Returns true if x is larger than y, and false if not.",examples:["2 > 3","5 > 2*2","a = 3.3","b = 6-2.8","(a > b)","(b < a)","5 cm > 2 inch"],seealso:["equal","unequal","smaller","smallereq","largereq","compare"]}},function(e){e.exports={name:"largereq",category:"Operators",syntax:["x >= y","largereq(x, y)"],description:"Check if value x is larger or equal to y. Returns true if x is larger or equal to y, and false if not.",examples:["2 > 1+1","2 >= 1+1","a = 3.2","b = 6-2.8","(a > b)"],seealso:["equal","unequal","smallereq","smaller","largereq","compare"]} +},function(e){e.exports={name:"lcm",category:"Arithmetic",syntax:["lcm(x, y)"],description:"Compute the least common multiple.",examples:["lcm(4, 6)","lcm(6, 21)","lcm(6, 21, 5)"],seealso:["gcd"]}},function(e){e.exports={name:"log",category:"Arithmetic",syntax:["log(x)","log(x, base)"],description:"Compute the logarithm of a value. If no base is provided, the natural logarithm of x is calculated. If base if provided, the logarithm is calculated for the specified base. log(x, base) is defined as log(x) / log(base).",examples:["log(3.5)","a = log(2.4)","exp(a)","10 ^ 3","log(1000, 10)","log(1000) / log(10)","b = logb(1024, 2)","2 ^ b"],seealso:["exp","log10"]}},function(e){e.exports={name:"log10",category:"Arithmetic",syntax:["log10(x)"],description:"Compute the 10-base logarithm of a value.",examples:["log10(1000)","10 ^ 3","log10(0.01)","log(1000) / log(10)","log(1000, 10)"],seealso:["exp","log"]}},function(e){e.exports={name:"mod",category:"Operators",syntax:["x % y","x mod y","mod(x, y)"],description:"Calculates the modulus, the remainder of an integer division.",examples:["7 % 3","11 % 2","10 mod 4","function isOdd(x) = x % 2","isOdd(2)","isOdd(3)"],seealso:[]}},function(e){e.exports={name:"multiply",category:"Operators",syntax:["x * y","multiply(x, y)"],description:"multiply two values.",examples:["2.1 * 3.6","ans / 3.6","2 * 3 + 4","2 * (3 + 4)","3 * 2.1 km"],seealso:["divide"]}},function(e){e.exports={name:"norm",category:"Arithmetic",syntax:["norm(x)","norm(x, p)"],description:"Calculate the norm of a number, vector or matrix.",examples:["norm([[1, 2], [3, 4]])","norm([[1, 2, 3, 4]], 3.5)","norm(-4.2)","norm([[1, 2], [-3, -4]], 'fro')"]}},function(e){e.exports={name:"pow",category:"Operators",syntax:["x ^ y","pow(x, y)"],description:"Calculates the power of x to y, x^y.",examples:["2^3 = 8","2*2*2","1 + e ^ (pi * i)"],seealso:["unequal","smaller","larger","smallereq","largereq"]}},function(e){e.exports={name:"round",category:"Arithmetic",syntax:["round(x)","round(x, n)"],description:"round a value towards the nearest integer.If x is complex, both real and imaginary part are rounded towards the nearest integer. When n is specified, the value is rounded to n decimals.",examples:["round(3.2)","round(3.8)","round(-4.2)","round(-4.8)","round(pi, 3)","round(123.45678, 2)"],seealso:["ceil","floor","fix"]}},function(e){e.exports={name:"sign",category:"Arithmetic",syntax:["sign(x)"],description:"Compute the sign of a value. The sign of a value x is 1 when x>1, -1 when x<0, and 0 when x=0.",examples:["sign(3.5)","sign(-4.2)","sign(0)"],seealso:["abs"]}},function(e){e.exports={name:"smaller",category:"Operators",syntax:["x < y","smaller(x, y)"],description:"Check if value x is smaller than value y. Returns true if x is smaller than y, and false if not.",examples:["2 < 3","5 < 2*2","a = 3.3","b = 6-2.8","(a < b)","5 cm < 2 inch"],seealso:["equal","unequal","larger","smallereq","largereq","compare"]}},function(e){e.exports={name:"smallereq",category:"Operators",syntax:["x <= y","smallereq(x, y)"],description:"Check if value x is smaller or equal to value y. Returns true if x is smaller than y, and false if not.",examples:["2 < 1+1","2 <= 1+1","a = 3.2","b = 6-2.8","(a < b)"],seealso:["equal","unequal","larger","smaller","largereq","compare"]}},function(e){e.exports={name:"sqrt",category:"Arithmetic",syntax:["sqrt(x)"],description:"Compute the square root value. If x = y * y, then y is the square root of x.",examples:["sqrt(25)","5 * 5","sqrt(-1)"],seealso:["square","multiply"]}},function(e){e.exports={name:"square",category:"Arithmetic",syntax:["square(x)"],description:"Compute the square of a value. The square of x is x * x.",examples:["square(3)","sqrt(9)","3^2","3 * 3"],seealso:["multiply","pow","sqrt","cube"]}},function(e){e.exports={name:"subtract",category:"Operators",syntax:["x - y","subtract(x, y)"],description:"subtract two values.",examples:["5.3 - 2","ans + 2","2/3 - 1/6","2 * 3 - 3","2.1 km - 500m"],seealso:["add"]}},function(e){e.exports={name:"unary",category:"Operators",syntax:["-x","unary(x)"],description:"Inverse the sign of a value.",examples:["-4.5","-(-5.6)"],seealso:["add","subtract"]}},function(e){e.exports={name:"unequal",category:"Operators",syntax:["x != y","unequal(x, y)"],description:"Check unequality of two values. Returns true if the values are unequal, and false if they are equal.",examples:["2+2 != 3","2+2 != 4","a = 3.2","b = 6-2.8","a != b","50cm != 0.5m","5 cm != 2 inch"],seealso:["equal","smaller","larger","smallereq","largereq","compare"]}},function(e){e.exports={name:"xgcd",category:"Arithmetic",syntax:["xgcd(a, b)"],description:"Calculate the extended greatest common divisor for two values",examples:["xgcd(8, 12)","gcd(8, 12)","xgcd(36163, 21199)"],seealso:["gcd","lcm"]}},function(e){e.exports={name:"arg",category:"Complex",syntax:["arg(x)"],description:"Compute the argument of a complex value. If x = a+bi, the argument is computed as atan2(b, a).",examples:["arg(2 + 2i)","atan2(3, 2)","arg(2 - 3i)"],seealso:["re","im","conj","abs"]}},function(e){e.exports={name:"conj",category:"Complex",syntax:["conj(x)"],description:"Compute the complex conjugate of a complex value. If x = a+bi, the complex conjugate is a-bi.",examples:["conj(2 + 3i)","conj(2 - 3i)","conj(-5.2i)"],seealso:["re","im","abs","arg"]}},function(e){e.exports={name:"re",category:"Complex",syntax:["re(x)"],description:"Get the real part of a complex number.",examples:["re(2 + 3i)","im(2 + 3i)","re(-5.2i)","re(2.4)"],seealso:["im","conj","abs","arg"]}},function(e){e.exports={name:"im",category:"Complex",syntax:["im(x)"],description:"Get the imaginary part of a complex number.",examples:["im(2 + 3i)","re(2 + 3i)","im(-5.2i)","im(2.4)"],seealso:["re","conj","abs","arg"]}},function(e){e.exports={name:"bignumber",category:"Type",syntax:["bignumber(x)"],description:"Create a big number from a number or string.",examples:["0.1 + 0.2","bignumber(0.1) + bignumber(0.2)",'bignumber("7.2")','bignumber("7.2e500")',"bignumber([0.1, 0.2, 0.3])"],seealso:["boolean","complex","index","matrix","string","unit"]}},function(e){e.exports={name:"boolean",category:"Type",syntax:["x","boolean(x)"],description:"Convert a string or number into a boolean.",examples:["boolean(0)","boolean(1)","boolean(3)",'boolean("true")','boolean("false")',"boolean([1, 0, 1, 1])"],seealso:["bignumber","complex","index","matrix","number","string","unit"]}},function(e){e.exports={name:"complex",category:"Type",syntax:["complex()","complex(re, im)","complex(string)"],description:"Create a complex number.",examples:["complex()","complex(2, 3)",'complex("7 - 2i")'],seealso:["bignumber","boolean","index","matrix","number","string","unit"]}},function(e){e.exports={name:"index",category:"Type",syntax:["[start]","[start:end]","[start:step:end]","[start1, start 2, ...]","[start1:end1, start2:end2, ...]","[start1:step1:end1, start2:step2:end2, ...]"],description:"Create an index to get or replace a subset of a matrix",examples:["[]","[1, 2, 3]","A = [1, 2, 3; 4, 5, 6]","A[1, :]","A[1, 2] = 50","A[0:2, 0:2] = ones(2, 2)"],seealso:["bignumber","boolean","complex","matrix,","number","range","string","unit"]}},function(e){e.exports={name:"matrix",category:"Type",syntax:["[]","[a1, b1, ...; a2, b2, ...]","matrix()","matrix([...])"],description:"Create a matrix.",examples:["[]","[1, 2, 3]","[1, 2, 3; 4, 5, 6]","matrix()","matrix([3, 4])"],seealso:["bignumber","boolean","complex","index","number","string","unit"]}},function(e){e.exports={name:"number",category:"Type",syntax:["x","number(x)"],description:"Create a number or convert a string or boolean into a number.",examples:["2","2e3","4.05","number(2)",'number("7.2")',"number(true)","number([true, false, true, true])"],seealso:["bignumber","boolean","complex","index","matrix","string","unit"]}},function(e){e.exports={name:"string",category:"Type",syntax:['"text"',"string(x)"],description:"Create a string or convert a value to a string",examples:['"Hello World!"',"string(4.2)","string(3 + 2i)"],seealso:["bignumber","boolean","complex","index","matrix","number","unit"]}},function(e){e.exports={name:"unit",category:"Type",syntax:["value unit","unit(value, unit)","unit(string)"],description:"Create a unit.",examples:["5.5 mm","3 inch",'unit(7.1, "kilogram")','unit("23 deg")'],seealso:["bignumber","boolean","complex","index","matrix","number","string"]}},function(e){e.exports={name:"eval",category:"Expression",syntax:["eval(expression)","eval([expr1, expr2, expr3, ...])"],description:"Evaluate an expression or an array with expressions.",examples:['eval("2 + 3")','eval("sqrt(" + 4 + ")")'],seealso:[]}},function(e){e.exports={name:"help",category:"Expression",syntax:["help(object)","help(string)"],description:"Display documentation on a function or data type.",examples:["help(sqrt)",'help("complex")'],seealso:[]}},function(e){e.exports={name:"concat",category:"Matrix",syntax:["concat(a, b, c, ...)","concat(a, b, c, ..., dim)"],description:"Concatenate matrices. By default, the matrices are concatenated by the first dimension. The dimension on which to concatenate can be provided as last argument.",examples:["a = [1, 2; 5, 6]","b = [3, 4; 7, 8]","concat(a, b)","[a, b]","concat(a, b, 2)","[a; b]"],seealso:["det","diag","eye","inv","ones","range","size","squeeze","subset","transpose","zeros"]}},function(e){e.exports={name:"det",category:"Matrix",syntax:["det(x)"],description:"Calculate the determinant of a matrix",examples:["det([1, 2; 3, 4])","det([-2, 2, 3; -1, 1, 3; 2, 0, -1])"],seealso:["concat","diag","eye","inv","ones","range","size","squeeze","subset","transpose","zeros"]}},function(e){e.exports={name:"diag",category:"Matrix",syntax:["diag(x)","diag(x, k)"],description:"Create a diagonal matrix or retrieve the diagonal of a matrix. When x is a vector, a matrix with the vector values on the diagonal will be returned. When x is a matrix, a vector with the diagonal values of the matrix is returned.When k is provided, the k-th diagonal will be filled in or retrieved, if k is positive, the values are placed on the super diagonal. When k is negative, the values are placed on the sub diagonal.",examples:["diag(1:3)","diag(1:3, 1)","a = [1, 2, 3; 4, 5, 6; 7, 8, 9]","diag(a)"],seealso:["concat","det","eye","inv","ones","range","size","squeeze","subset","transpose","zeros"]}},function(e){e.exports={name:"eye",category:"Matrix",syntax:["eye(n)","eye(m, n)","eye([m, n])","eye"],description:"Returns the identity matrix with size m-by-n. The matrix has ones on the diagonal and zeros elsewhere.",examples:["eye(3)","eye(3, 5)","a = [1, 2, 3; 4, 5, 6]","eye(size(a))"],seealso:["concat","det","diag","inv","ones","range","size","squeeze","subset","transpose","zeros"]}},function(e){e.exports={name:"inv",category:"Matrix",syntax:["inv(x)"],description:"Calculate the inverse of a matrix",examples:["inv([1, 2; 3, 4])","inv(4)","1 / 4"],seealso:["concat","det","diag","eye","ones","range","size","squeeze","subset","transpose","zeros"]}},function(e){e.exports={name:"ones",category:"Matrix",syntax:["ones(m)","ones(m, n)","ones(m, n, p, ...)","ones([m])","ones([m, n])","ones([m, n, p, ...])","ones"],description:"Create a matrix containing ones.",examples:["ones(3)","ones(3, 5)","ones([2,3]) * 4.5","a = [1, 2, 3; 4, 5, 6]","ones(size(a))"],seealso:["concat","det","diag","eye","inv","range","size","squeeze","subset","transpose","zeros"]}},function(e){e.exports={name:"range",category:"Type",syntax:["start:end","start:step:end","range(start, end)","range(start, end, step)","range(string)"],description:"Create a range. Lower bound of the range is included, upper bound is excluded.",examples:["1:5","3:-1:-3","range(3, 7)","range(0, 12, 2)",'range("4:10")',"a = [1, 2, 3, 4; 5, 6, 7, 8]","a[1:2, 1:2]"],seealso:["concat","det","diag","eye","inv","ones","size","squeeze","subset","transpose","zeros"]}},function(e){e.exports={name:"resize",category:"Matrix",syntax:["resize(x, size)","resize(x, size, defaultValue)"],description:"Resize a matrix.",examples:["resize([1,2,3,4,5], [3])","resize([1,2,3], [5], 0)","resize(2, [2, 3], 0)",'resize("hello", [8], "!")'],seealso:["size","subset","squeeze"]}},function(e){e.exports={name:"size",category:"Matrix",syntax:["size(x)"],description:"Calculate the size of a matrix.",examples:["size(2.3)",'size("hello world")',"a = [1, 2; 3, 4; 5, 6]","size(a)","size(1:6)"],seealso:["concat","det","diag","eye","inv","ones","range","squeeze","subset","transpose","zeros"]}},function(e){e.exports={name:"squeeze",category:"Matrix",syntax:["squeeze(x)"],description:"Remove singleton dimensions from a matrix.",examples:["a = zeros(1,3,2)","size(squeeze(a))","b = zeros(3,1,1)","size(squeeze(b))"],seealso:["concat","det","diag","eye","inv","ones","range","size","subset","transpose","zeros"]}},function(e){e.exports={name:"subset",category:"Matrix",syntax:["value(index)","value(index) = replacement","subset(value, [index])","subset(value, [index], replacement)"],description:"Get or set a subset of a matrix or string. Indexes are one-based. Both the ranges lower-bound and upper-bound are included.",examples:["d = [1, 2; 3, 4]","e = []","e[1, 1:2] = [5, 6]","e[2, :] = [7, 8]","f = d * e","f[2, 1]","f[:, 1]"],seealso:["concat","det","diag","eye","inv","ones","range","size","squeeze","transpose","zeros"]}},function(e){e.exports={name:"transpose",category:"Matrix",syntax:["x'","transpose(x)"],description:"Transpose a matrix",examples:["a = [1, 2, 3; 4, 5, 6]","a'","transpose(a)"],seealso:["concat","det","diag","eye","inv","ones","range","size","squeeze","subset","zeros"]}},function(e){e.exports={name:"zeros",category:"Matrix",syntax:["zeros(m)","zeros(m, n)","zeros(m, n, p, ...)","zeros([m])","zeros([m, n])","zeros([m, n, p, ...])","zeros"],description:"Create a matrix containing zeros.",examples:["zeros(3)","zeros(3, 5)","a = [1, 2, 3; 4, 5, 6]","zeros(size(a))"],seealso:["concat","det","diag","eye","inv","ones","range","size","squeeze","subset","transpose"]}},function(e){e.exports={name:"combinations",category:"Probability",syntax:["combinations(n, k)"],description:"Compute the number of combinations of n items taken k at a time",examples:["combinations(7, 5)"],seealso:["permutations","factorial"]}},function(e){e.exports={name:"distribution",category:"Probability",syntax:["distribution(name)","distribution(name, arg1, arg2, ...)"],description:'Create a distribution object of a specific type. A distribution object contains functions `random([size,] [min,] [max])`, `randomInt([size,] [min,] [max])`, and `pickRandom(array)`. Available types of distributions: "uniform", "normal". Note that the function distribution is currently not available via the expression parser.',examples:[],seealso:["random","randomInt"]}},function(e){e.exports={name:"factorial",category:"Probability",syntax:["n!","factorial(n)"],description:"Compute the factorial of a value",examples:["5!","5*4*3*2*1","3!"],seealso:[]}},function(e){e.exports={name:"permutations",category:"Probability",syntax:["permutations(n)","permutations(n, k)"],description:"Compute the number of permutations of n items taken k at a time",examples:["permutations(5)","permutations(5, 4)"],seealso:["combinations","factorial"]}},function(e){e.exports={name:"pickRandom",category:"Probability",syntax:["pickRandom(array)"],description:"Pick a random entry from a given array.",examples:["pickRandom(0:10)","pickRandom([1, 3, 1, 6])"],seealso:["distribution","random","randomInt"]}},function(e){e.exports={name:"random",category:"Probability",syntax:["random()","random(max)","random(min, max)","random(size)","random(size, max)","random(size, min, max)"],description:"Return a random number.",examples:["random()","random(10, 20)","random([2, 3])"],seealso:["distribution","pickRandom","randomInt"]}},function(e){e.exports={name:"randInt",category:"Probability",syntax:["randInt()","randInt(max)","randInt(min, max)","randInt(size)","randInt(size, max)","randInt(size, min, max)"],description:"Return a random integer number",examples:["randInt()","randInt(10, 20)","randInt([2, 3], 10)"],seealso:["distribution","pickRandom","random"]}},function(e){e.exports={name:"max",category:"Statistics",syntax:["max(a, b, c, ...)","max(A)","max(A, dim)"],description:"Compute the maximum value of a list of values.",examples:["max(2, 3, 4, 1)","max([2, 3, 4, 1])","max([2, 5; 4, 3], 0)","max([2, 5; 4, 3], 1)","max(2.7, 7.1, -4.5, 2.0, 4.1)","min(2.7, 7.1, -4.5, 2.0, 4.1)"],seealso:["mean","median","min","prod","std","sum","var"]}},function(e){e.exports={name:"mean",category:"Statistics",syntax:["mean(a, b, c, ...)","mean(A)","mean(A, dim)"],description:"Compute the arithmetic mean of a list of values.",examples:["mean(2, 3, 4, 1)","mean([2, 3, 4, 1])","mean([2, 5; 4, 3], 0)","mean([2, 5; 4, 3], 1)","mean([1.0, 2.7, 3.2, 4.0])"],seealso:["max","median","min","prod","std","sum","var"]}},function(e){e.exports={name:"median",category:"Statistics",syntax:["median(a, b, c, ...)","median(A)"],description:"Compute the median of all values. The values are sorted and the middle value is returned. In case of an even number of values, the average of the two middle values is returned.",examples:["median(4, 2, 7)","median([3, -1, 5, 7])"],seealso:["max","mean","min","prod","std","sum","var"]}},function(e){e.exports={name:"min",category:"Statistics",syntax:["min(a, b, c, ...)","min(A)","min(A, dim)"],description:"Compute the minimum value of a list of values.",examples:["min(2, 3, 4, 1)","min([2, 3, 4, 1])","min([2, 5; 4, 3], 0)","min([2, 5; 4, 3], 1)","min(2.7, 7.1, -4.5, 2.0, 4.1)","max(2.7, 7.1, -4.5, 2.0, 4.1)"],seealso:["max","mean","median","prod","std","sum","var"]}},function(e){e.exports={name:"prod",category:"Statistics",syntax:["prod(a, b, c, ...)","prod(A)"],description:"Compute the product of all values.",examples:["prod(2, 3, 4)","prod([2, 3, 4])","prod([2, 5; 4, 3])"],seealso:["max","mean","min","median","min","std","sum","var"]}},function(e){e.exports={name:"std",category:"Statistics",syntax:["std(a, b, c, ...)","std(A)","std(A, normalization)"],description:'Compute the standard deviation of all values, defined as std(A) = sqrt(var(A)). Optional parameter normalization can be "unbiased" (default), "uncorrected", or "biased".',examples:["std(2, 4, 6)","std([2, 4, 6, 8])",'std([2, 4, 6, 8], "uncorrected")','std([2, 4, 6, 8], "biased")',"std([1, 2, 3; 4, 5, 6])"],seealso:["max","mean","min","median","min","prod","sum","var"]}},function(e){e.exports={name:"sum",category:"Statistics",syntax:["sum(a, b, c, ...)","sum(A)"],description:"Compute the sum of all values.",examples:["sum(2, 3, 4, 1)","sum([2, 3, 4, 1])","sum([2, 5; 4, 3])"],seealso:["max","mean","median","min","prod","std","sum","var"]}},function(e){e.exports={name:"var",category:"Statistics",syntax:["var(a, b, c, ...)","var(A)","var(A, normalization)"],description:'Compute the variance of all values. Optional parameter normalization can be "unbiased" (default), "uncorrected", or "biased".',examples:["var(2, 4, 6)","var([2, 4, 6, 8])",'var([2, 4, 6, 8], "uncorrected")','var([2, 4, 6, 8], "biased")',"var([1, 2, 3; 4, 5, 6])"],seealso:["max","mean","min","median","min","prod","std","sum"]}},function(e){e.exports={name:"acos",category:"Trigonometry",syntax:["acos(x)"],description:"Compute the inverse cosine of a value in radians.",examples:["acos(0.5)","acos(cos(2.3))"],seealso:["cos","acos","asin"]}},function(e){e.exports={name:"asin",category:"Trigonometry",syntax:["asin(x)"],description:"Compute the inverse sine of a value in radians.",examples:["asin(0.5)","asin(sin(2.3))"],seealso:["sin","acos","asin"]}},function(e){e.exports={name:"atan",category:"Trigonometry",syntax:["atan(x)"],description:"Compute the inverse tangent of a value in radians.",examples:["atan(0.5)","atan(tan(2.3))"],seealso:["tan","acos","asin"]}},function(e){e.exports={name:"atan2",category:"Trigonometry",syntax:["atan2(y, x)"],description:"Computes the principal value of the arc tangent of y/x in radians.",examples:["atan2(2, 2) / pi","angle = 60 deg in rad","x = cos(angle)","y = sin(angle)","atan2(y, x)"],seealso:["sin","cos","tan"]}},function(e){e.exports={name:"cos",category:"Trigonometry",syntax:["cos(x)"],description:"Compute the cosine of x in radians.",examples:["cos(2)","cos(pi / 4) ^ 2","cos(180 deg)","cos(60 deg)","sin(0.2)^2 + cos(0.2)^2"],seealso:["acos","sin","tan"]}},function(e){e.exports={name:"cot",category:"Trigonometry",syntax:["cot(x)"],description:"Compute the cotangent of x in radians. Defined as 1/tan(x)",examples:["cot(2)","1 / tan(2)"],seealso:["sec","csc","tan"]}},function(e){e.exports={name:"csc",category:"Trigonometry",syntax:["csc(x)"],description:"Compute the cosecant of x in radians. Defined as 1/sin(x)",examples:["csc(2)","1 / sin(2)"],seealso:["sec","cot","sin"]}},function(e){e.exports={name:"sec",category:"Trigonometry",syntax:["sec(x)"],description:"Compute the secant of x in radians. Defined as 1/cos(x)",examples:["sec(2)","1 / cos(2)"],seealso:["cot","csc","cos"]}},function(e){e.exports={name:"sin",category:"Trigonometry",syntax:["sin(x)"],description:"Compute the sine of x in radians.",examples:["sin(2)","sin(pi / 4) ^ 2","sin(90 deg)","sin(30 deg)","sin(0.2)^2 + cos(0.2)^2"],seealso:["asin","cos","tan"]}},function(e){e.exports={name:"tan",category:"Trigonometry",syntax:["tan(x)"],description:"Compute the tangent of x in radians.",examples:["tan(0.5)","sin(0.5) / cos(0.5)","tan(pi / 4)","tan(45 deg)"],seealso:["atan","sin","cos"]}},function(e){e.exports={name:"to",category:"Units",syntax:["x to unit","to(x, unit)"],description:"Change the unit of a value.",examples:["5 inch in cm","3.2kg in g","16 bytes in bits"],seealso:[]}},function(e){e.exports={name:"clone",category:"Utils",syntax:["clone(x)"],description:"Clone a variable. Creates a copy of primitive variables,and a deep copy of matrices",examples:["clone(3.5)","clone(2 - 4i)","clone(45 deg)","clone([1, 2; 3, 4])",'clone("hello world")'],seealso:[]}},function(e){e.exports={name:"map",category:"Utils",syntax:["map(x, callback)"],description:"Create a new matrix or array with the results of the callback function executed on each entry of the matrix/array.",examples:["map([1, 2, 3], function(val) { return math.max(val, 1.5) })"],seealso:[]}},function(e){e.exports={name:"forEach",category:"Utils",syntax:["forEach(x, callback)"],description:"Iterates over all elements of a matrix/array, and executes the given callback.",examples:["forEach([1, 2, 3], function(val) { console.log(val) })"],seealso:[]}},function(e){e.exports={name:"format",category:"Utils",syntax:["format(value)","format(value, precision)"],description:"Format a value of any type as string.",examples:["format(2.3)","format(3 - 4i)","format([])","format(pi, 3)"],seealso:["print"]}},function(e){e.exports={name:"ifElse",category:"Utils",syntax:["ifElse(conditional, trueExpr, falseExpr)"],description:"Executes a conditional expression.",examples:["ifElse(10 > 0, 10, 0)",'ifElse("", true, false)',"ifElse([4, 6, 0, -1], true, false)"],seealso:[]}},function(e){e.exports={name:"import",category:"Utils",syntax:["import(string)"],description:"Import functions from a file.",examples:['import("numbers")','import("./mylib.js")'],seealso:[]}},function(e){e.exports={name:"typeof",category:"Utils",syntax:["typeof(x)"],description:"Get the type of a variable.",examples:["typeof(3.5)","typeof(2 - 4i)","typeof(45 deg)",'typeof("hello world")'],seealso:[]}},function(e,r){r.isBoolean=function(e){return e instanceof Boolean||"boolean"==typeof e}},function(e,r,t){var n=t(112),i=t(148).isNumber;digits=t(148).digits,r.isBigNumber=function(e){return e instanceof n},r.format=function(e,t){if("function"==typeof t)return t(e);if(!e.isFinite())return e.isNaN()?"NaN":e.gt(0)?"Infinity":"-Infinity";var n="auto",o=void 0;switch(void 0!==t&&(t.notation&&(n=t.notation),i(t)?o=t:t.precision&&(o=t.precision)),n){case"fixed":return r.toFixed(e,o);case"exponential":return r.toExponential(e,o);case"auto":var a=.001,s=1e5;t&&t.exponential&&(void 0!==t.exponential.lower&&(a=t.exponential.lower),void 0!==t.exponential.upper&&(s=t.exponential.upper));{({toExpNeg:e.constructor.toExpNeg,toExpPos:e.constructor.toExpPos})}if(e.constructor.config({toExpNeg:Math.round(Math.log(a)/Math.LN10),toExpPos:Math.round(Math.log(s)/Math.LN10)}),e.isZero())return"0";var u,f=e.abs();return u=f.gte(a)&&f.lt(s)?e.toSignificantDigits(o).toFixed():r.toExponential(e,o),u.replace(/((\.\d*?)(0+))($|e)/,function(){var e=arguments[2],r=arguments[4];return"."!==e?e+r:r});default:throw new Error('Unknown notation "'+n+'". Choose "auto", "exponential", or "fixed".')}},r.toExponential=function(e,r){return void 0!==r?e.toExponential(r-1):e.toExponential()},r.toFixed=function(e,r){return e.toFixed(r||0)}},function(e,r,t){function n(){var e=[].slice.call(arguments).join(" ");throw new Error([e,"we accept pull requests","http://github.com/dominictarr/crypto-browserify"].join("\n"))}function i(e,r){for(var t in e)r(e[t],t)}var o=t(252).Buffer,a=t(248);r.createHash=t(249),r.createHmac=t(250),r.randomBytes=function(e,r){if(!r||!r.call)return new o(a(e));try{r.call(this,void 0,new o(a(e)))}catch(t){r(t)}};var s=t(251)(r.createHmac);r.pbkdf2=s.pbkdf2,r.pbkdf2Sync=s.pbkdf2Sync,i(["createCredentials","createCipher","createCipheriv","createDecipher","createDecipheriv","createSign","createVerify","createDiffieHellman"],function(e){r[e]=function(){n("sorry,",e,"is not implemented yet")}})},function(e){e.exports=function(e){return e.webpackPolyfill||(e.deprecate=function(){},e.paths=[],e.children=[],e.webpackPolyfill=1),e}},function(e,r,t){(function(r){!function(){var t,n,i=this;t=function(e){for(var t,t,n=new r(e),i=0;e>i;i++)0==(3&i)&&(t=4294967296*Math.random()),n[i]=t>>>((3&i)<<3)&255;return n},i.crypto&&crypto.getRandomValues&&(n=function(e){var t=new r(e);return crypto.getRandomValues(t.buffer||t),t}),e.exports=n||t}()}).call(r,t(252).Buffer)},function(e,r,t){(function(r){function n(e){return function(){var t=[],n={update:function(e,n){return r.isBuffer(e)||(e=new r(e,n)),t.push(e),this},digest:function(n){var i=r.concat(t),o=e(i);return t=null,n?o.toString(n):o}};return n}}var i=t(254),o=n(t(253));e.exports=function(e){return"md5"===e?new o:i(e)}}).call(r,t(252).Buffer)},function(e,r,t){(function(r){function n(e,t){if(!(this instanceof n))return new n(e,t);this._opad=u,this._alg=e,t=this._key=r.isBuffer(t)?t:new r(t),t.length>o?t=i(e).update(t).digest():t.lengthf;f++)s[f]=54^t[f],u[f]=92^t[f];this._hash=i(e).update(s)}var i=t(249),o=64,a=new r(o);a.fill(0),e.exports=n,n.prototype.update=function(e,r){return this._hash.update(e,r),this},n.prototype.digest=function(e){var r=this._hash.digest();return i(this._alg).update(this._opad).update(r).digest(e)}}).call(r,t(252).Buffer)},function(e,r,t){var n=t(252).Buffer,i=64,o=new n(i);o.fill(0),e.exports=function(e,r){return r=r||{},r.pbkdf2=function(e,t,n,i,o){if("function"!=typeof o)throw new Error("No callback provided to pbkdf2");setTimeout(function(){cb(null,r.pbkdf2(e,t,n,i))})},r.pbkdf2Sync=function(r,t,a,s){if("number"!=typeof a)throw new TypeError("Iterations not a number");if(0>a)throw new TypeError("Bad iterations");if("number"!=typeof s)throw new TypeError("Key length not a number");if(0>s)throw new TypeError("Bad key length");var r=n.isBuffer(r)?r:new n(r);r.length>i?r=createHash(alg).update(r).digest():r.length20?20:s,m[0]=p>>24&255,m[1]=p>>16&255,m[2]=p>>8&255,m[3]=255&p,u=e("sha1",r),u.update(t),u.update(m),c=u.digest(),c.copy(h,l,0,f);for(var g=1;a>g;g++){u=e("sha1",r),u.update(c),c=u.digest();for(var d=0;f>d;d++)h[d]^=c[d]}s-=f,p++,l+=f}return h},r}},function(e,r,t){(function(e){function e(r,t,n){if(!(this instanceof e))return new e(r,t,n);var i=typeof r;if("base64"===t&&"string"===i)for(r=T(r);r.length%4!==0;)r+="=";var o;if("number"===i)o=C(r);else if("string"===i)o=e.byteLength(r,t);else{if("object"!==i)throw new Error("First argument needs to be a number, array or string.");o=C(r.length)}var a;e._useTypedArrays?a=e._augment(new Uint8Array(o)):(a=this,a.length=o,a._isBuffer=!0);var s;if(e._useTypedArrays&&"number"==typeof r.byteLength)a._set(r);else if(B(r))for(s=0;o>s;s++)a[s]=e.isBuffer(r)?r.readUInt8(s):r[s];else if("string"===i)a.write(r,0,t);else if("number"===i&&!e._useTypedArrays&&!n)for(s=0;o>s;s++)a[s]=0;return a}function n(r,t,n,i){n=Number(n)||0;var o=r.length-n;i?(i=Number(i),i>o&&(i=o)):i=o;var a=t.length;D(a%2===0,"Invalid hex string"),i>a/2&&(i=a/2);for(var s=0;i>s;s++){var u=parseInt(t.substr(2*s,2),16);D(!isNaN(u),"Invalid hex string"),r[n+s]=u}return e._charsWritten=2*s,s}function i(r,t,n,i){var o=e._charsWritten=j(U(t),r,n,i);return o}function o(r,t,n,i){var o=e._charsWritten=j(z(t),r,n,i);return o}function a(e,r,t,n){return o(e,r,t,n)}function s(r,t,n,i){var o=e._charsWritten=j(L(t),r,n,i);return o}function u(r,t,n,i){var o=e._charsWritten=j(q(t),r,n,i);return o}function f(e,r,t){return G.fromByteArray(0===r&&t===e.length?e:e.slice(r,t))}function c(e,r,t){var n="",i="";t=Math.min(e.length,t);for(var o=r;t>o;o++)e[o]<=127?(n+=R(i)+String.fromCharCode(e[o]),i=""):i+="%"+e[o].toString(16);return n+R(i)}function l(e,r,t){var n="";t=Math.min(e.length,t);for(var i=r;t>i;i++)n+=String.fromCharCode(e[i]);return n}function p(e,r,t){return l(e,r,t)}function m(e,r,t){var n=e.length;(!r||0>r)&&(r=0),(!t||0>t||t>n)&&(t=n);for(var i="",o=r;t>o;o++)i+=I(e[o]);return i}function h(e,r,t){for(var n=e.slice(r,t),i="",o=0;o=i)){var o;return t?(o=e[r],i>r+1&&(o|=e[r+1]<<8)):(o=e[r]<<8,i>r+1&&(o|=e[r+1])),o}}function d(e,r,t,n){n||(D("boolean"==typeof t,"missing or invalid endian"),D(void 0!==r&&null!==r,"missing offset"),D(r+3=i)){var o;return t?(i>r+2&&(o=e[r+2]<<16),i>r+1&&(o|=e[r+1]<<8),o|=e[r],i>r+3&&(o+=e[r+3]<<24>>>0)):(i>r+1&&(o=e[r+1]<<16),i>r+2&&(o|=e[r+2]<<8),i>r+3&&(o|=e[r+3]),o+=e[r]<<24>>>0),o}}function w(e,r,t,n){n||(D("boolean"==typeof t,"missing or invalid endian"),D(void 0!==r&&null!==r,"missing offset"),D(r+1=i)){var o=g(e,r,t,!0),a=32768&o;return a?-1*(65535-o+1):o}}function y(e,r,t,n){n||(D("boolean"==typeof t,"missing or invalid endian"),D(void 0!==r&&null!==r,"missing offset"),D(r+3=i)){var o=d(e,r,t,!0),a=2147483648&o;return a?-1*(4294967295-o+1):o}}function v(e,r,t,n){return n||(D("boolean"==typeof t,"missing or invalid endian"),D(r+3=o))for(var a=0,s=Math.min(o-t,2);s>a;a++)e[t+a]=(r&255<<8*(n?a:1-a))>>>8*(n?a:1-a)}function E(e,r,t,n,i){i||(D(void 0!==r&&null!==r,"missing value"),D("boolean"==typeof n,"missing or invalid endian"),D(void 0!==t&&null!==t,"missing offset"),D(t+3=o))for(var a=0,s=Math.min(o-t,4);s>a;a++)e[t+a]=r>>>8*(n?a:3-a)&255}function N(e,r,t,n,i){i||(D(void 0!==r&&null!==r,"missing value"),D("boolean"==typeof n,"missing or invalid endian"),D(void 0!==t&&null!==t,"missing offset"),D(t+1=o||(r>=0?b(e,r,t,n,i):b(e,65535+r+1,t,n,i))}function M(e,r,t,n,i){i||(D(void 0!==r&&null!==r,"missing value"),D("boolean"==typeof n,"missing or invalid endian"),D(void 0!==t&&null!==t,"missing offset"),D(t+3=o||(r>=0?E(e,r,t,n,i):E(e,4294967295+r+1,t,n,i))}function A(e,r,t,n,i){i||(D(void 0!==r&&null!==r,"missing value"),D("boolean"==typeof n,"missing or invalid endian"),D(void 0!==t&&null!==t,"missing offset"),D(t+3=o||V.write(e,r,t,n,23,4)}function S(e,r,t,n,i){i||(D(void 0!==r&&null!==r,"missing value"),D("boolean"==typeof n,"missing or invalid endian"),D(void 0!==t&&null!==t,"missing offset"),D(t+7=o||V.write(e,r,t,n,52,8)}function T(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}function O(e,r,t){return"number"!=typeof e?t:(e=~~e,e>=r?r:e>=0?e:(e+=r,e>=0?e:0))}function C(e){return e=~~Math.ceil(+e),0>e?0:e}function _(e){return(Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)})(e)}function B(r){return _(r)||e.isBuffer(r)||r&&"object"==typeof r&&"number"==typeof r.length}function I(e){return 16>e?"0"+e.toString(16):e.toString(16)}function U(e){for(var r=[],t=0;t=n)r.push(e.charCodeAt(t));else{var i=t;n>=55296&&57343>=n&&t++;for(var o=encodeURIComponent(e.slice(i,t+1)).substr(1).split("%"),a=0;a>8,n=r%256,i.push(n),i.push(t);return i}function L(e){return G.toByteArray(e)}function j(e,r,t,n){for(var i=0;n>i&&!(i+t>=r.length||i>=e.length);i++)r[i+t]=e[i];return i}function R(e){try{return decodeURIComponent(e)}catch(r){return String.fromCharCode(65533)}}function k(e,r){D("number"==typeof e,"cannot write a non-number as a number"),D(e>=0,"specified a negative value for writing an unsigned value"),D(r>=e,"value is larger than maximum value for type"),D(Math.floor(e)===e,"value has a fractional component")}function P(e,r,t){D("number"==typeof e,"cannot write a non-number as a number"),D(r>=e,"value larger than maximum allowed value"),D(e>=t,"value smaller than minimum allowed value"),D(Math.floor(e)===e,"value has a fractional component")}function F(e,r,t){D("number"==typeof e,"cannot write a non-number as a number"),D(r>=e,"value larger than maximum allowed value"),D(e>=t,"value smaller than minimum allowed value")}function D(e,r){if(!e)throw new Error(r||"Failed assertion")}var G=t(260),V=t(259);r.Buffer=e,r.SlowBuffer=e,r.INSPECT_MAX_BYTES=50,e.poolSize=8192,e._useTypedArrays=function(){try{var e=new ArrayBuffer(0),r=new Uint8Array(e);return r.foo=function(){return 42},42===r.foo()&&"function"==typeof r.subarray}catch(t){return!1}}(),e.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},e.isBuffer=function(e){return!(null===e||void 0===e||!e._isBuffer)},e.byteLength=function(e,r){var t;switch(e+="",r||"utf8"){case"hex":t=e.length/2;break;case"utf8":case"utf-8":t=U(e).length;break;case"ascii":case"binary":case"raw":t=e.length;break;case"base64":t=L(e).length;break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":t=2*e.length;break;default:throw new Error("Unknown encoding")}return t},e.concat=function(r,t){if(D(_(r),"Usage: Buffer.concat(list, [totalLength])\nlist should be an Array."),0===r.length)return new e(0);if(1===r.length)return r[0];var n;if("number"!=typeof t)for(t=0,n=0;nl&&(t=l)):t=l,f=String(f||"utf8").toLowerCase();var p;switch(f){case"hex":p=n(this,e,r,t);break;case"utf8":case"utf-8":p=i(this,e,r,t);break;case"ascii":p=o(this,e,r,t);break;case"binary":p=a(this,e,r,t);break;case"base64":p=s(this,e,r,t);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":p=u(this,e,r,t);break;default:throw new Error("Unknown encoding")}return p},e.prototype.toString=function(e,r,t){var n=this;if(e=String(e||"utf8").toLowerCase(),r=Number(r)||0,t=void 0!==t?Number(t):t=n.length,t===r)return"";var i;switch(e){case"hex":i=m(n,r,t);break;case"utf8":case"utf-8":i=c(n,r,t);break;case"ascii":i=l(n,r,t);break;case"binary":i=p(n,r,t);break;case"base64":i=f(n,r,t);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":i=h(n,r,t);break;default:throw new Error("Unknown encoding")}return i},e.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},e.prototype.copy=function(r,t,n,i){var o=this;if(n||(n=0),i||0===i||(i=this.length),t||(t=0),i!==n&&0!==r.length&&0!==o.length){D(i>=n,"sourceEnd < sourceStart"),D(t>=0&&t=0&&n=0&&i<=o.length,"sourceEnd out of bounds"),i>this.length&&(i=this.length),r.length-ta||!e._useTypedArrays)for(var s=0;a>s;s++)r[s+t]=this[s+n];else r._set(this.subarray(n,n+a),t)}},e.prototype.slice=function(r,t){var n=this.length;if(r=O(r,n,0),t=O(t,n,n),e._useTypedArrays)return e._augment(this.subarray(r,t));for(var i=t-r,o=new e(i,void 0,!0),a=0;i>a;a++)o[a]=this[a+r];return o},e.prototype.get=function(e){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(e)},e.prototype.set=function(e,r){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(e,r)},e.prototype.readUInt8=function(e,r){return r||(D(void 0!==e&&null!==e,"missing offset"),D(e=this.length?void 0:this[e]},e.prototype.readUInt16LE=function(e,r){return g(this,e,!0,r)},e.prototype.readUInt16BE=function(e,r){return g(this,e,!1,r)},e.prototype.readUInt32LE=function(e,r){return d(this,e,!0,r)},e.prototype.readUInt32BE=function(e,r){return d(this,e,!1,r)},e.prototype.readInt8=function(e,r){if(r||(D(void 0!==e&&null!==e,"missing offset"),D(e=this.length)){var t=128&this[e];return t?-1*(255-this[e]+1):this[e]}},e.prototype.readInt16LE=function(e,r){return w(this,e,!0,r)},e.prototype.readInt16BE=function(e,r){return w(this,e,!1,r)},e.prototype.readInt32LE=function(e,r){return y(this,e,!0,r)},e.prototype.readInt32BE=function(e,r){return y(this,e,!1,r)},e.prototype.readFloatLE=function(e,r){return v(this,e,!0,r)},e.prototype.readFloatBE=function(e,r){return v(this,e,!1,r)},e.prototype.readDoubleLE=function(e,r){return x(this,e,!0,r)},e.prototype.readDoubleBE=function(e,r){return x(this,e,!1,r)},e.prototype.writeUInt8=function(e,r,t){t||(D(void 0!==e&&null!==e,"missing value"),D(void 0!==r&&null!==r,"missing offset"),D(r=this.length||(this[r]=e)},e.prototype.writeUInt16LE=function(e,r,t){b(this,e,r,!0,t)},e.prototype.writeUInt16BE=function(e,r,t){b(this,e,r,!1,t)},e.prototype.writeUInt32LE=function(e,r,t){E(this,e,r,!0,t)},e.prototype.writeUInt32BE=function(e,r,t){E(this,e,r,!1,t)},e.prototype.writeInt8=function(e,r,t){t||(D(void 0!==e&&null!==e,"missing value"),D(void 0!==r&&null!==r,"missing offset"),D(r=this.length||(e>=0?this.writeUInt8(e,r,t):this.writeUInt8(255+e+1,r,t))},e.prototype.writeInt16LE=function(e,r,t){N(this,e,r,!0,t)},e.prototype.writeInt16BE=function(e,r,t){N(this,e,r,!1,t)},e.prototype.writeInt32LE=function(e,r,t){M(this,e,r,!0,t)},e.prototype.writeInt32BE=function(e,r,t){M(this,e,r,!1,t)},e.prototype.writeFloatLE=function(e,r,t){A(this,e,r,!0,t)},e.prototype.writeFloatBE=function(e,r,t){A(this,e,r,!1,t)},e.prototype.writeDoubleLE=function(e,r,t){S(this,e,r,!0,t)},e.prototype.writeDoubleBE=function(e,r,t){S(this,e,r,!1,t)},e.prototype.fill=function(e,r,t){if(e||(e=0),r||(r=0),t||(t=this.length),"string"==typeof e&&(e=e.charCodeAt(0)),D("number"==typeof e&&!isNaN(e),"value is not a number"),D(t>=r,"end < start"),t!==r&&0!==this.length){D(r>=0&&r=0&&t<=this.length,"end out of bounds");for(var n=r;t>n;n++)this[n]=e}},e.prototype.inspect=function(){for(var e=[],t=this.length,n=0;t>n;n++)if(e[n]=I(this[n]),n===r.INSPECT_MAX_BYTES){e[n+1]="...";break}return""},e.prototype.toArrayBuffer=function(){if("undefined"!=typeof Uint8Array){if(e._useTypedArrays)return new e(this).buffer;for(var r=new Uint8Array(this.length),t=0,n=r.length;n>t;t+=1)r[t]=this[t];return r.buffer}throw new Error("Buffer.toArrayBuffer not supported in this browser")};var H=e.prototype;e._augment=function(e){return e._isBuffer=!0,e._get=e.get,e._set=e.set,e.get=H.get,e.set=H.set,e.write=H.write,e.toString=H.toString,e.toLocaleString=H.toString,e.toJSON=H.toJSON,e.copy=H.copy,e.slice=H.slice,e.readUInt8=H.readUInt8,e.readUInt16LE=H.readUInt16LE,e.readUInt16BE=H.readUInt16BE,e.readUInt32LE=H.readUInt32LE,e.readUInt32BE=H.readUInt32BE,e.readInt8=H.readInt8,e.readInt16LE=H.readInt16LE,e.readInt16BE=H.readInt16BE,e.readInt32LE=H.readInt32LE,e.readInt32BE=H.readInt32BE,e.readFloatLE=H.readFloatLE,e.readFloatBE=H.readFloatBE,e.readDoubleLE=H.readDoubleLE,e.readDoubleBE=H.readDoubleBE,e.writeUInt8=H.writeUInt8,e.writeUInt16LE=H.writeUInt16LE,e.writeUInt16BE=H.writeUInt16BE,e.writeUInt32LE=H.writeUInt32LE,e.writeUInt32BE=H.writeUInt32BE,e.writeInt8=H.writeInt8,e.writeInt16LE=H.writeInt16LE,e.writeInt16BE=H.writeInt16BE,e.writeInt32LE=H.writeInt32LE,e.writeInt32BE=H.writeInt32BE,e.writeFloatLE=H.writeFloatLE,e.writeFloatBE=H.writeFloatBE,e.writeDoubleLE=H.writeDoubleLE,e.writeDoubleBE=H.writeDoubleBE,e.fill=H.fill,e.inspect=H.inspect,e.toArrayBuffer=H.toArrayBuffer,e}}).call(r,t(252).Buffer)},function(e,r,t){function n(e,r){e[r>>5]|=128<>>9<<4)+14]=r;for(var t=1732584193,n=-271733879,i=-1732584194,c=271733878,l=0;l>16)+(r>>16)+(t>>16);return n<<16|65535&t}function c(e,r){return e<>>32-r}var l=t(255);e.exports=function(e){return l.hash(e,n,16)}},function(e,r,t){var r=e.exports=function(e){var t=r[e];if(!t)throw new Error(e+" is not supported (we accept pull requests)");return new t},n=t(252).Buffer,i=t(256)(n);r.sha=r.sha1=t(257)(n,i),r.sha256=t(258)(n,i)},function(e,r,t){function n(e,r){if(e.length%s!==0){var t=e.length+(s-e.length%s);e=a.concat([e,u],t)}for(var n=[],i=r?e.readInt32BE:e.readInt32LE,o=0;ou;){var l=Math.min(o,f+a);i(c,r,n,u%a,f,l);var p=l-f;u+=p,f+=p,u%a||this._update(c)}return this._s=u,this},r.prototype.digest=function(e){var r=this._blockSize,t=this._finalSize,i=8*this._len,a=this._block,s=i%(8*r);a[this._len%r]=128,o(this._block,this._len%r+1),s>=8*t&&(this._update(this._block),n.zeroFill(this._block,0)),a.writeInt32BE(i,t+4);var u=this._update(this._block)||this._hash();return null==e?u:u.toString(e)},r.prototype._update=function(){throw new Error("_update must be implemented by subclass")},r}},function(e,r,t){e.exports=function(e,r){function n(){return g.length?g.pop().init():this instanceof n?(this._w=h,r.call(this,64,56),this._h=null,void this.init()):new n}function i(e,r,t,n){return 20>e?r&t|~r&n:40>e?r^t^n:60>e?r&t|r&n|t&n:r^t^n}function o(e){return 20>e?1518500249:40>e?1859775393:60>e?-1894007588:-899497514}function a(e,r){return e+r|0}function s(e,r){return e<>>32-r}var u=t(263).inherits;u(n,r);var f=0,c=4,l=8,p=12,m=16,h=new Int32Array(80),g=[];n.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,r.prototype.init.call(this),this},n.prototype._POOL=g;new e(1)instanceof DataView;return n.prototype._update=function(){{var e,r,t,n,u,f,c,l,p,m,h=this._block;this._h}e=f=this._a,r=c=this._b,t=l=this._c,n=p=this._d,u=m=this._e;for(var g=this._w,d=0;80>d;d++){var w=g[d]=16>d?h.readInt32BE(4*d):s(g[d-3]^g[d-8]^g[d-14]^g[d-16],1),y=a(a(s(e,5),i(d,r,t,n)),a(a(u,w),o(d)));u=n,n=t,t=s(r,30),r=e,e=y}this._a=a(e,f),this._b=a(r,c),this._c=a(t,l),this._d=a(n,p),this._e=a(u,m)},n.prototype._hash=function(){g.length<100&&g.push(this);var r=new e(20);return r.writeInt32BE(0|this._a,f),r.writeInt32BE(0|this._b,c),r.writeInt32BE(0|this._c,l),r.writeInt32BE(0|this._d,p),r.writeInt32BE(0|this._e,m),r},n}},function(e,r,t){{var n=t(263).inherits;t(262),t(261)}e.exports=function(e,r){function t(){h.length,this.init(),this._w=m,r.call(this,64,56)}function i(e,r){return e>>>r|e<<32-r}function o(e,r){return e>>>r}function a(e,r,t){return e&r^~e&t}function s(e,r,t){return e&r^e&t^r&t}function u(e){return i(e,2)^i(e,13)^i(e,22)}function f(e){return i(e,6)^i(e,11)^i(e,25)}function c(e){return i(e,7)^i(e,18)^o(e,3)}function l(e){return i(e,17)^i(e,19)^o(e,10)}var p=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];n(t,r);var m=new Array(64),h=[];t.prototype.init=function(){return this._a=1779033703,this._b=-1150833019,this._c=1013904242,this._d=-1521486534,this._e=1359893119,this._f=-1694144372,this._g=528734635,this._h=1541459225,this._len=this._s=0,this};return t.prototype._update=function(){var e,r,t,n,i,o,m,h,g,d,w=this._block,y=this._w;e=0|this._a,r=0|this._b,t=0|this._c,n=0|this._d,i=0|this._e,o=0|this._f,m=0|this._g,h=0|this._h;for(var v=0;64>v;v++){var x=y[v]=16>v?w.readInt32BE(4*v):l(y[v-2])+y[v-7]+c(y[v-15])+y[v-16];g=h+f(i)+a(i,o,m)+p[v]+x,d=u(e)+s(e,r,t),h=m,m=o,o=i,i=n+g,n=t,t=r,r=e,e=g+d}this._a=e+this._a|0,this._b=r+this._b|0,this._c=t+this._c|0,this._d=n+this._d|0,this._e=i+this._e|0,this._f=o+this._f|0,this._g=m+this._g|0,this._h=h+this._h|0},t.prototype._hash=function(){h.length<10&&h.push(this);var r=new e(32);return r.writeInt32BE(this._a,0),r.writeInt32BE(this._b,4),r.writeInt32BE(this._c,8),r.writeInt32BE(this._d,12),r.writeInt32BE(this._e,16),r.writeInt32BE(this._f,20),r.writeInt32BE(this._g,24),r.writeInt32BE(this._h,28),r},t}},function(e,r){r.read=function(e,r,t,n,i){var o,a,s=8*i-n-1,u=(1<>1,c=-7,l=t?i-1:0,p=t?-1:1,m=e[r+l];for(l+=p,o=m&(1<<-c)-1,m>>=-c,c+=s;c>0;o=256*o+e[r+l],l+=p,c-=8);for(a=o&(1<<-c)-1,o>>=-c,c+=n;c>0;a=256*a+e[r+l],l+=p,c-=8);if(0===o)o=1-f;else{if(o===u)return a?0/0:1/0*(m?-1:1);a+=Math.pow(2,n),o-=f}return(m?-1:1)*a*Math.pow(2,o-n)},r.write=function(e,r,t,n,i,o){var a,s,u,f=8*o-i-1,c=(1<>1,p=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,m=n?0:o-1,h=n?1:-1,g=0>r||0===r&&0>1/r?1:0;for(r=Math.abs(r),isNaN(r)||1/0===r?(s=isNaN(r)?1:0,a=c):(a=Math.floor(Math.log(r)/Math.LN2),r*(u=Math.pow(2,-a))<1&&(a--,u*=2),r+=a+l>=1?p/u:p*Math.pow(2,1-l),r*u>=2&&(a++,u/=2),a+l>=c?(s=0,a=c):a+l>=1?(s=(r*u-1)*Math.pow(2,i),a+=l):(s=r*Math.pow(2,l-1)*Math.pow(2,i),a=0));i>=8;e[t+m]=255&s,m+=h,s/=256,i-=8);for(a=a<0;e[t+m]=255&a,m+=h,a/=256,f-=8);e[t+m-h]|=128*g}},function(e){var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";!function(){"use strict";function t(e){var r=e.charCodeAt(0);return r===a?62:r===s?63:u>r?-1:u+10>r?r-u+26+26:c+26>r?r-c:f+26>r?r-f+26:void 0}function n(e){function r(e){f[l++]=e}var n,i,a,s,u,f;if(e.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var c=e.length;u="="===e.charAt(c-2)?2:"="===e.charAt(c-1)?1:0,f=new o(3*e.length/4-u),a=u>0?e.length-4:e.length;var l=0;for(n=0,i=0;a>n;n+=4,i+=3)s=t(e.charAt(n))<<18|t(e.charAt(n+1))<<12|t(e.charAt(n+2))<<6|t(e.charAt(n+3)),r((16711680&s)>>16),r((65280&s)>>8),r(255&s);return 2===u?(s=t(e.charAt(n))<<2|t(e.charAt(n+1))>>4,r(255&s)):1===u&&(s=t(e.charAt(n))<<10|t(e.charAt(n+1))<<4|t(e.charAt(n+2))>>2,r(s>>8&255),r(255&s)),f}function i(e){function t(e){return r.charAt(e)}function n(e){return t(e>>18&63)+t(e>>12&63)+t(e>>6&63)+t(63&e)}var i,o,a,s=e.length%3,u="";for(i=0,a=e.length-s;a>i;i+=3)o=(e[i]<<16)+(e[i+1]<<8)+e[i+2],u+=n(o);switch(s){case 1:o=e[e.length-1],u+=t(o>>2),u+=t(o<<4&63),u+="==";break;case 2:o=(e[e.length-2]<<8)+e[e.length-1],u+=t(o>>10),u+=t(o>>4&63),u+=t(o<<2&63),u+="="}return u}var o="undefined"!=typeof Uint8Array?Uint8Array:Array,a=("0".charCodeAt(0),"+".charCodeAt(0)),s="/".charCodeAt(0),u="0".charCodeAt(0),f="a".charCodeAt(0),c="A".charCodeAt(0);e.exports.toByteArray=n,e.exports.fromByteArray=i}()},function(e,r){function t(e,r,t,n,i,o){var a=o-i;if("ascii"===t||"binary"===t)for(var s=0;a>s;s++)e[n+s]=r.charCodeAt(s+i);else if(null==t)for(var s=0;a>s;s++)e[n+s]=r[s+i];else{if("hex"!==t)throw new Error("base64"===t?"base64 encoding not yet supported":t+" encoding not yet supported");for(var s=0;a>s;s++){var u=i+s;e[n+s]=parseInt(r[2*u]+r[2*u+1],16)}}}function n(e,r){for(var t=r;ta;a++){var s=4294967292&a|(n?3-a%4:a%4);i=i+(e[s]>>4).toString(16)+(15&e[s]).toString(16)+(r-1==a%r?" ":"")+(t-1==a%t?"\n":"")}return i}var n=e.exports=function(e,r){return r=r||{},r.groups=r.groups||4,r.wrap=r.wrap||16,t(e,r.groups,r.wrap,r.bigendian,r.ints)};if(n.defaults=function(e){return function(r){return n(r,e)}},!e.parent){var i=new r(64);console.log(n(i)),console.log(n(i,{bigendian:!0}))}}).call(r,t(247)(e),t(252).Buffer)},function(e,r,t){(function(e,n){function i(e,t){var n={seen:[],stylize:a};return arguments.length>=3&&(n.depth=arguments[2]),arguments.length>=4&&(n.colors=arguments[3]),g(t)?n.showHidden=t:t&&r._extend(n,t),b(n.showHidden)&&(n.showHidden=!1),b(n.depth)&&(n.depth=2),b(n.colors)&&(n.colors=!1),b(n.customInspect)&&(n.customInspect=!0),n.colors&&(n.stylize=o),u(n,e,n.depth)}function o(e,r){var t=i.styles[r];return t?"["+i.colors[t][0]+"m"+e+"["+i.colors[t][1]+"m":e}function a(e){return e}function s(e){var r={};return e.forEach(function(e){r[e]=!0}),r}function u(e,t,n){if(e.customInspect&&t&&S(t.inspect)&&t.inspect!==r.inspect&&(!t.constructor||t.constructor.prototype!==t)){var i=t.inspect(n,e);return v(i)||(i=u(e,i,n)),i}var o=f(e,t);if(o)return o;var a=Object.keys(t),g=s(a);if(e.showHidden&&(a=Object.getOwnPropertyNames(t)),A(t)&&(a.indexOf("message")>=0||a.indexOf("description")>=0))return c(t);if(0===a.length){if(S(t)){var d=t.name?": "+t.name:"";return e.stylize("[Function"+d+"]","special")}if(E(t))return e.stylize(RegExp.prototype.toString.call(t),"regexp");if(M(t))return e.stylize(Date.prototype.toString.call(t),"date");if(A(t))return c(t)}var w="",y=!1,x=["{","}"];if(h(t)&&(y=!0,x=["[","]"]),S(t)){var b=t.name?": "+t.name:"";w=" [Function"+b+"]"}if(E(t)&&(w=" "+RegExp.prototype.toString.call(t)),M(t)&&(w=" "+Date.prototype.toUTCString.call(t)),A(t)&&(w=" "+c(t)),0===a.length&&(!y||0==t.length))return x[0]+w+x[1];if(0>n)return E(t)?e.stylize(RegExp.prototype.toString.call(t),"regexp"):e.stylize("[Object]","special");e.seen.push(t);var N;return N=y?l(e,t,n,g,a):a.map(function(r){return p(e,t,n,g,r,y)}),e.seen.pop(),m(N,w,x)}function f(e,r){if(b(r))return e.stylize("undefined","undefined");if(v(r)){var t="'"+JSON.stringify(r).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(t,"string")}return y(r)?e.stylize(""+r,"number"):g(r)?e.stylize(""+r,"boolean"):d(r)?e.stylize("null","null"):void 0}function c(e){return"["+Error.prototype.toString.call(e)+"]"}function l(e,r,t,n,i){for(var o=[],a=0,s=r.length;s>a;++a)o.push(B(r,String(a))?p(e,r,t,n,String(a),!0):"");return i.forEach(function(i){i.match(/^\d+$/)||o.push(p(e,r,t,n,i,!0))}),o}function p(e,r,t,n,i,o){var a,s,f;if(f=Object.getOwnPropertyDescriptor(r,i)||{value:r[i]},f.get?s=f.set?e.stylize("[Getter/Setter]","special"):e.stylize("[Getter]","special"):f.set&&(s=e.stylize("[Setter]","special")),B(n,i)||(a="["+i+"]"),s||(e.seen.indexOf(f.value)<0?(s=d(t)?u(e,f.value,null):u(e,f.value,t-1),s.indexOf("\n")>-1&&(s=o?s.split("\n").map(function(e){return" "+e}).join("\n").substr(2):"\n"+s.split("\n").map(function(e){return" "+e}).join("\n"))):s=e.stylize("[Circular]","special")),b(a)){if(o&&i.match(/^\d+$/))return s;a=JSON.stringify(""+i),a.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(a=a.substr(1,a.length-2),a=e.stylize(a,"name")):(a=a.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),a=e.stylize(a,"string"))}return a+": "+s}function m(e,r,t){var n=0,i=e.reduce(function(e,r){return n++,r.indexOf("\n")>=0&&n++,e+r.replace(/\u001b\[\d\d?m/g,"").length+1},0);return i>60?t[0]+(""===r?"":r+"\n ")+" "+e.join(",\n ")+" "+t[1]:t[0]+r+" "+e.join(", ")+" "+t[1]}function h(e){return Array.isArray(e)}function g(e){return"boolean"==typeof e}function d(e){return null===e}function w(e){return null==e}function y(e){return"number"==typeof e}function v(e){return"string"==typeof e}function x(e){return"symbol"==typeof e}function b(e){return void 0===e}function E(e){return N(e)&&"[object RegExp]"===O(e)}function N(e){return"object"==typeof e&&null!==e}function M(e){return N(e)&&"[object Date]"===O(e)}function A(e){return N(e)&&("[object Error]"===O(e)||e instanceof Error)}function S(e){return"function"==typeof e}function T(e){return null===e||"boolean"==typeof e||"number"==typeof e||"string"==typeof e||"symbol"==typeof e||"undefined"==typeof e}function O(e){return Object.prototype.toString.call(e)}function C(e){return 10>e?"0"+e.toString(10):e.toString(10)}function _(){var e=new Date,r=[C(e.getHours()),C(e.getMinutes()),C(e.getSeconds())].join(":");return[e.getDate(),q[e.getMonth()],r].join(" ")}function B(e,r){return Object.prototype.hasOwnProperty.call(e,r)}var I=/%[sdj%]/g;r.format=function(e){if(!v(e)){for(var r=[],t=0;t=o)return e;switch(e){case"%s":return String(n[t++]);case"%d":return Number(n[t++]);case"%j":try{return JSON.stringify(n[t++])}catch(r){return"[Circular]"}default:return e}}),s=n[t];o>t;s=n[++t])a+=d(s)||!N(s)?" "+s:" "+i(s);return a},r.deprecate=function(t,i){function o(){if(!a){if(n.throwDeprecation)throw new Error(i);n.traceDeprecation?console.trace(i):console.error(i),a=!0}return t.apply(this,arguments)}if(b(e.process))return function(){return r.deprecate(t,i).apply(this,arguments)};if(n.noDeprecation===!0)return t;var a=!1;return o};var U,z={};r.debuglog=function(e){if(b(U)&&(U=n.env.NODE_DEBUG||""),e=e.toUpperCase(),!z[e])if(new RegExp("\\b"+e+"\\b","i").test(U)){var t=n.pid;z[e]=function(){var n=r.format.apply(r,arguments);console.error("%s %d: %s",e,t,n)}}else z[e]=function(){};return z[e]},r.inspect=i,i.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},i.styles={special:"cyan",number:"yellow","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"},r.isArray=h,r.isBoolean=g,r.isNull=d,r.isNullOrUndefined=w,r.isNumber=y,r.isString=v,r.isSymbol=x,r.isUndefined=b,r.isRegExp=E,r.isObject=N,r.isDate=M,r.isError=A,r.isFunction=S,r.isPrimitive=T,r.isBuffer=t(264);var q=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];r.log=function(){console.log("%s - %s",_(),r.format.apply(r,arguments))},r.inherits=t(266),r._extend=function(e,r){if(!r||!N(r))return e;for(var t=Object.keys(r),n=t.length;n--;)e[t[n]]=r[t[n]];return e}}).call(r,function(){return this}(),t(265))},function(e){e.exports=function(e){return e&&"object"==typeof e&&"function"==typeof e.copy&&"function"==typeof e.fill&&"function"==typeof e.readUInt8}},function(e){function r(){}var t=e.exports={};t.nextTick=function(){var e="undefined"!=typeof window&&window.setImmediate,r="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(e)return function(e){return window.setImmediate(e)};if(r){var t=[];return window.addEventListener("message",function(e){var r=e.source;if((r===window||null===r)&&"process-tick"===e.data&&(e.stopPropagation(),t.length>0)){var n=t.shift();n()}},!0),function(e){t.push(e),window.postMessage("process-tick","*")}}return function(e){setTimeout(e,0)}}(),t.title="browser",t.browser=!0,t.env={},t.argv=[],t.on=r,t.once=r,t.off=r,t.emit=r,t.binding=function(){throw new Error("process.binding is not supported")},t.cwd=function(){return"/"},t.chdir=function(){throw new Error("process.chdir is not supported")}},function(e){e.exports="function"==typeof Object.create?function(e,r){e.super_=r,e.prototype=Object.create(r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:function(e,r){e.super_=r;var t=function(){};t.prototype=r.prototype,e.prototype=new t,e.prototype.constructor=e}}])}); //# sourceMappingURL=math.map \ No newline at end of file diff --git a/misc/how_to_publish.md b/misc/how_to_publish.md index 301b0280d..9d69648dc 100644 --- a/misc/how_to_publish.md +++ b/misc/how_to_publish.md @@ -71,19 +71,8 @@ component(1) uses GitHub as it's registry. Publish at http://jspkg.com: go to the website, select the github project, select the new version and press the button. -Publish at cdnjs: - -*Auto update should be enabled since v0.19.0, if so, no need to publish at cdnjs -manually.* - -- clone the cdnjs project -- pull changes: `git pull upstream master` -- add the new version of the library under /ajax/libs/mathjs/ - - add new folder /x.y.z/ with the new library - - update the version number in package.json -- test the library by running `npm test` -- then do a pull request with as title "[author] Update mathjs to x.y.z" - (with correct version). +Publish at cdnjs: test after 30 to 60 minutes whether the new version is +published at cdnjs (should auto update). ## Test published libraries diff --git a/package.json b/package.json index 16dafa48a..4a87cfa54 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mathjs", - "version": "0.20.0-SNAPSHOT", + "version": "0.20.0", "description": "Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser and offers an integrated solution to work with numbers, big numbers, complex numbers, units, and matrices.", "author": "Jos de Jong (https://github.com/josdejong)", "contributors": [