log10.js 2.1 KB

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