UNPKG

1.89 kBJavaScriptView Raw
1import { factory } from '../../utils/factory';
2import { deepMap } from '../../utils/collection';
3import { log10Number } from '../../plain/number';
4var name = 'log10';
5var dependencies = ['typed', 'config', 'Complex'];
6export var createLog10 =
7/* #__PURE__ */
8factory(name, dependencies, function (_ref) {
9 var typed = _ref.typed,
10 config = _ref.config,
11 _Complex = _ref.Complex;
12
13 /**
14 * Calculate the 10-base logarithm of a value. This is the same as calculating `log(x, 10)`.
15 *
16 * For matrices, the function is evaluated element wise.
17 *
18 * Syntax:
19 *
20 * math.log10(x)
21 *
22 * Examples:
23 *
24 * math.log10(0.00001) // returns -5
25 * math.log10(10000) // returns 4
26 * math.log(10000) / math.log(10) // returns 4
27 * math.pow(10, 4) // returns 10000
28 *
29 * See also:
30 *
31 * exp, log, log1p, log2
32 *
33 * @param {number | BigNumber | Complex | Array | Matrix} x
34 * Value for which to calculate the logarithm.
35 * @return {number | BigNumber | Complex | Array | Matrix}
36 * Returns the 10-base logarithm of `x`
37 */
38 var log10 = typed(name, {
39 number: function number(x) {
40 if (x >= 0 || config.predictable) {
41 return log10Number(x);
42 } else {
43 // negative value -> complex value computation
44 return new _Complex(x, 0).log().div(Math.LN10);
45 }
46 },
47 Complex: function Complex(x) {
48 return new _Complex(x).log().div(Math.LN10);
49 },
50 BigNumber: function BigNumber(x) {
51 if (!x.isNegative() || config.predictable) {
52 return x.log();
53 } else {
54 // downgrade to number, return Complex valued result
55 return new _Complex(x.toNumber(), 0).log().div(Math.LN10);
56 }
57 },
58 'Array | Matrix': function ArrayMatrix(x) {
59 return deepMap(x, log10);
60 }
61 });
62 return log10;
63});
\No newline at end of file