simple-squiggle

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

cot.js (1565B)


      1 "use strict";
      2 
      3 Object.defineProperty(exports, "__esModule", {
      4   value: true
      5 });
      6 exports.createCot = void 0;
      7 
      8 var _factory = require("../../utils/factory.js");
      9 
     10 var _collection = require("../../utils/collection.js");
     11 
     12 var _index = require("../../plain/number/index.js");
     13 
     14 var name = 'cot';
     15 var dependencies = ['typed', 'BigNumber'];
     16 var createCot = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
     17   var typed = _ref.typed,
     18       _BigNumber = _ref.BigNumber;
     19 
     20   /**
     21    * Calculate the cotangent of a value. Defined as `cot(x) = 1 / tan(x)`.
     22    *
     23    * For matrices, the function is evaluated element wise.
     24    *
     25    * Syntax:
     26    *
     27    *    math.cot(x)
     28    *
     29    * Examples:
     30    *
     31    *    math.cot(2)      // returns number -0.45765755436028577
     32    *    1 / math.tan(2)  // returns number -0.45765755436028577
     33    *
     34    * See also:
     35    *
     36    *    tan, sec, csc
     37    *
     38    * @param {number | Complex | Unit | Array | Matrix} x  Function input
     39    * @return {number | Complex | Array | Matrix} Cotangent of x
     40    */
     41   return typed(name, {
     42     number: _index.cotNumber,
     43     Complex: function Complex(x) {
     44       return x.cot();
     45     },
     46     BigNumber: function BigNumber(x) {
     47       return new _BigNumber(1).div(x.tan());
     48     },
     49     Unit: function Unit(x) {
     50       if (!x.hasBase(x.constructor.BASE_UNITS.ANGLE)) {
     51         throw new TypeError('Unit in function cot is no angle');
     52       }
     53 
     54       return this(x.value);
     55     },
     56     'Array | Matrix': function ArrayMatrix(x) {
     57       return (0, _collection.deepMap)(x, this);
     58     }
     59   });
     60 });
     61 exports.createCot = createCot;