mathjs 3.1.3 → 3.1.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of mathjs might be problematic. Click here for more details.

package/HISTORY.md CHANGED
@@ -1,6 +1,20 @@
1
1
  # History
2
2
 
3
3
 
4
+ ## 2016-04-03, version 3.1.4
5
+
6
+ - Using ES6 Math functions like `Math.sinh`, `Math.cbrt`, `Math.sign`, etc when
7
+ available.
8
+ - Fixed #631: unit aliases `weeks`, `months`, and `years` where missing.
9
+ - Fixed #632: problem with escaped backslashes at the end of strings.
10
+ - Fixed #635: `Node.toString` options where not passed to function arguments.
11
+ - Fixed #629: expression parser throws an error when passing a number with
12
+ decimal exponent instead of parsing them as implicit multiplication.
13
+ - Fixed #484, #555: inaccuracy of `math.sinh` for values between -1 and 1.
14
+ - Fixed #625: Unit `in` (`inch`) not always working due to ambiguity with
15
+ the operator `a in b` (alias of `a to b`).
16
+
17
+
4
18
  ## 2016-03-24, version 3.1.3
5
19
 
6
20
  - Fix broken bundle.
package/dist/math.js CHANGED
@@ -6,8 +6,8 @@
6
6
  * It features real and complex numbers, units, matrices, a large set of
7
7
  * mathematical functions, and a flexible expression parser.
8
8
  *
9
- * @version 3.1.3
10
- * @date 2016-03-24
9
+ * @version 3.1.4
10
+ * @date 2016-04-03
11
11
  *
12
12
  * @license
13
13
  * Copyright (C) 2013-2016 Jos de Jong <wjosdejong@gmail.com>
@@ -2037,7 +2037,7 @@ return /******/ (function(modules) { // webpackBootstrap
2037
2037
  * @param {number} x
2038
2038
  * @returns {*}
2039
2039
  */
2040
- exports.sign = function(x) {
2040
+ exports.sign = Math.sign || function(x) {
2041
2041
  if (x > 0) {
2042
2042
  return 1;
2043
2043
  }
@@ -20736,6 +20736,9 @@ return /******/ (function(modules) { // webpackBootstrap
20736
20736
  hr: 'hour',
20737
20737
  hrs: 'hour',
20738
20738
  days: 'day',
20739
+ weeks: 'week',
20740
+ months: 'month',
20741
+ years: 'year',
20739
20742
 
20740
20743
  hertz: 'hertz',
20741
20744
 
@@ -23332,7 +23335,7 @@ return /******/ (function(modules) { // webpackBootstrap
23332
23335
  * math.format(value)
23333
23336
  * math.format(value, options)
23334
23337
  * math.format(value, precision)
23335
- * math.format(value, fn)
23338
+ * math.format(value, callback)
23336
23339
  *
23337
23340
  * Where:
23338
23341
  *
@@ -23367,10 +23370,12 @@ return /******/ (function(modules) { // webpackBootstrap
23367
23370
  * - `fraction: string`. Available values: 'ratio' (default) or 'decimal'.
23368
23371
  * For example `format(fraction(1, 3))` will output '1/3' when 'ratio' is
23369
23372
  * configured, and will output `0.(3)` when 'decimal' is configured.
23370
- * - `fn: Function`
23371
- * A custom formatting function. Can be used to override the built-in notations.
23372
- * Function `fn` is called with `value` as parameter and must return a string.
23373
- * Is useful for example to format all values inside a matrix in a particular way.
23373
+ * - `callback: function`
23374
+ * A custom formatting function, invoked for all numeric elements in `value`,
23375
+ * for example all elements of a matrix, or the real and imaginary
23376
+ * parts of a complex number. This callback can be used to override the
23377
+ * built-in numeric notation with any type of formatting. Function `callback`
23378
+ * is called with `value` as parameter and must return a string.
23374
23379
  *
23375
23380
  * When `value` is an Object:
23376
23381
  *
@@ -23398,6 +23403,11 @@ return /******/ (function(modules) { // webpackBootstrap
23398
23403
  * math.format(2.3, {notation: 'fixed', precision: 2}); // returns '2.30'
23399
23404
  * math.format(52.8, {notation: 'exponential'}); // returns '5.28e+1'
23400
23405
  *
23406
+ * function formatCurrency(value) {
23407
+ * return '$' + value.toFixed(2);
23408
+ * }
23409
+ * math.format([2.1, 3, 0.016], formatCurrency}; // returns '[$2.10, $3.00, $0.02]'
23410
+ *
23401
23411
  * See also:
23402
23412
  *
23403
23413
  * print
@@ -23737,7 +23747,7 @@ return /******/ (function(modules) { // webpackBootstrap
23737
23747
  /* 94 */
23738
23748
  /***/ function(module, exports) {
23739
23749
 
23740
- module.exports = '3.1.3';
23750
+ module.exports = '3.1.4';
23741
23751
  // Note: This file is automatically generated when building math.js.
23742
23752
  // Changes made in this file will be overwritten.
23743
23753
 
@@ -28381,7 +28391,7 @@ return /******/ (function(modules) { // webpackBootstrap
28381
28391
  next();
28382
28392
 
28383
28393
  if (!isDigit(c)) {
28384
- // this is no legal number, it is just a dot
28394
+ // this is no legal number, it is just a dot (can be dot notation)
28385
28395
  token_type = TOKENTYPE.UNKNOWN;
28386
28396
  }
28387
28397
  }
@@ -28402,24 +28412,33 @@ return /******/ (function(modules) { // webpackBootstrap
28402
28412
 
28403
28413
  // check for exponential notation like "2.3e-4", "1.23e50" or "2e+4"
28404
28414
  c2 = nextPreview();
28405
- if ((c == 'E' || c == 'e') && (isDigit(c2) || c2 == '-' || c2 == '+')) {
28406
- token += c;
28407
- next();
28408
-
28409
- if (c == '+' || c == '-') {
28415
+ if (c == 'E' || c == 'e') {
28416
+ if (isDigit(c2) || c2 == '-' || c2 == '+') {
28410
28417
  token += c;
28411
28418
  next();
28412
- }
28413
28419
 
28414
- // Scientific notation MUST be followed by an exponent
28415
- if (!isDigit(c)) {
28416
- // this is no legal number, exponent is missing.
28417
- token_type = TOKENTYPE.UNKNOWN;
28418
- }
28420
+ if (c == '+' || c == '-') {
28421
+ token += c;
28422
+ next();
28423
+ }
28419
28424
 
28420
- while (isDigit(c)) {
28421
- token += c;
28425
+ // Scientific notation MUST be followed by an exponent
28426
+ if (!isDigit(c)) {
28427
+ throw createSyntaxError('Digit expected, got "' + c + '"');
28428
+ }
28429
+
28430
+ while (isDigit(c)) {
28431
+ token += c;
28432
+ next();
28433
+ }
28434
+
28435
+ if (c == '.') {
28436
+ throw createSyntaxError('Digit expected, got "' + c + '"');
28437
+ }
28438
+ }
28439
+ else if (c2 == '.') {
28422
28440
  next();
28441
+ throw createSyntaxError('Digit expected, got "' + c + '"');
28423
28442
  }
28424
28443
  }
28425
28444
 
@@ -28884,8 +28903,16 @@ return /******/ (function(modules) { // webpackBootstrap
28884
28903
  fn = operators[name];
28885
28904
 
28886
28905
  getTokenSkipNewline();
28887
- params = [node, parseRange()];
28888
- node = new OperatorNode(name, fn, params);
28906
+
28907
+ if (name === 'in' && token === '') {
28908
+ // end of expression -> this is the unit 'in' ('inch')
28909
+ node = new OperatorNode('*', 'multiply', [node, new SymbolNode('in')], true);
28910
+ }
28911
+ else {
28912
+ // operator 'a to b' or 'a in b'
28913
+ params = [node, parseRange()];
28914
+ node = new OperatorNode(name, fn, params);
28915
+ }
28889
28916
  }
28890
28917
 
28891
28918
  return node;
@@ -29306,11 +29333,15 @@ return /******/ (function(modules) { // webpackBootstrap
29306
29333
  */
29307
29334
  function parseStringToken () {
29308
29335
  var str = '';
29309
- var tPrev = '';
29310
29336
 
29311
- while (c != '' && (c != '\"' || tPrev == '\\')) { // also handle escape character
29337
+ while (c != '' && c != '\"') {
29338
+ if (c == '\\') {
29339
+ // escape character
29340
+ str += c;
29341
+ next();
29342
+ }
29343
+
29312
29344
  str += c;
29313
- tPrev = c;
29314
29345
  next();
29315
29346
  }
29316
29347
 
@@ -32704,10 +32735,10 @@ return /******/ (function(modules) { // webpackBootstrap
32704
32735
  * @extends {Node}
32705
32736
  * An operator with two arguments, like 2+3
32706
32737
  *
32707
- * @param {string} op Operator name, for example '+'
32708
- * @param {string} fn Function name, for example 'add'
32709
- * @param {Node[]} args Operator arguments
32710
- * @param {boolean} implicit Is this an implicit multiplication?
32738
+ * @param {string} op Operator name, for example '+'
32739
+ * @param {string} fn Function name, for example 'add'
32740
+ * @param {Node[]} args Operator arguments
32741
+ * @param {boolean} [implicit] Is this an implicit multiplication?
32711
32742
  */
32712
32743
  function OperatorNode(op, fn, args, implicit) {
32713
32744
  if (!(this instanceof OperatorNode)) {
@@ -33318,7 +33349,7 @@ return /******/ (function(modules) { // webpackBootstrap
33318
33349
  */
33319
33350
  FunctionNode.prototype.toString = function (options) {
33320
33351
  var customString;
33321
- var name = this.fn.toString();
33352
+ var name = this.fn.toString(options);
33322
33353
  if (options && (typeof options.handler === 'object') && options.handler.hasOwnProperty(name)) {
33323
33354
  //callback is a map of callback functions
33324
33355
  customString = options.handler[name](this, options);
@@ -33338,8 +33369,12 @@ return /******/ (function(modules) { // webpackBootstrap
33338
33369
  * @return {string} str
33339
33370
  */
33340
33371
  FunctionNode.prototype._toString = function (options) {
33341
- // format the parameters like "add(2, 4.2)"
33342
- return this.fn.toString() + '(' + this.args.join(', ') + ')';
33372
+ var args = this.args.map(function (arg) {
33373
+ return arg.toString(options);
33374
+ });
33375
+
33376
+ // format the arguments like "add(2, 4.2)"
33377
+ return this.fn.toString(options) + '(' + args.join(', ') + ')';
33343
33378
  };
33344
33379
 
33345
33380
  /*
@@ -33451,9 +33486,6 @@ return /******/ (function(modules) { // webpackBootstrap
33451
33486
  * @return {string} str
33452
33487
  */
33453
33488
  FunctionNode.prototype._toTex = function (options) {
33454
- var parenthesis = (options && options.parenthesis) ? options.parenthesis : 'keep';
33455
-
33456
-
33457
33489
  var args = this.args.map(function (arg) { //get LaTeX of the arguments
33458
33490
  return arg.toTex(options);
33459
33491
  });
@@ -39901,38 +39933,6 @@ return /******/ (function(modules) { // webpackBootstrap
39901
39933
  }
39902
39934
  });
39903
39935
 
39904
- /**
39905
- * Calculate cbrt for a number
39906
- *
39907
- * Code from es6-shim.js:
39908
- * https://github.com/paulmillr/es6-shim/blob/master/es6-shim.js#L1564-L1577
39909
- *
39910
- * @param {number} x
39911
- * @returns {number | Complex} Returns the cubic root of x
39912
- * @private
39913
- */
39914
- function _cbrtNumber(x) {
39915
- if (x === 0) {
39916
- return x;
39917
- }
39918
-
39919
- var negate = x < 0;
39920
- var result;
39921
- if (negate) {
39922
- x = -x;
39923
- }
39924
-
39925
- if (isFinite(x)) {
39926
- result = Math.exp(Math.log(x) / 3);
39927
- // from http://en.wikipedia.org/wiki/Cube_root#Numerical_methods
39928
- result = (x / (result * result) + (2 * result)) / 3;
39929
- } else {
39930
- result = x;
39931
- }
39932
-
39933
- return negate ? -result : result;
39934
- }
39935
-
39936
39936
  /**
39937
39937
  * Calculate the cubic root for a complex number
39938
39938
  * @param {Complex} x
@@ -40015,6 +40015,38 @@ return /******/ (function(modules) { // webpackBootstrap
40015
40015
  return cbrt;
40016
40016
  }
40017
40017
 
40018
+ /**
40019
+ * Calculate cbrt for a number
40020
+ *
40021
+ * Code from es6-shim.js:
40022
+ * https://github.com/paulmillr/es6-shim/blob/master/es6-shim.js#L1564-L1577
40023
+ *
40024
+ * @param {number} x
40025
+ * @returns {number | Complex} Returns the cubic root of x
40026
+ * @private
40027
+ */
40028
+ var _cbrtNumber = Math.cbrt || function (x) {
40029
+ if (x === 0) {
40030
+ return x;
40031
+ }
40032
+
40033
+ var negate = x < 0;
40034
+ var result;
40035
+ if (negate) {
40036
+ x = -x;
40037
+ }
40038
+
40039
+ if (isFinite(x)) {
40040
+ result = Math.exp(Math.log(x) / 3);
40041
+ // from http://en.wikipedia.org/wiki/Cube_root#Numerical_methods
40042
+ result = (x / (result * result) + (2 * result)) / 3;
40043
+ } else {
40044
+ result = x;
40045
+ }
40046
+
40047
+ return negate ? -result : result;
40048
+ };
40049
+
40018
40050
  exports.name = 'cbrt';
40019
40051
  exports.factory = factory;
40020
40052
 
@@ -42157,7 +42189,7 @@ return /******/ (function(modules) { // webpackBootstrap
42157
42189
 
42158
42190
  function factory (type, config, load, typed) {
42159
42191
  /**
42160
- * Calculate the 10-base of a value. This is the same as calculating `log(x, 10)`.
42192
+ * Calculate the 10-base logarithm of a value. This is the same as calculating `log(x, 10)`.
42161
42193
  *
42162
42194
  * For matrices, the function is evaluated element wise.
42163
42195
  *
@@ -42184,7 +42216,7 @@ return /******/ (function(modules) { // webpackBootstrap
42184
42216
  var log10 = typed('log10', {
42185
42217
  'number': function (x) {
42186
42218
  if (x >= 0 || config.predictable) {
42187
- return Math.log(x) / Math.LN10;
42219
+ return _log10(x);
42188
42220
  }
42189
42221
  else {
42190
42222
  // negative value -> complex value computation
@@ -42216,6 +42248,16 @@ return /******/ (function(modules) { // webpackBootstrap
42216
42248
  return log10;
42217
42249
  }
42218
42250
 
42251
+ /**
42252
+ * Calculate the 10-base logarithm of a number
42253
+ * @param {number} x
42254
+ * @return {number}
42255
+ * @private
42256
+ */
42257
+ var _log10 = Math.log10 || function (x) {
42258
+ return Math.log(x) / Math.LN10;
42259
+ };
42260
+
42219
42261
  exports.name = 'log10';
42220
42262
  exports.factory = factory;
42221
42263
 
@@ -51034,7 +51076,7 @@ return /******/ (function(modules) { // webpackBootstrap
51034
51076
  var acosh = typed('acosh', {
51035
51077
  'number': function (x) {
51036
51078
  if (x >= 1 || config.predictable) {
51037
- return Math.log(Math.sqrt(x*x - 1) + x);
51079
+ return _acosh(x);
51038
51080
  }
51039
51081
  if (x <= -1) {
51040
51082
  return new type.Complex(Math.log(Math.sqrt(x*x - 1) - x), Math.PI);
@@ -51060,6 +51102,16 @@ return /******/ (function(modules) { // webpackBootstrap
51060
51102
  return acosh;
51061
51103
  }
51062
51104
 
51105
+ /**
51106
+ * Calculate the hyperbolic arccos of a number
51107
+ * @param {number} x
51108
+ * @return {number}
51109
+ * @private
51110
+ */
51111
+ var _acosh = Math.acosh || function (x) {
51112
+ return Math.log(Math.sqrt(x*x - 1) + x)
51113
+ };
51114
+
51063
51115
  exports.name = 'acosh';
51064
51116
  exports.factory = factory;
51065
51117
 
@@ -51539,7 +51591,7 @@ return /******/ (function(modules) { // webpackBootstrap
51539
51591
  * @return {number | Complex | Array | Matrix} Hyperbolic arcsine of x
51540
51592
  */
51541
51593
  var asinh = typed('asinh', {
51542
- 'number': function (x) {
51594
+ 'number': Math.asinh || function (x) {
51543
51595
  return Math.log(Math.sqrt(x*x + 1) + x);
51544
51596
  },
51545
51597
 
@@ -51818,7 +51870,7 @@ return /******/ (function(modules) { // webpackBootstrap
51818
51870
  var atanh = typed('atanh', {
51819
51871
  'number': function (x) {
51820
51872
  if ((x <= 1 && x >= -1) || config.predictable) {
51821
- return Math.log((1 + x)/(1 - x)) / 2;
51873
+ return _atanh(x);
51822
51874
  }
51823
51875
  return new type.Complex(x, 0).atanh();
51824
51876
  },
@@ -51842,6 +51894,16 @@ return /******/ (function(modules) { // webpackBootstrap
51842
51894
  return atanh;
51843
51895
  }
51844
51896
 
51897
+ /**
51898
+ * Calculate the hyperbolic arctangent of a number
51899
+ * @param {number} x
51900
+ * @return {number}
51901
+ * @private
51902
+ */
51903
+ var _atanh = Math.atanh || function (x) {
51904
+ return Math.log((1 + x)/(1 - x)) / 2
51905
+ };
51906
+
51845
51907
  exports.name = 'atanh';
51846
51908
  exports.factory = factory;
51847
51909
 
@@ -51978,9 +52040,9 @@ return /******/ (function(modules) { // webpackBootstrap
51978
52040
  * @returns {number}
51979
52041
  * @private
51980
52042
  */
51981
- function _cosh(x) {
52043
+ var _cosh = Math.cosh || function (x) {
51982
52044
  return (Math.exp(x) + Math.exp(-x)) / 2;
51983
- }
52045
+ };
51984
52046
 
51985
52047
  exports.name = 'cosh';
51986
52048
  exports.factory = factory;
@@ -52542,13 +52604,9 @@ return /******/ (function(modules) { // webpackBootstrap
52542
52604
  * @returns {number}
52543
52605
  * @private
52544
52606
  */
52545
- function _sinh (x) {
52546
- if (Math.abs(x) < 1) {
52547
- return x + (x * x * x) / 6 + (x * x * x * x * x) / 120;
52548
- } else {
52549
- return (Math.exp(x) - Math.exp(-x)) / 2;
52550
- }
52551
- }
52607
+ var _sinh = Math.sinh || function (x) {
52608
+ return (Math.exp(x) - Math.exp(-x)) / 2;
52609
+ };
52552
52610
 
52553
52611
  exports.name = 'sinh';
52554
52612
  exports.factory = factory;
@@ -52687,10 +52745,10 @@ return /******/ (function(modules) { // webpackBootstrap
52687
52745
  * @returns {number}
52688
52746
  * @private
52689
52747
  */
52690
- function _tanh (x) {
52748
+ var _tanh = Math.tanh || function (x) {
52691
52749
  var e = Math.exp(2 * x);
52692
52750
  return (e - 1) / (e + 1);
52693
- }
52751
+ };
52694
52752
 
52695
52753
  exports.name = 'tanh';
52696
52754
  exports.factory = factory;