simple-squiggle

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

tan.js (1500B)


      1 import { factory } from '../../utils/factory.js';
      2 import { deepMap } from '../../utils/collection.js';
      3 var name = 'tan';
      4 var dependencies = ['typed'];
      5 export var createTan = /* #__PURE__ */factory(name, dependencies, _ref => {
      6   var {
      7     typed
      8   } = _ref;
      9 
     10   /**
     11    * Calculate the tangent of a value. `tan(x)` is equal to `sin(x) / cos(x)`.
     12    *
     13    * For matrices, the function is evaluated element wise.
     14    *
     15    * Syntax:
     16    *
     17    *    math.tan(x)
     18    *
     19    * Examples:
     20    *
     21    *    math.tan(0.5)                    // returns number 0.5463024898437905
     22    *    math.sin(0.5) / math.cos(0.5)    // returns number 0.5463024898437905
     23    *    math.tan(math.pi / 4)            // returns number 1
     24    *    math.tan(math.unit(45, 'deg'))   // returns number 1
     25    *
     26    * See also:
     27    *
     28    *    atan, sin, cos
     29    *
     30    * @param {number | BigNumber | Complex | Unit | Array | Matrix} x  Function input
     31    * @return {number | BigNumber | Complex | Array | Matrix} Tangent of x
     32    */
     33   return typed(name, {
     34     number: Math.tan,
     35     Complex: function Complex(x) {
     36       return x.tan();
     37     },
     38     BigNumber: function BigNumber(x) {
     39       return x.tan();
     40     },
     41     Unit: function Unit(x) {
     42       if (!x.hasBase(x.constructor.BASE_UNITS.ANGLE)) {
     43         throw new TypeError('Unit in function tan is no angle');
     44       }
     45 
     46       return this(x.value);
     47     },
     48     'Array | Matrix': function ArrayMatrix(x) {
     49       // deep map collection, skip zeros since tan(0) = 0
     50       return deepMap(x, this, true);
     51     }
     52   });
     53 });