(x: Interval | IntervalResult)
| 329 | * - Contains/touches zero: partial with -Infinity lower bound |
| 330 | */ |
| 331 | export function ln(x: Interval | IntervalResult): IntervalResult { |
| 332 | const unwrapped = unwrapOrPropagate(x); |
| 333 | if (!Array.isArray(unwrapped)) return unwrapped; |
| 334 | const [xVal] = unwrapped; |
| 335 | // Case 1: Entirely non-positive - no valid values |
| 336 | if (xVal.hi <= 0) { |
| 337 | return { kind: 'empty' }; |
| 338 | } |
| 339 | |
| 340 | // Case 2: Entirely positive - straightforward |
| 341 | if (xVal.lo > 0) { |
| 342 | return ok({ lo: Math.log(xVal.lo), hi: Math.log(xVal.hi) }); |
| 343 | } |
| 344 | |
| 345 | // Case 3: Includes zero or negative values |
| 346 | // ln(x) -> -Infinity as x -> 0+ |
| 347 | return { |
| 348 | kind: 'partial', |
| 349 | value: { lo: -Infinity, hi: Math.log(xVal.hi) }, |
| 350 | domainClipped: 'lo', |
| 351 | }; |
| 352 | } |
| 353 | |
| 354 | /** |
| 355 | * Base-10 logarithm. |
no test coverage detected