mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-25 15:07:57 +00:00
math.options is no longer exposed as property
This commit is contained in:
parent
bcb1eaa790
commit
ea51c6c86c
@ -8,7 +8,7 @@ creating a math.js instance.
|
||||
Where possible, the type of matrix output from functions is determined from
|
||||
the function input: An array as input will return an Array, a Matrix as input
|
||||
will return a Matrix. In case of no matrix as input, the type of output is
|
||||
determined by the option `math.matrix.defaultType`. In case of mixed matrix
|
||||
determined by the option `options.matrix.defaultType`. In case of mixed matrix
|
||||
inputs, a matrix will be returned always.
|
||||
- `number.defaultType`. The default type of numbers. Available values are:
|
||||
`"number"` (default) or `"bignumber"`. Big numbers have higher precision
|
||||
|
||||
221
index.js
221
index.js
@ -9,59 +9,41 @@ var object = require('./lib/util/object');
|
||||
* var math = mathjs(options);
|
||||
*
|
||||
* @param {Object} [options] Available options:
|
||||
* {Number} format.precision
|
||||
* A number in the range 0-16. Default value is 5.
|
||||
* {String} matrix.defaultType
|
||||
* A string 'array' or 'matrix' (default).
|
||||
* A string 'matrix' (default) or 'array'.
|
||||
* {String} number.defaultType
|
||||
* A string 'number' (default) or 'bignumber'
|
||||
*/
|
||||
function mathjs (options) {
|
||||
// create new namespace
|
||||
var math = {};
|
||||
|
||||
// options
|
||||
// create configuration options
|
||||
// TODO: change options to properties with getters to validate the input value
|
||||
math.options = {
|
||||
var opt = {
|
||||
matrix: {
|
||||
// type of default matrix output. Choose 'array' or 'matrix' (default)
|
||||
// type of default matrix output. Choose 'matrix' (default) or 'array'
|
||||
'defaultType': 'matrix'
|
||||
},
|
||||
number: {
|
||||
// type of default number output. Choose 'number' (default) or 'bignumber'
|
||||
'defaultType': 'number'
|
||||
// TODO: add more options for BigNumber
|
||||
// TODO: document the new options
|
||||
// TODO: check all functions to see whether they need to support BigNumber output
|
||||
}
|
||||
};
|
||||
|
||||
// merge options
|
||||
object.deepExtend(math.options, options);
|
||||
object.deepExtend(opt, options);
|
||||
|
||||
// TODO: remove deprecated options some day (deprecated since version 0.15.0)
|
||||
if (Object.defineProperty) {
|
||||
var fnPrecision = function () {
|
||||
throw new Error('Option math.options.precision is deprecated. ' +
|
||||
'Use math.format(value, precision) instead.')
|
||||
};
|
||||
|
||||
Object.defineProperty(math.options, 'precision', {
|
||||
get: fnPrecision,
|
||||
set: fnPrecision,
|
||||
enumerable: false,
|
||||
configurable: false
|
||||
});
|
||||
|
||||
var fnDefault = function () {
|
||||
throw new Error('Option math.options.matrix.default is deprecated. ' +
|
||||
'Use math.options.matrix.defaultType instead.')
|
||||
};
|
||||
|
||||
Object.defineProperty(math.options.matrix, 'default', {
|
||||
get: fnDefault,
|
||||
set: fnDefault,
|
||||
enumerable: false,
|
||||
configurable: false
|
||||
});
|
||||
if (options && options.precision) {
|
||||
throw new Error('Option options.precision is deprecated. ' +
|
||||
'Use math.format(value, precision) instead.')
|
||||
}
|
||||
if (options && options.matrix && options.matrix.default) {
|
||||
throw new Error('Option math.options.matrix.default is deprecated. ' +
|
||||
'Use math.options.matrix.defaultType instead.')
|
||||
}
|
||||
|
||||
|
||||
@ -94,117 +76,118 @@ function mathjs (options) {
|
||||
|
||||
math.collection = require('./lib/type/collection.js');
|
||||
|
||||
|
||||
// expression parser
|
||||
require('./lib/function/expression/eval.js')(math);
|
||||
require('./lib/function/expression/help.js')(math);
|
||||
require('./lib/function/expression/parse.js')(math);
|
||||
require('./lib/function/expression/eval.js')(math, opt);
|
||||
require('./lib/function/expression/help.js')(math, opt);
|
||||
require('./lib/function/expression/parse.js')(math, opt);
|
||||
|
||||
// functions - arithmetic
|
||||
require('./lib/function/arithmetic/abs.js')(math);
|
||||
require('./lib/function/arithmetic/add.js')(math);
|
||||
require('./lib/function/arithmetic/add.js')(math);
|
||||
require('./lib/function/arithmetic/ceil.js')(math);
|
||||
require('./lib/function/arithmetic/cube.js')(math);
|
||||
require('./lib/function/arithmetic/divide.js')(math);
|
||||
require('./lib/function/arithmetic/edivide.js')(math);
|
||||
require('./lib/function/arithmetic/emultiply.js')(math);
|
||||
require('./lib/function/arithmetic/epow.js')(math);
|
||||
require('./lib/function/arithmetic/equal.js')(math);
|
||||
require('./lib/function/arithmetic/exp.js')(math);
|
||||
require('./lib/function/arithmetic/fix.js')(math);
|
||||
require('./lib/function/arithmetic/floor.js')(math);
|
||||
require('./lib/function/arithmetic/gcd.js')(math);
|
||||
require('./lib/function/arithmetic/larger.js')(math);
|
||||
require('./lib/function/arithmetic/largereq.js')(math);
|
||||
require('./lib/function/arithmetic/lcm.js')(math);
|
||||
require('./lib/function/arithmetic/log.js')(math);
|
||||
require('./lib/function/arithmetic/log10.js')(math);
|
||||
require('./lib/function/arithmetic/mod.js')(math);
|
||||
require('./lib/function/arithmetic/multiply.js')(math);
|
||||
require('./lib/function/arithmetic/pow.js')(math);
|
||||
require('./lib/function/arithmetic/round.js')(math);
|
||||
require('./lib/function/arithmetic/sign.js')(math);
|
||||
require('./lib/function/arithmetic/smaller.js')(math);
|
||||
require('./lib/function/arithmetic/smallereq.js')(math);
|
||||
require('./lib/function/arithmetic/sqrt.js')(math);
|
||||
require('./lib/function/arithmetic/square.js')(math);
|
||||
require('./lib/function/arithmetic/subtract.js')(math);
|
||||
require('./lib/function/arithmetic/unary.js')(math);
|
||||
require('./lib/function/arithmetic/unequal.js')(math);
|
||||
require('./lib/function/arithmetic/xgcd.js')(math);
|
||||
require('./lib/function/arithmetic/abs.js')(math, opt);
|
||||
require('./lib/function/arithmetic/add.js')(math, opt);
|
||||
require('./lib/function/arithmetic/add.js')(math, opt);
|
||||
require('./lib/function/arithmetic/ceil.js')(math, opt);
|
||||
require('./lib/function/arithmetic/cube.js')(math, opt);
|
||||
require('./lib/function/arithmetic/divide.js')(math, opt);
|
||||
require('./lib/function/arithmetic/edivide.js')(math, opt);
|
||||
require('./lib/function/arithmetic/emultiply.js')(math, opt);
|
||||
require('./lib/function/arithmetic/epow.js')(math, opt);
|
||||
require('./lib/function/arithmetic/equal.js')(math, opt);
|
||||
require('./lib/function/arithmetic/exp.js')(math, opt);
|
||||
require('./lib/function/arithmetic/fix.js')(math, opt);
|
||||
require('./lib/function/arithmetic/floor.js')(math, opt);
|
||||
require('./lib/function/arithmetic/gcd.js')(math, opt);
|
||||
require('./lib/function/arithmetic/larger.js')(math, opt);
|
||||
require('./lib/function/arithmetic/largereq.js')(math, opt);
|
||||
require('./lib/function/arithmetic/lcm.js')(math, opt);
|
||||
require('./lib/function/arithmetic/log.js')(math, opt);
|
||||
require('./lib/function/arithmetic/log10.js')(math, opt);
|
||||
require('./lib/function/arithmetic/mod.js')(math, opt);
|
||||
require('./lib/function/arithmetic/multiply.js')(math, opt);
|
||||
require('./lib/function/arithmetic/pow.js')(math, opt);
|
||||
require('./lib/function/arithmetic/round.js')(math, opt);
|
||||
require('./lib/function/arithmetic/sign.js')(math, opt);
|
||||
require('./lib/function/arithmetic/smaller.js')(math, opt);
|
||||
require('./lib/function/arithmetic/smallereq.js')(math, opt);
|
||||
require('./lib/function/arithmetic/sqrt.js')(math, opt);
|
||||
require('./lib/function/arithmetic/square.js')(math, opt);
|
||||
require('./lib/function/arithmetic/subtract.js')(math, opt);
|
||||
require('./lib/function/arithmetic/unary.js')(math, opt);
|
||||
require('./lib/function/arithmetic/unequal.js')(math, opt);
|
||||
require('./lib/function/arithmetic/xgcd.js')(math, opt);
|
||||
|
||||
// functions - complex
|
||||
require('./lib/function/complex/arg.js')(math);
|
||||
require('./lib/function/complex/conj.js')(math);
|
||||
require('./lib/function/complex/re.js')(math);
|
||||
require('./lib/function/complex/im.js')(math);
|
||||
require('./lib/function/complex/arg.js')(math, opt);
|
||||
require('./lib/function/complex/conj.js')(math, opt);
|
||||
require('./lib/function/complex/re.js')(math, opt);
|
||||
require('./lib/function/complex/im.js')(math, opt);
|
||||
|
||||
// functions - construction
|
||||
require('./lib/function/construction/bignumber')(math);
|
||||
require('./lib/function/construction/boolean.js')(math);
|
||||
require('./lib/function/construction/complex.js')(math);
|
||||
require('./lib/function/construction/index.js')(math);
|
||||
require('./lib/function/construction/matrix.js')(math);
|
||||
require('./lib/function/construction/number.js')(math);
|
||||
require('./lib/function/construction/parser.js')(math);
|
||||
require('./lib/function/construction/string.js')(math);
|
||||
require('./lib/function/construction/unit.js')(math);
|
||||
require('./lib/function/construction/bignumber')(math, opt);
|
||||
require('./lib/function/construction/boolean.js')(math, opt);
|
||||
require('./lib/function/construction/complex.js')(math, opt);
|
||||
require('./lib/function/construction/index.js')(math, opt);
|
||||
require('./lib/function/construction/matrix.js')(math, opt);
|
||||
require('./lib/function/construction/number.js')(math, opt);
|
||||
require('./lib/function/construction/parser.js')(math, opt);
|
||||
require('./lib/function/construction/string.js')(math, opt);
|
||||
require('./lib/function/construction/unit.js')(math, opt);
|
||||
|
||||
// functions - matrix
|
||||
require('./lib/function/matrix/concat.js')(math);
|
||||
require('./lib/function/matrix/det.js')(math);
|
||||
require('./lib/function/matrix/diag.js')(math);
|
||||
require('./lib/function/matrix/eye.js')(math);
|
||||
require('./lib/function/matrix/inv.js')(math);
|
||||
require('./lib/function/matrix/ones.js')(math);
|
||||
require('./lib/function/matrix/range.js')(math);
|
||||
require('./lib/function/matrix/resize.js')(math);
|
||||
require('./lib/function/matrix/size.js')(math);
|
||||
require('./lib/function/matrix/squeeze.js')(math);
|
||||
require('./lib/function/matrix/subset.js')(math);
|
||||
require('./lib/function/matrix/transpose.js')(math);
|
||||
require('./lib/function/matrix/zeros.js')(math);
|
||||
require('./lib/function/matrix/concat.js')(math, opt);
|
||||
require('./lib/function/matrix/det.js')(math, opt);
|
||||
require('./lib/function/matrix/diag.js')(math, opt);
|
||||
require('./lib/function/matrix/eye.js')(math, opt);
|
||||
require('./lib/function/matrix/inv.js')(math, opt);
|
||||
require('./lib/function/matrix/ones.js')(math, opt);
|
||||
require('./lib/function/matrix/range.js')(math, opt);
|
||||
require('./lib/function/matrix/resize.js')(math, opt);
|
||||
require('./lib/function/matrix/size.js')(math, opt);
|
||||
require('./lib/function/matrix/squeeze.js')(math, opt);
|
||||
require('./lib/function/matrix/subset.js')(math, opt);
|
||||
require('./lib/function/matrix/transpose.js')(math, opt);
|
||||
require('./lib/function/matrix/zeros.js')(math, opt);
|
||||
|
||||
// functions - probability
|
||||
require('./lib/function/probability/factorial.js')(math);
|
||||
require('./lib/function/probability/random.js')(math);
|
||||
require('./lib/function/probability/factorial.js')(math, opt);
|
||||
require('./lib/function/probability/random.js')(math, opt);
|
||||
|
||||
// functions - statistics
|
||||
require('./lib/function/statistics/min.js')(math);
|
||||
require('./lib/function/statistics/max.js')(math);
|
||||
require('./lib/function/statistics/mean.js')(math);
|
||||
require('./lib/function/statistics/min.js')(math, opt);
|
||||
require('./lib/function/statistics/max.js')(math, opt);
|
||||
require('./lib/function/statistics/mean.js')(math, opt);
|
||||
|
||||
// functions - trigonometry
|
||||
require('./lib/function/trigonometry/acos.js')(math);
|
||||
require('./lib/function/trigonometry/asin.js')(math);
|
||||
require('./lib/function/trigonometry/atan.js')(math);
|
||||
require('./lib/function/trigonometry/atan2.js')(math);
|
||||
require('./lib/function/trigonometry/cos.js')(math);
|
||||
require('./lib/function/trigonometry/cot.js')(math);
|
||||
require('./lib/function/trigonometry/csc.js')(math);
|
||||
require('./lib/function/trigonometry/sec.js')(math);
|
||||
require('./lib/function/trigonometry/sin.js')(math);
|
||||
require('./lib/function/trigonometry/tan.js')(math);
|
||||
require('./lib/function/trigonometry/acos.js')(math, opt);
|
||||
require('./lib/function/trigonometry/asin.js')(math, opt);
|
||||
require('./lib/function/trigonometry/atan.js')(math, opt);
|
||||
require('./lib/function/trigonometry/atan2.js')(math, opt);
|
||||
require('./lib/function/trigonometry/cos.js')(math, opt);
|
||||
require('./lib/function/trigonometry/cot.js')(math, opt);
|
||||
require('./lib/function/trigonometry/csc.js')(math, opt);
|
||||
require('./lib/function/trigonometry/sec.js')(math, opt);
|
||||
require('./lib/function/trigonometry/sin.js')(math, opt);
|
||||
require('./lib/function/trigonometry/tan.js')(math, opt);
|
||||
|
||||
// functions - units
|
||||
require('./lib/function/units/in.js')(math);
|
||||
require('./lib/function/units/in.js')(math, opt);
|
||||
|
||||
// functions - utils
|
||||
require('./lib/function/utils/clone.js')(math);
|
||||
require('./lib/function/utils/format.js')(math);
|
||||
require('./lib/function/utils/import.js')(math);
|
||||
require('./lib/function/utils/map.js')(math);
|
||||
require('./lib/function/utils/print.js')(math);
|
||||
require('./lib/function/utils/select.js')(math);
|
||||
require('./lib/function/utils/typeof.js')(math);
|
||||
require('./lib/function/utils/forEach.js')(math);
|
||||
require('./lib/function/utils/clone.js')(math, opt);
|
||||
require('./lib/function/utils/format.js')(math, opt);
|
||||
require('./lib/function/utils/import.js')(math, opt);
|
||||
require('./lib/function/utils/map.js')(math, opt);
|
||||
require('./lib/function/utils/print.js')(math, opt);
|
||||
require('./lib/function/utils/select.js')(math, opt);
|
||||
require('./lib/function/utils/typeof.js')(math, opt);
|
||||
require('./lib/function/utils/forEach.js')(math, opt);
|
||||
|
||||
// constants
|
||||
require('./lib/constants.js')(math);
|
||||
require('./lib/constants.js')(math, opt);
|
||||
|
||||
// selector (we initialize after all functions are loaded)
|
||||
math.chaining = {};
|
||||
math.chaining.Selector = require('./lib/chaining/Selector.js')(math);
|
||||
math.chaining.Selector = require('./lib/chaining/Selector.js')(math, opt);
|
||||
|
||||
// TODO: deprecated since version 0.13.0. Cleanup some day
|
||||
math.expr.Selector = function () {
|
||||
|
||||
@ -7,12 +7,12 @@ var Node = require('./Node'),
|
||||
/**
|
||||
* @constructor ArrayNode
|
||||
* Holds an 1-dimensional array with nodes
|
||||
* @param {Object} math The math namespace containing all functions
|
||||
* @param {Object} options Object with the math.js configuration options
|
||||
* @param {Array} nodes 1 dimensional array with nodes
|
||||
* @extends {Node}
|
||||
*/
|
||||
function ArrayNode(math, nodes) {
|
||||
this.math = math;
|
||||
function ArrayNode(options, nodes) {
|
||||
this.options = options; // math.js options
|
||||
this.nodes = nodes || [];
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ ArrayNode.prototype.eval = function() {
|
||||
results[i] = (result instanceof Matrix) ? result.valueOf() : result;
|
||||
}
|
||||
|
||||
return (this.math.options.matrix.defaultType === 'array') ? results : new Matrix(results);
|
||||
return (this.options.matrix.defaultType === 'array') ? results : new Matrix(results);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
module.exports = function (math) {
|
||||
module.exports = function (math, options) {
|
||||
var util = require('../../util/index'),
|
||||
|
||||
isString = util.string.isString,
|
||||
@ -1098,7 +1098,7 @@ module.exports = function (math) {
|
||||
}
|
||||
}
|
||||
|
||||
array = new ArrayNode(math, params);
|
||||
array = new ArrayNode(options, params);
|
||||
}
|
||||
else {
|
||||
// 1 dimensional vector
|
||||
@ -1113,7 +1113,7 @@ module.exports = function (math) {
|
||||
else {
|
||||
// this is an empty matrix "[ ]"
|
||||
getToken();
|
||||
array = new ArrayNode(math, []);
|
||||
array = new ArrayNode(options, []);
|
||||
}
|
||||
|
||||
// parse parameters
|
||||
@ -1152,7 +1152,7 @@ module.exports = function (math) {
|
||||
}
|
||||
}
|
||||
|
||||
return new ArrayNode(math, params);
|
||||
return new ArrayNode(options, params);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1166,7 +1166,7 @@ module.exports = function (math) {
|
||||
|
||||
if (token_type == TOKENTYPE.NUMBER) {
|
||||
// this is a number
|
||||
if (math.options.number.defaultType == 'bignumber') {
|
||||
if (options.number.defaultType == 'bignumber') {
|
||||
// parse a big number
|
||||
number = new BigNumber((token == '.') ? 0 : token);
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
module.exports = function (math) {
|
||||
module.exports = function (math, options) {
|
||||
var util = require('../../util/index'),
|
||||
|
||||
Matrix = require('../../type/Matrix'),
|
||||
@ -66,7 +66,7 @@ module.exports = function (math) {
|
||||
for (i = 0; i < iMax; i++) {
|
||||
data[i + kSub][i + kSuper] = object.clone(vector[i]);
|
||||
}
|
||||
return (math.options.matrix.defaultType === 'array') ? matrix.valueOf() : matrix;
|
||||
return (options.matrix.defaultType === 'array') ? matrix.valueOf() : matrix;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
@ -77,7 +77,7 @@ module.exports = function (math) {
|
||||
for (i = 0; i < iMax; i++) {
|
||||
vector[i] = object.clone(data[i + kSub][i + kSuper]);
|
||||
}
|
||||
return (math.options.matrix.defaultType === 'array') ? vector : new Matrix(vector);
|
||||
return (options.matrix.defaultType === 'array') ? vector : new Matrix(vector);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
module.exports = function (math) {
|
||||
module.exports = function (math, options) {
|
||||
var util = require('../../util/index'),
|
||||
|
||||
Matrix = require('../../type/Matrix'),
|
||||
@ -23,7 +23,7 @@ module.exports = function (math) {
|
||||
math.eye = function eye (size) {
|
||||
var args = collection.argsToArray(arguments),
|
||||
asMatrix = (size instanceof Matrix) ? true :
|
||||
(isArray(size) ? false : (math.options.matrix.defaultType === 'matrix'));
|
||||
(isArray(size) ? false : (options.matrix.defaultType === 'matrix'));
|
||||
|
||||
|
||||
if (args.length == 0) {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
module.exports = function (math) {
|
||||
module.exports = function (math, options) {
|
||||
var util = require('../../util/index'),
|
||||
|
||||
Matrix = require('../../type/Matrix'),
|
||||
@ -22,7 +22,7 @@ module.exports = function (math) {
|
||||
math.ones = function ones (size) {
|
||||
var args = collection.argsToArray(arguments);
|
||||
var asMatrix = (size instanceof Matrix) ? true :
|
||||
(isArray(size) ? false : (math.options.matrix.defaultType === 'matrix'));
|
||||
(isArray(size) ? false : (options.matrix.defaultType === 'matrix'));
|
||||
|
||||
if (args.length == 0) {
|
||||
// output an empty matrix
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
module.exports = function (math) {
|
||||
module.exports = function (math, options) {
|
||||
var util = require('../../util/index'),
|
||||
|
||||
Matrix = require('../../type/Matrix'),
|
||||
@ -91,7 +91,7 @@ module.exports = function (math) {
|
||||
}
|
||||
}
|
||||
|
||||
return (math.options.matrix.defaultType === 'array') ? array : new Matrix(array);
|
||||
return (options.matrix.defaultType === 'array') ? array : new Matrix(array);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
module.exports = function (math) {
|
||||
module.exports = function (math, options) {
|
||||
var util = require('../../util/index'),
|
||||
|
||||
Matrix = require('../../type/Matrix'),
|
||||
@ -28,7 +28,7 @@ module.exports = function (math) {
|
||||
}
|
||||
|
||||
var asMatrix = (x instanceof Matrix) ? true : isArray(x) ? false :
|
||||
(math.options.matrix.defaultType !== 'array');
|
||||
(options.matrix.defaultType !== 'array');
|
||||
|
||||
if (x instanceof Matrix) {
|
||||
x = x.valueOf(); // get Array
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
module.exports = function (math) {
|
||||
module.exports = function (math, options) {
|
||||
var util = require('../../util/index'),
|
||||
|
||||
Complex = require('../../type/Complex'),
|
||||
@ -25,7 +25,7 @@ module.exports = function (math) {
|
||||
throw new util.error.ArgumentsError('size', arguments.length, 1);
|
||||
}
|
||||
|
||||
var asArray = (math.options.matrix.defaultType === 'array');
|
||||
var asArray = (options.matrix.defaultType === 'array');
|
||||
|
||||
if (isNumber(x) || isComplex(x) || isUnit(x) || isBoolean(x) || x == null) {
|
||||
return asArray ? [] : new Matrix([]);
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
module.exports = function (math) {
|
||||
module.exports = function (math, options) {
|
||||
var util = require('../../util/index'),
|
||||
|
||||
Matrix = require('../../type/Matrix'),
|
||||
@ -21,7 +21,7 @@ module.exports = function (math) {
|
||||
math.zeros = function zeros (size) {
|
||||
var args = collection.argsToArray(arguments);
|
||||
var asMatrix = (size instanceof Matrix) ? true :
|
||||
(isArray(size) ? false : (math.options.matrix.defaultType === 'matrix'));
|
||||
(isArray(size) ? false : (options.matrix.defaultType === 'matrix'));
|
||||
|
||||
if (args.length == 0) {
|
||||
// output an empty matrix
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
module.exports = function (math) {
|
||||
module.exports = function (math, options) {
|
||||
var util = require('../../util/index'),
|
||||
|
||||
Matrix = require('../../type/Matrix'),
|
||||
@ -93,7 +93,7 @@ module.exports = function (math) {
|
||||
if (min === undefined) min = 0;
|
||||
if (size !== undefined) {
|
||||
var res = _randomDataForMatrix(size, min, max, _random);
|
||||
return (math.options.matrix.defaultType === 'array') ? res : new Matrix(res);
|
||||
return (options.matrix.defaultType === 'array') ? res : new Matrix(res);
|
||||
}
|
||||
else return _random(min, max);
|
||||
},
|
||||
@ -123,7 +123,7 @@ module.exports = function (math) {
|
||||
if (min === undefined) min = 0;
|
||||
if (size !== undefined) {
|
||||
var res = _randomDataForMatrix(size, min, max, _randomInt);
|
||||
return (math.options.matrix.defaultType === 'array') ? res : new Matrix(res);
|
||||
return (options.matrix.defaultType === 'array') ? res : new Matrix(res);
|
||||
}
|
||||
else return _randomInt(min, max);
|
||||
},
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
var assert = require('assert'),
|
||||
math = require('../../../index')(),
|
||||
mathjs = require('../../../index'),
|
||||
math = mathjs(),
|
||||
range = math.range,
|
||||
matrix = math.matrix;
|
||||
|
||||
@ -26,14 +27,13 @@ describe('range', function() {
|
||||
assert.deepEqual(range(2,-4,-2), matrix([2,0,-2]));
|
||||
});
|
||||
|
||||
it('should output an array when math.options.matrix.defaultType==="array"', function() {
|
||||
var old = math.options.matrix.defaultType;
|
||||
math.options.matrix.defaultType = 'array';
|
||||
it('should output an array when options.matrix.defaultType==="array"', function() {
|
||||
var math2 = mathjs({
|
||||
matrix: {defaultType: 'array'}
|
||||
});
|
||||
|
||||
assert.deepEqual(range(0,10,2), [0,2,4,6,8]);
|
||||
assert.deepEqual(range(5,0,-1), [5,4,3,2,1]);
|
||||
|
||||
math.options.matrix.defaultType = old;
|
||||
assert.deepEqual(math2.range(0,10,2), [0,2,4,6,8]);
|
||||
assert.deepEqual(math2.range(5,0,-1), [5,4,3,2,1]);
|
||||
});
|
||||
|
||||
it('should throw an error if called with an invalid string', function() {
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
// test options
|
||||
var assert = require('assert'),
|
||||
math = require('../index')();
|
||||
|
||||
|
||||
describe('options', function() {
|
||||
|
||||
it('should have option matrix.defaultType', function() {
|
||||
assert.equal(math.options.matrix.defaultType, 'matrix');
|
||||
});
|
||||
|
||||
it('should have option number.defaultType', function() {
|
||||
assert.equal(math.options.number.defaultType, 'number');
|
||||
});
|
||||
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user