1 | import { factory } from '../../utils/factory.js';
|
2 | import { deepMap } from '../../utils/collection.js';
|
3 | import { log10Number } from '../../plain/number/index.js';
|
4 | var name = 'log10';
|
5 | var dependencies = ['typed', 'config', 'Complex'];
|
6 | export var createLog10 = /* #__PURE__ */factory(name, dependencies, (_ref) => {
|
7 | var {
|
8 | typed,
|
9 | config,
|
10 | Complex: _Complex
|
11 | } = _ref;
|
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 | return 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, this);
|
60 | }
|
61 | });
|
62 | }); |
\ | No newline at end of file |