diff --git a/HISTORY.md b/HISTORY.md index 1736b3f22..4f07524a6 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -4,8 +4,7 @@ - Implemented set methods `setCartesian`, `setDifference`, `setDistinct`, `setIntersect`, `setIsSubset`, `setPowerset`, `setSize`. Thanks @Nekomajin42. - Implemented method `toHTML` on nodes. Thanks @Nekomajin42. -- Implemented comparing complex numbers in functions `compare`, - `smaller`, `smallerEq`, `larger`, `largerEq`. Thanks @gulfaraz. +- Implemented `compareNatural` and `sort([...], 'natural')`. - Upgraded dependencies to the latest versions: - `complex.js@2.0.4` - `decimal.js@7.2.1` diff --git a/lib/function/relational/compare.js b/lib/function/relational/compare.js index 1b07f0339..adf0bf62f 100644 --- a/lib/function/relational/compare.js +++ b/lib/function/relational/compare.js @@ -22,9 +22,6 @@ function factory (type, config, load, typed) { * * For matrices, the function is evaluated element wise. * - * For Complex numbers, first the real parts are compared. If equal, the - * imaginary parts are compared. - * * Syntax: * * math.compare(x, y) @@ -71,7 +68,9 @@ function factory (type, config, load, typed) { return new type.Fraction(x.compare(y)); }, - 'Complex, Complex': type.Complex.compare, + 'Complex, Complex': function () { + throw new TypeError('No ordering relation is defined for complex numbers'); + }, 'Unit, Unit': function (x, y) { if (!x.equalBase(y)) { diff --git a/lib/function/relational/larger.js b/lib/function/relational/larger.js index 741e44c24..ee0a1c9a7 100644 --- a/lib/function/relational/larger.js +++ b/lib/function/relational/larger.js @@ -63,8 +63,8 @@ function factory (type, config, load, typed) { return x.compare(y) === 1; }, - 'Complex, Complex': function (x, y) { - return type.Complex.compare(x, y) > 0; + 'Complex, Complex': function () { + throw new TypeError('No ordering relation is defined for complex numbers'); }, 'Unit, Unit': function (x, y) { diff --git a/lib/function/relational/largerEq.js b/lib/function/relational/largerEq.js index 526704e28..721bd43d3 100644 --- a/lib/function/relational/largerEq.js +++ b/lib/function/relational/largerEq.js @@ -59,8 +59,8 @@ function factory (type, config, load, typed) { return x.compare(y) !== -1; }, - 'Complex, Complex': function (x, y) { - return type.Complex.compare(x, y) >= 0; + 'Complex, Complex': function () { + throw new TypeError('No ordering relation is defined for complex numbers'); }, 'Unit, Unit': function (x, y) { diff --git a/lib/function/relational/smaller.js b/lib/function/relational/smaller.js index 351f2a19d..e2d0bede0 100644 --- a/lib/function/relational/smaller.js +++ b/lib/function/relational/smaller.js @@ -64,7 +64,7 @@ function factory (type, config, load, typed) { }, 'Complex, Complex': function (x, y) { - return type.Complex.compare(x, y) < 0; + throw new TypeError('No ordering relation is defined for complex numbers'); }, 'Unit, Unit': function (x, y) { diff --git a/lib/function/relational/smallerEq.js b/lib/function/relational/smallerEq.js index e60c4c8b8..304271b32 100644 --- a/lib/function/relational/smallerEq.js +++ b/lib/function/relational/smallerEq.js @@ -58,8 +58,8 @@ function factory (type, config, load, typed) { return x.compare(y) !== 1; }, - 'Complex, Complex': function (x, y) { - return type.Complex.compare(x, y) <= 0; + 'Complex, Complex': function () { + throw new TypeError('No ordering relation is defined for complex numbers'); }, 'Unit, Unit': function (x, y) { diff --git a/lib/function/set/setCartesian.js b/lib/function/set/setCartesian.js index 168089d4b..beae3abd0 100644 --- a/lib/function/set/setCartesian.js +++ b/lib/function/set/setCartesian.js @@ -35,8 +35,8 @@ function factory (type, config, load, typed) { var result = []; } else { - var b1 = Array.isArray(a1) ? sort(flatten(a1)) : sort(flatten(a1.toArray())); - var b2 = Array.isArray(a2) ? sort(flatten(a2)) : sort(flatten(a2.toArray())); + var b1 = sort(flatten(Array.isArray(a1) ? a1 : a1.toArray()), 'natural'); + var b2 = sort(flatten(Array.isArray(a2) ? a2 : a2.toArray()), 'natural'); var result = []; for (var i=0; i