simple-squiggle

A restricted subset of Squiggle
Log | Files | Refs | README

larger.js (5416B)


      1 "use strict";
      2 
      3 Object.defineProperty(exports, "__esModule", {
      4   value: true
      5 });
      6 exports.createLargerNumber = exports.createLarger = void 0;
      7 
      8 var _nearlyEqual = require("../../utils/bignumber/nearlyEqual.js");
      9 
     10 var _number = require("../../utils/number.js");
     11 
     12 var _factory = require("../../utils/factory.js");
     13 
     14 var _algorithm = require("../../type/matrix/utils/algorithm03.js");
     15 
     16 var _algorithm2 = require("../../type/matrix/utils/algorithm07.js");
     17 
     18 var _algorithm3 = require("../../type/matrix/utils/algorithm12.js");
     19 
     20 var _algorithm4 = require("../../type/matrix/utils/algorithm14.js");
     21 
     22 var _algorithm5 = require("../../type/matrix/utils/algorithm13.js");
     23 
     24 var name = 'larger';
     25 var dependencies = ['typed', 'config', 'matrix', 'DenseMatrix'];
     26 var createLarger = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
     27   var typed = _ref.typed,
     28       config = _ref.config,
     29       matrix = _ref.matrix,
     30       DenseMatrix = _ref.DenseMatrix;
     31   var algorithm03 = (0, _algorithm.createAlgorithm03)({
     32     typed: typed
     33   });
     34   var algorithm07 = (0, _algorithm2.createAlgorithm07)({
     35     typed: typed,
     36     DenseMatrix: DenseMatrix
     37   });
     38   var algorithm12 = (0, _algorithm3.createAlgorithm12)({
     39     typed: typed,
     40     DenseMatrix: DenseMatrix
     41   });
     42   var algorithm13 = (0, _algorithm5.createAlgorithm13)({
     43     typed: typed
     44   });
     45   var algorithm14 = (0, _algorithm4.createAlgorithm14)({
     46     typed: typed
     47   });
     48   /**
     49    * Test whether value x is larger than y.
     50    *
     51    * The function returns true when x is larger than y and the relative
     52    * difference between x and y is larger than the configured epsilon. The
     53    * function cannot be used to compare values smaller than approximately 2.22e-16.
     54    *
     55    * For matrices, the function is evaluated element wise.
     56    * Strings are compared by their numerical value.
     57    *
     58    * Syntax:
     59    *
     60    *    math.larger(x, y)
     61    *
     62    * Examples:
     63    *
     64    *    math.larger(2, 3)             // returns false
     65    *    math.larger(5, 2 + 2)         // returns true
     66    *
     67    *    const a = math.unit('5 cm')
     68    *    const b = math.unit('2 inch')
     69    *    math.larger(a, b)             // returns false
     70    *
     71    * See also:
     72    *
     73    *    equal, unequal, smaller, smallerEq, largerEq, compare
     74    *
     75    * @param  {number | BigNumber | Fraction | boolean | Unit | string | Array | Matrix} x First value to compare
     76    * @param  {number | BigNumber | Fraction | boolean | Unit | string | Array | Matrix} y Second value to compare
     77    * @return {boolean | Array | Matrix} Returns true when the x is larger than y, else returns false
     78    */
     79 
     80   return typed(name, {
     81     'boolean, boolean': function booleanBoolean(x, y) {
     82       return x > y;
     83     },
     84     'number, number': function numberNumber(x, y) {
     85       return x > y && !(0, _number.nearlyEqual)(x, y, config.epsilon);
     86     },
     87     'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
     88       return x.gt(y) && !(0, _nearlyEqual.nearlyEqual)(x, y, config.epsilon);
     89     },
     90     'Fraction, Fraction': function FractionFraction(x, y) {
     91       return x.compare(y) === 1;
     92     },
     93     'Complex, Complex': function ComplexComplex() {
     94       throw new TypeError('No ordering relation is defined for complex numbers');
     95     },
     96     'Unit, Unit': function UnitUnit(x, y) {
     97       if (!x.equalBase(y)) {
     98         throw new Error('Cannot compare units with different base');
     99       }
    100 
    101       return this(x.value, y.value);
    102     },
    103     'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
    104       return algorithm07(x, y, this);
    105     },
    106     'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
    107       return algorithm03(y, x, this, true);
    108     },
    109     'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
    110       return algorithm03(x, y, this, false);
    111     },
    112     'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
    113       return algorithm13(x, y, this);
    114     },
    115     'Array, Array': function ArrayArray(x, y) {
    116       // use matrix implementation
    117       return this(matrix(x), matrix(y)).valueOf();
    118     },
    119     'Array, Matrix': function ArrayMatrix(x, y) {
    120       // use matrix implementation
    121       return this(matrix(x), y);
    122     },
    123     'Matrix, Array': function MatrixArray(x, y) {
    124       // use matrix implementation
    125       return this(x, matrix(y));
    126     },
    127     'SparseMatrix, any': function SparseMatrixAny(x, y) {
    128       return algorithm12(x, y, this, false);
    129     },
    130     'DenseMatrix, any': function DenseMatrixAny(x, y) {
    131       return algorithm14(x, y, this, false);
    132     },
    133     'any, SparseMatrix': function anySparseMatrix(x, y) {
    134       return algorithm12(y, x, this, true);
    135     },
    136     'any, DenseMatrix': function anyDenseMatrix(x, y) {
    137       return algorithm14(y, x, this, true);
    138     },
    139     'Array, any': function ArrayAny(x, y) {
    140       // use matrix implementation
    141       return algorithm14(matrix(x), y, this, false).valueOf();
    142     },
    143     'any, Array': function anyArray(x, y) {
    144       // use matrix implementation
    145       return algorithm14(matrix(y), x, this, true).valueOf();
    146     }
    147   });
    148 });
    149 exports.createLarger = createLarger;
    150 var createLargerNumber = /* #__PURE__ */(0, _factory.factory)(name, ['typed', 'config'], function (_ref2) {
    151   var typed = _ref2.typed,
    152       config = _ref2.config;
    153   return typed(name, {
    154     'number, number': function numberNumber(x, y) {
    155       return x > y && !(0, _number.nearlyEqual)(x, y, config.epsilon);
    156     }
    157   });
    158 });
    159 exports.createLargerNumber = createLargerNumber;