simple-squiggle

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

csc.js (1370B)


      1 import { factory } from '../../utils/factory.js';
      2 import { deepMap } from '../../utils/collection.js';
      3 import { cscNumber } from '../../plain/number/index.js';
      4 var name = 'csc';
      5 var dependencies = ['typed', 'BigNumber'];
      6 export var createCsc = /* #__PURE__ */factory(name, dependencies, _ref => {
      7   var {
      8     typed,
      9     BigNumber: _BigNumber
     10   } = _ref;
     11 
     12   /**
     13    * Calculate the cosecant of a value, defined as `csc(x) = 1/sin(x)`.
     14    *
     15    * For matrices, the function is evaluated element wise.
     16    *
     17    * Syntax:
     18    *
     19    *    math.csc(x)
     20    *
     21    * Examples:
     22    *
     23    *    math.csc(2)      // returns number 1.099750170294617
     24    *    1 / math.sin(2)  // returns number 1.099750170294617
     25    *
     26    * See also:
     27    *
     28    *    sin, sec, cot
     29    *
     30    * @param {number | Complex | Unit | Array | Matrix} x  Function input
     31    * @return {number | Complex | Array | Matrix} Cosecant of x
     32    */
     33   return typed(name, {
     34     number: cscNumber,
     35     Complex: function Complex(x) {
     36       return x.csc();
     37     },
     38     BigNumber: function BigNumber(x) {
     39       return new _BigNumber(1).div(x.sin());
     40     },
     41     Unit: function Unit(x) {
     42       if (!x.hasBase(x.constructor.BASE_UNITS.ANGLE)) {
     43         throw new TypeError('Unit in function csc is no angle');
     44       }
     45 
     46       return this(x.value);
     47     },
     48     'Array | Matrix': function ArrayMatrix(x) {
     49       return deepMap(x, this);
     50     }
     51   });
     52 });