Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mathjs

Package Overview
Dependencies
Maintainers
1
Versions
282
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mathjs - npm Package Compare versions

Comparing version 0.16.0 to 0.17.0

examples/old_browser_example.html

25

docs/configuration.md

@@ -7,3 +7,3 @@ # Configuration

- `matrix.defaultType`. The default type of matrix output for functions.
- `matrix`. The default type of matrix output for functions.
Available values are: `'matrix'` (default) or `'array'`.

@@ -13,11 +13,12 @@ Where possible, the type of matrix output from functions is determined from

will return a Matrix. In case of no matrix as input, the type of output is
determined by the option `matrix.defaultType`. In case of mixed matrix
determined by the option `matrix`. In case of mixed matrix
inputs, a matrix will be returned always.
- `number.defaultType`. The default type of numbers. Available values are:
- `number`. The default type of numbers. Available values are:
`'number'` (default) or `'bignumber'`. Big numbers have higher precision
than the default numbers of JavaScript.
- `number.precision`. The number of significant digits for big numbers.
Only applies to big numbers, not to numbers. Default value is 20.
- `decimals`. The maximum number of decimal places behind the decimal
point (not the number of significant digits). Only applies to big numbers,
not to numbers. Default value is 20.

@@ -56,5 +57,3 @@ *Important: This setting is applied application wide to all BigNumbers.

var settings = {
matrix: {
defaultType: 'array'
}
matrix: 'array'
};

@@ -68,5 +67,3 @@ var math2 = mathjs(settings);

math2.config({
matrix: {
defaultType: 'matrix'
}
matrix: 'matrix'
});

@@ -86,6 +83,4 @@

var math3 = mathjs({
number: {
defaultType: 'bignumber',
precision: 32
}
number: 'bignumber',
decimals: 32
});

@@ -92,0 +87,0 @@

23

docs/datatypes/bignumbers.md

@@ -19,6 +19,4 @@ # Big Numbers

math = mathjs({
number: {
defaultType: 'bignumber', // Choose from: 'number' (default), 'bignumber',
precision: 20 // For bignumbers. Default value is 20.
}
number: 'bignumber', // Default type of number: 'number' (default) or 'bignumber'
decimals: 20 // Number decimal places behind the dot for big numbers
});

@@ -32,7 +30,6 @@

BigNumber is not supported by the following functions:
`exp`, `gcd`, `lcm`, `log`, `log10`, `xgcd`,
`arg`,
`random`,
`acos`, `asin`, `atan`, `atan2`, `cos`, `cot`, `csc`, `sec`, `sin`, `tan`,
`range`.
exp, gcd, lcm, log, log10, xgcd,
arg,
random,
acos, asin, atan, atan2, cos, cot, csc, sec, sin, tan.
These functions will downgrade BigNumber to Number, and return a Number.*

@@ -62,10 +59,8 @@

*Important: the bignumber.js library uses fixed point numbers and is therefore
not suitable to handle extremely large (> 1e+100) and small (< 1e-100) numbers.
To work with small numbers, `DECIMAL_PLACES` must be configured sufficiently
large.*
*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
`number` and `bignumber`. When converting a big number to a number, the high
precision of the will be lost.When a BigNumber is too large to be represented
precision of the will be lost. When a BigNumber is too large to be represented
as Number, it will be initialized as `Infinity`.

@@ -72,0 +67,0 @@

@@ -23,3 +23,3 @@ # Matrices

For functions where the type of output cannot be determined from the
input, the output is determined by the configuration option `matrix.defaultType`,
input, the output is determined by the configuration option `matrix`,
which can be a string `'matrix'` (default) or `'array'`.

@@ -41,3 +41,3 @@

// create a matrix. Type of output of function ones is determined by the
// configuration option matrix.defaultType
// configuration option `matrix`
math.ones(2, 3); // Matrix, [[1, 1, 1], [1, 1, 1]]

@@ -105,3 +105,3 @@ ```

be a Matrix. Note that in case of numbers as arguments, the output is
determined by the option `matrix.defaultType` as discussed in section
determined by the option `matrix` as discussed in section
[Arrays and matrices](#Arrays_and_matrices).

@@ -162,5 +162,5 @@

The size of a matrix can be calculated with the function `size`. Function `size`
returns a `Matrix` or `Array`, depending on the configuration option
`matrix.defaultType`. Furthermore, matrices have a function `size`
as well, which always returns an Array.
returns a `Matrix` or `Array`, depending on the configuration option `matrix`.
Furthermore, matrices have a function `size` as well, which always returns
an Array.

@@ -167,0 +167,0 @@ ```js

@@ -7,3 +7,3 @@ # Numbers

- BigNumber for arbitrary precision arithmetic, describe on the page
[Big Numbers]](bignumbers.md).
[Big Numbers](bignumbers.md).

@@ -15,5 +15,3 @@ The default number type can be configured when instantiating math.js:

math = mathjs({
number: {
defaultType: 'number' // Choose from: 'number' (default), 'bignumber'
}
number: 'number' // Default type of number: 'number' (default) or 'bignumber'
});

@@ -20,0 +18,0 @@ ```

@@ -423,5 +423,3 @@ # Expressions

math = mathjs({
number: {
defaultType: 'bignumber' // Choose from: 'number' (default) or 'bignumber'
}
number: 'bignumber' // Default type of number: 'number' (default) or 'bignumber'
});

@@ -428,0 +426,0 @@

@@ -76,2 +76,7 @@ # Getting Started

If support for old browsers (Internet Explorer 8 and older) is required,
the [es5-shim](https://github.com/kriskowal/es5-shim) library must be loaded
as well.
### Require.js

@@ -78,0 +83,0 @@

@@ -7,6 +7,4 @@ // big numbers

math = mathjs({
number: {
defaultType: 'number', // Choose from: 'number' (default), 'bignumber'
precision: 20 // number of digits for big numbers
}
number: 'bignumber', // Default type of number: 'number' (default) or 'bignumber'
decimals: 20 // number decimal places behind the dot for big numbers
});

@@ -13,0 +11,0 @@

@@ -5,2 +5,14 @@ # math.js history

## 2013-12-12, version 0.17.0
- Renamed and flattened configuration settings:
- `number.defaultType` is now `number`.
- `number.precision` is now `decimals`.
- `matrix.defaultType` is now `matrix`.
- Function `multiply` now consistently outputs a complex number on complex input.
- Fixed `mod` and `in` not working as function (only as operator).
- Fixed support for old browsers (IE8 and older), compatible when using es5-shim.
- Fixed support for Java's ScriptEngine.
## 2013-11-28, version 0.16.0

@@ -7,0 +19,0 @@

@@ -60,3 +60,3 @@ // constants

exports.bignumber = require('./function/construction/bignumber');
exports.boolean = require('./function/construction/boolean');
exports['boolean'] = require('./function/construction/boolean');
exports.complex = require('./function/construction/complex');

@@ -63,0 +63,0 @@ exports.index = require('./function/construction/index');

@@ -37,3 +37,3 @@ var Node = require('./Node'),

return (this.settings.matrix.defaultType === 'array') ? results : new Matrix(results);
return (this.settings.matrix === 'array') ? results : new Matrix(results);
};

@@ -40,0 +40,0 @@

@@ -38,8 +38,4 @@ var Node = require('./Node');

// TODO: don't override the functions default toString()
this.fn.toString = function() {
// TODO: what to return as toString?
return name + '(' + variables.join(', ') + ')';
//return name + '(' + variableNames.join(', ') + ') = ' + expr.toString();
};
// add a field describing the function syntax
this.fn.syntax = name + '(' + variables.join(', ') + ')';
}

@@ -86,5 +82,5 @@

FunctionNode.prototype.toString = function() {
return this.fn.toString();
return this.fn.description;
};
module.exports = FunctionNode;

@@ -69,3 +69,3 @@ var number = require('../../util/number'),

return (this.settings.matrix.defaultType === 'array') ? array : new Matrix(array);
return (this.settings.matrix === 'array') ? array : new Matrix(array);
};

@@ -72,0 +72,0 @@

@@ -10,3 +10,3 @@ module.exports = function (math) {

isNumber = util.number.isNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isComplex = Complex.isComplex,

@@ -13,0 +13,0 @@ isCollection = collection.isCollection;

@@ -10,3 +10,3 @@ module.exports = function (math) {

isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isNumber = util.number.isNumber,

@@ -13,0 +13,0 @@ toNumber = util.number.toNumber,

@@ -9,3 +9,3 @@ module.exports = function (math) {

isNumber = util.number.isNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isCollection =collection.isCollection,

@@ -12,0 +12,0 @@ isComplex = Complex.isComplex;

@@ -9,3 +9,3 @@ module.exports = function (math) {

isNumber = util.number.isNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isComplex = Complex.isComplex,

@@ -12,0 +12,0 @@ isCollection = collection.isCollection;

@@ -13,3 +13,3 @@ module.exports = function(math) {

toBigNumber = util.number.toBigNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isComplex = Complex.isComplex,

@@ -16,0 +16,0 @@ isUnit = Unit.isUnit,

@@ -12,3 +12,3 @@ module.exports = function (math) {

toBigNumber = util.number.toBigNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isString = util.string.isString,

@@ -15,0 +15,0 @@ isComplex = Complex.isComplex,

@@ -10,3 +10,3 @@ module.exports = function (math) {

isNumber = util.number.isNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isComplex = Complex.isComplex,

@@ -13,0 +13,0 @@ isCollection = collection.isCollection;

@@ -9,3 +9,3 @@ module.exports = function (math) {

isNumber = util.number.isNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isComplex = Complex.isComplex,

@@ -12,0 +12,0 @@ isCollection = collection.isCollection;

@@ -9,3 +9,3 @@ module.exports = function (math) {

isNumber = util.number.isNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isComplex = Complex.isComplex,

@@ -12,0 +12,0 @@ isCollection = collection.isCollection;

@@ -9,3 +9,3 @@ module.exports = function (math) {

toNumber = util.number.toNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isInteger = util.number.isInteger,

@@ -12,0 +12,0 @@ isCollection = collection.isCollection;

@@ -12,3 +12,3 @@ module.exports = function (math) {

toBigNumber = util.number.toBigNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isString = util.string.isString,

@@ -15,0 +15,0 @@ isComplex = Complex.isComplex,

@@ -12,3 +12,3 @@ module.exports = function (math) {

toBigNumber = util.number.toBigNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isString = util.string.isString,

@@ -15,0 +15,0 @@ isComplex = Complex.isComplex,

@@ -9,3 +9,3 @@ module.exports = function (math) {

toNumber = util.number.toNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isInteger = util.number.isInteger,

@@ -12,0 +12,0 @@ isCollection = collection.isCollection;

@@ -9,3 +9,3 @@ module.exports = function (math) {

isNumber = util.number.isNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isComplex = Complex.isComplex,

@@ -12,0 +12,0 @@ isCollection = collection.isCollection;

@@ -9,3 +9,3 @@ module.exports = function (math) {

isNumber = util.number.isNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isComplex = Complex.isComplex,

@@ -12,0 +12,0 @@ isCollection = collection.isCollection;

@@ -10,3 +10,3 @@ module.exports = function (math) {

toBigNumber = util.number.toBigNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isCollection = collection.isCollection;

@@ -13,0 +13,0 @@

@@ -14,3 +14,3 @@ module.exports = function(math) {

toBigNumber = util.number.toBigNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isComplex = Complex.isComplex,

@@ -337,3 +337,3 @@ isArray = Array.isArray,

// y is pure real
return x.re * y.re;
return new Complex(x.re * y.re, 0);
}

@@ -366,3 +366,3 @@ else if (y.re == 0) {

// y is pure complex
return -x.im * y.im;
return new Complex(-x.im * y.im, 0);
}

@@ -369,0 +369,0 @@ else {

@@ -13,3 +13,3 @@ module.exports = function (math) {

toBigNumber = util.number.toBigNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isArray = Array.isArray,

@@ -16,0 +16,0 @@ isInteger = util.number.isInteger,

@@ -10,3 +10,3 @@ module.exports = function (math) {

isInteger = util.number.isInteger,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isComplex = Complex.isComplex,

@@ -13,0 +13,0 @@ isCollection = collection.isCollection;

@@ -10,3 +10,3 @@ module.exports = function (math) {

isNumber = util.number.isNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isComplex = Complex.isComplex,

@@ -13,0 +13,0 @@ isCollection = collection.isCollection;

@@ -12,3 +12,3 @@ module.exports = function (math) {

toBigNumber = util.number.toBigNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isString = util.string.isString,

@@ -15,0 +15,0 @@ isComplex = Complex.isComplex,

@@ -12,3 +12,3 @@ module.exports = function (math) {

toBigNumber = util.number.toBigNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isString = util.string.isString,

@@ -15,0 +15,0 @@ isComplex = Complex.isComplex,

@@ -9,3 +9,3 @@ module.exports = function (math) {

isNumber = util.number.isNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isComplex = Complex.isComplex,

@@ -12,0 +12,0 @@ isCollection = collection.isCollection;

@@ -9,3 +9,3 @@ module.exports = function (math) {

isNumber = util.number.isNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isComplex = Complex.isComplex,

@@ -12,0 +12,0 @@ isCollection = collection.isCollection;

@@ -12,3 +12,3 @@ module.exports = function (math) {

toBigNumber = util.number.toBigNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isNumber = util.number.isNumber,

@@ -15,0 +15,0 @@ isComplex = Complex.isComplex,

@@ -10,3 +10,3 @@ module.exports = function (math) {

isNumber = util.number.isNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isComplex = Complex.isComplex,

@@ -13,0 +13,0 @@ isUnit = Unit.isUnit,

@@ -12,3 +12,3 @@ module.exports = function (math) {

toBigNumber = util.number.toBigNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isString = util.string.isString,

@@ -15,0 +15,0 @@ isComplex = Complex.isComplex,

@@ -8,3 +8,3 @@ module.exports = function (math) {

isNumber = util.number.isNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isInteger = util.number.isInteger;

@@ -11,0 +11,0 @@

@@ -9,3 +9,3 @@ module.exports = function (math) {

isNumber = util.number.isNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isCollection = collection.isCollection,

@@ -12,0 +12,0 @@ isComplex = Complex.isComplex;

@@ -10,3 +10,3 @@ module.exports = function (math) {

isNumber = util.number.isNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isCollection =collection.isCollection,

@@ -13,0 +13,0 @@ isComplex = Complex.isComplex;

@@ -9,3 +9,3 @@ module.exports = function (math) {

isNumber = util.number.isNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isCollection =collection.isCollection,

@@ -12,0 +12,0 @@ isComplex = Complex.isComplex;

@@ -10,3 +10,3 @@ module.exports = function (math) {

isNumber = util.number.isNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isCollection = collection.isCollection,

@@ -13,0 +13,0 @@ isComplex = Complex.isComplex;

@@ -10,3 +10,3 @@ module.exports = function (math) {

isString = util.string.isString,
isBoolean = util.boolean.isBoolean;
isBoolean = util['boolean'].isBoolean;

@@ -13,0 +13,0 @@ // extend BigNumber with a function clone

@@ -573,3 +573,3 @@ module.exports = function (math, settings) {

// implicit start=1 (one-based)
var one = (settings.number.defaultType === 'bignumber') ? new BigNumber(1) : 1;
var one = (settings.number === 'bignumber') ? new BigNumber(1) : 1;
node = new ConstantNode(one);

@@ -944,3 +944,4 @@ }

if (token_type == TOKENTYPE.SYMBOL) {
if (token_type == TOKENTYPE.SYMBOL ||
(token_type == TOKENTYPE.DELIMITER && token in NAMED_DELIMITERS)) {
name = token;

@@ -1173,3 +1174,3 @@

// this is a number
if (settings.number.defaultType == 'bignumber') {
if (settings.number == 'bignumber') {
// parse a big number

@@ -1176,0 +1177,0 @@ number = new BigNumber((token == '.') ? 0 : token);

@@ -69,3 +69,3 @@ module.exports = function (math, settings) {

}
return (settings.matrix.defaultType === 'array') ? matrix.valueOf() : matrix;
return (settings.matrix === 'array') ? matrix.valueOf() : matrix;
break;

@@ -81,3 +81,3 @@

}
return (settings.matrix.defaultType === 'array') ? vector : new Matrix(vector);
return (settings.matrix === 'array') ? vector : new Matrix(vector);
break;

@@ -84,0 +84,0 @@

@@ -28,3 +28,3 @@ module.exports = function (math, settings) {

asMatrix = (size instanceof Matrix) ? true :
(isArray(size) ? false : (settings.matrix.defaultType === 'matrix'));
(isArray(size) ? false : (settings.matrix === 'matrix'));

@@ -31,0 +31,0 @@

@@ -27,3 +27,3 @@ module.exports = function (math, settings) {

var asMatrix = (size instanceof Matrix) ? true :
(isArray(size) ? false : (settings.matrix.defaultType === 'matrix'));
(isArray(size) ? false : (settings.matrix === 'matrix'));

@@ -30,0 +30,0 @@ if (args.length == 0) {

@@ -113,3 +113,3 @@ module.exports = function (math, settings) {

// return as array or matrix
return (settings.matrix.defaultType === 'array') ? array : new Matrix(array);
return (settings.matrix === 'array') ? array : new Matrix(array);
};

@@ -185,3 +185,3 @@

if (settings.number.defaultType === 'bignumber') {
if (settings.number === 'bignumber') {
// bignumber

@@ -188,0 +188,0 @@ try {

@@ -33,4 +33,3 @@ module.exports = function (math, settings) {

var asMatrix = (x instanceof Matrix) ? true : isArray(x) ? false :
(settings.matrix.defaultType !== 'array');
var asMatrix = (x instanceof Matrix) ? true : isArray(x) ? false : (settings.matrix !== 'array');

@@ -78,8 +77,8 @@ if (x instanceof Matrix) {

* @param {Number[]} size
* @param {string} char Default character
* @param {string} defaultChar
* @private
*/
function _resizeString(str, size, char) {
if (char !== undefined) {
if (!isString(char) || char.length !== 1) {
function _resizeString(str, size, defaultChar) {
if (defaultChar !== undefined) {
if (!isString(defaultChar) || defaultChar.length !== 1) {
throw new TypeError('Single character expected as defaultValue');

@@ -89,3 +88,3 @@ }

else {
char = ' ';
defaultChar = ' ';
}

@@ -107,3 +106,3 @@

for (var i = 0, ii = len - str.length; i < ii; i++) {
res += char;
res += defaultChar;
}

@@ -110,0 +109,0 @@ return res;

@@ -11,3 +11,3 @@ module.exports = function (math, settings) {

isNumber = util.number.isNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isString = util.string.isString,

@@ -30,3 +30,3 @@ isComplex = Complex.isComplex,

var asArray = (settings.matrix.defaultType === 'array');
var asArray = (settings.matrix === 'array');

@@ -33,0 +33,0 @@ if (isNumber(x) || isComplex(x) || isUnit(x) || isBoolean(x) ||

@@ -26,3 +26,3 @@ module.exports = function (math, settings) {

var asMatrix = (size instanceof Matrix) ? true :
(isArray(size) ? false : (settings.matrix.defaultType === 'matrix'));
(isArray(size) ? false : (settings.matrix === 'matrix'));

@@ -29,0 +29,0 @@ if (args.length == 0) {

@@ -8,3 +8,3 @@ module.exports = function (math) {

isNumber = util.number.isNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isInteger = util.number.isInteger,

@@ -11,0 +11,0 @@ isCollection = collection.isCollection;

@@ -94,3 +94,3 @@ module.exports = function (math, settings) {

var res = _randomDataForMatrix(size, min, max, _random);
return (settings.matrix.defaultType === 'array') ? res : new Matrix(res);
return (settings.matrix === 'array') ? res : new Matrix(res);
}

@@ -125,3 +125,3 @@ else return _random(min, max);

var res = _randomDataForMatrix(size, min, max, _randomInt);
return (settings.matrix.defaultType === 'array') ? res : new Matrix(res);
return (settings.matrix === 'array') ? res : new Matrix(res);
}

@@ -128,0 +128,0 @@ else return _randomInt(min, max);

@@ -9,3 +9,3 @@ module.exports = function (math) {

isNumber = util.number.isNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isComplex = Complex.isComplex,

@@ -12,0 +12,0 @@ isCollection = collection.isCollection;

@@ -9,3 +9,3 @@ module.exports = function (math) {

isNumber = util.number.isNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isComplex = Complex.isComplex,

@@ -12,0 +12,0 @@ isCollection = collection.isCollection;

@@ -9,3 +9,3 @@ module.exports = function (math) {

isNumber = util.number.isNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isComplex = Complex.isComplex,

@@ -12,0 +12,0 @@ isCollection = collection.isCollection;

@@ -10,3 +10,3 @@ module.exports = function (math) {

isNumber = util.number.isNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isComplex = Complex.isComplex,

@@ -13,0 +13,0 @@ isCollection = collection.isCollection;

@@ -10,3 +10,3 @@ module.exports = function (math) {

isNumber = util.number.isNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isComplex = Complex.isComplex,

@@ -13,0 +13,0 @@ isUnit = Unit.isUnit,

@@ -10,3 +10,3 @@ module.exports = function (math) {

isNumber = util.number.isNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isComplex = Complex.isComplex,

@@ -13,0 +13,0 @@ isUnit = Unit.isUnit,

@@ -10,3 +10,3 @@ module.exports = function (math) {

isNumber = util.number.isNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isComplex = Complex.isComplex,

@@ -13,0 +13,0 @@ isUnit = Unit.isUnit,

@@ -10,3 +10,3 @@ module.exports = function (math) {

isNumber = util.number.isNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isComplex = Complex.isComplex,

@@ -13,0 +13,0 @@ isUnit = Unit.isUnit,

@@ -10,3 +10,3 @@ module.exports = function (math) {

isNumber = util.number.isNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isComplex = Complex.isComplex,

@@ -13,0 +13,0 @@ isUnit = Unit.isUnit,

@@ -10,3 +10,3 @@ module.exports = function (math) {

isNumber = util.number.isNumber,
isBoolean = util.boolean.isBoolean,
isBoolean = util['boolean'].isBoolean,
isComplex = Complex.isComplex,

@@ -13,0 +13,0 @@ isUnit = Unit.isUnit,

@@ -12,8 +12,17 @@ var object = require('./util/object');

* @param {Object} [settings] Available settings:
* {String} matrix.defaultType
* {String} matrix
* A string 'matrix' (default) or 'array'.
* {String} number.defaultType
* {String} number
* A string 'number' (default) or 'bignumber'
* {Number} decimals
* The number of decimals behind the decimal
* point for BigNumber. Not applicable for Numbers.
*/
function mathjs (settings) {
// simple test for ES5 support
if (typeof Array.prototype.map !== 'function') {
throw new Error('ES5 not supported by this JavaScript engine. ' +
'Please load the es5-shim library for compatibility.');
}
// create new namespace

@@ -24,10 +33,7 @@ var math = {};

var _settings = {
matrix: {
// 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'
}
// type of default matrix output. Choose 'matrix' (default) or 'array'
matrix: 'matrix',
// type of default number output. Choose 'number' (default) or 'bignumber'
number: 'number'
};

@@ -38,9 +44,9 @@

* @param {Object} [settings] Available settings:
* {String} matrix.defaultType
* {String} matrix
* A string 'matrix' (default) or 'array'.
* {String} number.defaultType
* {String} number
* A string 'number' (default) or 'bignumber'
* {Number} number.precision
* The number of digits in BigNumber.
* Not applicable for Numbers.
* {Number} decimals
* The number of decimals behind the decimal
* point for BigNumber. Not applicable for Numbers.
* @return {Object} settings The currently applied settings

@@ -55,12 +61,30 @@ */

if (settings.number && settings.number.precision) {
if (settings.decimals) {
BigNumber.config({
DECIMAL_PLACES: settings.number.precision
DECIMAL_PLACES: settings.decimals
});
}
// 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.')
}
// 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.')
}
// 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.')
}
// 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.defaultType instead.')
if (settings.matrix && settings.matrix['default']) {
throw new Error('setting `matrix.default` is deprecated. ' +
'Use `matrix` instead.')
}

@@ -71,3 +95,3 @@ }

var current = object.clone(_settings);
current.number.precision = BigNumber.config().DECIMAL_PLACES;
current.decimals = BigNumber.config().DECIMAL_PLACES;
return current;

@@ -234,29 +258,1 @@ };

module.exports = mathjs;
// error messages for deprecated static library (deprecated since v0.15.0) TODO: remove some day
var placeholder = function () {
throw new Error('Static function calls are deprecated. Create an instance of math.js:\n\t"var math = require(\'mathjs\')();" on node.js, \n\t"var math = mathjs();" in the browser.');
};
var instance = mathjs();
for (var prop in instance) {
if (instance.hasOwnProperty(prop)) {
var fn = instance[prop];
if (typeof fn === 'function') {
mathjs[prop] = placeholder;
}
else {
if (Object.defineProperty) {
Object.defineProperty(mathjs, prop, {
get: placeholder,
set: placeholder,
enumerable: true,
configurable: false
});
}
}
}
}
if (typeof window !== 'undefined') {
window.math = mathjs;
}
exports.array = require('./array');
exports.boolean = require('./boolean');
exports['boolean'] = require('./boolean');
exports.number = require('./number');

@@ -4,0 +4,0 @@ exports.object = require('./object');

@@ -196,3 +196,7 @@ var BigNumber = require('bignumber.js');

else { // Number
str = parseFloat(value.toPrecision(precision ? Math.min(precision, 21) : precision)) + '';
// Note: IE7 does not allow value.toPrecision(undefined)
var valueStr = precision ?
value.toPrecision(Math.min(precision, 21)) :
value.toPrecision();
str = parseFloat(valueStr) + '';
}

@@ -199,0 +203,0 @@ }

@@ -1,5 +0,1 @@

var number = require('./number'),
string = require('./string'),
bool = require('./boolean');
/**

@@ -10,2 +6,5 @@ * Clone an object

*
* Can clone any primitive type, array, and object.
* If x has a function clone, this function will be invoked to clone the object.
*
* @param {*} x

@@ -15,15 +14,16 @@ * @return {*} clone

exports.clone = function clone(x) {
if (x == null) {
// null or undefined
var type = typeof x;
// immutable primitive types
if (type === 'number' || type === 'string' || type === 'boolean' ||
x === null || x === undefined) {
return x;
}
if (typeof(x.clone) === 'function') {
// use clone function of the object when available
if (typeof x.clone === 'function') {
return x.clone();
}
if (number.isNumber(x) || string.isString(x) || bool.isBoolean(x)) {
return x;
}
// array
if (Array.isArray(x)) {

@@ -35,2 +35,3 @@ return x.map(function (value) {

// object
if (x instanceof Object) {

@@ -46,2 +47,3 @@ var m = {};

// this should never happen
throw new TypeError('Cannot clone ' + x);

@@ -48,0 +50,0 @@ };

@@ -31,2 +31,5 @@ var number = require('./number'),

*
* If value is a function, the returned string is 'function' unless the function
* has a property `description`, in that case this properties value is returned.
*
* Example usage:

@@ -58,2 +61,6 @@ * math.format(2/7); // '0.2857142857142857'

if (typeof value === 'function') {
return value.syntax ? value.syntax + '' : 'function';
}
if (value instanceof Object) {

@@ -60,0 +67,0 @@ if (typeof value.format === 'function') {

{
"name": "mathjs",
"version": "0.16.0",
"version": "0.17.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.",

@@ -37,10 +37,10 @@ "author": "Jos de Jong <wjosdejong@gmail.com> (https://github.com/josdejong)",

"devDependencies": {
"jake": ">= 0.5.9",
"browserify": "2.x",
"mocha": "1.x",
"numbers": "0.4.0",
"uglify-js": "2.4.4",
"dateable": ">= 0.1.2",
"underscore": "1.4.x",
"seed-random": ">= 1.0.1"
"jake": "latest",
"browserify": "latest",
"mocha": "latest",
"numbers": "latest",
"uglify-js": "latest",
"dateable": "latest",
"underscore": "latest",
"seed-random": "latest"
},

@@ -47,0 +47,0 @@ "main": "./index",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc