simple-squiggle

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

sec.js (1370B)


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