simple-squiggle

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

atan2.js (4296B)


      1 import { factory } from '../../utils/factory.js';
      2 import { createAlgorithm02 } from '../../type/matrix/utils/algorithm02.js';
      3 import { createAlgorithm03 } from '../../type/matrix/utils/algorithm03.js';
      4 import { createAlgorithm09 } from '../../type/matrix/utils/algorithm09.js';
      5 import { createAlgorithm11 } from '../../type/matrix/utils/algorithm11.js';
      6 import { createAlgorithm12 } from '../../type/matrix/utils/algorithm12.js';
      7 import { createAlgorithm13 } from '../../type/matrix/utils/algorithm13.js';
      8 import { createAlgorithm14 } from '../../type/matrix/utils/algorithm14.js';
      9 var name = 'atan2';
     10 var dependencies = ['typed', 'matrix', 'equalScalar', 'BigNumber', 'DenseMatrix'];
     11 export var createAtan2 = /* #__PURE__ */factory(name, dependencies, _ref => {
     12   var {
     13     typed,
     14     matrix,
     15     equalScalar,
     16     BigNumber,
     17     DenseMatrix
     18   } = _ref;
     19   var algorithm02 = createAlgorithm02({
     20     typed,
     21     equalScalar
     22   });
     23   var algorithm03 = createAlgorithm03({
     24     typed
     25   });
     26   var algorithm09 = createAlgorithm09({
     27     typed,
     28     equalScalar
     29   });
     30   var algorithm11 = createAlgorithm11({
     31     typed,
     32     equalScalar
     33   });
     34   var algorithm12 = createAlgorithm12({
     35     typed,
     36     DenseMatrix
     37   });
     38   var algorithm13 = createAlgorithm13({
     39     typed
     40   });
     41   var algorithm14 = createAlgorithm14({
     42     typed
     43   });
     44   /**
     45    * Calculate the inverse tangent function with two arguments, y/x.
     46    * By providing two arguments, the right quadrant of the computed angle can be
     47    * determined.
     48    *
     49    * For matrices, the function is evaluated element wise.
     50    *
     51    * Syntax:
     52    *
     53    *    math.atan2(y, x)
     54    *
     55    * Examples:
     56    *
     57    *    math.atan2(2, 2) / math.pi       // returns number 0.25
     58    *
     59    *    const angle = math.unit(60, 'deg') // returns Unit 60 deg
     60    *    const x = math.cos(angle)
     61    *    const y = math.sin(angle)
     62    *
     63    *    math.atan(2)             // returns Complex 1.5707963267948966 -1.3169578969248166 i
     64    *
     65    * See also:
     66    *
     67    *    tan, atan, sin, cos
     68    *
     69    * @param {number | Array | Matrix} y  Second dimension
     70    * @param {number | Array | Matrix} x  First dimension
     71    * @return {number | Array | Matrix} Four-quadrant inverse tangent
     72    */
     73 
     74   return typed(name, {
     75     'number, number': Math.atan2,
     76     // Complex numbers doesn't seem to have a reasonable implementation of
     77     // atan2(). Even Matlab removed the support, after they only calculated
     78     // the atan only on base of the real part of the numbers and ignored the imaginary.
     79     'BigNumber, BigNumber': function BigNumberBigNumber(y, x) {
     80       return BigNumber.atan2(y, x);
     81     },
     82     'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
     83       return algorithm09(x, y, this, false);
     84     },
     85     'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
     86       // mind the order of y and x!
     87       return algorithm02(y, x, this, true);
     88     },
     89     'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
     90       return algorithm03(x, y, this, false);
     91     },
     92     'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
     93       return algorithm13(x, y, this);
     94     },
     95     'Array, Array': function ArrayArray(x, y) {
     96       return this(matrix(x), matrix(y)).valueOf();
     97     },
     98     'Array, Matrix': function ArrayMatrix(x, y) {
     99       return this(matrix(x), y);
    100     },
    101     'Matrix, Array': function MatrixArray(x, y) {
    102       return this(x, matrix(y));
    103     },
    104     'SparseMatrix, number | BigNumber': function SparseMatrixNumberBigNumber(x, y) {
    105       return algorithm11(x, y, this, false);
    106     },
    107     'DenseMatrix, number | BigNumber': function DenseMatrixNumberBigNumber(x, y) {
    108       return algorithm14(x, y, this, false);
    109     },
    110     'number | BigNumber, SparseMatrix': function numberBigNumberSparseMatrix(x, y) {
    111       // mind the order of y and x
    112       return algorithm12(y, x, this, true);
    113     },
    114     'number | BigNumber, DenseMatrix': function numberBigNumberDenseMatrix(x, y) {
    115       // mind the order of y and x
    116       return algorithm14(y, x, this, true);
    117     },
    118     'Array, number | BigNumber': function ArrayNumberBigNumber(x, y) {
    119       return algorithm14(matrix(x), y, this, false).valueOf();
    120     },
    121     'number | BigNumber, Array': function numberBigNumberArray(x, y) {
    122       return algorithm14(matrix(y), x, this, true).valueOf();
    123     }
    124   });
    125 });