simple-squiggle

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

log10.js (2066B)


      1 "use strict";
      2 
      3 Object.defineProperty(exports, "__esModule", {
      4   value: true
      5 });
      6 exports.createLog10 = 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 = 'log10';
     15 var dependencies = ['typed', 'config', 'Complex'];
     16 var createLog10 = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
     17   var typed = _ref.typed,
     18       config = _ref.config,
     19       _Complex = _ref.Complex;
     20 
     21   /**
     22    * Calculate the 10-base logarithm of a value. This is the same as calculating `log(x, 10)`.
     23    *
     24    * For matrices, the function is evaluated element wise.
     25    *
     26    * Syntax:
     27    *
     28    *    math.log10(x)
     29    *
     30    * Examples:
     31    *
     32    *    math.log10(0.00001)            // returns -5
     33    *    math.log10(10000)              // returns 4
     34    *    math.log(10000) / math.log(10) // returns 4
     35    *    math.pow(10, 4)                // returns 10000
     36    *
     37    * See also:
     38    *
     39    *    exp, log, log1p, log2
     40    *
     41    * @param {number | BigNumber | Complex | Array | Matrix} x
     42    *            Value for which to calculate the logarithm.
     43    * @return {number | BigNumber | Complex | Array | Matrix}
     44    *            Returns the 10-base logarithm of `x`
     45    */
     46   return typed(name, {
     47     number: function number(x) {
     48       if (x >= 0 || config.predictable) {
     49         return (0, _index.log10Number)(x);
     50       } else {
     51         // negative value -> complex value computation
     52         return new _Complex(x, 0).log().div(Math.LN10);
     53       }
     54     },
     55     Complex: function Complex(x) {
     56       return new _Complex(x).log().div(Math.LN10);
     57     },
     58     BigNumber: function BigNumber(x) {
     59       if (!x.isNegative() || config.predictable) {
     60         return x.log();
     61       } else {
     62         // downgrade to number, return Complex valued result
     63         return new _Complex(x.toNumber(), 0).log().div(Math.LN10);
     64       }
     65     },
     66     'Array | Matrix': function ArrayMatrix(x) {
     67       return (0, _collection.deepMap)(x, this);
     68     }
     69   });
     70 });
     71 exports.createLog10 = createLog10;