simple-squiggle

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

cube.js (1785B)


      1 "use strict";
      2 
      3 Object.defineProperty(exports, "__esModule", {
      4   value: true
      5 });
      6 exports.createCube = 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 = 'cube';
     15 var dependencies = ['typed'];
     16 var createCube = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
     17   var typed = _ref.typed;
     18 
     19   /**
     20    * Compute the cube of a value, `x * x * x`.
     21    * For matrices, the function is evaluated element wise.
     22    *
     23    * Syntax:
     24    *
     25    *    math.cube(x)
     26    *
     27    * Examples:
     28    *
     29    *    math.cube(2)            // returns number 8
     30    *    math.pow(2, 3)          // returns number 8
     31    *    math.cube(4)            // returns number 64
     32    *    4 * 4 * 4               // returns number 64
     33    *
     34    *    math.cube([1, 2, 3, 4]) // returns Array [1, 8, 27, 64]
     35    *
     36    * See also:
     37    *
     38    *    multiply, square, pow, cbrt
     39    *
     40    * @param  {number | BigNumber | Fraction | Complex | Array | Matrix | Unit} x  Number for which to calculate the cube
     41    * @return {number | BigNumber | Fraction | Complex | Array | Matrix | Unit} Cube of x
     42    */
     43   return typed(name, {
     44     number: _index.cubeNumber,
     45     Complex: function Complex(x) {
     46       return x.mul(x).mul(x); // Is faster than pow(x, 3)
     47     },
     48     BigNumber: function BigNumber(x) {
     49       return x.times(x).times(x);
     50     },
     51     Fraction: function Fraction(x) {
     52       return x.pow(3); // Is faster than mul()mul()mul()
     53     },
     54     'Array | Matrix': function ArrayMatrix(x) {
     55       // deep map collection, skip zeros since cube(0) = 0
     56       return (0, _collection.deepMap)(x, this, true);
     57     },
     58     Unit: function Unit(x) {
     59       return x.pow(3);
     60     }
     61   });
     62 });
     63 exports.createCube = createCube;