MCPcopy
hub / github.com/formatjs/formatjs / log

Method log

packages/bigdecimal/index.ts:454–477  ·  view source on GitHub ↗
(base: number)

Source from the content-addressed store, hash-verified

452 }
453
454 log(base: number): BigDecimal {
455 if (this._special === SpecialValue.NAN) return this
456 if (this._special === SpecialValue.NEGATIVE_INFINITY) {
457 return BigDecimal._create(0n, 0, SpecialValue.NAN, false)
458 }
459 if (this._special === SpecialValue.POSITIVE_INFINITY) {
460 return BigDecimal._create(0n, 0, SpecialValue.POSITIVE_INFINITY, false)
461 }
462 if (this._mantissa < 0n) {
463 return BigDecimal._create(0n, 0, SpecialValue.NAN, false)
464 }
465 if (this._mantissa === 0n) {
466 return BigDecimal._create(0n, 0, SpecialValue.NEGATIVE_INFINITY, false)
467 }
468
469 if (base === 10) {
470 return this._log10()
471 }
472
473 // General case: log_b(x) = log10(x) / log10(b)
474 const log10x = this._log10()
475 const log10b = new BigDecimal(Math.log10(base))
476 return log10x.div(log10b)
477 }
478
479 private _log10(): BigDecimal {
480 // log10(mantissa * 10^exponent) = log10(mantissa) + exponent

Callers 15

mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
bigdecimal.test.tsFile · 0.80
analyzeProfileFunction · 0.80
mainFunction · 0.80
profile.tsFile · 0.80
runFunction · 0.80
analyzeProfileFunction · 0.80
mainFunction · 0.80

Calls 3

_log10Method · 0.95
_createMethod · 0.80
divMethod · 0.80

Tested by

no test coverage detected