MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / fpln

Function fpln

src/big-decimal/utils.ts:351–362  ·  view source on GitHub ↗
(x: bigint, bits: number)

Source from the content-addressed store, hash-verified

349const LN_AGM_MIN_BITS = 40000; // ≈ 12040 decimal digits
350
351export function fpln(x: bigint, bits: number): bigint {
352 const scale = 1n << BigInt(bits);
353 // Defense in depth: a non-positive input is a caller bug (callers
354 // range-reduce so the kernel only sees O(1) positive values). A zero
355 // input used to hang forever in the sqrt-reduction loop (fpsqrt(0) = 0).
356 if (x <= 0n) throw new RangeError('fpln: input must be positive');
357
358 // ln(1) = 0
359 if (x === scale) return 0n;
360
361 return bits >= LN_AGM_MIN_BITS ? fplnAGM(x, bits) : fplnDirect(x, bits);
362}
363
364/**
365 * Direct-log fixed-point natural logarithm (machine-seed + log1p correction).

Callers 3

utils.test.tsFile · 0.90
ln10FixedFunction · 0.90
transcendentals.tsFile · 0.90

Calls 2

fplnAGMFunction · 0.85
fplnDirectFunction · 0.85

Tested by

no test coverage detected