Merge lp:~rpadovani/ubuntu-calculator-app/bumpMathJs150122 into lp:ubuntu-calculator-app

Proposed by Riccardo Padovani
Status: Merged
Approved by: Giulio Collura
Approved revision: 72
Merged at revision: 73
Proposed branch: lp:~rpadovani/ubuntu-calculator-app/bumpMathJs150122
Merge into: lp:ubuntu-calculator-app
Diff against target: 10196 lines (+4460/-2213)
2 files modified
app/engine/math.js (+4458/-2211)
app/ubuntu-calculator-app.qml (+2/-2)
To merge this branch: bzr merge lp:~rpadovani/ubuntu-calculator-app/bumpMathJs150122
Reviewer Review Type Date Requested Status
Giulio Collura Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+247335@code.launchpad.net

Commit message

Updated math.js to 1.2.0

Description of the change

Bumped math.js to 1.2.0 and added comments to explain diffs

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Giulio Collura (gcollura) wrote :

It looks good! Thank you!
Approved.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'app/engine/math.js'
2--- app/engine/math.js 2015-01-10 18:37:05 +0000
3+++ app/engine/math.js 2015-01-22 17:57:11 +0000
4@@ -1,4 +1,11 @@
5+// All edits done for the Ubuntu Calculator App are preceded by a comment that
6+// starts with 'UCA:' and describes the edit
7+
8+// UCA: add a var to which we will refer to when we include the code in qml
9+// in app/ubuntu-calculator-app.qml with import "engine/math.js" as MathJs and
10+// then property var mathJs: MathJs.mathJs;
11 var mathJs;
12+
13 /**
14 * math.js
15 * https://github.com/josdejong/mathjs
16@@ -7,8 +14,8 @@
17 * It features real and complex numbers, units, matrices, a large set of
18 * mathematical functions, and a flexible expression parser.
19 *
20- * @version 1.1.0
21- * @date 2014-11-15
22+ * @version 1.2.0
23+ * @date 2014-12-25
24 *
25 * @license
26 * Copyright (C) 2013-2014 Jos de Jong <wjosdejong@gmail.com>
27@@ -27,6 +34,7 @@
28 */
29
30 (function webpackUniversalModuleDefinition(root, factory) {
31+ // UCA: we delete all exports, we don't need them, and we keep only our var
32 mathJs = factory();
33 })(this, function() {
34 return /******/ (function(modules) { // webpackBootstrap
35@@ -197,7 +205,7 @@
36 math.create = create;
37
38 // create a new BigNumber factory for this instance of math.js
39- var BigNumber = __webpack_require__(142).constructor();
40+ var BigNumber = __webpack_require__(159).constructor();
41
42 // extend BigNumber with a function clone
43 if (typeof BigNumber.prototype.clone !== 'function') {
44@@ -206,7 +214,7 @@
45 * @return {BigNumber} clone
46 */
47 BigNumber.prototype.clone = function() {
48- return new BigNumber(this);
49+ return this; // just return itself (a BigNumber is immutable)
50 };
51 }
52
53@@ -290,9 +298,9 @@
54 __webpack_require__(58)(math, _config);
55 __webpack_require__(59)(math, _config);
56 __webpack_require__(60)(math, _config);
57-
58- // functions - relational
59 __webpack_require__(61)(math, _config);
60+
61+ // functions - bitwise
62 __webpack_require__(62)(math, _config);
63 __webpack_require__(63)(math, _config);
64 __webpack_require__(64)(math, _config);
65@@ -319,11 +327,13 @@
66 __webpack_require__(81)(math, _config);
67 __webpack_require__(82)(math, _config);
68
69- // functions - matrix
70+ // functions - logical
71 __webpack_require__(83)(math, _config);
72 __webpack_require__(84)(math, _config);
73 __webpack_require__(85)(math, _config);
74 __webpack_require__(86)(math, _config);
75+
76+ // functions - matrix
77 __webpack_require__(87)(math, _config);
78 __webpack_require__(88)(math, _config);
79 __webpack_require__(89)(math, _config);
80@@ -336,32 +346,32 @@
81 __webpack_require__(96)(math, _config);
82 __webpack_require__(97)(math, _config);
83 __webpack_require__(98)(math, _config);
84-
85- // functions - probability
86- //require('./function/probability/distribution')(math, _config); // TODO: rethink math.distribution
87 __webpack_require__(99)(math, _config);
88 __webpack_require__(100)(math, _config);
89 __webpack_require__(101)(math, _config);
90 __webpack_require__(102)(math, _config);
91+
92+ // functions - probability
93+ //require('./function/probability/distribution')(math, _config); // TODO: rethink math.distribution
94 __webpack_require__(103)(math, _config);
95 __webpack_require__(104)(math, _config);
96-
97- // functions - statistics
98 __webpack_require__(105)(math, _config);
99 __webpack_require__(106)(math, _config);
100 __webpack_require__(107)(math, _config);
101 __webpack_require__(108)(math, _config);
102 __webpack_require__(109)(math, _config);
103+
104+ // functions - relational
105 __webpack_require__(110)(math, _config);
106 __webpack_require__(111)(math, _config);
107 __webpack_require__(112)(math, _config);
108-
109- // functions - trigonometry
110 __webpack_require__(113)(math, _config);
111 __webpack_require__(114)(math, _config);
112 __webpack_require__(115)(math, _config);
113 __webpack_require__(116)(math, _config);
114 __webpack_require__(117)(math, _config);
115+
116+ // functions - statistics
117 __webpack_require__(118)(math, _config);
118 __webpack_require__(119)(math, _config);
119 __webpack_require__(120)(math, _config);
120@@ -370,14 +380,12 @@
121 __webpack_require__(123)(math, _config);
122 __webpack_require__(124)(math, _config);
123 __webpack_require__(125)(math, _config);
124+
125+ // functions - trigonometry
126 __webpack_require__(126)(math, _config);
127 __webpack_require__(127)(math, _config);
128 __webpack_require__(128)(math, _config);
129-
130- // functions - units
131 __webpack_require__(129)(math, _config);
132-
133- // functions - utils
134 __webpack_require__(130)(math, _config);
135 __webpack_require__(131)(math, _config);
136 __webpack_require__(132)(math, _config);
137@@ -387,6 +395,23 @@
138 __webpack_require__(136)(math, _config);
139 __webpack_require__(137)(math, _config);
140 __webpack_require__(138)(math, _config);
141+ __webpack_require__(139)(math, _config);
142+ __webpack_require__(140)(math, _config);
143+ __webpack_require__(141)(math, _config);
144+
145+ // functions - units
146+ __webpack_require__(142)(math, _config);
147+
148+ // functions - utils
149+ __webpack_require__(143)(math, _config);
150+ __webpack_require__(144)(math, _config);
151+ __webpack_require__(145)(math, _config);
152+ __webpack_require__(146)(math, _config);
153+ __webpack_require__(147)(math, _config);
154+ __webpack_require__(148)(math, _config);
155+ __webpack_require__(149)(math, _config);
156+ __webpack_require__(150)(math, _config);
157+ __webpack_require__(151)(math, _config);
158
159 // TODO: deprecated since version 0.25.0, remove some day.
160 math.ifElse = function () {
161@@ -410,7 +435,8 @@
162
163 // selector (we initialize after all functions are loaded)
164 math.chaining = {};
165- math.chaining.Selector = __webpack_require__(28)(math, _config);
166+ math.chaining.Chain = __webpack_require__(28)(math, _config);
167+ math.chaining.Selector = math.chaining.Chain; // TODO: deprecate in v2.0
168
169 // apply provided configuration options
170 math.config(_config); // apply the default options
171@@ -439,90 +465,17 @@
172 'use strict';
173
174 module.exports = function (math, config) {
175- var bignumber = __webpack_require__(139);
176+ var bignumber = __webpack_require__(152);
177 var Complex = __webpack_require__(6);
178 var BigNumber = math.type.BigNumber;
179
180- /**
181- * Calculate BigNumber e
182- * @returns {BigNumber} Returns e
183- */
184- function bigE() {
185- return new BigNumber(1).exp();
186- }
187-
188- /**
189- * Calculate BigNumber golden ratio, phi = (1+sqrt(5))/2
190- * @returns {BigNumber} Returns phi
191- */
192- function bigPhi() {
193- return new BigNumber(1).plus(new BigNumber(5).sqrt()).div(2);
194- }
195-
196- /**
197- * arctan(x) = x - x^3/3 + x^5/5 - x^7/7 + x^9/9 - ...
198- * = x - x^2*x^1/3 + x^2*x^3/5 - x^2*x^5/7 + x^2*x^7/9 - ...
199- * @param {BigNumber} x
200- * @returns {BigNumber} arc tangent of x
201- */
202- function arctan(x) {
203- var y = x;
204- var yPrev = NaN;
205- var x2 = x.times(x);
206- var num = x;
207- var sign = -1;
208-
209- for (var k = 3; !y.equals(yPrev); k += 2) {
210- num = num.times(x2);
211-
212- yPrev = y;
213- y = (sign > 0) ? y.plus(num.div(k)) : y.minus(num.div(k));
214- sign = -sign;
215- }
216-
217- return y;
218- }
219-
220- /**
221- * Calculate BigNumber pi.
222- *
223- * Uses Machin's formula: pi / 4 = 4 * arctan(1 / 5) - arctan(1 / 239)
224- * http://milan.milanovic.org/math/english/pi/machin.html
225- * @returns {BigNumber} Returns pi
226- */
227- function bigPi() {
228- // we calculate pi with a few decimal places extra to prevent round off issues
229- var Big = BigNumber.constructor({precision: BigNumber.precision + 4});
230- var pi4th = new Big(4).times(arctan(new Big(1).div(5)))
231- .minus(arctan(new Big(1).div(239)));
232-
233- // the final pi has the requested number of decimals
234- return new BigNumber(4).times(pi4th);
235- }
236-
237- /**
238- * Calculate BigNumber tau, tau = 2 * pi
239- * @returns {BigNumber} Returns tau
240- */
241- function bigTau() {
242- // we calculate pi at a slightly higher precision than configured to prevent round off errors
243- // when multiplying by two in the end
244- BigNumber.config({precision: config.precision + 2});
245-
246- var pi = bigPi();
247-
248- BigNumber.config({precision: config.precision});
249-
250- return new BigNumber(2).times(pi);
251- }
252-
253 var big = config.number === 'bignumber';
254
255 // TODO: in case of support for defineProperty, we can lazy evaluate the BigNumber constants by creating them as properties (calculation of PI is slow for example)
256- math.pi = big ? bigPi() : Math.PI;
257- math.tau = big ? bigTau() : Math.PI * 2;
258- math.e = big ? bigE() : Math.E;
259- math.phi = big ? bigPhi() : 1.61803398874989484820458683436563811772030917980576286213545; // golden ratio, (1+sqrt(5))/2
260+ math.pi = big ? bignumber.pi(config.precision) : Math.PI;
261+ math.tau = big ? bignumber.tau(config.precision) : Math.PI * 2;
262+ math.e = big ? bignumber.e(config.precision) : Math.E;
263+ math.phi = big ? bignumber.phi(config.precision) : 1.61803398874989484820458683436563811772030917980576286213545; // golden ratio, (1+sqrt(5))/2
264
265 math.i = new Complex(0, 1);
266
267@@ -531,7 +484,7 @@
268 math['true'] = true;
269 math['false'] = false;
270 math['null'] = null;
271- math['uninitialized'] = __webpack_require__(140).UNINITIALIZED;
272+ math['uninitialized'] = __webpack_require__(153).UNINITIALIZED;
273
274 // uppercase constants (for compatibility with built-in Math)
275 math.E = math.e;
276@@ -544,7 +497,7 @@
277 math.SQRT2 = big ? new BigNumber(2).sqrt() : Math.SQRT2;
278
279 // meta information
280- math.version = __webpack_require__(141);
281+ math.version = __webpack_require__(154);
282 };
283
284
285@@ -990,10 +943,10 @@
286
287 'use strict';
288
289- exports.ArgumentsError = __webpack_require__(143);
290- exports.DimensionError = __webpack_require__(144);
291- exports.IndexError = __webpack_require__(145);
292- exports.UnsupportedTypeError = __webpack_require__(146);
293+ exports.ArgumentsError = __webpack_require__(155);
294+ exports.DimensionError = __webpack_require__(156);
295+ exports.IndexError = __webpack_require__(157);
296+ exports.UnsupportedTypeError = __webpack_require__(158);
297
298 // TODO: implement an InvalidValueError?
299
300@@ -1004,7 +957,7 @@
301
302 'use strict';
303
304- var util = __webpack_require__(147),
305+ var util = __webpack_require__(160),
306 Unit = __webpack_require__(10),
307 number = util.number,
308
309@@ -1448,7 +1401,7 @@
310
311 'use strict';
312
313- var util = __webpack_require__(147);
314+ var util = __webpack_require__(160);
315
316 var number = util.number;
317 var string = util.string;
318@@ -1723,7 +1676,7 @@
319
320 'use strict';
321
322- var util = __webpack_require__(147),
323+ var util = __webpack_require__(160),
324
325 Range = __webpack_require__(7),
326
327@@ -1998,8 +1951,8 @@
328
329 'use strict';
330
331- var util = __webpack_require__(147),
332- DimensionError = __webpack_require__(144),
333+ var util = __webpack_require__(160),
334+ DimensionError = __webpack_require__(156),
335
336 Index = __webpack_require__(8),
337
338@@ -2519,7 +2472,7 @@
339
340 'use strict';
341
342- var util = __webpack_require__(147),
343+ var util = __webpack_require__(160),
344
345 number = util.number,
346 string = util.string,
347@@ -2866,6 +2819,7 @@
348 */
349 Unit.prototype.to = function (valuelessUnit) {
350 var other;
351+ var value = this.value == null ? this._normalize(1) : this.value;
352 if (isString(valuelessUnit)) {
353 other = new Unit(null, valuelessUnit);
354
355@@ -2873,7 +2827,7 @@
356 throw new Error('Units do not match');
357 }
358
359- other.value = this.value;
360+ other.value = value;
361 other.fixPrefix = true;
362 return other;
363 }
364@@ -2886,7 +2840,7 @@
365 }
366
367 other = valuelessUnit.clone();
368- other.value = this.value;
369+ other.value = value;
370 other.fixPrefix = true;
371 return other;
372 }
373@@ -3390,7 +3344,7 @@
374
375 'use strict';
376
377- var util = __webpack_require__(147),
378+ var util = __webpack_require__(160),
379 object = util.object,
380 string = util.string;
381
382@@ -3459,7 +3413,7 @@
383 res = e;
384 }
385 desc += ' ' + expr + '\n';
386- if (res && !(res instanceof Help)) {
387+ if (res !== undefined && !(res instanceof Help)) {
388 desc += ' ' + string.format(res, {precision: 14}) + '\n';
389 }
390 }
391@@ -3535,10 +3489,10 @@
392 // utility methods for arrays and matrices
393 'use strict';
394
395- var util = __webpack_require__(147),
396+ var util = __webpack_require__(160),
397
398- IndexError = __webpack_require__(145),
399- DimensionError = __webpack_require__(144),
400+ IndexError = __webpack_require__(157),
401+ DimensionError = __webpack_require__(156),
402
403 Matrix = __webpack_require__(9),
404
405@@ -3801,9 +3755,9 @@
406
407 'use strict';
408
409- var util = __webpack_require__(147),
410+ var util = __webpack_require__(160),
411
412- ArgumentsError = __webpack_require__(143),
413+ ArgumentsError = __webpack_require__(155),
414
415 isString = util.string.isString,
416 isArray = Array.isArray,
417@@ -3816,18 +3770,18 @@
418 collection = __webpack_require__(13),
419
420 // scope and nodes
421- ArrayNode = __webpack_require__(148),
422- AssignmentNode = __webpack_require__(149),
423- BlockNode = __webpack_require__(150),
424- ConditionalNode = __webpack_require__(151),
425- ConstantNode = __webpack_require__(152),
426- FunctionAssignmentNode = __webpack_require__(153),
427- IndexNode = __webpack_require__(154),
428- OperatorNode = __webpack_require__(155),
429- FunctionNode = __webpack_require__(156),
430- RangeNode = __webpack_require__(157),
431- SymbolNode = __webpack_require__(158),
432- UpdateNode = __webpack_require__(159);
433+ ArrayNode = __webpack_require__(161),
434+ AssignmentNode = __webpack_require__(162),
435+ BlockNode = __webpack_require__(163),
436+ ConditionalNode = __webpack_require__(164),
437+ ConstantNode = __webpack_require__(165),
438+ FunctionAssignmentNode = __webpack_require__(166),
439+ IndexNode = __webpack_require__(167),
440+ OperatorNode = __webpack_require__(168),
441+ FunctionNode = __webpack_require__(169),
442+ RangeNode = __webpack_require__(170),
443+ SymbolNode = __webpack_require__(171),
444+ UpdateNode = __webpack_require__(172);
445
446 /**
447 * Parse an expression. Returns a node tree, which can be evaluated by
448@@ -3917,7 +3871,11 @@
449 '%': true,
450 '^': true,
451 '.^': true,
452+ '~': true,
453 '!': true,
454+ '&': true,
455+ '|': true,
456+ '^|': true,
457 '\'': true,
458 '=': true,
459 ':': true,
460@@ -3928,14 +3886,22 @@
461 '<': true,
462 '>': true,
463 '<=': true,
464- '>=': true
465+ '>=': true,
466+
467+ '<<': true,
468+ '>>': true,
469+ '>>>': true
470 };
471
472 // map with all named delimiters
473 var NAMED_DELIMITERS = {
474 'mod': true,
475 'to': true,
476- 'in': true
477+ 'in': true,
478+ 'and': true,
479+ 'xor': true,
480+ 'or': true,
481+ 'not': true
482 };
483
484 var extra_nodes = {}; // current extra nodes
485@@ -3981,6 +3947,15 @@
486 }
487
488 /**
489+ * Preview the second next character from the expression.
490+ * @return {String} cNext
491+ * @private
492+ */
493+ function nextNextPreview() {
494+ return expression.charAt(index + 2);
495+ }
496+
497+ /**
498 * Get next token in the current string expr.
499 * The token and token type are available as token and token_type
500 * @private
501@@ -4018,8 +3993,19 @@
502 return;
503 }
504
505+ // check for delimiters consisting of 3 characters
506+ var c2 = c + nextPreview();
507+ var c3 = c2 + nextNextPreview();
508+ if (c3.length == 3 && DELIMITERS[c3]) {
509+ token_type = TOKENTYPE.DELIMITER;
510+ token = c3;
511+ next();
512+ next();
513+ next();
514+ return;
515+ }
516+
517 // check for delimiters consisting of 2 characters
518- var c2 = c + nextPreview();
519 if (c2.length == 2 && DELIMITERS[c2]) {
520 token_type = TOKENTYPE.DELIMITER;
521 token = c2;
522@@ -4337,7 +4323,7 @@
523 * @private
524 */
525 function parseConditional () {
526- var node = parseRelational();
527+ var node = parseLogicalOr();
528
529 while (token == '?') {
530 // set a conditional level, the range operator will be ignored as long
531@@ -4347,14 +4333,14 @@
532 getTokenSkipNewline();
533
534 var condition = node;
535- var trueExpr = parseRelational();
536+ var trueExpr = parseLogicalOr();
537
538 if (token != ':') throw createSyntaxError('False part of conditional expression expected');
539
540 conditional_level = null;
541 getTokenSkipNewline();
542
543- var falseExpr = parseConditional(); // Note: we don't do parseRelational() here
544+ var falseExpr = parseConditional(); // Note: check for conditional operator again, right associativity
545
546 node = new ConditionalNode(condition, trueExpr, falseExpr);
547
548@@ -4366,66 +4352,100 @@
549 }
550
551 /**
552- * conditional operators and bitshift
553- * @return {Node} node
554- * @private
555- */
556- /* TODO: implement bitwise conditions. put on right place for precedence
557- function parseBitwiseConditions () {
558- var node = parseRange();
559-
560- var operators = {
561- '&' : 'bitwiseand',
562- '|' : 'bitwiseor',
563- // todo: bitwise xor?
564- '<<': 'bitshiftleft',
565- '>>': 'bitshiftright'
566- };
567- while (token in operators) {
568- var name = token;
569-
570- getTokenSkipNewline();
571- var params = [node, parseRelational()];
572- node = new OperatorNode(name, fn, params);
573- }
574-
575- return node;
576- }
577- */
578-
579- /**
580- * conditions like and, or, in
581- * @return {Node} node
582- * @private
583- */
584- /* TODO: conditional and, or, in, etc.
585- function parseConditions () {
586- var node, operators, name, fn, params;
587-
588- node = parseRelational();
589-
590- // TODO: precedence of And above Or?
591- // TODO: implement a method for unit to number conversion
592- operators = {
593- 'and' : 'and',
594- '&&' : 'and',
595- 'or': 'or',
596- '||': 'or',
597- 'xor': 'xor'
598- };
599-
600- while (token in operators) {
601- name = token;
602- fn = operators[name];
603-
604- getTokenSkipNewline();
605- params = [node, parseRelational()];
606- node = new OperatorNode(name, fn, params);
607- }
608-
609- return node;
610- }
611- */
612+ * logical or, 'x or y'
613+ * @return {Node} node
614+ * @private
615+ */
616+ function parseLogicalOr() {
617+ var node = parseLogicalXor();
618+
619+ while (token == 'or') {
620+ getTokenSkipNewline();
621+ node = new OperatorNode('or', 'or', [node, parseLogicalXor()]);
622+ }
623+
624+ return node;
625+ }
626+
627+ /**
628+ * logical exclusive or, 'x xor y'
629+ * @return {Node} node
630+ * @private
631+ */
632+ function parseLogicalXor() {
633+ var node = parseLogicalAnd();
634+
635+ while (token == 'xor') {
636+ getTokenSkipNewline();
637+ node = new OperatorNode('xor', 'xor', [node, parseLogicalAnd()]);
638+ }
639+
640+ return node;
641+ }
642+
643+ /**
644+ * logical and, 'x and y'
645+ * @return {Node} node
646+ * @private
647+ */
648+ function parseLogicalAnd() {
649+ var node = parseBitwiseOr();
650+
651+ while (token == 'and') {
652+ getTokenSkipNewline();
653+ node = new OperatorNode('and', 'and', [node, parseBitwiseOr()]);
654+ }
655+
656+ return node;
657+ }
658+
659+ /**
660+ * bitwise or, 'x | y'
661+ * @return {Node} node
662+ * @private
663+ */
664+ function parseBitwiseOr() {
665+ var node = parseBitwiseXor();
666+
667+ while (token == '|') {
668+ getTokenSkipNewline();
669+ node = new OperatorNode('|', 'bitOr', [node, parseBitwiseXor()]);
670+ }
671+
672+ return node;
673+ }
674+
675+ /**
676+ * bitwise exclusive or (xor), 'x ^| y'
677+ * @return {Node} node
678+ * @private
679+ */
680+ function parseBitwiseXor() {
681+ var node = parseBitwiseAnd();
682+
683+ while (token == '^|') {
684+ getTokenSkipNewline();
685+ node = new OperatorNode('^|', 'bitXor', [node, parseBitwiseAnd()]);
686+ }
687+
688+ return node;
689+ }
690+
691+ /**
692+ * bitwise and, 'x & y'
693+ * @return {Node} node
694+ * @private
695+ */
696+ function parseBitwiseAnd () {
697+ var node = parseRelational();
698+
699+ while (token == '&') {
700+ getTokenSkipNewline();
701+ node = new OperatorNode('&', 'bitAnd', [node, parseRelational()]);
702+ }
703+
704+ return node;
705+ }
706
707 /**
708 * relational operators
709@@ -4435,7 +4455,7 @@
710 function parseRelational () {
711 var node, operators, name, fn, params;
712
713- node = parseConversion();
714+ node = parseShift();
715
716 operators = {
717 '==': 'equal',
718@@ -4450,6 +4470,34 @@
719 fn = operators[name];
720
721 getTokenSkipNewline();
722+ params = [node, parseShift()];
723+ node = new OperatorNode(name, fn, params);
724+ }
725+
726+ return node;
727+ }
728+
729+ /**
730+ * Bitwise left shift, bitwise right arithmetic shift, bitwise right logical shift
731+ * @return {Node} node
732+ * @private
733+ */
734+ function parseShift () {
735+ var node, operators, name, fn, params;
736+
737+ node = parseConversion();
738+
739+ operators = {
740+ '<<' : 'leftShift',
741+ '>>' : 'rightArithShift',
742+ '>>>' : 'rightLogShift'
743+ };
744+
745+ while (token in operators) {
746+ name = token;
747+ fn = operators[name];
748+
749+ getTokenSkipNewline();
750 params = [node, parseConversion()];
751 node = new OperatorNode(name, fn, params);
752 }
753@@ -4605,16 +4653,21 @@
754 }
755
756 /**
757- * Unary plus and minus
758+ * Unary plus and minus, and logical and bitwise not
759 * @return {Node} node
760 * @private
761 */
762 function parseUnary () {
763- var name, fn, params;
764+ var name, params;
765+ var fn = {
766+ '-': 'unaryMinus',
767+ '+': 'unaryPlus',
768+ '~': 'bitNot',
769+ 'not': 'not'
770+ }[token];
771
772- if (token == '-' || token == '+') {
773+ if (fn) {
774 name = token;
775- fn = name == '+' ? 'unaryPlus' : 'unaryMinus';
776
777 getTokenSkipNewline();
778 params = [parseUnary()];
779@@ -5239,19 +5292,19 @@
780
781 'use strict';
782
783- exports.ArrayNode = __webpack_require__(148);
784- exports.AssignmentNode = __webpack_require__(149);
785- exports.BlockNode = __webpack_require__(150);
786- exports.ConditionalNode = __webpack_require__(151);
787- exports.ConstantNode = __webpack_require__(152);
788- exports.IndexNode = __webpack_require__(154);
789- exports.FunctionAssignmentNode = __webpack_require__(153);
790- exports.FunctionNode = __webpack_require__(156);
791- exports.Node = __webpack_require__(160);
792- exports.OperatorNode = __webpack_require__(155);
793- exports.RangeNode = __webpack_require__(157);
794- exports.SymbolNode = __webpack_require__(158);
795- exports.UpdateNode = __webpack_require__(159);
796+ exports.ArrayNode = __webpack_require__(161);
797+ exports.AssignmentNode = __webpack_require__(162);
798+ exports.BlockNode = __webpack_require__(163);
799+ exports.ConditionalNode = __webpack_require__(164);
800+ exports.ConstantNode = __webpack_require__(165);
801+ exports.IndexNode = __webpack_require__(167);
802+ exports.FunctionAssignmentNode = __webpack_require__(166);
803+ exports.FunctionNode = __webpack_require__(169);
804+ exports.Node = __webpack_require__(173);
805+ exports.OperatorNode = __webpack_require__(168);
806+ exports.RangeNode = __webpack_require__(170);
807+ exports.SymbolNode = __webpack_require__(171);
808+ exports.UpdateNode = __webpack_require__(172);
809
810
811 /***/ },
812@@ -5259,154 +5312,170 @@
813 /***/ function(module, exports, __webpack_require__) {
814
815 // constants
816- exports.e = __webpack_require__(164);
817- exports.E = __webpack_require__(164);
818- exports['false'] = __webpack_require__(165);
819- exports.i = __webpack_require__(166);
820- exports['Infinity'] = __webpack_require__(167);
821- exports.LN2 = __webpack_require__(168);
822- exports.LN10 = __webpack_require__(169);
823- exports.LOG2E = __webpack_require__(170);
824- exports.LOG10E = __webpack_require__(171);
825- exports.NaN = __webpack_require__(172);
826- exports['null'] = __webpack_require__(173);
827- exports.pi = __webpack_require__(174);
828- exports.PI = __webpack_require__(174);
829- exports.phi = __webpack_require__(175);
830- exports.SQRT1_2 = __webpack_require__(176);
831- exports.SQRT2 = __webpack_require__(177);
832- exports.tau = __webpack_require__(178);
833- exports['true'] = __webpack_require__(179);
834- exports.version = __webpack_require__(180);
835+ exports.e = __webpack_require__(177);
836+ exports.E = __webpack_require__(177);
837+ exports['false'] = __webpack_require__(178);
838+ exports.i = __webpack_require__(179);
839+ exports['Infinity'] = __webpack_require__(180);
840+ exports.LN2 = __webpack_require__(181);
841+ exports.LN10 = __webpack_require__(182);
842+ exports.LOG2E = __webpack_require__(183);
843+ exports.LOG10E = __webpack_require__(184);
844+ exports.NaN = __webpack_require__(185);
845+ exports['null'] = __webpack_require__(186);
846+ exports.pi = __webpack_require__(187);
847+ exports.PI = __webpack_require__(187);
848+ exports.phi = __webpack_require__(188);
849+ exports.SQRT1_2 = __webpack_require__(189);
850+ exports.SQRT2 = __webpack_require__(190);
851+ exports.tau = __webpack_require__(191);
852+ exports['true'] = __webpack_require__(192);
853+ exports.version = __webpack_require__(193);
854
855 // functions - arithmetic
856- exports.abs = __webpack_require__(184);
857- exports.add = __webpack_require__(185);
858- exports.ceil = __webpack_require__(186);
859- exports.cube = __webpack_require__(187);
860- exports.divide = __webpack_require__(188);
861- exports.dotDivide = __webpack_require__(189);
862- exports.dotMultiply = __webpack_require__(190);
863- exports.dotPow = __webpack_require__(191);
864- exports.exp = __webpack_require__(192);
865- exports.fix = __webpack_require__(193);
866- exports.floor = __webpack_require__(194);
867- exports.gcd = __webpack_require__(195);
868- exports.lcm = __webpack_require__(196);
869- exports.log = __webpack_require__(197);
870- exports.log10 = __webpack_require__(198);
871- exports.mod = __webpack_require__(199);
872- exports.multiply = __webpack_require__(200);
873- exports.norm = __webpack_require__(201);
874- exports.nthRoot = __webpack_require__(202);
875- exports.pow = __webpack_require__(203);
876- exports.round = __webpack_require__(204);
877- exports.sign = __webpack_require__(205);
878- exports.sqrt = __webpack_require__(206);
879- exports.square = __webpack_require__(207);
880- exports.subtract = __webpack_require__(208);
881- exports.unaryMinus = __webpack_require__(209);
882- exports.unaryPlus = __webpack_require__(210);
883- exports.xgcd = __webpack_require__(211);
884+ exports.abs = __webpack_require__(197);
885+ exports.add = __webpack_require__(198);
886+ exports.ceil = __webpack_require__(199);
887+ exports.cube = __webpack_require__(200);
888+ exports.divide = __webpack_require__(201);
889+ exports.dotDivide = __webpack_require__(202);
890+ exports.dotMultiply = __webpack_require__(203);
891+ exports.dotPow = __webpack_require__(204);
892+ exports.exp = __webpack_require__(205);
893+ exports.fix = __webpack_require__(206);
894+ exports.floor = __webpack_require__(207);
895+ exports.gcd = __webpack_require__(208);
896+ exports.lcm = __webpack_require__(209);
897+ exports.log = __webpack_require__(210);
898+ exports.log10 = __webpack_require__(211);
899+ exports.mod = __webpack_require__(212);
900+ exports.multiply = __webpack_require__(213);
901+ exports.norm = __webpack_require__(214);
902+ exports.nthRoot = __webpack_require__(215);
903+ exports.pow = __webpack_require__(216);
904+ exports.round = __webpack_require__(217);
905+ exports.sign = __webpack_require__(218);
906+ exports.sqrt = __webpack_require__(219);
907+ exports.square = __webpack_require__(220);
908+ exports.subtract = __webpack_require__(221);
909+ exports.unaryMinus = __webpack_require__(222);
910+ exports.unaryPlus = __webpack_require__(223);
911+ exports.xgcd = __webpack_require__(224);
912
913- // functions - relational
914- exports.compare = __webpack_require__(212);
915- exports.deepEqual = __webpack_require__(213);
916- exports['equal'] = __webpack_require__(214);
917- exports.larger = __webpack_require__(215);
918- exports.largerEq = __webpack_require__(216);
919- exports.smaller = __webpack_require__(217);
920- exports.smallerEq = __webpack_require__(218);
921- exports.unequal = __webpack_require__(219);
922+ // functions - bitwise
923+ exports.bitAnd = __webpack_require__(225);
924+ exports.bitNot = __webpack_require__(226);
925+ exports.bitOr = __webpack_require__(227);
926+ exports.bitXor = __webpack_require__(228);
927+ exports.leftShift = __webpack_require__(229);
928+ exports.rightArithShift = __webpack_require__(230);
929+ exports.rightLogShift = __webpack_require__(231);
930
931 // functions - complex
932- exports.arg = __webpack_require__(220);
933- exports.conj = __webpack_require__(221);
934- exports.re = __webpack_require__(222);
935- exports.im = __webpack_require__(223);
936+ exports.arg = __webpack_require__(232);
937+ exports.conj = __webpack_require__(233);
938+ exports.re = __webpack_require__(234);
939+ exports.im = __webpack_require__(235);
940
941 // functions - construction
942- exports.bignumber = __webpack_require__(224);
943- exports['boolean'] = __webpack_require__(225);
944- exports.complex = __webpack_require__(226);
945- exports.index = __webpack_require__(227);
946- exports.matrix = __webpack_require__(228);
947- exports.number = __webpack_require__(229);
948- exports.string = __webpack_require__(230);
949- exports.unit = __webpack_require__(231);
950+ exports.bignumber = __webpack_require__(236);
951+ exports['boolean'] = __webpack_require__(237);
952+ exports.complex = __webpack_require__(238);
953+ exports.index = __webpack_require__(239);
954+ exports.matrix = __webpack_require__(240);
955+ exports.number = __webpack_require__(241);
956+ exports.string = __webpack_require__(242);
957+ exports.unit = __webpack_require__(243);
958
959 // functions - expression
960- exports['eval'] = __webpack_require__(232);
961- exports.help = __webpack_require__(233);
962+ exports['eval'] = __webpack_require__(244);
963+ exports.help = __webpack_require__(245);
964+
965+ // functions - logical
966+ exports['and'] = __webpack_require__(246);
967+ exports['not'] = __webpack_require__(247);
968+ exports['or'] = __webpack_require__(248);
969+ exports['xor'] = __webpack_require__(249);
970
971 // functions - matrix
972- exports['concat'] = __webpack_require__(234);
973- exports.cross = __webpack_require__(235);
974- exports.det = __webpack_require__(236);
975- exports.diag = __webpack_require__(237);
976- exports.dot = __webpack_require__(238);
977- exports.eye = __webpack_require__(239);
978- exports.flatten = __webpack_require__(240);
979- exports.inv = __webpack_require__(241);
980- exports.ones = __webpack_require__(242);
981- exports.range = __webpack_require__(243);
982- exports.resize = __webpack_require__(244);
983- exports.size = __webpack_require__(245);
984- exports.squeeze = __webpack_require__(246);
985- exports.subset = __webpack_require__(247);
986- exports.transpose = __webpack_require__(248);
987- exports.zeros = __webpack_require__(249);
988+ exports['concat'] = __webpack_require__(250);
989+ exports.cross = __webpack_require__(251);
990+ exports.det = __webpack_require__(252);
991+ exports.diag = __webpack_require__(253);
992+ exports.dot = __webpack_require__(254);
993+ exports.eye = __webpack_require__(255);
994+ exports.flatten = __webpack_require__(256);
995+ exports.inv = __webpack_require__(257);
996+ exports.ones = __webpack_require__(258);
997+ exports.range = __webpack_require__(259);
998+ exports.resize = __webpack_require__(260);
999+ exports.size = __webpack_require__(261);
1000+ exports.squeeze = __webpack_require__(262);
1001+ exports.subset = __webpack_require__(263);
1002+ exports.transpose = __webpack_require__(264);
1003+ exports.zeros = __webpack_require__(265);
1004
1005 // functions - probability
1006- exports.combinations = __webpack_require__(250);
1007+ exports.combinations = __webpack_require__(266);
1008 //exports.distribution = require('./function/probability/distribution');
1009- exports.factorial = __webpack_require__(251);
1010- exports.permutations = __webpack_require__(252);
1011- exports.pickRandom = __webpack_require__(253);
1012- exports.random = __webpack_require__(254);
1013- exports.randomInt = __webpack_require__(255);
1014+ exports.factorial = __webpack_require__(267);
1015+ exports.gamma = __webpack_require__(268);
1016+ exports.permutations = __webpack_require__(269);
1017+ exports.pickRandom = __webpack_require__(270);
1018+ exports.random = __webpack_require__(271);
1019+ exports.randomInt = __webpack_require__(272);
1020+
1021+ // functions - relational
1022+ exports.compare = __webpack_require__(273);
1023+ exports.deepEqual = __webpack_require__(274);
1024+ exports['equal'] = __webpack_require__(275);
1025+ exports.larger = __webpack_require__(276);
1026+ exports.largerEq = __webpack_require__(277);
1027+ exports.smaller = __webpack_require__(278);
1028+ exports.smallerEq = __webpack_require__(279);
1029+ exports.unequal = __webpack_require__(280);
1030
1031 // functions - statistics
1032- exports.max = __webpack_require__(256);
1033- exports.mean = __webpack_require__(257);
1034- exports.median = __webpack_require__(258);
1035- exports.min = __webpack_require__(259);
1036- exports.prod = __webpack_require__(260);
1037- exports.std = __webpack_require__(261);
1038- exports.sum = __webpack_require__(262);
1039- exports['var'] = __webpack_require__(263);
1040+ exports.max = __webpack_require__(281);
1041+ exports.mean = __webpack_require__(282);
1042+ exports.median = __webpack_require__(283);
1043+ exports.min = __webpack_require__(284);
1044+ exports.prod = __webpack_require__(285);
1045+ exports.std = __webpack_require__(286);
1046+ exports.sum = __webpack_require__(287);
1047+ exports['var'] = __webpack_require__(288);
1048
1049 // functions - trigonometry
1050- exports.acos = __webpack_require__(264);
1051- exports.asin = __webpack_require__(265);
1052- exports.atan = __webpack_require__(266);
1053- exports.atan2 = __webpack_require__(267);
1054- exports.cos = __webpack_require__(268);
1055- exports.cosh = __webpack_require__(269);
1056- exports.cot = __webpack_require__(270);
1057- exports.coth = __webpack_require__(271);
1058- exports.csc = __webpack_require__(272);
1059- exports.csch = __webpack_require__(273);
1060- exports.sec = __webpack_require__(274);
1061- exports.sech = __webpack_require__(275);
1062- exports.sin = __webpack_require__(276);
1063- exports.sinh = __webpack_require__(277);
1064- exports.tan = __webpack_require__(278);
1065- exports.tanh = __webpack_require__(279);
1066+ exports.acos = __webpack_require__(289);
1067+ exports.asin = __webpack_require__(290);
1068+ exports.atan = __webpack_require__(291);
1069+ exports.atan2 = __webpack_require__(292);
1070+ exports.cos = __webpack_require__(293);
1071+ exports.cosh = __webpack_require__(294);
1072+ exports.cot = __webpack_require__(295);
1073+ exports.coth = __webpack_require__(296);
1074+ exports.csc = __webpack_require__(297);
1075+ exports.csch = __webpack_require__(298);
1076+ exports.sec = __webpack_require__(299);
1077+ exports.sech = __webpack_require__(300);
1078+ exports.sin = __webpack_require__(301);
1079+ exports.sinh = __webpack_require__(302);
1080+ exports.tan = __webpack_require__(303);
1081+ exports.tanh = __webpack_require__(304);
1082
1083 // functions - units
1084- exports.to = __webpack_require__(280);
1085+ exports.to = __webpack_require__(305);
1086
1087 // functions - utils
1088- exports.clone = __webpack_require__(281);
1089- exports.map = __webpack_require__(282);
1090- exports.filter = __webpack_require__(283);
1091- exports.forEach = __webpack_require__(284);
1092- exports.format = __webpack_require__(285);
1093+ exports.clone = __webpack_require__(306);
1094+ exports.map = __webpack_require__(307);
1095+ exports.filter = __webpack_require__(308);
1096+ exports.forEach = __webpack_require__(309);
1097+ exports.format = __webpack_require__(310);
1098 // exports.print = require('./function/utils/print'); // TODO: add documentation for print as soon as the parser supports objects.
1099- exports['import'] = __webpack_require__(286);
1100- exports.sort = __webpack_require__(287);
1101- exports['typeof'] = __webpack_require__(288);
1102+ exports['import'] = __webpack_require__(311);
1103+ exports.sort = __webpack_require__(312);
1104+ exports['typeof'] = __webpack_require__(313);
1105
1106
1107 /***/ },
1108@@ -5415,10 +5484,10 @@
1109
1110 'use strict';
1111
1112- var BigNumber = __webpack_require__(142);
1113- var errorTransform = __webpack_require__(161).transform;
1114+ var BigNumber = __webpack_require__(159);
1115+ var errorTransform = __webpack_require__(174).transform;
1116 var isNumber = __webpack_require__(4).isNumber;
1117- var argsToArray = __webpack_require__(140).argsToArray;
1118+ var argsToArray = __webpack_require__(153).argsToArray;
1119
1120 /**
1121 * Attach a transform function to math.range
1122@@ -5459,10 +5528,10 @@
1123
1124 'use strict';
1125
1126- var SymbolNode = __webpack_require__(158);
1127- var isBoolean = __webpack_require__(162).isBoolean;
1128- var argsToArray = __webpack_require__(140).argsToArray;
1129- var ArgumentsError = __webpack_require__(143);
1130+ var SymbolNode = __webpack_require__(171);
1131+ var isBoolean = __webpack_require__(175).isBoolean;
1132+ var argsToArray = __webpack_require__(153).argsToArray;
1133+ var ArgumentsError = __webpack_require__(155);
1134
1135 /**
1136 * Attach a transform function to math.filter
1137@@ -5574,7 +5643,7 @@
1138
1139 'use strict';
1140
1141- var BigNumber = __webpack_require__(142);
1142+ var BigNumber = __webpack_require__(159);
1143 var Range = __webpack_require__(7);
1144 var Index = __webpack_require__(8);
1145 var Matrix = __webpack_require__(9);
1146@@ -5626,7 +5695,7 @@
1147 'use strict';
1148
1149 var Matrix = __webpack_require__(9);
1150- var BigNumber = __webpack_require__(142);
1151+ var BigNumber = __webpack_require__(159);
1152 var Range = __webpack_require__(7);
1153 var Index = __webpack_require__(8);
1154 var isNumber = __webpack_require__(4).isNumber;
1155@@ -5678,11 +5747,11 @@
1156
1157 'use strict';
1158
1159- var BigNumber = __webpack_require__(142);
1160- var errorTransform = __webpack_require__(161).transform;
1161+ var BigNumber = __webpack_require__(159);
1162+ var errorTransform = __webpack_require__(174).transform;
1163 var isNumber = __webpack_require__(4).isNumber;
1164 var isCollection = __webpack_require__(13).isCollection;
1165- var argsToArray = __webpack_require__(140).argsToArray;
1166+ var argsToArray = __webpack_require__(153).argsToArray;
1167
1168 /**
1169 * Attach a transform function to math.max
1170@@ -5723,11 +5792,11 @@
1171
1172 'use strict';
1173
1174- var BigNumber = __webpack_require__(142);
1175- var errorTransform = __webpack_require__(161).transform;
1176+ var BigNumber = __webpack_require__(159);
1177+ var errorTransform = __webpack_require__(174).transform;
1178 var isNumber = __webpack_require__(4).isNumber;
1179 var isCollection = __webpack_require__(13).isCollection;
1180- var argsToArray = __webpack_require__(140).argsToArray;
1181+ var argsToArray = __webpack_require__(153).argsToArray;
1182
1183 /**
1184 * Attach a transform function to math.mean
1185@@ -5768,11 +5837,11 @@
1186
1187 'use strict';
1188
1189- var BigNumber = __webpack_require__(142);
1190- var errorTransform = __webpack_require__(161).transform;
1191+ var BigNumber = __webpack_require__(159);
1192+ var errorTransform = __webpack_require__(174).transform;
1193 var isNumber = __webpack_require__(4).isNumber;
1194 var isCollection = __webpack_require__(13).isCollection;
1195- var argsToArray = __webpack_require__(140).argsToArray;
1196+ var argsToArray = __webpack_require__(153).argsToArray;
1197
1198 /**
1199 * Attach a transform function to math.min
1200@@ -5813,8 +5882,8 @@
1201
1202 'use strict';
1203
1204- var isBoolean = __webpack_require__(162).isBoolean;
1205- var argsToArray = __webpack_require__(140).argsToArray;
1206+ var isBoolean = __webpack_require__(175).isBoolean;
1207+ var argsToArray = __webpack_require__(153).argsToArray;
1208
1209 /**
1210 * Attach a transform function to math.range
1211@@ -5844,9 +5913,9 @@
1212
1213 'use strict';
1214
1215- var errorTransform = __webpack_require__(161).transform;
1216- var isBoolean = __webpack_require__(162).isBoolean;
1217- var argsToArray = __webpack_require__(140).argsToArray;
1218+ var errorTransform = __webpack_require__(174).transform;
1219+ var isBoolean = __webpack_require__(175).isBoolean;
1220+ var argsToArray = __webpack_require__(153).argsToArray;
1221
1222 /**
1223 * Attach a transform function to math.subset
1224@@ -5874,32 +5943,32 @@
1225 'use strict';
1226
1227 module.exports = function (math) {
1228- var string = __webpack_require__(163);
1229+ var string = __webpack_require__(176);
1230
1231 /**
1232- * @constructor Selector
1233- * Wrap any value in a Selector, allowing to perform chained operations on
1234+ * @constructor Chain
1235+ * Wrap any value in a chain, allowing to perform chained operations on
1236 * the value.
1237 *
1238- * All methods available in the math.js library can be called upon the selector,
1239+ * All methods available in the math.js library can be called upon the chain,
1240 * and then will be evaluated with the value itself as first argument.
1241- * The selector can be closed by executing selector.done(), which will return
1242+ * The chain can be closed by executing chain.done(), which will return
1243 * the final value.
1244 *
1245- * The Selector has a number of special functions:
1246+ * The Chain has a number of special functions:
1247 * - done() Finalize the chained operation and return the
1248- * selectors value.
1249+ * chain's value.
1250 * - valueOf() The same as done()
1251- * - toString() Returns a string representation of the selectors value.
1252+ * - toString() Returns a string representation of the chain's value.
1253 *
1254 * @param {*} [value]
1255 */
1256- function Selector (value) {
1257- if (!(this instanceof Selector)) {
1258+ function Chain (value) {
1259+ if (!(this instanceof Chain)) {
1260 throw new SyntaxError('Constructor must be called with the new operator');
1261 }
1262
1263- if (value instanceof Selector) {
1264+ if (value instanceof Chain) {
1265 this.value = value.value;
1266 }
1267 else {
1268@@ -5908,33 +5977,33 @@
1269 }
1270
1271 /**
1272- * Close the selector. Returns the final value.
1273+ * Close the chain. Returns the final value.
1274 * Does the same as method valueOf()
1275 * @returns {*} value
1276 */
1277- Selector.prototype.done = function () {
1278+ Chain.prototype.done = function () {
1279 return this.value;
1280 };
1281
1282 /**
1283- * Close the selector. Returns the final value.
1284+ * Close the chain. Returns the final value.
1285 * Does the same as method done()
1286 * @returns {*} value
1287 */
1288- Selector.prototype.valueOf = function () {
1289+ Chain.prototype.valueOf = function () {
1290 return this.value;
1291 };
1292
1293 /**
1294- * Get a string representation of the value in the selector
1295+ * Get a string representation of the value in the chain
1296 * @returns {String}
1297 */
1298- Selector.prototype.toString = function () {
1299+ Chain.prototype.toString = function () {
1300 return string.format(this.value);
1301 };
1302
1303 /**
1304- * Create a proxy method for the selector
1305+ * Create a proxy method for the chain
1306 * @param {String} name
1307 * @param {*} value The value or function to be proxied
1308 */
1309@@ -5942,18 +6011,18 @@
1310 var slice = Array.prototype.slice;
1311 if (typeof value === 'function') {
1312 // a function
1313- Selector.prototype[name] = function () {
1314+ Chain.prototype[name] = function () {
1315 var args = [this.value].concat(slice.call(arguments, 0));
1316- return new Selector(value.apply(this, args));
1317+ return new Chain(value.apply(this, args));
1318 }
1319 }
1320 else {
1321 // a constant
1322- Selector.prototype[name] = new Selector(value);
1323+ Chain.prototype[name] = new Chain(value);
1324 }
1325 }
1326
1327- Selector.createProxy = createProxy;
1328+ Chain.createProxy = createProxy;
1329
1330 /**
1331 * initialise the Chain prototype with all functions and constants in math
1332@@ -5964,7 +6033,7 @@
1333 }
1334 }
1335
1336- return Selector;
1337+ return Chain;
1338 };
1339
1340
1341@@ -5975,7 +6044,7 @@
1342 'use strict';
1343
1344 module.exports = function (math, config) {
1345- var util = __webpack_require__(147),
1346+ var util = __webpack_require__(160),
1347 _parse = __webpack_require__(14),
1348
1349 collection = __webpack_require__(13),
1350@@ -6047,7 +6116,7 @@
1351 'use strict';
1352
1353 module.exports = function (math) {
1354- var util = __webpack_require__(147),
1355+ var util = __webpack_require__(160),
1356 _parse = __webpack_require__(14),
1357
1358 collection = __webpack_require__(13),
1359@@ -6176,7 +6245,9 @@
1360 }
1361
1362 var doc = math.expression.docs[text];
1363- if (!text || !doc) {
1364+ if (!text) {
1365+ throw new Error('Cannot find "' + search + '" in math.js');
1366+ } else if (!doc) {
1367 throw new Error('No documentation found on "' + text + '"');
1368 }
1369 return new Help(math, doc);
1370@@ -6239,7 +6310,7 @@
1371 'use strict';
1372
1373 module.exports = function (math) {
1374- var util = __webpack_require__(147),
1375+ var util = __webpack_require__(160),
1376
1377 BigNumber = math.type.BigNumber,
1378 Complex = __webpack_require__(6),
1379@@ -6312,7 +6383,7 @@
1380 'use strict';
1381
1382 module.exports = function (math) {
1383- var util = __webpack_require__(147),
1384+ var util = __webpack_require__(160),
1385
1386 BigNumber = math.type.BigNumber,
1387 Complex = __webpack_require__(6),
1388@@ -6474,7 +6545,7 @@
1389 'use strict';
1390
1391 module.exports = function (math) {
1392- var util = __webpack_require__(147),
1393+ var util = __webpack_require__(160),
1394
1395 BigNumber = math.type.BigNumber,
1396 Complex = __webpack_require__(6),
1397@@ -6553,7 +6624,7 @@
1398 'use strict';
1399
1400 module.exports = function (math) {
1401- var util = __webpack_require__(147),
1402+ var util = __webpack_require__(160),
1403
1404 BigNumber = math.type.BigNumber,
1405 Complex = __webpack_require__(6),
1406@@ -6625,19 +6696,141 @@
1407 'use strict';
1408
1409 module.exports = function(math) {
1410- var util = __webpack_require__(147),
1411-
1412- BigNumber = math.type.BigNumber,
1413- Complex = __webpack_require__(6),
1414- Matrix = __webpack_require__(9),
1415- Unit = __webpack_require__(10),
1416- collection = __webpack_require__(13),
1417-
1418- isNumber = util.number.isNumber,
1419- isBoolean = util['boolean'].isBoolean,
1420- isComplex = Complex.isComplex,
1421- isUnit = Unit.isUnit,
1422- isCollection = collection.isCollection;
1423+ var util = __webpack_require__(160);
1424+
1425+ var BigNumber = math.type.BigNumber;
1426+ var Complex = __webpack_require__(6);
1427+ var Matrix = __webpack_require__(9);
1428+ var Unit = __webpack_require__(10);
1429+
1430+ var isNumber = util.number.isNumber;
1431+ var isBoolean = util['boolean'].isBoolean;
1432+ var isComplex = Complex.isComplex;
1433+ var isUnit = Unit.isUnit;
1434+
1435+ /**
1436+ * Divide two scalar values, `x / y`.
1437+ * This function is meant for internal use: it is used by the public functions
1438+ * `divide` and `inv`.
1439+ *
1440+ * This function does not support collections (Array or Matrix), and does
1441+ * not validate the number of of inputs.
1442+ *
1443+ * @param {Number | BigNumber | Boolean | Complex | Unit | null} x Numerator
1444+ * @param {Number | BigNumber | Boolean | Complex | null} y Denominator
1445+ * @return {Number | BigNumber | Complex | Unit} Quotient, `x / y`
1446+ * @private
1447+ */
1448+ math._divide = function _divide(x, y) {
1449+ // TODO: this is a temporary function, to be removed as soon as the library is modularized (i.e. no dependencies on math from the individual functions)
1450+ if (isNumber(x)) {
1451+ if (isNumber(y)) {
1452+ // number / number
1453+ return x / y;
1454+ }
1455+ else if (isComplex(y)) {
1456+ // number / complex
1457+ return _divideComplex(new Complex(x, 0), y);
1458+ }
1459+ }
1460+
1461+ if (isComplex(x)) {
1462+ if (isComplex(y)) {
1463+ // complex / complex
1464+ return _divideComplex(x, y);
1465+ }
1466+ else if (isNumber(y)) {
1467+ // complex / number
1468+ return _divideComplex(x, new Complex(y, 0));
1469+ }
1470+ }
1471+
1472+ if (x instanceof BigNumber) {
1473+ // try to convert to big number
1474+ if (isNumber(y)) {
1475+ y = BigNumber.convert(y);
1476+ }
1477+ else if (isBoolean(y) || y === null) {
1478+ y = new BigNumber(y ? 1 : 0);
1479+ }
1480+
1481+ if (y instanceof BigNumber) {
1482+ return x.div(y);
1483+ }
1484+
1485+ // downgrade to Number
1486+ return _divide(x.toNumber(), y);
1487+ }
1488+ if (y instanceof BigNumber) {
1489+ // try to convert to big number
1490+ if (isNumber(x)) {
1491+ x = BigNumber.convert(x);
1492+ }
1493+ else if (isBoolean(x) || x === null) {
1494+ x = new BigNumber(x ? 1 : 0);
1495+ }
1496+
1497+ if (x instanceof BigNumber) {
1498+ return x.div(y)
1499+ }
1500+
1501+ // downgrade to Number
1502+ return _divide(x, y.toNumber());
1503+ }
1504+
1505+ if (isUnit(x)) {
1506+ if (isNumber(y)) {
1507+ var res = x.clone();
1508+ res.value = ((res.value === null) ? res._normalize(1) : res.value) / y;
1509+ return res;
1510+ }
1511+ }
1512+
1513+ if (isBoolean(x) || x === null) {
1514+ return _divide(+x, y);
1515+ }
1516+ if (isBoolean(y) || y === null) {
1517+ return _divide(x, +y);
1518+ }
1519+
1520+ throw new math.error.UnsupportedTypeError('divide', math['typeof'](x), math['typeof'](y));
1521+ };
1522+
1523+ /**
1524+ * Divide two complex numbers. x / y or divide(x, y)
1525+ * @param {Complex} x
1526+ * @param {Complex} y
1527+ * @return {Complex} res
1528+ * @private
1529+ */
1530+ function _divideComplex (x, y) {
1531+ var den = y.re * y.re + y.im * y.im;
1532+ if (den != 0) {
1533+ return new Complex(
1534+ (x.re * y.re + x.im * y.im) / den,
1535+ (x.im * y.re - x.re * y.im) / den
1536+ );
1537+ }
1538+ else {
1539+ // both y.re and y.im are zero
1540+ return new Complex(
1541+ (x.re != 0) ? (x.re / 0) : 0,
1542+ (x.im != 0) ? (x.im / 0) : 0
1543+ );
1544+ }
1545+ }
1546+ };
1547+
1548+
1549+/***/ },
1550+/* 38 */
1551+/***/ function(module, exports, __webpack_require__) {
1552+
1553+ 'use strict';
1554+
1555+ module.exports = function(math) {
1556+ var collection = __webpack_require__(13);
1557+ var isCollection = collection.isCollection;
1558
1559 /**
1560 * Divide two values, `x / y`.
1561@@ -6670,74 +6863,11 @@
1562 * @param {Number | BigNumber | Boolean | Complex | Array | Matrix | null} y Denominator
1563 * @return {Number | BigNumber | Complex | Unit | Array | Matrix} Quotient, `x / y`
1564 */
1565- math.divide = function divide(x, y) {
1566+ math.divide = function(x, y) {
1567 if (arguments.length != 2) {
1568 throw new math.error.ArgumentsError('divide', arguments.length, 2);
1569 }
1570
1571- if (isNumber(x)) {
1572- if (isNumber(y)) {
1573- // number / number
1574- return x / y;
1575- }
1576- else if (isComplex(y)) {
1577- // number / complex
1578- return _divideComplex(new Complex(x, 0), y);
1579- }
1580- }
1581-
1582- if (isComplex(x)) {
1583- if (isComplex(y)) {
1584- // complex / complex
1585- return _divideComplex(x, y);
1586- }
1587- else if (isNumber(y)) {
1588- // complex / number
1589- return _divideComplex(x, new Complex(y, 0));
1590- }
1591- }
1592-
1593- if (x instanceof BigNumber) {
1594- // try to convert to big number
1595- if (isNumber(y)) {
1596- y = BigNumber.convert(y);
1597- }
1598- else if (isBoolean(y) || y === null) {
1599- y = new BigNumber(y ? 1 : 0);
1600- }
1601-
1602- if (y instanceof BigNumber) {
1603- return x.div(y);
1604- }
1605-
1606- // downgrade to Number
1607- return divide(x.toNumber(), y);
1608- }
1609- if (y instanceof BigNumber) {
1610- // try to convert to big number
1611- if (isNumber(x)) {
1612- x = BigNumber.convert(x);
1613- }
1614- else if (isBoolean(x) || x === null) {
1615- x = new BigNumber(x ? 1 : 0);
1616- }
1617-
1618- if (x instanceof BigNumber) {
1619- return x.div(y)
1620- }
1621-
1622- // downgrade to Number
1623- return divide(x, y.toNumber());
1624- }
1625-
1626- if (isUnit(x)) {
1627- if (isNumber(y)) {
1628- var res = x.clone();
1629- res.value /= y;
1630- return res;
1631- }
1632- }
1633-
1634 if (isCollection(x)) {
1635 if (isCollection(y)) {
1636 // TODO: implement matrix right division using pseudo inverse
1637@@ -6748,7 +6878,7 @@
1638 }
1639 else {
1640 // matrix / scalar
1641- return collection.deepMap2(x, y, divide);
1642+ return collection.deepMap2(x, y, math._divide);
1643 }
1644 }
1645
1646@@ -6757,44 +6887,14 @@
1647 return math.multiply(x, math.inv(y));
1648 }
1649
1650- if (isBoolean(x) || x === null) {
1651- return divide(+x, y);
1652- }
1653- if (isBoolean(y) || y === null) {
1654- return divide(x, +y);
1655- }
1656-
1657- throw new math.error.UnsupportedTypeError('divide', math['typeof'](x), math['typeof'](y));
1658+ // divide two scalars
1659+ return math._divide(x, y);
1660 };
1661-
1662- /**
1663- * Divide two complex numbers. x / y or divide(x, y)
1664- * @param {Complex} x
1665- * @param {Complex} y
1666- * @return {Complex} res
1667- * @private
1668- */
1669- function _divideComplex (x, y) {
1670- var den = y.re * y.re + y.im * y.im;
1671- if (den != 0) {
1672- return new Complex(
1673- (x.re * y.re + x.im * y.im) / den,
1674- (x.im * y.re - x.re * y.im) / den
1675- );
1676- }
1677- else {
1678- // both y.re and y.im are zero
1679- return new Complex(
1680- (x.re != 0) ? (x.re / 0) : 0,
1681- (x.im != 0) ? (x.im / 0) : 0
1682- );
1683- }
1684- }
1685 };
1686
1687
1688 /***/ },
1689-/* 38 */
1690+/* 39 */
1691 /***/ function(module, exports, __webpack_require__) {
1692
1693 'use strict';
1694@@ -6844,13 +6944,13 @@
1695
1696
1697 /***/ },
1698-/* 39 */
1699+/* 40 */
1700 /***/ function(module, exports, __webpack_require__) {
1701
1702 'use strict';
1703
1704 module.exports = function (math) {
1705- var util = __webpack_require__(147),
1706+ var util = __webpack_require__(160),
1707 collection = __webpack_require__(13);
1708
1709 /**
1710@@ -6895,13 +6995,13 @@
1711
1712
1713 /***/ },
1714-/* 40 */
1715+/* 41 */
1716 /***/ function(module, exports, __webpack_require__) {
1717
1718 'use strict';
1719
1720 module.exports = function (math) {
1721- var util = __webpack_require__(147),
1722+ var util = __webpack_require__(160),
1723 collection = __webpack_require__(13);
1724
1725 /**
1726@@ -6943,13 +7043,13 @@
1727
1728
1729 /***/ },
1730-/* 41 */
1731+/* 42 */
1732 /***/ function(module, exports, __webpack_require__) {
1733
1734 'use strict';
1735
1736 module.exports = function (math) {
1737- var util = __webpack_require__(147),
1738+ var util = __webpack_require__(160),
1739
1740 BigNumber = math.type.BigNumber,
1741 Complex = __webpack_require__(6),
1742@@ -7024,13 +7124,13 @@
1743
1744
1745 /***/ },
1746-/* 42 */
1747+/* 43 */
1748 /***/ function(module, exports, __webpack_require__) {
1749
1750 'use strict';
1751
1752 module.exports = function (math) {
1753- var util = __webpack_require__(147),
1754+ var util = __webpack_require__(160),
1755
1756 BigNumber = math.type.BigNumber,
1757 Complex = __webpack_require__(6),
1758@@ -7102,13 +7202,13 @@
1759
1760
1761 /***/ },
1762-/* 43 */
1763+/* 44 */
1764 /***/ function(module, exports, __webpack_require__) {
1765
1766 'use strict';
1767
1768 module.exports = function (math) {
1769- var util = __webpack_require__(147),
1770+ var util = __webpack_require__(160),
1771
1772 BigNumber = math.type.BigNumber,
1773 Complex = __webpack_require__(6),
1774@@ -7180,13 +7280,13 @@
1775
1776
1777 /***/ },
1778-/* 44 */
1779+/* 45 */
1780 /***/ function(module, exports, __webpack_require__) {
1781
1782 'use strict';
1783
1784 module.exports = function (math) {
1785- var util = __webpack_require__(147),
1786+ var util = __webpack_require__(160),
1787
1788 BigNumber = math.type.BigNumber,
1789 collection = __webpack_require__(13),
1790@@ -7327,13 +7427,13 @@
1791
1792
1793 /***/ },
1794-/* 45 */
1795+/* 46 */
1796 /***/ function(module, exports, __webpack_require__) {
1797
1798 'use strict';
1799
1800 module.exports = function (math) {
1801- var util = __webpack_require__(147),
1802+ var util = __webpack_require__(160),
1803
1804 BigNumber = math.type.BigNumber,
1805 collection = __webpack_require__(13),
1806@@ -7489,13 +7589,13 @@
1807
1808
1809 /***/ },
1810-/* 46 */
1811+/* 47 */
1812 /***/ function(module, exports, __webpack_require__) {
1813
1814 'use strict';
1815
1816 module.exports = function (math) {
1817- var util = __webpack_require__(147),
1818+ var util = __webpack_require__(160),
1819
1820 BigNumber = math.type.BigNumber,
1821 Complex = __webpack_require__(6),
1822@@ -7592,13 +7692,13 @@
1823
1824
1825 /***/ },
1826-/* 47 */
1827+/* 48 */
1828 /***/ function(module, exports, __webpack_require__) {
1829
1830 'use strict';
1831
1832 module.exports = function (math) {
1833- var util = __webpack_require__(147),
1834+ var util = __webpack_require__(160),
1835
1836 BigNumber = math.type.BigNumber,
1837 Complex = __webpack_require__(6),
1838@@ -7680,13 +7780,13 @@
1839
1840
1841 /***/ },
1842-/* 48 */
1843+/* 49 */
1844 /***/ function(module, exports, __webpack_require__) {
1845
1846 'use strict';
1847
1848 module.exports = function (math) {
1849- var util = __webpack_require__(147),
1850+ var util = __webpack_require__(160),
1851
1852 BigNumber = math.type.BigNumber,
1853 collection = __webpack_require__(13),
1854@@ -7819,13 +7919,13 @@
1855
1856
1857 /***/ },
1858-/* 49 */
1859+/* 50 */
1860 /***/ function(module, exports, __webpack_require__) {
1861
1862 'use strict';
1863
1864 module.exports = function(math) {
1865- var util = __webpack_require__(147),
1866+ var util = __webpack_require__(160),
1867
1868 BigNumber = math.type.BigNumber,
1869 Complex = __webpack_require__(6),
1870@@ -7959,7 +8059,7 @@
1871 throw new RangeError('Dimension mismatch in multiplication. ' +
1872 'Length of A must match length of B ' +
1873 '(A is ' + sizeX[0] +
1874- ', B is ' + sizeY[0] +
1875+ ', B is ' + sizeY[0] + ', ' +
1876 sizeX[0] + ' != ' + sizeY[0] + ')');
1877 }
1878
1879@@ -8250,15 +8350,15 @@
1880
1881
1882 /***/ },
1883-/* 50 */
1884+/* 51 */
1885 /***/ function(module, exports, __webpack_require__) {
1886
1887 'use strict';
1888
1889 module.exports = function (math) {
1890- var util = __webpack_require__(147),
1891+ var util = __webpack_require__(160),
1892
1893- array = __webpack_require__(140),
1894+ array = __webpack_require__(153),
1895
1896 BigNumber = math.type.BigNumber,
1897 Complex = __webpack_require__(6),
1898@@ -8438,13 +8538,13 @@
1899
1900
1901 /***/ },
1902-/* 51 */
1903+/* 52 */
1904 /***/ function(module, exports, __webpack_require__) {
1905
1906 'use strict';
1907
1908 module.exports = function (math) {
1909- var util = __webpack_require__(147);
1910+ var util = __webpack_require__(160);
1911
1912 var BigNumber = math.type.BigNumber;
1913 var collection = __webpack_require__(13);
1914@@ -8637,13 +8737,13 @@
1915
1916
1917 /***/ },
1918-/* 52 */
1919+/* 53 */
1920 /***/ function(module, exports, __webpack_require__) {
1921
1922 'use strict';
1923
1924 module.exports = function (math) {
1925- var util = __webpack_require__(147),
1926+ var util = __webpack_require__(160),
1927
1928 BigNumber = math.type.BigNumber,
1929 Complex = __webpack_require__(6),
1930@@ -8723,7 +8823,7 @@
1931 }
1932
1933 if (y instanceof BigNumber) {
1934- if (y.isInteger() && !x.isNegative()) {
1935+ if (y.isInteger() || !x.isNegative()) {
1936 return x.pow(y);
1937 }
1938 else {
1939@@ -8821,13 +8921,13 @@
1940
1941
1942 /***/ },
1943-/* 53 */
1944+/* 54 */
1945 /***/ function(module, exports, __webpack_require__) {
1946
1947 'use strict';
1948
1949 module.exports = function (math) {
1950- var util = __webpack_require__(147),
1951+ var util = __webpack_require__(160),
1952
1953 BigNumber = math.type.BigNumber,
1954 Complex = __webpack_require__(6),
1955@@ -8961,13 +9061,13 @@
1956
1957
1958 /***/ },
1959-/* 54 */
1960+/* 55 */
1961 /***/ function(module, exports, __webpack_require__) {
1962
1963 'use strict';
1964
1965 module.exports = function (math) {
1966- var util = __webpack_require__(147),
1967+ var util = __webpack_require__(160),
1968
1969 BigNumber = math.type.BigNumber,
1970 Complex = __webpack_require__(6),
1971@@ -9041,13 +9141,13 @@
1972
1973
1974 /***/ },
1975-/* 55 */
1976+/* 56 */
1977 /***/ function(module, exports, __webpack_require__) {
1978
1979 'use strict';
1980
1981 module.exports = function (math) {
1982- var util = __webpack_require__(147),
1983+ var util = __webpack_require__(160),
1984
1985 BigNumber = math.type.BigNumber,
1986 Complex = __webpack_require__(6),
1987@@ -9147,13 +9247,13 @@
1988
1989
1990 /***/ },
1991-/* 56 */
1992+/* 57 */
1993 /***/ function(module, exports, __webpack_require__) {
1994
1995 'use strict';
1996
1997 module.exports = function (math) {
1998- var util = __webpack_require__(147),
1999+ var util = __webpack_require__(160),
2000
2001 BigNumber = math.type.BigNumber,
2002 Complex = __webpack_require__(6),
2003@@ -9221,13 +9321,13 @@
2004
2005
2006 /***/ },
2007-/* 57 */
2008+/* 58 */
2009 /***/ function(module, exports, __webpack_require__) {
2010
2011 'use strict';
2012
2013 module.exports = function (math) {
2014- var util = __webpack_require__(147),
2015+ var util = __webpack_require__(160),
2016
2017 BigNumber = math.type.BigNumber,
2018 Complex = __webpack_require__(6),
2019@@ -9381,13 +9481,13 @@
2020
2021
2022 /***/ },
2023-/* 58 */
2024+/* 59 */
2025 /***/ function(module, exports, __webpack_require__) {
2026
2027 'use strict';
2028
2029 module.exports = function (math, config) {
2030- var util = __webpack_require__(147),
2031+ var util = __webpack_require__(160),
2032
2033 BigNumber = math.type.BigNumber,
2034 Complex = __webpack_require__(6),
2035@@ -9470,13 +9570,13 @@
2036
2037
2038 /***/ },
2039-/* 59 */
2040+/* 60 */
2041 /***/ function(module, exports, __webpack_require__) {
2042
2043 'use strict';
2044
2045 module.exports = function (math, config) {
2046- var util = __webpack_require__(147),
2047+ var util = __webpack_require__(160),
2048
2049 BigNumber = math.type.BigNumber,
2050 Complex = __webpack_require__(6),
2051@@ -9550,13 +9650,13 @@
2052
2053
2054 /***/ },
2055-/* 60 */
2056+/* 61 */
2057 /***/ function(module, exports, __webpack_require__) {
2058
2059 'use strict';
2060
2061 module.exports = function (math, config) {
2062- var util = __webpack_require__(147),
2063+ var util = __webpack_require__(160),
2064
2065 Matrix = __webpack_require__(9),
2066 BigNumber = math.type.BigNumber,
2067@@ -9732,217 +9832,101 @@
2068
2069
2070 /***/ },
2071-/* 61 */
2072-/***/ function(module, exports, __webpack_require__) {
2073-
2074- 'use strict';
2075-
2076- module.exports = function (math, config) {
2077- var util = __webpack_require__(147),
2078-
2079- BigNumber = math.type.BigNumber,
2080- Complex = __webpack_require__(6),
2081- Unit = __webpack_require__(10),
2082- collection = __webpack_require__(13),
2083-
2084- isNumber = util.number.isNumber,
2085- nearlyEqual = util.number.nearlyEqual,
2086- isBoolean = util['boolean'].isBoolean,
2087- isString = util.string.isString,
2088- isComplex = Complex.isComplex,
2089- isUnit = Unit.isUnit,
2090- isCollection = collection.isCollection;
2091-
2092- /**
2093- * Compare two values. Returns 1 when x > y, -1 when x < y, and 0 when x == y.
2094- *
2095- * x and y are considered equal when the relative difference between x and y
2096- * is smaller than the configured epsilon. The function cannot be used to
2097- * compare values smaller than approximately 2.22e-16.
2098- *
2099- * For matrices, the function is evaluated element wise.
2100- *
2101- * Syntax:
2102- *
2103- * math.compare(x, y)
2104- *
2105- * Examples:
2106- *
2107- * math.compare(6, 1); // returns 1
2108- * math.compare(2, 3); // returns -1
2109- * math.compare(7, 7); // returns 0
2110- *
2111- * var a = math.unit('5 cm');
2112- * var b = math.unit('40 mm');
2113- * math.compare(a, b); // returns 1
2114- *
2115- * math.compare(2, [1, 2, 3]); // returns [1, 0, -1]
2116- *
2117- * See also:
2118- *
2119- * equal, unequal, smaller, smallerEq, larger, largerEq
2120- *
2121- * @param {Number | BigNumber | Boolean | Unit | String | Array | Matrix | null} x First value to compare
2122- * @param {Number | BigNumber | Boolean | Unit | String | Array | Matrix | null} y Second value to compare
2123- * @return {Number | BigNumber | Array | Matrix} Returns the result of the comparison: 1, 0 or -1.
2124- */
2125- math.compare = function compare(x, y) {
2126- if (arguments.length != 2) {
2127- throw new math.error.ArgumentsError('compare', arguments.length, 2);
2128- }
2129-
2130- if (isNumber(x) && isNumber(y)) {
2131- return nearlyEqual(x, y, config.epsilon) ? 0 : (x > y ? 1 : -1);
2132- }
2133-
2134- if (x instanceof BigNumber) {
2135- // try to convert to big number
2136- if (isNumber(y)) {
2137- y = BigNumber.convert(y);
2138- }
2139- else if (isBoolean(y) || y === null) {
2140- y = new BigNumber(y ? 1 : 0);
2141- }
2142-
2143- if (y instanceof BigNumber) {
2144- return new BigNumber(x.cmp(y));
2145- }
2146-
2147- // downgrade to Number
2148- return compare(x.toNumber(), y);
2149- }
2150- if (y instanceof BigNumber) {
2151- // try to convert to big number
2152- if (isNumber(x)) {
2153- x = BigNumber.convert(x);
2154- }
2155- else if (isBoolean(x) || x === null) {
2156- x = new BigNumber(x ? 1 : 0);
2157- }
2158-
2159- if (x instanceof BigNumber) {
2160- return new BigNumber(x.cmp(y));
2161- }
2162-
2163- // downgrade to Number
2164- return compare(x, y.toNumber());
2165- }
2166-
2167- if ((isUnit(x)) && (isUnit(y))) {
2168- if (!x.equalBase(y)) {
2169- throw new Error('Cannot compare units with different base');
2170- }
2171- return (x.value > y.value) ? 1 : ((x.value < y.value) ? -1 : 0);
2172- }
2173-
2174- if (isCollection(x) || isCollection(y)) {
2175- return collection.deepMap2(x, y, compare);
2176- }
2177-
2178- // Note: test strings after testing collections,
2179- // else we can't compare a string with a matrix
2180- if (isString(x) || isString(y)) {
2181- return (x > y) ? 1 : ((x < y) ? -1 : 0);
2182- }
2183-
2184- if (isBoolean(x) || x === null) {
2185- return compare(+x, y);
2186- }
2187- if (isBoolean(y) || y === null) {
2188- return compare(x, +y);
2189- }
2190-
2191- if (isComplex(x) || isComplex(y)) {
2192- throw new TypeError('No ordering relation is defined for complex numbers');
2193- }
2194-
2195- throw new math.error.UnsupportedTypeError('compare', math['typeof'](x), math['typeof'](y));
2196- };
2197- };
2198-
2199-
2200-/***/ },
2201 /* 62 */
2202 /***/ function(module, exports, __webpack_require__) {
2203
2204 'use strict';
2205
2206- module.exports = function (math) {
2207- var collection = __webpack_require__(13),
2208-
2209+ module.exports = function (math, config) {
2210+ var util = __webpack_require__(160),
2211+
2212+ BigNumber = math.type.BigNumber,
2213+ Matrix = __webpack_require__(9),
2214+ Unit = __webpack_require__(10),
2215+ collection = __webpack_require__(13),
2216+
2217+ isBoolean = util['boolean'].isBoolean,
2218+ isInteger = util.number.isInteger,
2219+ isNumber = util.number.isNumber,
2220 isCollection = collection.isCollection,
2221- isArray = Array.isArray;
2222+
2223+ bigBitAnd = util.bignumber.and;
2224
2225 /**
2226- * Test element wise whether two matrices are equal.
2227- * The function accepts both matrices and scalar values.
2228+ * Bitwise AND two values, `x & y`.
2229+ * For matrices, the function is evaluated element wise.
2230 *
2231 * Syntax:
2232 *
2233- * math.deepEqual(x, y)
2234+ * math.bitAnd(x, y)
2235 *
2236 * Examples:
2237 *
2238- * math.deepEqual(2, 4); // returns false
2239- *
2240- * a = [2, 5, 1];
2241- * b = [2, 7, 1];
2242- *
2243- * math.deepEqual(a, b); // returns false
2244- * math.equal(a, b); // returns [true, false, true]
2245+ * math.bitAnd(53, 131); // returns Number 1
2246+ *
2247+ * math.bitAnd([1, 12, 31], 42); // returns Array [0, 8, 10]
2248 *
2249 * See also:
2250 *
2251- * equal, unequal
2252+ * bitNot, bitOr, bitXor, leftShift, rightArithShift, rightLogShift
2253 *
2254- * @param {Number | BigNumber | Boolean | Complex | Unit | Array | Matrix | null} x First matrix to compare
2255- * @param {Number | BigNumber | Boolean | Complex | Unit | Array | Matrix | null} y Second matrix to compare
2256- * @return {Number | BigNumber | Complex | Unit | Array | Matrix}
2257- * Returns true when the input matrices have the same size and each of their elements is equal.
2258+ * @param {Number | BigNumber | Boolean | Array | Matrix | null} x First value to and
2259+ * @param {Number | BigNumber | Boolean | Array | Matrix | null} y Second value to and
2260+ * @return {Number | BigNumber | Array | Matrix} AND of `x` and `y`
2261 */
2262- math.deepEqual = function deepEqual(x, y) {
2263+ math.bitAnd = function bitAnd(x, y) {
2264 if (arguments.length != 2) {
2265- throw new math.error.ArgumentsError('deepEqual', arguments.length, 2);
2266+ throw new math.error.ArgumentsError('bitAnd', arguments.length, 2);
2267+ }
2268+
2269+ if (isNumber(x) && isNumber(y)) {
2270+ if (!isInteger(x) || !isInteger(y)) {
2271+ throw new Error('Parameters in function bitAnd must be integer numbers');
2272+ }
2273+
2274+ return x & y;
2275 }
2276
2277 if (isCollection(x) || isCollection(y)) {
2278- return _deepEqual(x.valueOf(), y.valueOf());
2279- }
2280-
2281- return math.equal(x, y);
2282+ return collection.deepMap2(x, y, bitAnd);
2283+ }
2284+
2285+ if (isBoolean(x) || x === null) {
2286+ return bitAnd(+x, y);
2287+ }
2288+ if (isBoolean(y) || y === null) {
2289+ return bitAnd(x, +y);
2290+ }
2291+
2292+ if (x instanceof BigNumber) {
2293+ // try to convert to big number
2294+ if (isNumber(y)) {
2295+ y = BigNumber.convert(y);
2296+ }
2297+
2298+ if (y instanceof BigNumber) {
2299+ return bigBitAnd(x, y);
2300+ }
2301+
2302+ // downgrade to Number
2303+ return bitAnd(x.toNumber(), y);
2304+ }
2305+ if (y instanceof BigNumber) {
2306+ // try to convert to big number
2307+ if (isNumber(x)) {
2308+ x = BigNumber.convert(x);
2309+ }
2310+
2311+ if (x instanceof BigNumber) {
2312+ return bigBitAnd(x, y);
2313+ }
2314+
2315+ // downgrade to Number
2316+ return bitAnd(x, y.toNumber());
2317+ }
2318+
2319+ throw new math.error.UnsupportedTypeError('bitAnd', math['typeof'](x), math['typeof'](y));
2320 };
2321-
2322- /**
2323- * Test whether two arrays have the same size and all elements are equal
2324- * @param {Array | *} x
2325- * @param {Array | *} y
2326- * @return {boolean} Returns true if both arrays are deep equal
2327- */
2328- function _deepEqual(x, y) {
2329- if (isArray(x)) {
2330- if (isArray(y)) {
2331- var len = x.length;
2332- if (len !== y.length) return false;
2333-
2334- for (var i = 0; i < len; i++) {
2335- if (!_deepEqual(x[i], y[i])) return false;
2336- }
2337-
2338- return true;
2339- }
2340- else {
2341- return false;
2342- }
2343- }
2344- else {
2345- if (isArray(y)) {
2346- return false;
2347- }
2348- else {
2349- return math.equal(x, y);
2350- }
2351- }
2352- }
2353 };
2354
2355
2356@@ -9953,159 +9937,68 @@
2357 'use strict';
2358
2359 module.exports = function (math, config) {
2360- var util = __webpack_require__(147),
2361+ var util = __webpack_require__(160),
2362
2363 BigNumber = math.type.BigNumber,
2364- Complex = __webpack_require__(6),
2365+ Matrix = __webpack_require__(9),
2366 Unit = __webpack_require__(10),
2367 collection = __webpack_require__(13),
2368
2369+ isBoolean = util['boolean'].isBoolean,
2370+ isInteger = util.number.isInteger,
2371 isNumber = util.number.isNumber,
2372- nearlyEqual = util.number.nearlyEqual,
2373- isBoolean = util['boolean'].isBoolean,
2374- isString = util.string.isString,
2375- isComplex = Complex.isComplex,
2376- isUnit = Unit.isUnit,
2377- isCollection = collection.isCollection;
2378+ isCollection = collection.isCollection,
2379+
2380+ bigBitNot = util.bignumber.not;
2381
2382 /**
2383- * Test whether two values are equal.
2384- *
2385- * The function tests whether the relative difference between x and y is
2386- * smaller than the configured epsilon. The function cannot be used to
2387- * compare values smaller than approximately 2.22e-16.
2388- *
2389+ * Bitwise NOT value, `~x`.
2390 * For matrices, the function is evaluated element wise.
2391- * In case of complex numbers, x.re must equal y.re, and x.im must equal y.im.
2392- *
2393- * Values `null` and `undefined` are compared strictly, thus `null` is only
2394- * equal to `null` and nothing else, and `undefined` is only equal to
2395- * `undefined` and nothing else.
2396+ * For units, the function is evaluated on the best prefix base.
2397 *
2398 * Syntax:
2399 *
2400- * math.equal(x, y)
2401+ * math.bitNot(x)
2402 *
2403 * Examples:
2404 *
2405- * math.equal(2 + 2, 3); // returns false
2406- * math.equal(2 + 2, 4); // returns true
2407- *
2408- * var a = math.unit('50 cm');
2409- * var b = math.unit('5 m');
2410- * math.equal(a, b); // returns true
2411- *
2412- * var c = [2, 5, 1];
2413- * var d = [2, 7, 1];
2414- *
2415- * math.equal(c, d); // returns [true, false, true]
2416- * math.deepEqual(c, d); // returns false
2417- *
2418- * math.equal(0, null); // returns false
2419+ * math.bitNot(1); // returns Number -2
2420+ *
2421+ * math.bitNot([2, -3, 4]); // returns Array [-3, 2, 5]
2422 *
2423 * See also:
2424 *
2425- * unequal, smaller, smallerEq, larger, largerEq, compare, deepEqual
2426+ * bitAnd, bitOr, bitXor, leftShift, rightArithShift, rightLogShift
2427 *
2428- * @param {Number | BigNumber | Boolean | Complex | Unit | String | Array | Matrix | null | undefined} x First value to compare
2429- * @param {Number | BigNumber | Boolean | Complex | Unit | String | Array | Matrix | null | undefined} y Second value to compare
2430- * @return {Boolean | Array | Matrix} Returns true when the compared values are equal, else returns false
2431+ * @param {Number | BigNumber | Boolean | Array | Matrix | null} x Value to not
2432+ * @return {Number | BigNumber | Array | Matrix} NOT of `x`
2433 */
2434- math.equal = function equal(x, y) {
2435- if (arguments.length != 2) {
2436- throw new math.error.ArgumentsError('equal', arguments.length, 2);
2437+ math.bitNot = function bitNot(x) {
2438+ if (arguments.length != 1) {
2439+ throw new math.error.ArgumentsError('bitNot', arguments.length, 1);
2440 }
2441
2442 if (isNumber(x)) {
2443- if (isNumber(y)) {
2444- return nearlyEqual(x, y, config.epsilon);
2445- }
2446- else if (isComplex(y)) {
2447- return nearlyEqual(x, y.re, config.epsilon) && nearlyEqual(y.im, 0, config.epsilon);
2448- }
2449- }
2450+ if (!isInteger(x)) {
2451+ throw new Error('Parameter in function bitNot must be integer numbers');
2452+ }
2453
2454- if (isComplex(x)) {
2455- if (isNumber(y)) {
2456- return nearlyEqual(x.re, y, config.epsilon) && nearlyEqual(x.im, 0, config.epsilon);
2457- }
2458- else if (isComplex(y)) {
2459- return nearlyEqual(x.re, y.re, config.epsilon) && nearlyEqual(x.im, y.im, config.epsilon);
2460- }
2461+ return ~x;
2462 }
2463
2464 if (x instanceof BigNumber) {
2465- // try to convert to big number
2466- if (isNumber(y)) {
2467- y = BigNumber.convert(y);
2468- }
2469- else if (isBoolean(y)) {
2470- y = new BigNumber(y ? 1 : 0);
2471- }
2472-
2473- if (y instanceof BigNumber) {
2474- return x.eq(y);
2475- }
2476-
2477- // downgrade to Number
2478- return equal(x.toNumber(), y);
2479- }
2480- if (y instanceof BigNumber) {
2481- // try to convert to big number
2482- if (isNumber(x)) {
2483- x = BigNumber.convert(x);
2484- }
2485- else if (isBoolean(x)) {
2486- x = new BigNumber(x ? 1 : 0);
2487- }
2488-
2489- if (x instanceof BigNumber) {
2490- return x.eq(y);
2491- }
2492-
2493- // downgrade to Number
2494- return equal(x, y.toNumber());
2495- }
2496-
2497- if ((isUnit(x)) && (isUnit(y))) {
2498- if (!x.equalBase(y)) {
2499- throw new Error('Cannot compare units with different base');
2500- }
2501- return x.value == y.value;
2502- }
2503-
2504- if (isCollection(x) || isCollection(y)) {
2505- return collection.deepMap2(x, y, equal);
2506- }
2507-
2508- // Note: test strings after testing collections,
2509- // else we can accidentally compare a stringified array with a string
2510- if (isString(x) || isString(y)) {
2511- return x == y;
2512- }
2513-
2514- if (isBoolean(x)) {
2515- return equal(+x, y);
2516- }
2517- if (isBoolean(y)) {
2518- return equal(x, +y);
2519- }
2520-
2521- if (x === null) {
2522- return y === null;
2523- }
2524- if (y === null) {
2525- return x === null;
2526- }
2527-
2528- if (x === undefined) {
2529- return y === undefined;
2530- }
2531- if (y === undefined) {
2532- return x === undefined;
2533- }
2534-
2535- throw new math.error.UnsupportedTypeError('equal', math['typeof'](x), math['typeof'](y));
2536+ return bigBitNot(x);
2537+ }
2538+
2539+ if (isCollection(x)) {
2540+ return collection.deepMap(x, bitNot);
2541+ }
2542+
2543+ if (isBoolean(x) || x === null) {
2544+ return bitNot(+x);
2545+ }
2546+
2547+ throw new math.error.UnsupportedTypeError('bitNot', math['typeof'](x));
2548 };
2549 };
2550
2551@@ -10117,58 +10010,65 @@
2552 'use strict';
2553
2554 module.exports = function (math, config) {
2555- var util = __webpack_require__(147),
2556+ var util = __webpack_require__(160),
2557
2558 BigNumber = math.type.BigNumber,
2559- Complex = __webpack_require__(6),
2560+ Matrix = __webpack_require__(9),
2561 Unit = __webpack_require__(10),
2562 collection = __webpack_require__(13),
2563
2564+ isBoolean = util['boolean'].isBoolean,
2565+ isInteger = util.number.isInteger,
2566 isNumber = util.number.isNumber,
2567- nearlyEqual = util.number.nearlyEqual,
2568- isBoolean = util['boolean'].isBoolean,
2569- isString = util.string.isString,
2570- isComplex = Complex.isComplex,
2571- isUnit = Unit.isUnit,
2572- isCollection = collection.isCollection;
2573+ isCollection = collection.isCollection,
2574+
2575+ bigBitOr = util.bignumber.or;
2576
2577 /**
2578- * Test whether value x is larger than y.
2579- *
2580- * The function returns true when x is larger than y and the relative
2581- * difference between x and y is larger than the configured epsilon. The
2582- * function cannot be used to compare values smaller than approximately 2.22e-16.
2583- *
2584+ * Bitwise OR two values, `x | y`.
2585 * For matrices, the function is evaluated element wise.
2586+ * For units, the function is evaluated on the lowest print base.
2587 *
2588 * Syntax:
2589 *
2590- * math.larger(x, y)
2591+ * math.bitOr(x, y)
2592 *
2593 * Examples:
2594 *
2595- * math.larger(2, 3); // returns false
2596- * math.larger(5, 2 + 2); // returns true
2597+ * math.bitOr(1, 2); // returns Number 3
2598 *
2599- * var a = math.unit('5 cm');
2600- * var b = math.unit('2 inch');
2601- * math.larger(a, b); // returns false
2602+ * math.bitOr([1, 2, 3], 4); // returns Array [5, 6, 7]
2603 *
2604 * See also:
2605 *
2606- * equal, unequal, smaller, smallerEq, largerEq, compare
2607+ * bitAnd, bitNot, bitXor, leftShift, rightArithShift, rightLogShift
2608 *
2609- * @param {Number | BigNumber | Boolean | Unit | String | Array | Matrix | null} x First value to compare
2610- * @param {Number | BigNumber | Boolean | Unit | String | Array | Matrix | null} y Second value to compare
2611- * @return {Boolean | Array | Matrix} Returns true when the x is larger than y, else returns false
2612+ * @param {Number | BigNumber | Boolean | Array | Matrix | null} x First value to or
2613+ * @param {Number | BigNumber | Boolean | Array | Matrix | null} y Second value to or
2614+ * @return {Number | BigNumber | Array | Matrix} OR of `x` and `y`
2615 */
2616- math.larger = function larger(x, y) {
2617+ math.bitOr = function bitOr(x, y) {
2618 if (arguments.length != 2) {
2619- throw new math.error.ArgumentsError('larger', arguments.length, 2);
2620+ throw new math.error.ArgumentsError('bitOr', arguments.length, 2);
2621 }
2622
2623 if (isNumber(x) && isNumber(y)) {
2624- return !nearlyEqual(x, y, config.epsilon) && x > y;
2625+ if (!isInteger(x) || !isInteger(y)) {
2626+ throw new Error('Parameters in function bitOr must be integer numbers');
2627+ }
2628+
2629+ return x | y;
2630+ }
2631+
2632+ if (isCollection(x) || isCollection(y)) {
2633+ return collection.deepMap2(x, y, bitOr);
2634+ }
2635+
2636+ if (isBoolean(x) || x === null) {
2637+ return bitOr(+x, y);
2638+ }
2639+ if (isBoolean(y) || y === null) {
2640+ return bitOr(x, +y);
2641 }
2642
2643 if (x instanceof BigNumber) {
2644@@ -10176,63 +10076,29 @@
2645 if (isNumber(y)) {
2646 y = BigNumber.convert(y);
2647 }
2648- else if (isBoolean(y) || y === null) {
2649- y = new BigNumber(y ? 1 : 0);
2650- }
2651
2652 if (y instanceof BigNumber) {
2653- return x.gt(y);
2654+ return bigBitOr(x, y);
2655 }
2656
2657 // downgrade to Number
2658- return larger(x.toNumber(), y);
2659+ return bitOr(x.toNumber(), y);
2660 }
2661 if (y instanceof BigNumber) {
2662 // try to convert to big number
2663 if (isNumber(x)) {
2664 x = BigNumber.convert(x);
2665 }
2666- else if (isBoolean(x) || x === null) {
2667- x = new BigNumber(x ? 1 : 0);
2668- }
2669
2670 if (x instanceof BigNumber) {
2671- return x.gt(y)
2672+ return bigBitOr(x, y);
2673 }
2674
2675 // downgrade to Number
2676- return larger(x, y.toNumber());
2677- }
2678-
2679- if ((isUnit(x)) && (isUnit(y))) {
2680- if (!x.equalBase(y)) {
2681- throw new Error('Cannot compare units with different base');
2682- }
2683- return x.value > y.value;
2684- }
2685-
2686- if (isCollection(x) || isCollection(y)) {
2687- return collection.deepMap2(x, y, larger);
2688- }
2689-
2690- // Note: test strings after testing collections,
2691- // else we can't compare a string with a matrix
2692- if (isString(x) || isString(y)) {
2693- return x > y;
2694- }
2695-
2696- if (isBoolean(x) || x === null) {
2697- return larger(+x, y);
2698- }
2699- if (isBoolean(y) || y === null) {
2700- return larger(x, +y);
2701- }
2702-
2703- if (isComplex(x) || isComplex(y)) {
2704- throw new TypeError('No ordering relation is defined for complex numbers');
2705- }
2706-
2707- throw new math.error.UnsupportedTypeError('larger', math['typeof'](x), math['typeof'](y));
2708+ return bitOr(x, y.toNumber());
2709+ }
2710+
2711+ throw new math.error.UnsupportedTypeError('bitOr', math['typeof'](x), math['typeof'](y));
2712 };
2713 };
2714
2715@@ -10244,54 +10110,64 @@
2716 'use strict';
2717
2718 module.exports = function (math, config) {
2719- var util = __webpack_require__(147),
2720+ var util = __webpack_require__(160),
2721
2722 BigNumber = math.type.BigNumber,
2723- Complex = __webpack_require__(6),
2724+ Matrix = __webpack_require__(9),
2725 Unit = __webpack_require__(10),
2726 collection = __webpack_require__(13),
2727
2728+ isBoolean = util['boolean'].isBoolean,
2729+ isInteger = util.number.isInteger,
2730 isNumber = util.number.isNumber,
2731- nearlyEqual = util.number.nearlyEqual,
2732- isBoolean = util['boolean'].isBoolean,
2733- isString = util.string.isString,
2734- isComplex = Complex.isComplex,
2735- isUnit = Unit.isUnit,
2736- isCollection = collection.isCollection;
2737+ isCollection = collection.isCollection,
2738+
2739+ bigBitXor = util.bignumber.xor;
2740
2741 /**
2742- * Test whether value x is larger or equal to y.
2743- *
2744- * The function returns true when x is larger than y or the relative
2745- * difference between x and y is smaller than the configured epsilon. The
2746- * function cannot be used to compare values smaller than approximately 2.22e-16.
2747- *
2748+ * Bitwise XOR two values, `x ^ y`.
2749 * For matrices, the function is evaluated element wise.
2750 *
2751 * Syntax:
2752 *
2753- * math.largerEq(x, y)
2754+ * math.bitXor(x, y)
2755 *
2756 * Examples:
2757 *
2758- * math.larger(2, 1 + 1); // returns false
2759- * math.largerEq(2, 1 + 1); // returns true
2760+ * math.bitXor(1, 2); // returns Number 3
2761+ *
2762+ * math.bitXor([2, 3, 4], 4); // returns Array [6, 7, 0]
2763 *
2764 * See also:
2765 *
2766- * equal, unequal, smaller, smallerEq, larger, compare
2767+ * bitAnd, bitNot, bitOr, leftShift, rightArithShift, rightLogShift
2768 *
2769- * @param {Number | BigNumber | Boolean | Unit | String | Array | Matrix | null} x First value to compare
2770- * @param {Number | BigNumber | Boolean | Unit | String | Array | Matrix | null} y Second value to compare
2771- * @return {Boolean | Array | Matrix} Returns true when the x is larger or equal to y, else returns false
2772+ * @param {Number | BigNumber | Boolean | Array | Matrix | null} x First value to xor
2773+ * @param {Number | BigNumber | Boolean | Array | Matrix | null} y Second value to xor
2774+ * @return {Number | BigNumber | Array | Matrix} XOR of `x` and `y`
2775 */
2776- math.largerEq = function largerEq(x, y) {
2777+ math.bitXor = function bitXor(x, y) {
2778 if (arguments.length != 2) {
2779- throw new math.error.ArgumentsError('largerEq', arguments.length, 2);
2780+ throw new math.error.ArgumentsError('bitXor', arguments.length, 2);
2781 }
2782
2783 if (isNumber(x) && isNumber(y)) {
2784- return nearlyEqual(x, y, config.epsilon) || x > y;
2785+ if (!isInteger(x) || !isInteger(y)) {
2786+ throw new Error('Parameters in function bitXor must be integer numbers');
2787+ }
2788+
2789+ return x ^ y;
2790+ }
2791+
2792+ if (isCollection(x) || isCollection(y)) {
2793+ return collection.deepMap2(x, y, bitXor);
2794+ }
2795+
2796+ if (isBoolean(x) || x === null) {
2797+ return bitXor(+x, y);
2798+ }
2799+ if (isBoolean(y) || y === null) {
2800+ return bitXor(x, +y);
2801 }
2802
2803 if (x instanceof BigNumber) {
2804@@ -10299,69 +10175,30 @@
2805 if (isNumber(y)) {
2806 y = BigNumber.convert(y);
2807 }
2808- else if (isBoolean(y) || y === null) {
2809- y = new BigNumber(y ? 1 : 0);
2810- }
2811
2812 if (y instanceof BigNumber) {
2813- return x.gte(y);
2814+ return bigBitXor(x, y);
2815 }
2816
2817 // downgrade to Number
2818- return largerEq(x.toNumber(), y);
2819+ return bitXor(x.toNumber(), y);
2820 }
2821 if (y instanceof BigNumber) {
2822 // try to convert to big number
2823 if (isNumber(x)) {
2824 x = BigNumber.convert(x);
2825 }
2826- else if (isBoolean(x) || x === null) {
2827- x = new BigNumber(x ? 1 : 0);
2828- }
2829
2830 if (x instanceof BigNumber) {
2831- return x.gte(y)
2832+ return bigBitXor(x, y);
2833 }
2834
2835 // downgrade to Number
2836- return largerEq(x, y.toNumber());
2837- }
2838-
2839- if ((isUnit(x)) && (isUnit(y))) {
2840- if (!x.equalBase(y)) {
2841- throw new Error('Cannot compare units with different base');
2842- }
2843- return x.value >= y.value;
2844- }
2845-
2846- if (isCollection(x) || isCollection(y)) {
2847- return collection.deepMap2(x, y, largerEq);
2848- }
2849-
2850- // Note: test strings after testing collections,
2851- // else we can't compare a string with a matrix
2852- if (isString(x) || isString(y)) {
2853- return x >= y;
2854- }
2855-
2856- if (isBoolean(x) || x === null) {
2857- return largerEq(+x, y);
2858- }
2859- if (isBoolean(y) || y === null) {
2860- return largerEq(x, +y);
2861- }
2862-
2863- if (isComplex(x) || isComplex(y)) {
2864- throw new TypeError('No ordering relation is defined for complex numbers');
2865- }
2866-
2867- throw new math.error.UnsupportedTypeError('largerEq', math['typeof'](x), math['typeof'](y));
2868+ return bitXor(x, y.toNumber());
2869+ }
2870+
2871+ throw new math.error.UnsupportedTypeError('bitXor', math['typeof'](x), math['typeof'](y));
2872 };
2873-
2874- // TODO: deprecated since version 0.23.0, cleanup some day
2875- math.largereq = function () {
2876- throw new Error('Function largereq is renamed to largerEq');
2877- }
2878 };
2879
2880
2881@@ -10372,122 +10209,117 @@
2882 'use strict';
2883
2884 module.exports = function (math, config) {
2885- var util = __webpack_require__(147),
2886+ var util = __webpack_require__(160),
2887
2888 BigNumber = math.type.BigNumber,
2889- Complex = __webpack_require__(6),
2890+ Matrix = __webpack_require__(9),
2891 Unit = __webpack_require__(10),
2892 collection = __webpack_require__(13),
2893
2894+ isBoolean = util['boolean'].isBoolean,
2895+ isInteger = util.number.isInteger,
2896 isNumber = util.number.isNumber,
2897- nearlyEqual = util.number.nearlyEqual,
2898- isBoolean = util['boolean'].isBoolean,
2899- isString = util.string.isString,
2900- isComplex = Complex.isComplex,
2901- isUnit = Unit.isUnit,
2902- isCollection = collection.isCollection;
2903+ isCollection = collection.isCollection,
2904+
2905+ bigLeftShift = util.bignumber.leftShift;
2906
2907 /**
2908- * Test whether value x is smaller than y.
2909- *
2910- * The function returns true when x is smaller than y and the relative
2911- * difference between x and y is larger than the configured epsilon. The
2912- * function cannot be used to compare values smaller than approximately 2.22e-16.
2913- *
2914+ * Bitwise left logical shift of a value x by y number of bits, `x << y`.
2915 * For matrices, the function is evaluated element wise.
2916+ * For units, the function is evaluated on the best prefix base.
2917 *
2918 * Syntax:
2919 *
2920- * math.smaller(x, y)
2921+ * math.leftShift(x, y)
2922 *
2923 * Examples:
2924 *
2925- * math.smaller(2, 3); // returns true
2926- * math.smaller(5, 2 * 2); // returns false
2927+ * math.leftShift(1, 2); // returns Number 4
2928 *
2929- * var a = math.unit('5 cm');
2930- * var b = math.unit('2 inch');
2931- * math.smaller(a, b); // returns true
2932+ * math.leftShift([1, 2, 3], 4); // returns Array [16, 32, 64]
2933 *
2934 * See also:
2935 *
2936- * equal, unequal, smallerEq, larger, largerEq, compare
2937+ * bitAnd, bitNot, bitOr, bitXor, rightArithShift, rightLogShift
2938 *
2939- * @param {Number | BigNumber | Boolean | Unit | String | Array | Matrix | null} x First value to compare
2940- * @param {Number | BigNumber | Boolean | Unit | String | Array | Matrix | null} y Second value to compare
2941- * @return {Boolean | Array | Matrix} Returns true when the x is smaller than y, else returns false
2942+ * @param {Number | BigNumber | Boolean | Array | Matrix | null} x Value to be shifted
2943+ * @param {Number | BigNumber | Boolean | null} y Amount of shifts
2944+ * @return {Number | BigNumber | Array | Matrix} `x` shifted left `y` times
2945 */
2946- math.smaller = function smaller(x, y) {
2947+ math.leftShift = function leftShift(x, y) {
2948 if (arguments.length != 2) {
2949- throw new math.error.ArgumentsError('smaller', arguments.length, 2);
2950- }
2951-
2952- if (isNumber(x) && isNumber(y)) {
2953- return !nearlyEqual(x, y, config.epsilon) && x < y;
2954- }
2955-
2956- if (x instanceof BigNumber) {
2957- // try to convert to big number
2958+ throw new math.error.ArgumentsError('leftShift', arguments.length, 2);
2959+ }
2960+
2961+ if (isNumber(x)) {
2962 if (isNumber(y)) {
2963+ if (!isInteger(x) || !isInteger(y)) {
2964+ throw new Error('Parameters in function leftShift must be integer numbers');
2965+ }
2966+
2967+ return x << y;
2968+ }
2969+
2970+ if (y instanceof BigNumber) {
2971+ return bigLeftShift(BigNumber.convert(x), y);
2972+ }
2973+ }
2974+ if (isNumber(y)) {
2975+ if (isFinite(y) && !isInteger(y)) {
2976+ throw new Error('Parameters in function leftShift must be integer numbers');
2977+ }
2978+
2979+ if (x instanceof BigNumber) {
2980+ if (x.isFinite() && !x.isInteger()) {
2981+ throw new Error('Parameters in function leftShift must be integer numbers');
2982+ }
2983+
2984+ if (x.isNaN() || isNaN(y) || y < 0) {
2985+ return new BigNumber(NaN);
2986+ }
2987+
2988+ if (y == 0 || x.isZero()) {
2989+ return x;
2990+ }
2991+ if (y == Infinity && !x.isFinite()) {
2992+ return new BigNumber(NaN);
2993+ }
2994+
2995+ // Math.pow(2, y) is fully precise for y < 55, and fast
2996+ if (y < 55) {
2997+ return x.times(Math.pow(2, y) + '');
2998+ }
2999+
3000 y = BigNumber.convert(y);
3001- }
3002- else if (isBoolean(y) || y === null) {
3003- y = new BigNumber(y ? 1 : 0);
3004- }
3005-
3006- if (y instanceof BigNumber) {
3007- return x.lt(y);
3008- }
3009-
3010- // downgrade to Number
3011- return smaller(x.toNumber(), y);
3012- }
3013- if (y instanceof BigNumber) {
3014- // try to convert to big number
3015- if (isNumber(x)) {
3016- x = BigNumber.convert(x);
3017- }
3018- else if (isBoolean(x) || x === null) {
3019- x = new BigNumber(x ? 1 : 0);
3020- }
3021-
3022- if (x instanceof BigNumber) {
3023- return x.lt(y)
3024- }
3025-
3026- // downgrade to Number
3027- return smaller(x, y.toNumber());
3028- }
3029-
3030- if ((isUnit(x)) && (isUnit(y))) {
3031- if (!x.equalBase(y)) {
3032- throw new Error('Cannot compare units with different base');
3033- }
3034- return x.value < y.value;
3035- }
3036-
3037- if (isCollection(x) || isCollection(y)) {
3038- return collection.deepMap2(x, y, smaller);
3039- }
3040-
3041- // Note: test strings after testing collections,
3042- // else we can't compare a string with a matrix
3043- if (isString(x) || isString(y)) {
3044- return x < y;
3045+ return bigLeftShift(x, y);
3046+ }
3047+ }
3048+
3049+ if (isCollection(x) && isNumber(y)) {
3050+ return collection.deepMap2(x, y, leftShift);
3051 }
3052
3053 if (isBoolean(x) || x === null) {
3054- return smaller(+x, y);
3055+ return leftShift(+x, y);
3056 }
3057 if (isBoolean(y) || y === null) {
3058- return smaller(x, +y);
3059- }
3060-
3061- if (isComplex(x) || isComplex(y)) {
3062- throw new TypeError('No ordering relation is defined for complex numbers');
3063- }
3064-
3065- throw new math.error.UnsupportedTypeError('smaller', math['typeof'](x), math['typeof'](y));
3066+ return leftShift(x, +y);
3067+ }
3068+
3069+ if (x instanceof BigNumber) {
3070+ if (y instanceof BigNumber) {
3071+ return bigLeftShift(x, y);
3072+ }
3073+
3074+ // downgrade to Number
3075+ return leftShift(x.toNumber(), y);
3076+ }
3077+ if (y instanceof BigNumber) {
3078+ // x is probably incompatible with BigNumber
3079+ return leftShift(x, y.toNumber());
3080+ }
3081+
3082+ throw new math.error.UnsupportedTypeError('leftShift', math['typeof'](x), math['typeof'](y));
3083 };
3084 };
3085
3086@@ -10499,123 +10331,120 @@
3087 'use strict';
3088
3089 module.exports = function (math, config) {
3090- var util = __webpack_require__(147),
3091+ var util = __webpack_require__(160),
3092
3093 BigNumber = math.type.BigNumber,
3094- Complex = __webpack_require__(6),
3095+ Matrix = __webpack_require__(9),
3096 Unit = __webpack_require__(10),
3097 collection = __webpack_require__(13),
3098
3099+ isBoolean = util['boolean'].isBoolean,
3100+ isInteger = util.number.isInteger,
3101 isNumber = util.number.isNumber,
3102- nearlyEqual = util.number.nearlyEqual,
3103- isBoolean = util['boolean'].isBoolean,
3104- isString = util.string.isString,
3105- isComplex = Complex.isComplex,
3106- isUnit = Unit.isUnit,
3107- isCollection = collection.isCollection;
3108+ isCollection = collection.isCollection,
3109+
3110+ bigRightShift = util.bignumber.rightShift;
3111
3112 /**
3113- * Test whether value x is smaller or equal to y.
3114- *
3115- * The function returns true when x is smaller than y or the relative
3116- * difference between x and y is smaller than the configured epsilon. The
3117- * function cannot be used to compare values smaller than approximately 2.22e-16.
3118+ * Bitwise right arithmetic shift of a value x by y number of bits, `x >> y`.
3119 * For matrices, the function is evaluated element wise.
3120+ * For units, the function is evaluated on the best prefix base.
3121 *
3122 * Syntax:
3123 *
3124- * math.smallerEq(x, y)
3125+ * math.rightArithShift(x, y)
3126 *
3127 * Examples:
3128 *
3129- * math.smaller(1 + 2, 3); // returns false
3130- * math.smallerEq(1 + 2, 3); // returns true
3131+ * math.rightArithShift(4, 2); // returns Number 1
3132+ *
3133+ * math.rightArithShift([16, -32, 64], 4); // returns Array [1, -2, 3]
3134 *
3135 * See also:
3136 *
3137- * equal, unequal, smaller, larger, largerEq, compare
3138+ * bitAnd, bitNot, bitOr, bitXor, leftShift, rightLogShift
3139 *
3140- * @param {Number | BigNumber | Boolean | Unit | String | Array | Matrix | null} x First value to compare
3141- * @param {Number | BigNumber | Boolean | Unit | String | Array | Matrix | null} y Second value to compare
3142- * @return {Boolean | Array | Matrix} Returns true when the x is smaller than y, else returns false
3143+ * @param {Number | BigNumber | Boolean | Array | Matrix | null} x Value to be shifted
3144+ * @param {Number | BigNumber | Boolean | null} y Amount of shifts
3145+ * @return {Number | BigNumber | Array | Matrix} `x` sign-filled shifted right `y` times
3146 */
3147- math.smallerEq = function smallerEq(x, y) {
3148+ math.rightArithShift = function rightArithShift(x, y) {
3149 if (arguments.length != 2) {
3150- throw new math.error.ArgumentsError('smallerEq', arguments.length, 2);
3151- }
3152-
3153- if (isNumber(x) && isNumber(y)) {
3154- return nearlyEqual(x, y, config.epsilon) || x < y;
3155- }
3156-
3157- if (x instanceof BigNumber) {
3158- // try to convert to big number
3159+ throw new math.error.ArgumentsError('rightArithShift', arguments.length, 2);
3160+ }
3161+
3162+ if (isNumber(x)) {
3163 if (isNumber(y)) {
3164+ if (!isInteger(x) || !isInteger(y)) {
3165+ throw new Error('Parameters in function rightArithShift must be integer numbers');
3166+ }
3167+
3168+ return x >> y;
3169+ }
3170+
3171+ if (y instanceof BigNumber) {
3172+ return bigRightShift(BigNumber.convert(x), y);
3173+ }
3174+ }
3175+ if (isNumber(y)) {
3176+ if (isFinite(y) && !isInteger(y)) {
3177+ throw new Error('Parameters in function rightArithShift must be integer numbers');
3178+ }
3179+
3180+ if (x instanceof BigNumber) {
3181+ if (x.isFinite() && !x.isInteger()) {
3182+ throw new Error('Parameters in function rightArithShift must be integer numbers');
3183+ }
3184+
3185+ if (x.isNaN() || isNaN(y) || y < 0) {
3186+ return new BigNumber(NaN);
3187+ }
3188+ if (y == Infinity) {
3189+ if (x.isNegative()) {
3190+ return new BigNumber(-1);
3191+ }
3192+ if (!x.isFinite()) {
3193+ return new BigNumber(NaN);
3194+ }
3195+ return new BigNumber(0);
3196+ }
3197+
3198+ // Math.pow(2, y) is fully precise for y < 55, and fast
3199+ if (y < 55) {
3200+ return x.div(Math.pow(2, y) + '').floor();
3201+ }
3202+
3203 y = BigNumber.convert(y);
3204- }
3205- else if (isBoolean(y) || y === null) {
3206- y = new BigNumber(y ? 1 : 0);
3207- }
3208-
3209- if (y instanceof BigNumber) {
3210- return x.lte(y);
3211- }
3212-
3213- // downgrade to Number
3214- return smallerEq(x.toNumber(), y);
3215- }
3216- if (y instanceof BigNumber) {
3217- // try to convert to big number
3218- if (isNumber(x)) {
3219- x = BigNumber.convert(x);
3220- }
3221- else if (isBoolean(x) || x === null) {
3222- x = new BigNumber(x ? 1 : 0);
3223- }
3224-
3225- if (x instanceof BigNumber) {
3226- return x.lte(y)
3227- }
3228-
3229- // downgrade to Number
3230- return smallerEq(x, y.toNumber());
3231- }
3232-
3233- if ((isUnit(x)) && (isUnit(y))) {
3234- if (!x.equalBase(y)) {
3235- throw new Error('Cannot compare units with different base');
3236- }
3237- return x.value <= y.value;
3238- }
3239-
3240- if (isCollection(x) || isCollection(y)) {
3241- return collection.deepMap2(x, y, smallerEq);
3242- }
3243-
3244- // Note: test strings after testing collections,
3245- // else we can't compare a string with a matrix
3246- if (isString(x) || isString(y)) {
3247- return x <= y;
3248+ return bigRightShift(x, y);
3249+ }
3250+ }
3251+
3252+ if (isCollection(x) && isNumber(y)) {
3253+ return collection.deepMap2(x, y, rightArithShift);
3254 }
3255
3256 if (isBoolean(x) || x === null) {
3257- return smallerEq(+x, y);
3258+ return rightArithShift(+x, y);
3259 }
3260 if (isBoolean(y) || y === null) {
3261- return smallerEq(x, +y);
3262- }
3263-
3264- if (isComplex(x) || isComplex(y)) {
3265- throw new TypeError('No ordering relation is defined for complex numbers');
3266- }
3267-
3268- throw new math.error.UnsupportedTypeError('smallerEq', math['typeof'](x), math['typeof'](y));
3269+ return rightArithShift(x, +y);
3270+ }
3271+
3272+ if (x instanceof BigNumber) {
3273+ if (y instanceof BigNumber) {
3274+ return bigRightShift(x, y);
3275+ }
3276+
3277+ // downgrade to Number
3278+ return rightArithShift(x.toNumber(), y);
3279+ }
3280+ if (y instanceof BigNumber) {
3281+ // x is probably incompatible with BigNumber
3282+ return rightArithShift(x, y.toNumber());
3283+ }
3284+
3285+ throw new math.error.UnsupportedTypeError('rightArithShift', math['typeof'](x), math['typeof'](y));
3286 };
3287-
3288- // TODO: deprecated since version 0.23.0, cleanup some day
3289- math.smallereq = function () {
3290- throw new Error('Function smallereq is renamed to smallerEq');
3291- }
3292 };
3293
3294
3295@@ -10626,158 +10455,65 @@
3296 'use strict';
3297
3298 module.exports = function (math, config) {
3299- var util = __webpack_require__(147),
3300+ var util = __webpack_require__(160),
3301
3302- BigNumber = math.type.BigNumber,
3303- Complex = __webpack_require__(6),
3304+ Matrix = __webpack_require__(9),
3305 Unit = __webpack_require__(10),
3306 collection = __webpack_require__(13),
3307
3308+ isBoolean = util['boolean'].isBoolean,
3309+ isInteger = util.number.isInteger,
3310 isNumber = util.number.isNumber,
3311- nearlyEqual = util.number.nearlyEqual,
3312- isBoolean = util['boolean'].isBoolean,
3313- isString = util.string.isString,
3314- isComplex = Complex.isComplex,
3315- isUnit = Unit.isUnit,
3316 isCollection = collection.isCollection;
3317
3318 /**
3319- * Test whether two values are unequal.
3320- *
3321- * The function tests whether the relative difference between x and y is
3322- * larger than the configured epsilon. The function cannot be used to compare
3323- * values smaller than approximately 2.22e-16.
3324- *
3325+ * Bitwise right logical shift of value x by y number of bits, `x >>> y`.
3326 * For matrices, the function is evaluated element wise.
3327- * In case of complex numbers, x.re must unequal y.re, or x.im must unequal y.im.
3328- *
3329- * Values `null` and `undefined` are compared strictly, thus `null` is unequal
3330- * with everything except `null`, and `undefined` is unequal with everying
3331- * except. `undefined`.
3332+ * For units, the function is evaluated on the best prefix base.
3333 *
3334 * Syntax:
3335 *
3336- * math.unequal(x, y)
3337+ * math.rightLogShift(x, y)
3338 *
3339 * Examples:
3340 *
3341- * math.unequal(2 + 2, 3); // returns true
3342- * math.unequal(2 + 2, 4); // returns false
3343- *
3344- * var a = math.unit('50 cm');
3345- * var b = math.unit('5 m');
3346- * math.unequal(a, b); // returns false
3347- *
3348- * var c = [2, 5, 1];
3349- * var d = [2, 7, 1];
3350- *
3351- * math.unequal(c, d); // returns [false, true, false]
3352- * math.deepEqual(c, d); // returns false
3353- *
3354- * math.unequal(0, null); // returns true
3355+ * math.rightLogShift(4, 2); // returns Number 1
3356+ *
3357+ * math.rightLogShift([16, -32, 64], 4); // returns Array [1, 2, 3]
3358+ *
3359 * See also:
3360 *
3361- * equal, deepEqual, smaller, smallerEq, larger, largerEq, compare
3362+ * bitAnd, bitNot, bitOr, bitXor, leftShift, rightArithShift
3363 *
3364- * @param {Number | BigNumber | Boolean | Complex | Unit | String | Array | Matrix | null | undefined} x First value to compare
3365- * @param {Number | BigNumber | Boolean | Complex | Unit | String | Array | Matrix | null | undefined} y Second value to compare
3366- * @return {Boolean | Array | Matrix} Returns true when the compared values are unequal, else returns false
3367+ * @param {Number | Boolean | Array | Matrix | null} x Value to be shifted
3368+ * @param {Number | Boolean | null} y Amount of shifts
3369+ * @return {Number | Array | Matrix} `x` zero-filled shifted right `y` times
3370 */
3371- math.unequal = function unequal(x, y) {
3372+ math.rightLogShift = function rightLogShift(x, y) {
3373 if (arguments.length != 2) {
3374- throw new math.error.ArgumentsError('unequal', arguments.length, 2);
3375- }
3376-
3377- if (isNumber(x)) {
3378- if (isNumber(y)) {
3379- return !nearlyEqual(x, y, config.epsilon);
3380- }
3381- else if (isComplex(y)) {
3382- return !nearlyEqual(x, y.re, config.epsilon) || !nearlyEqual(y.im, 0, config.epsilon);
3383- }
3384- }
3385-
3386- if (isComplex(x)) {
3387- if (isNumber(y)) {
3388- return !nearlyEqual(x.re, y, config.epsilon) || !nearlyEqual(x.im, 0, config.epsilon);
3389- }
3390- else if (isComplex(y)) {
3391- return !nearlyEqual(x.re, y.re, config.epsilon) || !nearlyEqual(x.im, y.im, config.epsilon);
3392- }
3393- }
3394-
3395- if (x instanceof BigNumber) {
3396- // try to convert to big number
3397- if (isNumber(y)) {
3398- y = BigNumber.convert(y);
3399- }
3400- else if (isBoolean(y)) {
3401- y = new BigNumber(y ? 1 : 0);
3402- }
3403-
3404- if (y instanceof BigNumber) {
3405- return !x.eq(y);
3406- }
3407-
3408- // downgrade to Number
3409- return unequal(x.toNumber(), y);
3410- }
3411- if (y instanceof BigNumber) {
3412- // try to convert to big number
3413- if (isNumber(x)) {
3414- x = BigNumber.convert(x);
3415- }
3416- else if (isBoolean(x)) {
3417- x = new BigNumber(x ? 1 : 0);
3418- }
3419-
3420- if (x instanceof BigNumber) {
3421- return !x.eq(y)
3422- }
3423-
3424- // downgrade to Number
3425- return unequal(x, y.toNumber());
3426- }
3427-
3428- if ((isUnit(x)) && (isUnit(y))) {
3429- if (!x.equalBase(y)) {
3430- throw new Error('Cannot compare units with different base');
3431- }
3432- return x.value != y.value;
3433- }
3434-
3435- if (isCollection(x) || isCollection(y)) {
3436- return collection.deepMap2(x, y, unequal);
3437- }
3438-
3439- // Note: test strings after testing collections,
3440- // else we can accidentally compare a stringified array with a string
3441- if (isString(x) || isString(y)) {
3442- return x != y;
3443- }
3444-
3445- if (isBoolean(x)) {
3446- return unequal(+x, y);
3447- }
3448- if (isBoolean(y)) {
3449- return unequal(x, +y);
3450- }
3451-
3452- if (x === null) {
3453- return y !== null;
3454- }
3455- if (y === null) {
3456- return x !== null;
3457- }
3458-
3459- if (x === undefined) {
3460- return y !== undefined;
3461- }
3462- if (y === undefined) {
3463- return x !== undefined;
3464- }
3465-
3466- throw new math.error.UnsupportedTypeError('unequal', math['typeof'](x), math['typeof'](y));
3467+ throw new math.error.ArgumentsError('rightLogShift', arguments.length, 2);
3468+ }
3469+
3470+ if (isNumber(x) && isNumber(y)) {
3471+ if (!isInteger(x) || !isInteger(y)) {
3472+ throw new Error('Parameters in function rightLogShift must be integer numbers');
3473+ }
3474+
3475+ return x >>> y;
3476+ }
3477+
3478+ if (isCollection(x) && isNumber(y)) {
3479+ return collection.deepMap2(x, y, rightLogShift);
3480+ }
3481+
3482+ if (isBoolean(x) || x === null) {
3483+ return rightLogShift(+x, y);
3484+ }
3485+ if (isBoolean(y) || y === null) {
3486+ return rightLogShift(x, +y);
3487+ }
3488+
3489+ throw new math.error.UnsupportedTypeError('rightLogShift', math['typeof'](x), math['typeof'](y));
3490 };
3491 };
3492
3493@@ -10789,7 +10525,7 @@
3494 'use strict';
3495
3496 module.exports = function (math) {
3497- var util = __webpack_require__(147),
3498+ var util = __webpack_require__(160),
3499
3500 BigNumber = math.type.BigNumber,
3501 Complex = __webpack_require__(6),
3502@@ -10866,7 +10602,7 @@
3503 'use strict';
3504
3505 module.exports = function (math) {
3506- var util = __webpack_require__(147),
3507+ var util = __webpack_require__(160),
3508
3509 BigNumber = math.type.BigNumber,
3510 Complex = __webpack_require__(6),
3511@@ -10941,7 +10677,7 @@
3512 'use strict';
3513
3514 module.exports = function (math) {
3515- var util = __webpack_require__(147),
3516+ var util = __webpack_require__(160),
3517
3518 BigNumber = math.type.BigNumber,
3519 Complex = __webpack_require__(6),
3520@@ -11018,7 +10754,7 @@
3521 'use strict';
3522
3523 module.exports = function (math) {
3524- var util = __webpack_require__(147),
3525+ var util = __webpack_require__(160),
3526
3527 BigNumber = math.type.BigNumber,
3528 Complex = __webpack_require__(6),
3529@@ -11094,7 +10830,7 @@
3530 'use strict';
3531
3532 module.exports = function (math) {
3533- var util = __webpack_require__(147),
3534+ var util = __webpack_require__(160),
3535
3536 // take the BigNumber instance the provided math.js instance
3537 BigNumber = math.type.BigNumber,
3538@@ -11163,7 +10899,7 @@
3539 'use strict';
3540
3541 module.exports = function (math) {
3542- var util = __webpack_require__(147),
3543+ var util = __webpack_require__(160),
3544
3545 BigNumber = math.type.BigNumber,
3546 collection = __webpack_require__(13),
3547@@ -11257,7 +10993,7 @@
3548 'use strict';
3549
3550 module.exports = function (math) {
3551- var util = __webpack_require__(147),
3552+ var util = __webpack_require__(160),
3553
3554 BigNumber = math.type.BigNumber,
3555 Complex = __webpack_require__(6),
3556@@ -11390,7 +11126,7 @@
3557 'use strict';
3558
3559 module.exports = function (math) {
3560- var util = __webpack_require__(147),
3561+ var util = __webpack_require__(160),
3562
3563 BigNumber = math.type.BigNumber,
3564 Index = __webpack_require__(8);
3565@@ -11464,7 +11200,7 @@
3566 'use strict';
3567
3568 module.exports = function (math) {
3569- var util = __webpack_require__(147),
3570+ var util = __webpack_require__(160),
3571 Matrix = __webpack_require__(9);
3572
3573 /**
3574@@ -11479,7 +11215,7 @@
3575 *
3576 * Examples:
3577 *
3578- * var m = math.matrix([[1, 2], [3, 4]);
3579+ * var m = math.matrix([[1, 2], [3, 4]]);
3580 * m.size(); // Array [2, 2]
3581 * m.resize([3, 2], 5);
3582 * m.valueOf(); // Array [[1, 2], [3, 4], [5, 5]]
3583@@ -11509,7 +11245,7 @@
3584 'use strict';
3585
3586 module.exports = function (math) {
3587- var util = __webpack_require__(147);
3588+ var util = __webpack_require__(160);
3589
3590 var BigNumber = math.type.BigNumber;
3591 var Unit = math.type.Unit;
3592@@ -11665,44 +11401,58 @@
3593
3594 module.exports = function (math) {
3595 /**
3596- * Wrap any value in a Selector, allowing to perform chained operations on
3597+ * Wrap any value in a chain, allowing to perform chained operations on
3598 * the value.
3599 *
3600- * All methods available in the math.js library can be called upon the selector,
3601+ * All methods available in the math.js library can be called upon the chain,
3602 * and then will be evaluated with the value itself as first argument.
3603- * The selector can be closed by executing `selector.done()`, which returns
3604+ * The chain can be closed by executing `chain.done()`, which returns
3605 * the final value.
3606 *
3607- * The Selector has a number of special functions:
3608+ * The chain has a number of special functions:
3609 *
3610- * - `done()` Finalize the chained operation and return the selectors value.
3611+ * - `done()` Finalize the chain and return the chain's value.
3612 * - `valueOf()` The same as `done()`
3613- * - `toString()` Executes `math.format()` onto the selectors value, returning
3614+ * - `toString()` Executes `math.format()` onto the chain's value, returning
3615 * a string representation of the value.
3616 *
3617 * Syntax:
3618 *
3619- * math.select(value)
3620+ * math.chain(value)
3621 *
3622 * Examples:
3623 *
3624- * math.select(3)
3625+ * math.chain(3)
3626 * .add(4)
3627 * .subtract(2)
3628 * .done(); // 5
3629 *
3630- * math.select( [[1, 2], [3, 4]] )
3631+ * math.chain( [[1, 2], [3, 4]] )
3632 * .set([1, 1], 8)
3633 * .multiply(3)
3634 * .done(); // [[24, 6], [9, 12]]
3635 *
3636 * @param {*} [value] A value of any type on which to start a chained operation.
3637- * @return {math.chaining.Selector} The created selector
3638+ * @return {math.chaining.Chain} The created chain
3639 */
3640- math.select = function select(value) {
3641+ math.chain = function(value) {
3642 // TODO: check number of arguments
3643- return new math.chaining.Selector(value);
3644+ return new math.chaining.Chain(value);
3645 };
3646+
3647+ // TODO: deprecate math.select in v2.0
3648+ math.select = function(value) {
3649+ // give a warning once.
3650+ if (console && typeof console.log === 'function') {
3651+ console.log('WARNING: Function "select" is renamed to "chain". It will be deprecated in v2.0.')
3652+ }
3653+
3654+ // replace warning function with chain function
3655+ math.select = math.chain;
3656+ math.chaining.Chain.prototype['select'] = math.select;
3657+
3658+ return math.chain(value);
3659+ }
3660 };
3661
3662
3663@@ -11713,7 +11463,7 @@
3664 'use strict';
3665
3666 module.exports = function (math) {
3667- var util = __webpack_require__(147),
3668+ var util = __webpack_require__(160),
3669
3670 collection = __webpack_require__(13),
3671
3672@@ -11780,7 +11530,7 @@
3673 'use strict';
3674
3675 module.exports = function (math) {
3676- var util = __webpack_require__(147),
3677+ var util = __webpack_require__(160),
3678
3679 BigNumber = math.type.BigNumber,
3680 Unit = __webpack_require__(10),
3681@@ -11867,9 +11617,390 @@
3682 'use strict';
3683
3684 module.exports = function (math) {
3685- var util = __webpack_require__(147),
3686-
3687- BigNumber = __webpack_require__(142),
3688+ var util = __webpack_require__(160),
3689+
3690+ BigNumber = math.type.BigNumber,
3691+ Complex = __webpack_require__(6),
3692+ Unit = __webpack_require__(10),
3693+ collection = __webpack_require__(13),
3694+
3695+ isNumber = util.number.isNumber,
3696+ isBoolean = util['boolean'].isBoolean,
3697+ isComplex = Complex.isComplex,
3698+ isUnit = Unit.isUnit,
3699+ isCollection = collection.isCollection;
3700+
3701+ /**
3702+ * Logical `and`. Test whether two values are both defined with a nonzero/nonempty value.
3703+ * For matrices, the function is evaluated element wise.
3704+ *
3705+ * Syntax:
3706+ *
3707+ * math.and(x, y)
3708+ *
3709+ * Examples:
3710+ *
3711+ * math.and(2, 4); // returns true
3712+ *
3713+ * a = [2, 0, 0];
3714+ * b = [3, 7, 0];
3715+ * c = 0;
3716+ *
3717+ * math.and(a, b); // returns [true, false, false]
3718+ * math.and(a, c); // returns [false, false, false]
3719+ *
3720+ * See also:
3721+ *
3722+ * not, or, xor
3723+ *
3724+ * @param {Number | BigNumber | Boolean | Complex | Unit | Array | Matrix | null} x First value to check
3725+ * @param {Number | BigNumber | Boolean | Complex | Unit | Array | Matrix | null} y Second value to check
3726+ * @return {Boolean | Array | Matrix}
3727+ * Returns true when both inputs are defined with a nonzero/nonempty value.
3728+ */
3729+ math.and = function and(x, y) {
3730+ if (arguments.length != 2) {
3731+ throw new math.error.ArgumentsError('and', arguments.length, 2);
3732+ }
3733+
3734+ if ((isNumber(x) || isBoolean(x) || x === null) &&
3735+ (isNumber(y) || isBoolean(y) || y === null)) {
3736+ return !!(x && y);
3737+ }
3738+
3739+ if (isComplex(x)) {
3740+ if (x.re == 0 && x.im == 0) {
3741+ return false;
3742+ }
3743+
3744+ return and(true, y);
3745+ }
3746+ if (isComplex(y)) {
3747+ if (y.re == 0 && y.im == 0) {
3748+ return false;
3749+ }
3750+
3751+ return and(x, true);
3752+ }
3753+
3754+ if (x instanceof BigNumber) {
3755+ if (x.isZero() || x.isNaN()) {
3756+ return false;
3757+ }
3758+
3759+ return and(true, y);
3760+ }
3761+ if (y instanceof BigNumber) {
3762+ if (y.isZero() || y.isNaN()) {
3763+ return false;
3764+ }
3765+
3766+ return and(x, true);
3767+ }
3768+
3769+ if (isUnit(x)) {
3770+ if (x.value === null || x.value == 0) {
3771+ return false;
3772+ }
3773+
3774+ return and(true, y);
3775+ }
3776+ if (isUnit(y)) {
3777+ if (y.value === null || y.value == 0) {
3778+ return false;
3779+ }
3780+
3781+ return and(x, true);
3782+ }
3783+
3784+ if (isCollection(x) || isCollection(y)) {
3785+ return collection.deepMap2(x, y, and);
3786+ }
3787+
3788+ throw new math.error.UnsupportedTypeError('and', math['typeof'](x), math['typeof'](y));
3789+ };
3790+ };
3791+
3792+
3793+/***/ },
3794+/* 84 */
3795+/***/ function(module, exports, __webpack_require__) {
3796+
3797+ 'use strict';
3798+
3799+ module.exports = function (math) {
3800+ var util = __webpack_require__(160),
3801+
3802+ BigNumber = math.type.BigNumber,
3803+ Complex = __webpack_require__(6),
3804+ Unit = __webpack_require__(10),
3805+ collection = __webpack_require__(13),
3806+
3807+ isNumber = util.number.isNumber,
3808+ isBoolean = util['boolean'].isBoolean,
3809+ isComplex = Complex.isComplex,
3810+ isUnit = Unit.isUnit,
3811+ isCollection = collection.isCollection;
3812+
3813+ /**
3814+ * Logical `not`. Flips boolean value of a given parameter.
3815+ * For matrices, the function is evaluated element wise.
3816+ *
3817+ * Syntax:
3818+ *
3819+ * math.not(x)
3820+ *
3821+ * Examples:
3822+ *
3823+ * math.not(2); // returns false
3824+ * math.not(0); // returns true
3825+ * math.not(true); // returns false
3826+ *
3827+ * a = [2, -7, 0];
3828+ * math.not(a); // returns [false, false, true]
3829+ *
3830+ * See also:
3831+ *
3832+ * and, or, xor
3833+ *
3834+ * @param {Number | BigNumber | Boolean | Complex | Unit | Array | Matrix | null} x First value to check
3835+ * @return {Boolean | Array | Matrix}
3836+ * Returns true when input is a zero or empty value.
3837+ */
3838+ math.not = function not(x) {
3839+ if (arguments.length != 1) {
3840+ throw new math.error.ArgumentsError('not', arguments.length, 1);
3841+ }
3842+
3843+ if (isNumber(x) || isBoolean(x) || x === null) {
3844+ return !x;
3845+ }
3846+
3847+ if (isComplex(x)) {
3848+ return x.re == 0 && x.im == 0;
3849+ }
3850+
3851+ if (x instanceof BigNumber) {
3852+ return x.isZero() || x.isNaN();
3853+ }
3854+
3855+ if (isUnit(x)) {
3856+ return x.value === null || x.value == 0;
3857+ }
3858+
3859+ if (isCollection(x)) {
3860+ return collection.deepMap(x, not);
3861+ }
3862+
3863+ throw new math.error.UnsupportedTypeError('not', math['typeof'](x));
3864+ };
3865+ };
3866+
3867+
3868+/***/ },
3869+/* 85 */
3870+/***/ function(module, exports, __webpack_require__) {
3871+
3872+ 'use strict';
3873+
3874+ module.exports = function (math) {
3875+ var util = __webpack_require__(160),
3876+
3877+ BigNumber = math.type.BigNumber,
3878+ Complex = __webpack_require__(6),
3879+ Unit = __webpack_require__(10),
3880+ collection = __webpack_require__(13),
3881+
3882+ isNumber = util.number.isNumber,
3883+ isBoolean = util['boolean'].isBoolean,
3884+ isComplex = Complex.isComplex,
3885+ isUnit = Unit.isUnit,
3886+ isCollection = collection.isCollection;
3887+
3888+ /**
3889+ * Logical `or`. Test if at least one value is defined with a nonzero/nonempty value.
3890+ * For matrices, the function is evaluated element wise.
3891+ *
3892+ * Syntax:
3893+ *
3894+ * math.or(x, y)
3895+ *
3896+ * Examples:
3897+ *
3898+ * math.or(2, 4); // returns true
3899+ *
3900+ * a = [2, 5, 0];
3901+ * b = [0, 22, 0];
3902+ * c = 0;
3903+ *
3904+ * math.or(a, b); // returns [true, true, false]
3905+ * math.or(b, c); // returns [false, true, false]
3906+ *
3907+ * See also:
3908+ *
3909+ * and, not, xor
3910+ *
3911+ * @param {Number | BigNumber | Boolean | Complex | Unit | Array | Matrix | null} x First value to check
3912+ * @param {Number | BigNumber | Boolean | Complex | Unit | Array | Matrix | null} y Second value to check
3913+ * @return {Boolean | Array | Matrix}
3914+ * Returns true when one of the inputs is defined with a nonzero/nonempty value.
3915+ */
3916+ math.or = function or(x, y) {
3917+ if (arguments.length != 2) {
3918+ throw new math.error.ArgumentsError('or', arguments.length, 2);
3919+ }
3920+
3921+ if ((isNumber(x) || isBoolean(x) || x === null) &&
3922+ (isNumber(y) || isBoolean(y) || y === null)) {
3923+ return !!(x || y);
3924+ }
3925+
3926+ if (isComplex(x)) {
3927+ if (x.re == 0 && x.im == 0) {
3928+ return or(false, y);
3929+ }
3930+ return true;
3931+ }
3932+ if (isComplex(y)) {
3933+ if (y.re == 0 && y.im == 0) {
3934+ return or(x, false);
3935+ }
3936+ return true;
3937+ }
3938+
3939+ if (x instanceof BigNumber) {
3940+ if (x.isZero() || x.isNaN()) {
3941+ return or(false, y);
3942+ }
3943+ return true;
3944+ }
3945+ if (y instanceof BigNumber) {
3946+ if (y.isZero() || y.isNaN()) {
3947+ return or(x, false);
3948+ }
3949+ return true;
3950+ }
3951+
3952+ if (isUnit(x)) {
3953+ if (x.value === null || x.value == 0) {
3954+ return or(false, y);
3955+ }
3956+ return true;
3957+ }
3958+ if (isUnit(y)) {
3959+ if (y.value === null || y.value == 0) {
3960+ return or(x, false);
3961+ }
3962+ return true;
3963+ }
3964+
3965+ if (isCollection(x) || isCollection(y)) {
3966+ return collection.deepMap2(x, y, or);
3967+ }
3968+
3969+ throw new math.error.UnsupportedTypeError('or', math['typeof'](x), math['typeof'](y));
3970+ };
3971+ };
3972+
3973+
3974+/***/ },
3975+/* 86 */
3976+/***/ function(module, exports, __webpack_require__) {
3977+
3978+ 'use strict';
3979+
3980+ module.exports = function (math) {
3981+ var util = __webpack_require__(160),
3982+
3983+ BigNumber = math.type.BigNumber,
3984+ Complex = __webpack_require__(6),
3985+ Unit = __webpack_require__(10),
3986+ collection = __webpack_require__(13),
3987+
3988+ isNumber = util.number.isNumber,
3989+ isBoolean = util['boolean'].isBoolean,
3990+ isComplex = Complex.isComplex,
3991+ isUnit = Unit.isUnit,
3992+ isCollection = collection.isCollection;
3993+
3994+ /**
3995+ * Logical `xor`. Test whether one and only one value is defined with a nonzero/nonempty value.
3996+ * For matrices, the function is evaluated element wise.
3997+ *
3998+ * Syntax:
3999+ *
4000+ * math.xor(x, y)
4001+ *
4002+ * Examples:
4003+ *
4004+ * math.xor(2, 4); // returns false
4005+ *
4006+ * a = [2, 0, 0];
4007+ * b = [2, 7, 0];
4008+ * c = 0;
4009+ *
4010+ * math.xor(a, b); // returns [false, true, false]
4011+ * math.xor(a, c); // returns [true, false, false]
4012+ *
4013+ * See also:
4014+ *
4015+ * and, not, or
4016+ *
4017+ * @param {Number | BigNumber | Boolean | Complex | Unit | Array | Matrix | null} x First value to check
4018+ * @param {Number | BigNumber | Boolean | Complex | Unit | Array | Matrix | null} y Second value to check
4019+ * @return {Boolean | Array | Matrix}
4020+ * Returns true when one and only one input is defined with a nonzero/nonempty value.
4021+ */
4022+ math.xor = function xor(x, y) {
4023+ if (arguments.length != 2) {
4024+ throw new math.error.ArgumentsError('xor', arguments.length, 2);
4025+ }
4026+
4027+ if ((isNumber(x) || isBoolean(x) || x === null) &&
4028+ (isNumber(y) || isBoolean(y) || y === null)) {
4029+ return !!(!!x ^ !!y);
4030+ }
4031+
4032+ if (isComplex(x)) {
4033+ return xor(!(x.re == 0 && x.im == 0), y);
4034+ }
4035+ if (isComplex(y)) {
4036+ return xor(x, !(y.re == 0 && y.im == 0));
4037+ }
4038+
4039+ if (x instanceof BigNumber) {
4040+ return xor(!(x.isZero() || x.isNaN()), y);
4041+ }
4042+ if (y instanceof BigNumber) {
4043+ return xor(x, !(y.isZero() || y.isNaN()));
4044+ }
4045+
4046+ if (isUnit(x)) {
4047+ return xor(!(x.value === null || x.value == 0), y);
4048+ }
4049+ if (isUnit(y)) {
4050+ return xor(x, !(y.value === null || y.value == 0));
4051+ }
4052+
4053+ if (isCollection(x) || isCollection(y)) {
4054+ return collection.deepMap2(x, y, xor);
4055+ }
4056+
4057+ throw new math.error.UnsupportedTypeError('xor', math['typeof'](x), math['typeof'](y));
4058+ };
4059+ };
4060+
4061+
4062+/***/ },
4063+/* 87 */
4064+/***/ function(module, exports, __webpack_require__) {
4065+
4066+ 'use strict';
4067+
4068+ module.exports = function (math) {
4069+ var util = __webpack_require__(160),
4070+
4071+ BigNumber = __webpack_require__(159),
4072 Matrix = __webpack_require__(9),
4073 collection = __webpack_require__(13),
4074
4075@@ -12003,13 +12134,13 @@
4076
4077
4078 /***/ },
4079-/* 84 */
4080+/* 88 */
4081 /***/ function(module, exports, __webpack_require__) {
4082
4083 'use strict';
4084
4085 module.exports = function(math) {
4086- var array = __webpack_require__(140);
4087+ var array = __webpack_require__(153);
4088 var Matrix = __webpack_require__(9);
4089
4090 /**
4091@@ -12088,13 +12219,13 @@
4092
4093
4094 /***/ },
4095-/* 85 */
4096+/* 89 */
4097 /***/ function(module, exports, __webpack_require__) {
4098
4099 'use strict';
4100
4101 module.exports = function (math) {
4102- var util = __webpack_require__(147),
4103+ var util = __webpack_require__(160),
4104
4105 Matrix = __webpack_require__(9),
4106
4107@@ -12249,13 +12380,13 @@
4108
4109
4110 /***/ },
4111-/* 86 */
4112+/* 90 */
4113 /***/ function(module, exports, __webpack_require__) {
4114
4115 'use strict';
4116
4117 module.exports = function (math) {
4118- var util = __webpack_require__(147),
4119+ var util = __webpack_require__(160),
4120
4121 BigNumber = math.type.BigNumber,
4122 Matrix = __webpack_require__(9),
4123@@ -12366,13 +12497,13 @@
4124
4125
4126 /***/ },
4127-/* 87 */
4128+/* 91 */
4129 /***/ function(module, exports, __webpack_require__) {
4130
4131 'use strict';
4132
4133 module.exports = function(math) {
4134- var array = __webpack_require__(140);
4135+ var array = __webpack_require__(153);
4136 var Matrix = __webpack_require__(9);
4137
4138 /**
4139@@ -12447,13 +12578,13 @@
4140
4141
4142 /***/ },
4143-/* 88 */
4144+/* 92 */
4145 /***/ function(module, exports, __webpack_require__) {
4146
4147 'use strict';
4148
4149 module.exports = function (math, config) {
4150- var util = __webpack_require__(147),
4151+ var util = __webpack_require__(160),
4152
4153 BigNumber = math.type.BigNumber,
4154 Matrix = __webpack_require__(9),
4155@@ -12550,13 +12681,13 @@
4156
4157
4158 /***/ },
4159-/* 89 */
4160+/* 93 */
4161 /***/ function(module, exports, __webpack_require__) {
4162
4163 'use strict';
4164
4165 module.exports = function (math, config) {
4166- var util = __webpack_require__(147);
4167+ var util = __webpack_require__(160);
4168
4169 var Matrix = __webpack_require__(9);
4170
4171@@ -12603,16 +12734,14 @@
4172
4173
4174 /***/ },
4175-/* 90 */
4176+/* 94 */
4177 /***/ function(module, exports, __webpack_require__) {
4178
4179 'use strict';
4180
4181 module.exports = function (math) {
4182- var util = __webpack_require__(147),
4183- string = util.string,
4184-
4185- Matrix = __webpack_require__(9);
4186+ var util = __webpack_require__(160);
4187+ var Matrix = __webpack_require__(9);
4188
4189 /**
4190 * Calculate the inverse of a square matrix.
4191@@ -12642,25 +12771,25 @@
4192 switch (size.length) {
4193 case 0:
4194 // scalar
4195- return math.divide(1, x);
4196+ return math._divide(1, x);
4197
4198 case 1:
4199 // vector
4200 if (size[0] == 1) {
4201 if (x instanceof Matrix) {
4202 return new Matrix([
4203- math.divide(1, x.valueOf()[0])
4204+ math._divide(1, x.valueOf()[0])
4205 ]);
4206 }
4207 else {
4208 return [
4209- math.divide(1, x[0])
4210+ math._divide(1, x[0])
4211 ];
4212 }
4213 }
4214 else {
4215 throw new RangeError('Matrix must be square ' +
4216- '(size: ' + string.format(size) + ')');
4217+ '(size: ' + util.string.format(size) + ')');
4218 }
4219
4220 case 2:
4221@@ -12680,13 +12809,13 @@
4222 }
4223 else {
4224 throw new RangeError('Matrix must be square ' +
4225- '(size: ' + string.format(size) + ')');
4226+ '(size: ' + util.string.format(size) + ')');
4227 }
4228
4229 default:
4230 // multi dimensional array
4231 throw new RangeError('Matrix must be two dimensional ' +
4232- '(size: ' + string.format(size) + ')');
4233+ '(size: ' + util.string.format(size) + ')');
4234 }
4235 };
4236
4237@@ -12708,7 +12837,7 @@
4238 throw Error('Cannot calculate inverse, determinant is zero');
4239 }
4240 return [[
4241- math.divide(1, value)
4242+ math._divide(1, value)
4243 ]];
4244 }
4245 else if (rows == 2) {
4246@@ -12719,12 +12848,12 @@
4247 }
4248 return [
4249 [
4250- math.divide(matrix[1][1], d),
4251- math.divide(math.unaryMinus(matrix[0][1]), d)
4252+ math._divide(matrix[1][1], d),
4253+ math._divide(math.unaryMinus(matrix[0][1]), d)
4254 ],
4255 [
4256- math.divide(math.unaryMinus(matrix[1][0]), d),
4257- math.divide(matrix[0][0], d)
4258+ math._divide(math.unaryMinus(matrix[1][0]), d),
4259+ math._divide(matrix[0][0], d)
4260 ]
4261 ];
4262 }
4263@@ -12771,7 +12900,7 @@
4264 if(r != c) {
4265 // eliminate value at column c and row r
4266 if (Ar[c] != 0) {
4267- f = math.divide(math.unaryMinus(Ar[c]), Ac[c]);
4268+ f = math._divide(math.unaryMinus(Ar[c]), Ac[c]);
4269
4270 // add (f * row c) to row r to eliminate the value
4271 // at column c
4272@@ -12788,10 +12917,10 @@
4273 // divide each value on row r with the value at Acc
4274 f = Ac[c];
4275 for (s = c; s < cols; s++) {
4276- Ar[s] = math.divide(Ar[s], f);
4277+ Ar[s] = math._divide(Ar[s], f);
4278 }
4279 for (s = 0; s < cols; s++) {
4280- Br[s] = math.divide(Br[s], f);
4281+ Br[s] = math._divide(Br[s], f);
4282 }
4283 }
4284 }
4285@@ -12803,13 +12932,13 @@
4286
4287
4288 /***/ },
4289-/* 91 */
4290+/* 95 */
4291 /***/ function(module, exports, __webpack_require__) {
4292
4293 'use strict';
4294
4295 module.exports = function (math, config) {
4296- var util = __webpack_require__(147),
4297+ var util = __webpack_require__(160),
4298
4299 BigNumber = math.type.BigNumber,
4300 Matrix = __webpack_require__(9),
4301@@ -12880,13 +13009,13 @@
4302
4303
4304 /***/ },
4305-/* 92 */
4306+/* 96 */
4307 /***/ function(module, exports, __webpack_require__) {
4308
4309 'use strict';
4310
4311 module.exports = function (math, config) {
4312- var util = __webpack_require__(147),
4313+ var util = __webpack_require__(160),
4314
4315 BigNumber = math.type.BigNumber,
4316 Matrix = __webpack_require__(9),
4317@@ -13206,13 +13335,13 @@
4318
4319
4320 /***/ },
4321-/* 93 */
4322+/* 97 */
4323 /***/ function(module, exports, __webpack_require__) {
4324
4325 'use strict';
4326
4327 module.exports = function (math, config) {
4328- var util = __webpack_require__(147),
4329+ var util = __webpack_require__(160),
4330
4331 BigNumber = math.type.BigNumber,
4332 Matrix = __webpack_require__(9),
4333@@ -13341,13 +13470,13 @@
4334
4335
4336 /***/ },
4337-/* 94 */
4338+/* 98 */
4339 /***/ function(module, exports, __webpack_require__) {
4340
4341 'use strict';
4342
4343 module.exports = function (math, config) {
4344- var util = __webpack_require__(147),
4345+ var util = __webpack_require__(160),
4346
4347 BigNumber = math.type.BigNumber,
4348 Complex = __webpack_require__(6),
4349@@ -13414,13 +13543,13 @@
4350
4351
4352 /***/ },
4353-/* 95 */
4354+/* 99 */
4355 /***/ function(module, exports, __webpack_require__) {
4356
4357 'use strict';
4358
4359 module.exports = function (math) {
4360- var util = __webpack_require__(147),
4361+ var util = __webpack_require__(160),
4362
4363 Matrix = __webpack_require__(9),
4364
4365@@ -13478,13 +13607,13 @@
4366
4367
4368 /***/ },
4369-/* 96 */
4370+/* 100 */
4371 /***/ function(module, exports, __webpack_require__) {
4372
4373 'use strict';
4374
4375 module.exports = function (math) {
4376- var util = __webpack_require__(147),
4377+ var util = __webpack_require__(160),
4378
4379 Matrix = __webpack_require__(9),
4380 Index = __webpack_require__(8),
4381@@ -13695,13 +13824,13 @@
4382
4383
4384 /***/ },
4385-/* 97 */
4386+/* 101 */
4387 /***/ function(module, exports, __webpack_require__) {
4388
4389 'use strict';
4390
4391 module.exports = function (math) {
4392- var util = __webpack_require__(147),
4393+ var util = __webpack_require__(160),
4394
4395 Matrix = __webpack_require__(9),
4396
4397@@ -13778,13 +13907,13 @@
4398
4399
4400 /***/ },
4401-/* 98 */
4402+/* 102 */
4403 /***/ function(module, exports, __webpack_require__) {
4404
4405 'use strict';
4406
4407 module.exports = function (math, config) {
4408- var util = __webpack_require__(147),
4409+ var util = __webpack_require__(160),
4410
4411 BigNumber = math.type.BigNumber,
4412 Matrix = __webpack_require__(9),
4413@@ -13854,13 +13983,13 @@
4414
4415
4416 /***/ },
4417-/* 99 */
4418+/* 103 */
4419 /***/ function(module, exports, __webpack_require__) {
4420
4421 'use strict';
4422
4423 module.exports = function (math) {
4424- var util = __webpack_require__(147),
4425+ var util = __webpack_require__(160),
4426
4427 BigNumber = math.type.BigNumber,
4428 collection = __webpack_require__(13),
4429@@ -13887,7 +14016,7 @@
4430 *
4431 * See also:
4432 *
4433- * combinations, permutations
4434+ * combinations, gamma, permutations
4435 *
4436 * @param {Number | BigNumber | Array | Matrix | Boolean | null} n An integer number
4437 * @return {Number | BigNumber | Array | Matrix} The factorial of `n`
4438@@ -13900,47 +14029,39 @@
4439 }
4440
4441 if (isNumber(n)) {
4442- if (!isInteger(n) || n < 0) {
4443- throw new TypeError('Positive integer value expected in function factorial');
4444- }
4445-
4446- value = n - 1;
4447- res = n;
4448- while (value > 1) {
4449- res *= value;
4450- value--;
4451- }
4452-
4453- if (res == 0) {
4454- res = 1; // 0! is per definition 1
4455- }
4456-
4457- return res;
4458+ return math.gamma(n + 1);
4459 }
4460
4461 if (n instanceof BigNumber) {
4462- if (!(isPositiveInteger(n))) {
4463- throw new TypeError('Positive integer value expected in function factorial');
4464+ if (!(isPositiveInteger(n)) && n.isFinite()) {
4465+ return math.gamma(n.plus(1));
4466+ }
4467+
4468+ if (!n.isFinite()) {
4469+ return new BigNumber(n);
4470+ }
4471+
4472+ n = n.toNumber();
4473+ if (n < fac.length) {
4474+ return (n < 21)
4475+ ? new BigNumber(fac[n])
4476+ : fac[n];
4477 }
4478
4479 var one = new BigNumber(1);
4480-
4481- value = n.minus(one);
4482- res = n;
4483- while (value.gt(one)) {
4484+ value = new BigNumber(fac.length);
4485+ res = fac[fac.length - 1];
4486+ for (var i = fac.length; i < n; ++i) {
4487 res = res.times(value);
4488- value = value.minus(one);
4489- }
4490-
4491- if (res.equals(0)) {
4492- res = one; // 0! is per definition 1
4493- }
4494-
4495- return res;
4496+ value = value.plus(one);
4497+ fac[i] = res;
4498+ }
4499+
4500+ return fac[n] = res.times(value);
4501 }
4502
4503 if (isBoolean(n) || n === null) {
4504- return 1; // factorial(1) = 1, factorial(0) = 1
4505+ return 1; // factorial(1) = 1, factorial(0) = 1
4506 }
4507
4508 if (isCollection(n)) {
4509@@ -13956,19 +14077,239 @@
4510 * @returns {boolean} isPositiveInteger
4511 */
4512 var isPositiveInteger = function(n) {
4513- return n.isInteger() && n.gte(0);
4514- };
4515- };
4516-
4517-
4518-/***/ },
4519-/* 100 */
4520+ return n.isInteger() && (!n.isNegative() || n.isZero());
4521+ };
4522+
4523+ // 0-21! values
4524+ var fac = [
4525+ 1,
4526+ 1,
4527+ 2,
4528+ 6,
4529+ 24,
4530+ 120,
4531+ 720,
4532+ 5040,
4533+ 40320,
4534+ 362880,
4535+ 3628800,
4536+ 39916800,
4537+ 479001600,
4538+ 6227020800,
4539+ 87178291200,
4540+ 1307674368000,
4541+ 20922789888000,
4542+ 355687428096000,
4543+ 6402373705728000,
4544+ 121645100408832000,
4545+ 2432902008176640000,
4546+ new BigNumber('51090942171709440000')
4547+ ]
4548+ };
4549+
4550+
4551+/***/ },
4552+/* 104 */
4553+/***/ function(module, exports, __webpack_require__) {
4554+
4555+ 'use strict';
4556+
4557+ module.exports = function (math, config) {
4558+ var util = __webpack_require__(160),
4559+
4560+ BigNumber = math.type.BigNumber,
4561+ Complex = __webpack_require__(6),
4562+ collection = __webpack_require__(13),
4563+
4564+ isBoolean = util['boolean'].isBoolean,
4565+ isComplex = Complex.isComplex,
4566+ isNumber = util.number.isNumber,
4567+ isInteger = util.number.isInteger,
4568+ isCollection = collection.isCollection;
4569+
4570+ /**
4571+ * Compute the gamma function of a value using Lanczos approximation for
4572+ * small values, and an extended Stirling approximation for large values.
4573+ *
4574+ * For matrices, the function is evaluated element wise.
4575+ *
4576+ * Syntax:
4577+ *
4578+ * math.gamma(n)
4579+ *
4580+ * Examples:
4581+ *
4582+ * math.gamma(5); // returns 24
4583+ * math.gamma(-0.5); // returns -3.5449077018110335
4584+ * math.gamma(math.i); // returns -0.15494982830180973 - 0.49801566811835596i
4585+ *
4586+ * See also:
4587+ *
4588+ * combinations, factorial, permutations
4589+ *
4590+ * @param {Number | Array | Matrix | Boolean | null} n An integer number
4591+ * @return {Number | Array | Matrix} The gamma of `n`
4592+ */
4593+ math.gamma = function gamma (n) {
4594+ var t, x;
4595+ var g = 4.7421875;
4596+
4597+ if (arguments.length != 1) {
4598+ throw new math.error.ArgumentsError('gamma', arguments.length, 1);
4599+ }
4600+
4601+ if (isNumber(n)) {
4602+ if (isInteger(n)) {
4603+ if (n <= 0) {
4604+ return isFinite(n)
4605+ ? Infinity
4606+ : NaN;
4607+ }
4608+
4609+ if (n > 171) {
4610+ return Infinity; // Will overflow
4611+ }
4612+
4613+ var value = n - 2;
4614+ var res = n - 1;
4615+ while (value > 1) {
4616+ res *= value;
4617+ value--;
4618+ }
4619+
4620+ if (res == 0) {
4621+ res = 1; // 0! is per definition 1
4622+ }
4623+
4624+ return res;
4625+ }
4626+
4627+ if (n < 0.5) {
4628+ return Math.PI / (Math.sin(Math.PI*n) * gamma(1-n));
4629+ }
4630+
4631+ if (n >= 171.35) {
4632+ return Infinity; // will overflow
4633+ }
4634+
4635+ if (n > 85.0) { // Extended Stirling Approx
4636+ var twoN = n*n;
4637+ var threeN = twoN*n;
4638+ var fourN = threeN*n;
4639+ var fiveN = fourN*n;
4640+ return Math.sqrt(2*Math.PI/n) * Math.pow((n/Math.E), n) *
4641+ (1 + 1/(12*n) + 1/(288*twoN) - 139/(51840*threeN) -
4642+ 571/(2488320*fourN) + 163879/(209018880*fiveN) +
4643+ 5246819/(75246796800*fiveN*n));
4644+ }
4645+
4646+ --n;
4647+ x = p[0];
4648+ for (var i = 1; i < p.length; ++i) {
4649+ x += p[i] / (n+i);
4650+ }
4651+
4652+ t = n + g + 0.5;
4653+ return Math.sqrt(2*Math.PI) * Math.pow(t, n+0.5) * Math.exp(-t) * x;
4654+ }
4655+
4656+ if (isComplex(n)) {
4657+ if (n.im == 0) {
4658+ return gamma(n.re);
4659+ }
4660+
4661+ n = new Complex(n.re - 1, n.im);
4662+ x = new Complex(p[0], 0);
4663+ for (var i = 1; i < p.length; ++i) {
4664+ var real = n.re + i; // x += p[i]/(n+i)
4665+ var den = real*real + n.im*n.im;
4666+ if (den != 0) {
4667+ x.re += p[i] * real / den;
4668+ x.im += -(p[i] * n.im) / den;
4669+ } else {
4670+ x.re = p[i] < 0
4671+ ? -Infinity
4672+ : Infinity;
4673+ }
4674+ }
4675+
4676+ t = new Complex(n.re + g + 0.5, n.im);
4677+ var twoPiSqrt = Math.sqrt(2*Math.PI);
4678+
4679+ n.re += 0.5;
4680+ var result = math.pow(t, n);
4681+ if (result.im == 0) { // sqrt(2*PI)*result
4682+ result.re *= twoPiSqrt;
4683+ } else if (result.re == 0) {
4684+ result.im *= twoPiSqrt;
4685+ } else {
4686+ result.re *= twoPiSqrt;
4687+ result.im *= twoPiSqrt;
4688+ }
4689+
4690+ var r = Math.exp(-t.re); // exp(-t)
4691+ t.re = r * Math.cos(-t.im);
4692+ t.im = r * Math.sin(-t.im);
4693+
4694+ return math.multiply(math.multiply(result, t), x);
4695+ }
4696+
4697+ if (n instanceof BigNumber) {
4698+ if (n.isInteger()) {
4699+ return n.isNegative() || n.isZero()
4700+ ? new BigNumber(Infinity)
4701+ : math.factorial(n.minus(1));
4702+ }
4703+
4704+ if (!n.isFinite()) {
4705+ return new BigNumber(n.isNegative()
4706+ ? NaN
4707+ : Infinity);
4708+ }
4709+ }
4710+
4711+ if (isBoolean(n) || n === null) {
4712+ return n
4713+ ? 1
4714+ : Infinity;
4715+ }
4716+
4717+ if (isCollection(n)) {
4718+ return collection.deepMap(n, gamma);
4719+ }
4720+
4721+ throw new math.error.UnsupportedTypeError('gamma', math['typeof'](n));
4722+ };
4723+
4724+ var p = [
4725+ 0.99999999999999709182,
4726+ 57.156235665862923517,
4727+ -59.597960355475491248,
4728+ 14.136097974741747174,
4729+ -0.49191381609762019978,
4730+ 0.33994649984811888699e-4,
4731+ 0.46523628927048575665e-4,
4732+ -0.98374475304879564677e-4,
4733+ 0.15808870322491248884e-3,
4734+ -0.21026444172410488319e-3,
4735+ 0.21743961811521264320e-3,
4736+ -0.16431810653676389022e-3,
4737+ 0.84418223983852743293e-4,
4738+ -0.26190838401581408670e-4,
4739+ 0.36899182659531622704e-5
4740+ ];
4741+
4742+ };
4743+
4744+
4745+/***/ },
4746+/* 105 */
4747 /***/ function(module, exports, __webpack_require__) {
4748
4749 'use strict';
4750
4751 module.exports = function (math) {
4752- var distribution = __webpack_require__(181)(math);
4753+ var distribution = __webpack_require__(194)(math);
4754
4755 /**
4756 * Return a random number larger or equal to `min` and smaller than `max`
4757@@ -14005,13 +14346,13 @@
4758
4759
4760 /***/ },
4761-/* 101 */
4762+/* 106 */
4763 /***/ function(module, exports, __webpack_require__) {
4764
4765 'use strict';
4766
4767 module.exports = function (math) {
4768- var distribution = __webpack_require__(181)(math);
4769+ var distribution = __webpack_require__(194)(math);
4770
4771 /**
4772 * Return a random integer number larger or equal to `min` and smaller than `max`
4773@@ -14048,13 +14389,13 @@
4774
4775
4776 /***/ },
4777-/* 102 */
4778+/* 107 */
4779 /***/ function(module, exports, __webpack_require__) {
4780
4781 'use strict';
4782
4783 module.exports = function (math) {
4784- var distribution = __webpack_require__(181)(math);
4785+ var distribution = __webpack_require__(194)(math);
4786
4787 /**
4788 * Random pick a value from a one dimensional array.
4789@@ -14080,13 +14421,13 @@
4790
4791
4792 /***/ },
4793-/* 103 */
4794+/* 108 */
4795 /***/ function(module, exports, __webpack_require__) {
4796
4797 'use strict';
4798
4799 module.exports = function (math) {
4800- var util = __webpack_require__(147),
4801+ var util = __webpack_require__(160),
4802
4803 BigNumber = math.type.BigNumber,
4804
4805@@ -14193,13 +14534,13 @@
4806
4807
4808 /***/ },
4809-/* 104 */
4810+/* 109 */
4811 /***/ function(module, exports, __webpack_require__) {
4812
4813 'use strict';
4814
4815 module.exports = function (math) {
4816- var util = __webpack_require__(147),
4817+ var util = __webpack_require__(160),
4818
4819 BigNumber = math.type.BigNumber,
4820 collection = __webpack_require__(13),
4821@@ -14290,7 +14631,1058 @@
4822
4823
4824 /***/ },
4825-/* 105 */
4826+/* 110 */
4827+/***/ function(module, exports, __webpack_require__) {
4828+
4829+ 'use strict';
4830+
4831+ module.exports = function (math, config) {
4832+ var util = __webpack_require__(160),
4833+
4834+ BigNumber = math.type.BigNumber,
4835+ Complex = __webpack_require__(6),
4836+ Unit = __webpack_require__(10),
4837+ collection = __webpack_require__(13),
4838+
4839+ isNumber = util.number.isNumber,
4840+ nearlyEqual = util.number.nearlyEqual,
4841+ isBoolean = util['boolean'].isBoolean,
4842+ isString = util.string.isString,
4843+ isComplex = Complex.isComplex,
4844+ isUnit = Unit.isUnit,
4845+ isCollection = collection.isCollection;
4846+
4847+ /**
4848+ * Compare two values. Returns 1 when x > y, -1 when x < y, and 0 when x == y.
4849+ *
4850+ * x and y are considered equal when the relative difference between x and y
4851+ * is smaller than the configured epsilon. The function cannot be used to
4852+ * compare values smaller than approximately 2.22e-16.
4853+ *
4854+ * For matrices, the function is evaluated element wise.
4855+ *
4856+ * Syntax:
4857+ *
4858+ * math.compare(x, y)
4859+ *
4860+ * Examples:
4861+ *
4862+ * math.compare(6, 1); // returns 1
4863+ * math.compare(2, 3); // returns -1
4864+ * math.compare(7, 7); // returns 0
4865+ *
4866+ * var a = math.unit('5 cm');
4867+ * var b = math.unit('40 mm');
4868+ * math.compare(a, b); // returns 1
4869+ *
4870+ * math.compare(2, [1, 2, 3]); // returns [1, 0, -1]
4871+ *
4872+ * See also:
4873+ *
4874+ * equal, unequal, smaller, smallerEq, larger, largerEq
4875+ *
4876+ * @param {Number | BigNumber | Boolean | Unit | String | Array | Matrix | null} x First value to compare
4877+ * @param {Number | BigNumber | Boolean | Unit | String | Array | Matrix | null} y Second value to compare
4878+ * @return {Number | BigNumber | Array | Matrix} Returns the result of the comparison: 1, 0 or -1.
4879+ */
4880+ math.compare = function compare(x, y) {
4881+ if (arguments.length != 2) {
4882+ throw new math.error.ArgumentsError('compare', arguments.length, 2);
4883+ }
4884+
4885+ if (isNumber(x) && isNumber(y)) {
4886+ return nearlyEqual(x, y, config.epsilon) ? 0 : (x > y ? 1 : -1);
4887+ }
4888+
4889+ if (x instanceof BigNumber) {
4890+ // try to convert to big number
4891+ if (isNumber(y)) {
4892+ y = BigNumber.convert(y);
4893+ }
4894+ else if (isBoolean(y) || y === null) {
4895+ y = new BigNumber(y ? 1 : 0);
4896+ }
4897+
4898+ if (y instanceof BigNumber) {
4899+ return new BigNumber(x.cmp(y));
4900+ }
4901+
4902+ // downgrade to Number
4903+ return compare(x.toNumber(), y);
4904+ }
4905+ if (y instanceof BigNumber) {
4906+ // try to convert to big number
4907+ if (isNumber(x)) {
4908+ x = BigNumber.convert(x);
4909+ }
4910+ else if (isBoolean(x) || x === null) {
4911+ x = new BigNumber(x ? 1 : 0);
4912+ }
4913+
4914+ if (x instanceof BigNumber) {
4915+ return new BigNumber(x.cmp(y));
4916+ }
4917+
4918+ // downgrade to Number
4919+ return compare(x, y.toNumber());
4920+ }
4921+
4922+ if ((isUnit(x)) && (isUnit(y))) {
4923+ if (!x.equalBase(y)) {
4924+ throw new Error('Cannot compare units with different base');
4925+ }
4926+ return (x.value > y.value) ? 1 : ((x.value < y.value) ? -1 : 0);
4927+ }
4928+
4929+ if (isCollection(x) || isCollection(y)) {
4930+ return collection.deepMap2(x, y, compare);
4931+ }
4932+
4933+ // Note: test strings after testing collections,
4934+ // else we can't compare a string with a matrix
4935+ if (isString(x) || isString(y)) {
4936+ return (x > y) ? 1 : ((x < y) ? -1 : 0);
4937+ }
4938+
4939+ if (isBoolean(x) || x === null) {
4940+ return compare(+x, y);
4941+ }
4942+ if (isBoolean(y) || y === null) {
4943+ return compare(x, +y);
4944+ }
4945+
4946+ if (isComplex(x) || isComplex(y)) {
4947+ throw new TypeError('No ordering relation is defined for complex numbers');
4948+ }
4949+
4950+ throw new math.error.UnsupportedTypeError('compare', math['typeof'](x), math['typeof'](y));
4951+ };
4952+ };
4953+
4954+
4955+/***/ },
4956+/* 111 */
4957+/***/ function(module, exports, __webpack_require__) {
4958+
4959+ 'use strict';
4960+
4961+ module.exports = function (math) {
4962+ var collection = __webpack_require__(13),
4963+
4964+ isCollection = collection.isCollection,
4965+ isArray = Array.isArray;
4966+
4967+ /**
4968+ * Test element wise whether two matrices are equal.
4969+ * The function accepts both matrices and scalar values.
4970+ *
4971+ * Syntax:
4972+ *
4973+ * math.deepEqual(x, y)
4974+ *
4975+ * Examples:
4976+ *
4977+ * math.deepEqual(2, 4); // returns false
4978+ *
4979+ * a = [2, 5, 1];
4980+ * b = [2, 7, 1];
4981+ *
4982+ * math.deepEqual(a, b); // returns false
4983+ * math.equal(a, b); // returns [true, false, true]
4984+ *
4985+ * See also:
4986+ *
4987+ * equal, unequal
4988+ *
4989+ * @param {Number | BigNumber | Boolean | Complex | Unit | Array | Matrix | null} x First matrix to compare
4990+ * @param {Number | BigNumber | Boolean | Complex | Unit | Array | Matrix | null} y Second matrix to compare
4991+ * @return {Number | BigNumber | Complex | Unit | Array | Matrix}
4992+ * Returns true when the input matrices have the same size and each of their elements is equal.
4993+ */
4994+ math.deepEqual = function deepEqual(x, y) {
4995+ if (arguments.length != 2) {
4996+ throw new math.error.ArgumentsError('deepEqual', arguments.length, 2);
4997+ }
4998+
4999+ if (isCollection(x) || isCollection(y)) {
5000+ return _deepEqual(x.valueOf(), y.valueOf());
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches