Fixed #200: A new instanceof of math.js must now be created as math.create([options]) instead of math([options])

This commit is contained in:
jos 2014-08-03 21:42:12 +02:00
parent 6b833a581c
commit 8a12c8e9bc
129 changed files with 182 additions and 164 deletions

View File

@ -3,6 +3,9 @@
## not yet released, version 0.25.1
- A new instance of math.js can no longer be created like `math([options])`,
to prevent side effects from math being a function instead of an object.
Instead, use the function `math.create([options])` to create a new instance.
- Implemented `BigNumber` support for all constants: `pi`, `tau`, `e`, `phi`,
`E`, `LN2`, `LN10`, `LOG2E`, `LOG10E`, `PI`, `SQRT1_2`, and `SQRT2`.
- Implemented `BigNumber` support for functions `gcd`, `xgcd`, and `lcm`.

View File

@ -5,8 +5,8 @@ configure math.js:
- Configure an existing instance of math.js using `math.config(options)`,
for example `math.config({number: 'bignumber'})` to change to BigNumbers.
- Create and configure a new instance of math.js using `math([options])`,
for example `var bigmath = math({number: 'bignumber'})` to create a new
- Create and configure a new instance of math.js using `math.create([options])`,
for example `var bigmath = math.create({number: 'bignumber'})` to create a new
instance configured to use BigNumbers.
The following configuration options are available:
@ -51,7 +51,7 @@ math.range(0, 4); // Matrix [0, 1, 2, 3]
// create a new instance configured to use Arrays
var math2 = math({
var math2 = math.create({
matrix: 'array' // Choose 'matrix' (default) or 'array'
});
@ -68,7 +68,7 @@ math2.range(0, 4); // Matrix [0, 1, 2, 3]
// create an instance of math.js with bignumber configuration
var bigmath = math({
var bigmath = math.create({
number: 'bignumber', // Choose 'number' (default) or 'bignumber'
precision: 32 // 64 by default, only applicable for BigNumbers
});
@ -102,7 +102,7 @@ bigmath.eval('1 / 3'); // BigNumber, 0.33333333333333333333333333333333
math.range(0, 4); // Array [0, 1, 2, 3]
// create a new instance of math.js with bignumber configuration
var bigmath = math({
var bigmath = math.create({
number: 'bignumber', // Choose 'number' (default) or 'bignumber'
precision: 32 // 64 by default, only applicable for BigNumbers
});

View File

@ -1,8 +1,10 @@
// BigNumbers
// load math.js
// the default type of numbers is configured as BigNumbers
var math = require('../index')({
var math = require('../index');
// configure the default type of numbers as BigNumbers
math.config({
number: 'bignumber', // Default type of number: 'number' (default) or 'bignumber'
precision: 20 // Number of significant digits for BigNumbers
});

View File

@ -4,6 +4,7 @@ var Node = require('./Node');
var latex = require('../../util/latex');
var BigNumber = require('decimal.js');
var Complex = require('../../type/Complex');
var Unit = require('../../type/Unit');
var util = require('../../util');
var isString = util.string.isString;
var isNumber = util.number.isNumber;

View File

@ -15,17 +15,15 @@ var digits = require('./util/number').digits;
* The number of significant digits for BigNumbers.
* Not applicable for Numbers.
*/
function factory (config) {
function create (config) {
// simple test for ES5 support
if (typeof Object.create !== 'function') {
throw new Error('ES5 not supported by this JavaScript engine. ' +
'Please load the es5-shim and es5-sham library for compatibility.');
}
// create namespace (and factory for a new instance)
function math (config) {
return factory(config);
}
// create namespace
var math = {};
// create configuration options. These are private
var _config = {
@ -100,6 +98,20 @@ function factory (config) {
return object.clone(_config);
};
/**
* math.js factory function. Creates a new instance of math.js
*
* @param {Object} [config] Available configuration options:
* {String} matrix
* A string 'matrix' (default) or 'array'.
* {String} number
* A string 'number' (default) or 'bignumber'
* {Number} precision
* The number of significant digits for BigNumbers.
* Not applicable for Numbers.
*/
math.create = create;
// create a new BigNumber factory for this instance of math.js
var BigNumber = require('decimal.js').constructor();
@ -318,12 +330,12 @@ function factory (config) {
}
// create a default instance of math.js
var math = factory();
var math = create();
if (typeof window !== 'undefined') {
window.mathjs = math; // TODO: deprecate the mathjs namespace some day (replaced with 'math' since version 0.25.0)
}
// export the default instance
module.exports = factory();
module.exports = math;

View File

@ -1,5 +1,5 @@
var assert = require('assert'),
math = require('../index')(),
math = require('../index'),
approx = require('../tools/approx');
describe('constants', function() {
@ -57,7 +57,7 @@ describe('constants', function() {
});
describe('bignumber', function () {
var bigmath = math({number: 'bignumber', precision: 64});
var bigmath = math.create({number: 'bignumber', precision: 64});
it('should have bignumber pi', function() {
assert.equal(bigmath.pi.toString(), '3.141592653589793238462643383279502884197169399375105820974944592');

View File

@ -7,7 +7,7 @@ describe('deprecated stuff', function() {
it ('should throw an error when using deprecated setting number.defaultType', function () {
assert.throws(function () {
math({
math.create({
number: {
defaultType: 'number'
}
@ -17,7 +17,7 @@ describe('deprecated stuff', function() {
it ('should throw an error when using deprecated setting number.precision', function () {
assert.throws(function () {
math({
math.create({
number: {
precision: 14
}
@ -27,7 +27,7 @@ describe('deprecated stuff', function() {
it ('should throw an error when using deprecated setting decimals', function () {
assert.throws(function () {
math({
math.create({
decimals: 100
})
}, /is deprecated/);
@ -35,7 +35,7 @@ describe('deprecated stuff', function() {
it ('should throw an error when using deprecated setting matrix.defaultType', function () {
assert.throws(function () {
math({
math.create({
matrix: {
defaultType: 'array'
}
@ -45,7 +45,7 @@ describe('deprecated stuff', function() {
it ('should throw an error when using deprecated setting matrix.default', function () {
assert.throws(function () {
math({
math.create({
matrix: {
'default': 'array'
}

View File

@ -3,7 +3,7 @@
var assert = require('assert'),
approx = require('../../tools/approx'),
Parser = require('../../lib/expression/Parser'),
math = require('../../index')();
math = require('../../index');
describe('parser', function() {

View File

@ -48,7 +48,7 @@ describe('ArrayNode', function() {
var expr = n.compile(math);
assert.deepEqual(expr.eval(), math.matrix([1,2,3,4]));
var mathArray = math({matrix: 'array'});
var mathArray = math.create({matrix: 'array'});
var expr2 = n.compile(mathArray);
assert.deepEqual(expr2.eval(), [1,2,3,4]);
});

View File

@ -1,7 +1,7 @@
// test AssignmentNode
var assert = require('assert'),
approx = require('../../../tools/approx'),
math = require('../../../index')(),
math = require('../../../index'),
Node = require('../../../lib/expression/node/Node'),
ConstantNode = require('../../../lib/expression/node/ConstantNode'),
SymbolNode = require('../../../lib/expression/node/SymbolNode'),

View File

@ -1,7 +1,7 @@
// test BlockNode
var assert = require('assert');
var approx = require('../../../tools/approx');
var math = require('../../../index')();
var math = require('../../../index');
var Node = require('../../../lib/expression/node/Node');
var ConstantNode = require('../../../lib/expression/node/ConstantNode');
var SymbolNode = require('../../../lib/expression/node/SymbolNode');

View File

@ -1,7 +1,7 @@
// test ConditionalNode
var assert = require('assert'),
approx = require('../../../tools/approx'),
math = require('../../../index')(),
math = require('../../../index'),
Node = require('../../../lib/expression/node/Node'),
ConstantNode = require('../../../lib/expression/node/ConstantNode'),
SymbolNode = require('../../../lib/expression/node/SymbolNode'),

View File

@ -1,8 +1,8 @@
// test ConstantNode
var assert = require('assert'),
approx = require('../../../tools/approx'),
math = require('../../../index')(),
bigmath = require('../../../index')({number: 'bignumber'}),
math = require('../../../index'),
bigmath = require('../../../index').create({number: 'bignumber'}),
Node = require('../../../lib/expression/node/Node'),
ConstantNode = require('../../../lib/expression/node/ConstantNode'),
SymbolNode = require('../../../lib/expression/node/SymbolNode');

View File

@ -1,7 +1,7 @@
// test FunctionAssignmentNode
var assert = require('assert'),
approx = require('../../../tools/approx'),
math = require('../../../index')(),
math = require('../../../index'),
Node = require('../../../lib/expression/node/Node'),
ConstantNode = require('../../../lib/expression/node/ConstantNode'),
OperatorNode = require('../../../lib/expression/node/OperatorNode'),

View File

@ -1,7 +1,7 @@
// test FunctionNode
var assert = require('assert'),
approx = require('../../../tools/approx'),
math = require('../../../index')(),
math = require('../../../index'),
Node = require('../../../lib/expression/node/Node'),
ConstantNode = require('../../../lib/expression/node/ConstantNode'),
SymbolNode = require('../../../lib/expression/node/SymbolNode'),

View File

@ -1,7 +1,7 @@
// test IndexNode
var assert = require('assert'),
approx = require('../../../tools/approx'),
bigmath = require('../../../index')({number: 'bignumber'}),
bigmath = require('../../../index').create({number: 'bignumber'}),
Node = require('../../../lib/expression/node/Node'),
ConstantNode = require('../../../lib/expression/node/ConstantNode'),
RangeNode = require('../../../lib/expression/node/RangeNode'),

View File

@ -1,7 +1,7 @@
// test Node
var assert = require('assert'),
approx = require('../../../tools/approx'),
math = require('../../../index')(),
math = require('../../../index'),
Node = require('../../../lib/expression/node/Node');
describe('Node', function() {

View File

@ -1,7 +1,7 @@
// test OperatorNode
var assert = require('assert'),
approx = require('../../../tools/approx'),
math = require('../../../index')(),
math = require('../../../index'),
Node = require('../../../lib/expression/node/Node'),
ConstantNode = require('../../../lib/expression/node/ConstantNode'),
SymbolNode = require('../../../lib/expression/node/SymbolNode'),

View File

@ -1,7 +1,7 @@
// test SymbolNode
var assert = require('assert'),
approx = require('../../../tools/approx'),
math = require('../../../index')(),
math = require('../../../index'),
Node = require('../../../lib/expression/node/Node'),
ConstantNode = require('../../../lib/expression/node/ConstantNode'),
SymbolNode = require('../../../lib/expression/node/SymbolNode');

View File

@ -2,7 +2,7 @@
var assert = require('assert'),
approx = require('../../../tools/approx'),
math = require('../../../index'),
bigmath = math({number: 'bignumber'}),
bigmath = math.create({number: 'bignumber'}),
Node = require('../../../lib/expression/node/Node'),
ConstantNode = require('../../../lib/expression/node/ConstantNode'),
RangeNode = require('../../../lib/expression/node/RangeNode'),

View File

@ -147,7 +147,7 @@ describe('parse', function() {
});
it('should output bignumbers if default number type is bignumber', function() {
var bigmath = math({
var bigmath = math.create({
number: 'bignumber'
});
@ -1007,7 +1007,7 @@ describe('parse', function() {
});
describe('bignumber', function () {
var bigmath = math({
var bigmath = math.create({
number: 'bignumber'
});
var BigNumber = bigmath.type.BigNumber;

View File

@ -1,7 +1,7 @@
// test abs
var assert = require('assert'),
error = require('../../../lib/error'),
math = require('../../../index')();
math = require('../../../index');
describe('abs', function () {
it('should return the abs value of a boolean', function () {

View File

@ -2,7 +2,7 @@
var assert = require('assert'),
approx = require('../../../tools/approx'),
error = require('../../../lib/error/index'),
math = require('../../../index')(),
math = require('../../../index'),
bignumber = math.bignumber,
add = math.add;

View File

@ -2,7 +2,7 @@
var assert = require('assert'),
approx = require('../../../tools/approx'),
error = require('../../../lib/error/index'),
math = require('../../../index')(),
math = require('../../../index'),
bignumber = math.bignumber,
complex = math.complex,
matrix = math.matrix,

View File

@ -1,6 +1,6 @@
// test cube
var assert = require('assert'),
math = require('../../../index')(),
math = require('../../../index'),
error = require('../../../lib/error/index'),
unit = math.unit,
bignumber = math.bignumber,

View File

@ -1,6 +1,6 @@
// test divide
var assert = require('assert'),
math = require('../../../index')(),
math = require('../../../index'),
error = require('../../../lib/error/index'),
approx = require('../../../tools/approx'),
divide = math.divide,

View File

@ -1,6 +1,6 @@
// test dotDivide (element-wise divide)
var assert = require('assert'),
math = require('../../../index')(),
math = require('../../../index'),
error = require('../../../lib/error/index'),
approx = require('../../../tools/approx'),
dotDivide = math.dotDivide,

View File

@ -1,6 +1,6 @@
// test dotMultiply (element-wise multiply)
var assert = require('assert'),
math = require('../../../index')(),
math = require('../../../index'),
approx = require('../../../tools/approx'),
error = require('../../../lib/error/index'),
dotMultiply = math.dotMultiply,

View File

@ -2,7 +2,7 @@
var assert = require('assert'),
approx = require('../../../tools/approx'),
error = require('../../../lib/error/index'),
math = require('../../../index')(),
math = require('../../../index'),
complex = math.complex,
matrix = math.matrix,
unit = math.unit,

View File

@ -27,7 +27,7 @@ describe('exp', function() {
});
it('should exponentiate a bignumber', function() {
var bigmath = math({precision: 100});
var bigmath = math.create({precision: 100});
assert.deepEqual(bigmath.exp(bigmath.bignumber(1)), bigmath.bignumber('2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427'));
});

View File

@ -2,7 +2,7 @@
var assert = require('assert'),
error = require('../../../lib/error/index'),
approx = require('../../../tools/approx'),
math = require('../../../index')(),
math = require('../../../index'),
bignumber = math.bignumber,
complex = math.complex,
matrix = math.matrix,

View File

@ -2,7 +2,7 @@
var assert = require('assert'),
approx = require('../../../tools/approx'),
error = require('../../../lib/error/index'),
math = require('../../../index')(),
math = require('../../../index'),
bignumber = math.bignumber,
complex = math.complex,
matrix = math.matrix,

View File

@ -1,7 +1,7 @@
// test gcd
var assert = require('assert'),
error = require('../../../lib/error/index'),
math = require('../../../index')(),
math = require('../../../index'),
gcd = math.gcd;
describe('gcd', function() {

View File

@ -1,6 +1,6 @@
var assert = require('assert'),
error = require('../../../lib/error/index'),
math = require('../../../index')(),
math = require('../../../index'),
lcm = math.lcm;
describe('lcm', function() {

View File

@ -45,7 +45,7 @@ describe('log', function() {
});
it('should return the log of positive bignumbers', function() {
var bigmath = math({precision: 100});
var bigmath = math.create({precision: 100});
assert.deepEqual(bigmath.log(bigmath.bignumber(1)), bigmath.bignumber('0'));
assert.deepEqual(bigmath.log(bigmath.bignumber(2)), bigmath.bignumber('0.6931471805599453094172321214581765680755001343602552541206800094933936219696947156058633269964186875'));
@ -56,7 +56,7 @@ describe('log', function() {
});
it('should return the log of negative bignumbers', function() {
var bigmath = math({precision: 100});
var bigmath = math.create({precision: 100});
approx.deepEqual(bigmath.log(bigmath.bignumber(-1)), bigmath.complex('0.000000000000000 + 3.141592653589793i'));
approx.deepEqual(bigmath.log(bigmath.bignumber(-2)), bigmath.complex('0.693147180559945 + 3.141592653589793i'));
@ -64,7 +64,7 @@ describe('log', function() {
});
it('should return the log of a bignumber with value zero', function() {
var bigmath = math({precision: 100});
var bigmath = math.create({precision: 100});
assert.deepEqual(bigmath.log(bigmath.bignumber(0)), bigmath.bignumber(-Infinity));
});

View File

@ -39,7 +39,7 @@ describe('log10', function() {
});
it('should return the log of positive bignumbers', function() {
var bigmath = math({precision: 100});
var bigmath = math.create({precision: 100});
assert.deepEqual(bigmath.log10(bigmath.bignumber(1)), bigmath.bignumber(0));
assert.deepEqual(bigmath.log10(bigmath.bignumber(10)), bigmath.bignumber(1));
@ -50,7 +50,7 @@ describe('log10', function() {
});
it('should return the log of negative bignumbers', function() {
var bigmath = math({precision: 100});
var bigmath = math.create({precision: 100});
approx.deepEqual(bigmath.log10(bigmath.bignumber(-1)), bigmath.complex('0.000000000000000 + 1.364376353841841i'));
approx.deepEqual(bigmath.log10(bigmath.bignumber(-2)), bigmath.complex('0.301029995663981 + 1.364376353841841i'));
@ -58,7 +58,7 @@ describe('log10', function() {
});
it('should return the log of a bignumber with value zero', function() {
var bigmath = math({precision: 100});
var bigmath = math.create({precision: 100});
assert.deepEqual(bigmath.log10(bigmath.bignumber(0)), bigmath.bignumber(-Infinity));
});

View File

@ -2,7 +2,7 @@
var assert = require('assert'),
approx = require('../../../tools/approx'),
error = require('../../../lib/error/index'),
math = require('../../../index')(),
math = require('../../../index'),
bignumber = math.bignumber,
matrix = math.matrix,
range = math.range,

View File

@ -1,6 +1,6 @@
// test multiply
var assert = require('assert'),
math = require('../../../index')(),
math = require('../../../index'),
error = require('../../../lib/error/index'),
approx = require('../../../tools/approx'),
multiply = math.multiply,

View File

@ -1,7 +1,7 @@
// test norm
var assert = require('assert'),
error = require('../../../lib/error/index'),
math = require('../../../index')();
math = require('../../../index');
describe('norm', function () {

View File

@ -2,7 +2,7 @@
var assert = require('assert'),
approx = require('../../../tools/approx'),
error = require('../../../lib/error/index'),
math = require('../../../index')(),
math = require('../../../index'),
bignumber = math.bignumber,
complex = math.complex,
matrix = math.matrix,

View File

@ -2,7 +2,7 @@
var assert = require('assert'),
approx = require('../../../tools/approx'),
error = require('../../../lib/error/index'),
math = require('../../../index')(),
math = require('../../../index'),
bignumber = math.bignumber,
round = math.round;

View File

@ -2,7 +2,7 @@
var assert = require('assert'),
approx = require('../../../tools/approx'),
error = require('../../../lib/error/index'),
math = require('../../../index')(),
math = require('../../../index'),
bignumber = math.bignumber;
describe('sign', function() {

View File

@ -35,7 +35,7 @@ describe('sqrt', function() {
assert.deepEqual(sqrt(bignumber(25)), bignumber(5));
// validate whether we are really working at high precision
var bigmath = math({precision: 100});
var bigmath = math.create({precision: 100});
assert.deepEqual(bigmath.sqrt(bigmath.bignumber(2)), bigmath.bignumber('1.414213562373095048801688724209698078569671875376948073176679737990732478462107038850387534327641573'));
});

View File

@ -1,6 +1,6 @@
// test square
var assert = require('assert'),
math = require('../../../index')(),
math = require('../../../index'),
error = require('../../../lib/error/index'),
unit = math.unit,
bignumber = math.bignumber,

View File

@ -2,7 +2,7 @@
var assert = require('assert'),
approx = require('../../../tools/approx'),
error = require('../../../lib/error/index'),
math = require('../../../index')(),
math = require('../../../index'),
bignumber = math.bignumber,
subtract = math.subtract;

View File

@ -11,7 +11,7 @@ describe('unaryMinus', function() {
});
it('should return bignumber unary minus of a boolean', function () {
var bigmath = math({number: 'bignumber'});
var bigmath = math.create({number: 'bignumber'});
assert.deepEqual(bigmath.unaryMinus(true), bigmath.bignumber(-1));
assert.deepEqual(bigmath.unaryMinus(false), bigmath.bignumber(-0));
});
@ -22,7 +22,7 @@ describe('unaryMinus', function() {
});
it('should return bignumber unary minus on a string', function() {
var bigmath = math({number: 'bignumber'});
var bigmath = math.create({number: 'bignumber'});
assert.deepEqual(bigmath.unaryMinus('2'), bigmath.bignumber(-2));
assert.deepEqual(bigmath.unaryMinus('-2'), bigmath.bignumber(2));
});

View File

@ -11,7 +11,7 @@ describe('unaryPlus', function() {
});
it('should return bignumber unary plus of a boolean', function () {
var bigmath = math({number: 'bignumber'});
var bigmath = math.create({number: 'bignumber'});
assert.deepEqual(bigmath.unaryPlus(true), bigmath.bignumber(1));
assert.deepEqual(bigmath.unaryPlus(false), bigmath.bignumber(0));
});
@ -22,7 +22,7 @@ describe('unaryPlus', function() {
});
it('should return bignumber unary plus on a string', function() {
var bigmath = math({number: 'bignumber'});
var bigmath = math.create({number: 'bignumber'});
assert.deepEqual(bigmath.unaryPlus('2'), bigmath.bignumber(2));
assert.deepEqual(bigmath.unaryPlus('-2'), bigmath.bignumber(-2));
});

View File

@ -1,7 +1,7 @@
// test xgcd
var assert = require('assert'),
error = require('../../../lib/error/index'),
math = require('../../../index')({matrix: 'array'}),
math = require('../../../index').create({matrix: 'array'}),
gcd = math.gcd,
xgcd = math.xgcd;
@ -73,10 +73,10 @@ describe('xgcd', function() {
});
it('should return a matrix when configured to use matrices', function() {
var math1 = math({matrix: 'matrix'});
var math1 = math.create({matrix: 'matrix'});
assert.deepEqual(math1.xgcd(65, 40), math.matrix([5, -3, 5]));
var math2 = math({matrix: 'array'});
var math2 = math.create({matrix: 'array'});
assert.deepEqual(math2.xgcd(65, 40), [5, -3, 5]);
});

View File

@ -1,7 +1,7 @@
var assert = require('assert'),
error = require('../../../lib/error/index'),
approx = require('../../../tools/approx'),
math = require('../../../index')(),
math = require('../../../index'),
arg = math.arg;
describe('arg', function() {

View File

@ -1,6 +1,6 @@
var assert = require('assert'),
error = require('../../../lib/error/index'),
math = require('../../../index')(),
math = require('../../../index'),
conj = math.conj;
describe('conj', function() {

View File

@ -1,6 +1,6 @@
var assert = require('assert'),
error = require('../../../lib/error/index'),
math = require('../../../index')();
math = require('../../../index');
describe('im', function() {

View File

@ -1,6 +1,6 @@
var assert = require('assert'),
error = require('../../../lib/error/index'),
math = require('../../../index')();
math = require('../../../index');
describe('re', function() {

View File

@ -53,7 +53,7 @@ describe('bignumber', function() {
});
it('should apply precision setting to bignumbers', function() {
var mymath = math({
var mymath = math.create({
precision: 32
});

View File

@ -1,6 +1,6 @@
var assert = require('assert'),
error = require('../../../lib/error/index'),
math = require('../../../index')(),
math = require('../../../index'),
bool = math['boolean'];
describe('boolean', function() {

View File

@ -1,6 +1,6 @@
var assert = require('assert'),
error = require('../../../lib/error/index'),
math = require('../../../index')(),
math = require('../../../index'),
complex = math.complex;
describe('complex', function() {

View File

@ -1,7 +1,7 @@
// test index construction
var assert = require('assert'),
error = require('../../../lib/error/index'),
math = require('../../../index')();
math = require('../../../index');
describe('index', function() {

View File

@ -1,7 +1,7 @@
// test matrix construction
var assert = require('assert'),
error = require('../../../lib/error/index'),
math = require('../../../index')(),
math = require('../../../index'),
matrix = math.matrix;
describe('matrix', function() {

View File

@ -1,6 +1,6 @@
var assert = require('assert'),
error = require('../../../lib/error/index'),
math = require('../../../index')(),
math = require('../../../index'),
approx = require('../../../tools/approx'),
number = math.number;

View File

@ -1,7 +1,7 @@
var assert = require('assert'),
error = require('../../../lib/error/index'),
Parser = require('../../../lib/expression/Parser'),
math = require('../../../index')();
math = require('../../../index');
describe('parser', function() {

View File

@ -1,5 +1,5 @@
var assert = require('assert'),
math = require('../../../index')(),
math = require('../../../index'),
Selector = math.chaining.Selector;
describe('select', function() {

View File

@ -1,6 +1,6 @@
var assert = require('assert'),
error = require('../../../lib/error/index'),
math = require('../../../index')(),
math = require('../../../index'),
string = math.string;
describe('string', function() {

View File

@ -1,6 +1,6 @@
var assert = require('assert'),
error = require('../../../lib/error/index'),
math = require('../../../index')(),
math = require('../../../index'),
unit = math.unit;
Unit = require('../../../lib/type/Unit');

View File

@ -1,7 +1,7 @@
// test parse
var assert = require('assert'),
error = require('../../../lib/error/index'),
math = require('../../../index')(),
math = require('../../../index'),
Node = require('../../../lib/expression/node/Node');
describe('parse', function() {

View File

@ -2,7 +2,7 @@
var assert = require('assert');
var approx = require('../../../tools/approx');
var error = require('../../../lib/error/index');
var math = require('../../../index')();
var math = require('../../../index');
var Complex = math.type.Complex;
var Matrix = math.type.Matrix;
var Unit = math.type.Unit;

View File

@ -1,6 +1,6 @@
var assert = require('assert'),
error = require('../../../lib/error/index'),
math = require('../../../index')();
math = require('../../../index');
describe('help', function() {

View File

@ -1,7 +1,7 @@
// test parse
var assert = require('assert'),
error = require('../../../lib/error/index'),
math = require('../../../index')(),
math = require('../../../index'),
Node = require('../../../lib/expression/node/Node');
describe('parse', function() {

View File

@ -1,6 +1,6 @@
var assert = require('assert'),
error = require('../../../lib/error/index'),
math = require('../../../index')(),
math = require('../../../index'),
bignumber = math.bignumber;
describe('concat', function() {

View File

@ -1,7 +1,7 @@
var assert = require('assert'),
error = require('../../../lib/error/index'),
approx = require('../../../tools/approx'),
math = require('../../../index')();
math = require('../../../index');
describe('det', function() {

View File

@ -1,6 +1,6 @@
var assert = require('assert'),
error = require('../../../lib/error/index'),
math = require('../../../index')(),
math = require('../../../index'),
bignumber = math.bignumber;
describe('diag', function() {

View File

@ -33,7 +33,7 @@ describe('eye', function() {
});
it('should return an array when setting matrix=="array"', function() {
var math2 = math({matrix: 'array'});
var math2 = math.create({matrix: 'array'});
assert.deepEqual(math2.eye(2), [[1,0],[0,1]]);
});

View File

@ -2,7 +2,7 @@
var assert = require('assert'),
approx = require('../../../tools/approx'),
error = require('../../../lib/error/index'),
math = require('../../../index')(),
math = require('../../../index'),
inv = math.inv;
describe('inv', function() {

View File

@ -1,7 +1,7 @@
// test ones
var assert = require('assert'),
error = require('../../../lib/error/index'),
math = require('../../../index')(),
math = require('../../../index'),
ones = math.ones,
matrix = math.matrix;

View File

@ -43,7 +43,7 @@ describe('range', function() {
});
it('should output an array when setting matrix==="array"', function() {
var math2 = math({
var math2 = math.create({
matrix: 'array'
});
@ -79,14 +79,14 @@ describe('range', function() {
});
it('should parse a range with bignumbers', function() {
var bigmath = math({number: 'bignumber'});
var bigmath = math.create({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)]));
});
it('should throw an error when parsing a an invalid string to a bignumber range', function() {
var bigmath = math({number: 'bignumber'});
var bigmath = math.create({number: 'bignumber'});
assert.throws(function () {bigmath.range('1:a')}, /is no valid range/);
});

View File

@ -1,7 +1,7 @@
// test resize
var assert = require('assert'),
error = require('../../../lib/error/index'),
math = require('../../../index')(),
math = require('../../../index'),
Matrix = math.type.Matrix;
describe('resize', function() {
@ -60,20 +60,20 @@ describe('resize', function() {
});
it('should resize a scalar into an array when array is specified in settings', function() {
var math2 = math({matrix: 'array'});
var math2 = math.create({matrix: 'array'});
assert.deepEqual(math2.resize(2, [3], 4), [2, 4, 4]);
assert.deepEqual(math2.resize(2, [2,2], 4), [[2,4], [4,4]]);
});
it('should resize a vector into a 2d matrix', function() {
var math2 = math({matrix: 'array'});
var math2 = math.create({matrix: 'array'});
assert.deepEqual(math2.resize([1,2,3], [3,2], 0), [[1, 0], [2, 0], [3, 0]]);
});
it('should resize 2d matrix into a vector', function() {
var math2 = math({matrix: 'array'});
var math2 = math.create({matrix: 'array'});
assert.deepEqual(math2.resize([[1,2],[3,4],[5,6]], [3], 0), [1,3,5]);
});

View File

@ -40,7 +40,7 @@ describe('size', function() {
});
it('should calculate the size of a scalar with setting matrix=="array"', function() {
var math2 = math({matrix: 'array'});
var math2 = math.create({matrix: 'array'});
assert.deepEqual(math2.size(2), []);
assert.deepEqual(math2.size(math.bignumber(2)), []);
assert.deepEqual(math2.size(math.complex(2,3)), []);

View File

@ -1,7 +1,7 @@
// test squeeze
var assert = require('assert'),
error = require('../../../lib/error/index'),
math = require('../../../index')(),
math = require('../../../index'),
squeeze = math.squeeze,
size = math.size,
matrix = math.matrix;

View File

@ -1,6 +1,6 @@
var assert = require('assert'),
error = require('../../../lib/error/index'),
math = require('../../../index')(),
math = require('../../../index'),
subset = math.subset,
matrix = math.matrix,
range = math.range,

View File

@ -1,7 +1,7 @@
// test transpose
var assert = require('assert'),
error = require('../../../lib/error/index'),
math = require('../../../index')(),
math = require('../../../index'),
transpose = math.transpose;
describe('transpose', function() {

View File

@ -1,7 +1,7 @@
// test zeros
var assert = require('assert'),
error = require('../../../lib/error/index'),
math = require('../../../index')(),
math = require('../../../index'),
zeros = math.zeros,
matrix = math.matrix;

View File

@ -1,6 +1,6 @@
var assert = require('assert'),
error = require('../../../lib/error/index'),
math = require('../../../index')(),
math = require('../../../index'),
combinations = math.combinations;
describe('combinations', function() {

View File

@ -3,7 +3,7 @@ var assert = require('assert'),
seed = require('seed-random'),
_ = require('underscore'),
Matrix = require('../../../lib/type/Matrix'),
math = require('../../../index')();
math = require('../../../index');
var assertApproxEqual = function(testVal, val, tolerance) {
var diff = Math.abs(val - testVal);

View File

@ -1,6 +1,6 @@
var assert = require('assert'),
error = require('../../../lib/error/index'),
math = require('../../../index')(),
math = require('../../../index'),
factorial = math.factorial;
describe('factorial', function() {

View File

@ -1,6 +1,6 @@
var assert = require('assert'),
error = require('../../../lib/error/index'),
math = require('../../../index')(),
math = require('../../../index'),
permutations = math.permutations;
describe('permutations', function() {

View File

@ -1,5 +1,5 @@
var assert = require('assert'),
math = require('../../../index')();
math = require('../../../index');
describe('pickRandom', function () {
// Note: pickRandom is a convenience function generated by distribution

View File

@ -1,5 +1,5 @@
var assert = require('assert'),
math = require('../../../index')();
math = require('../../../index');
describe('random', function () {
// Note: random is a convenience function generated by distribution

View File

@ -1,5 +1,5 @@
var assert = require('assert'),
math = require('../../../index')();
math = require('../../../index');
describe('randomInt', function () {
// Note: randomInt is a convenience function generated by distribution

View File

@ -106,7 +106,7 @@ describe('compare', function() {
});
it('should apply configuration option epsilon', function() {
var mymath = math();
var mymath = math.create();
assert.equal(mymath.compare(1, 0.991), 1);
mymath.config({epsilon: 1e-2});
assert.equal(mymath.compare(1, 0.991), 0);

View File

@ -119,7 +119,7 @@ describe('equal', function() {
});
it('should apply configuration option epsilon', function() {
var mymath = math();
var mymath = math.create();
assert.equal(mymath.equal(1, 0.991), false);
mymath.config({epsilon: 1e-2});
assert.equal(mymath.equal(1, 0.991), true);

View File

@ -79,7 +79,7 @@ describe('larger', function() {
});
it('should apply configuration option epsilon', function() {
var mymath = math();
var mymath = math.create();
assert.equal(mymath.larger(1, 0.991), true);
mymath.config({epsilon: 1e-2});
assert.equal(mymath.larger(1, 0.991), false);

View File

@ -82,7 +82,7 @@ describe('largerEq', function() {
});
it('should apply configuration option epsilon', function() {
var mymath = math();
var mymath = math.create();
assert.equal(mymath.largerEq(1, 1.01), false);
mymath.config({epsilon: 1e-2});
assert.equal(mymath.largerEq(1, 1.01), true);

View File

@ -84,7 +84,7 @@ describe('smaller', function() {
});
it('should apply configuration option epsilon', function() {
var mymath = math();
var mymath = math.create();
assert.equal(mymath.smaller(0.991, 1), true);
mymath.config({epsilon: 1e-2});
assert.equal(mymath.smaller(0.991, 1), false);

View File

@ -85,7 +85,7 @@ describe('smallerEq', function() {
});
it('should apply configuration option epsilon', function() {
var mymath = math();
var mymath = math.create();
assert.equal(mymath.smallerEq(1.01, 1), false);
mymath.config({epsilon: 1e-2});
assert.equal(mymath.smallerEq(1.01, 1), true);

View File

@ -122,7 +122,7 @@ describe('unequal', function() {
});
it('should apply configuration option epsilon', function() {
var mymath = math();
var mymath = math.create();
assert.equal(mymath.unequal(1, 0.991), true);
mymath.config({epsilon: 1e-2});
assert.equal(mymath.unequal(1, 0.991), false);

View File

@ -1,5 +1,5 @@
var assert = require('assert'),
math = require('../../../index')(),
math = require('../../../index'),
bignumber = math.bignumber,
max = math.max;

View File

@ -1,5 +1,5 @@
var assert = require('assert'),
math = require('../../../index')(),
math = require('../../../index'),
bignumber = math.bignumber,
mean = math.mean;

View File

@ -1,6 +1,6 @@
var assert = require('assert'),
approx = require('../../../tools/approx'),
math = require('../../../index')(),
math = require('../../../index'),
bignumber = math.bignumber,
median = math.median;

View File

@ -1,5 +1,5 @@
var assert = require('assert'),
math = require('../../../index')(),
math = require('../../../index'),
bignumber = math.bignumber,
min = math.min;

View File

@ -1,5 +1,5 @@
var assert = require('assert'),
math = require('../../../index')(),
math = require('../../../index'),
bignumber = math.bignumber,
prod = math.prod;

View File

@ -1,6 +1,6 @@
var assert = require('assert'),
approx = require('../../../tools/approx'),
math = require('../../../index')(),
math = require('../../../index'),
bignumber = math.bignumber,
std = math.std;

View File

@ -1,5 +1,5 @@
var assert = require('assert'),
math = require('../../../index')(),
math = require('../../../index'),
bignumber = math.bignumber,
sum = math.sum;

Some files were not shown because too many files have changed in this diff Show More