mathjs
Version:
Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with dif
80 lines (78 loc) • 2.61 kB
JavaScript
import { factory } from '../../utils/factory.js';
import { createMatAlgo03xDSf } from '../../type/matrix/utils/matAlgo03xDSf.js';
import { createMatAlgo05xSfSf } from '../../type/matrix/utils/matAlgo05xSfSf.js';
import { createMatAlgo12xSfs } from '../../type/matrix/utils/matAlgo12xSfs.js';
import { createMatrixAlgorithmSuite } from '../../type/matrix/utils/matrixAlgorithmSuite.js';
var name = 'atan2';
var dependencies = ['typed', 'matrix', 'BigNumber', 'DenseMatrix'];
export var createAtan2 = /* #__PURE__ */factory(name, dependencies, _ref => {
var typed = _ref.typed,
matrix = _ref.matrix,
BigNumber = _ref.BigNumber,
DenseMatrix = _ref.DenseMatrix;
var matAlgo03xDSf = createMatAlgo03xDSf({
typed
});
var matAlgo05xSfSf = createMatAlgo05xSfSf({
typed
});
var matAlgo12xSfs = createMatAlgo12xSfs({
typed,
DenseMatrix
});
var matrixAlgorithmSuite = createMatrixAlgorithmSuite({
typed,
matrix
});
/**
* Calculate the inverse tangent function with two arguments, y/x.
* By providing two arguments, the right quadrant of the computed angle can be
* determined.
*
* For matrices, the function is evaluated element wise.
*
* Syntax:
*
* math.atan2(y, x)
*
* Examples:
*
* math.atan2(2, 2) / math.pi // returns number 0.25
*
* const angle = math.unit(60, 'deg')
* const x = math.cos(angle)
* const y = math.sin(angle)
* math.atan2(y, x) * 180 / math.pi // returns 60
*
* math.atan(2) // returns number 1.1071487177940904
*
* See also:
*
* tan, atan, sin, cos
*
* History:
*
* v11.6 Support matrix broadcasting
* v1.5 Support BigNumber arguments
*
* @param {number | Array | Matrix} y Second dimension
* @param {number | Array | Matrix} x First dimension
* @return {number | Array | Matrix} Four-quadrant inverse tangent
*/
return typed(name, {
'number, number': Math.atan2,
// Complex numbers doesn't seem to have a reasonable implementation of
// atan2(). Even Matlab removed the support, after they only calculated
// the atan only on base of the real part of the numbers and ignored
// the imaginary.
'BigNumber, BigNumber': (y, x) => BigNumber.atan2(y, x)
}, matrixAlgorithmSuite({
scalar: 'number | BigNumber',
// atan2(0, x) is not 0 for x < 0 and atan2(y, 0) is not 0 for y != 0,
// so every entry has to be evaluated, not only the ones where both
// operands are nonzero
SS: matAlgo05xSfSf,
DS: matAlgo03xDSf,
Ss: matAlgo12xSfs
}));
});