(x: bigint, bits: number)
| 349 | const LN_AGM_MIN_BITS = 40000; // ≈ 12040 decimal digits |
| 350 | |
| 351 | export 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). |
no test coverage detected