simple-squiggle

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

cos.js (1687B)


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