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

Function mod

src/compute-engine/interval/elementary.ts:589–651  ·  view source on GitHub ↗
(
  a: Interval | IntervalResult,
  b: Interval | IntervalResult
)

Source from the content-addressed store, hash-verified

587 * Domain: positive reals (x > 0)
588 * - Entirely non-positive: empty
589 * - Entirely positive: straightforward monotonic
590 * - Contains/touches zero: partial with -Infinity lower bound
591 */
592function lnRaw(x: Interval | IntervalResult): IntervalResult {
593 const unwrapped = unwrapOrPropagate(x);
594 if (!Array.isArray(unwrapped)) return unwrapped;
595 const [xVal] = unwrapped;
596 // Case 1: Entirely non-positive - no valid values
597 if (xVal.hi <= 0) {
598 return { kind: 'empty' };
599 }
600
601 // Case 2: Entirely positive - straightforward
602 if (xVal.lo > 0) {
603 return ok({ lo: Math.log(xVal.lo), hi: Math.log(xVal.hi) });
604 }
605
606 // Case 3: Includes zero or negative values
607 // ln(x) -> -Infinity as x -> 0+
608 return {
609 kind: 'partial',
610 value: { lo: -Infinity, hi: Math.log(xVal.hi) },
611 domainClipped: 'lo',
612 };
613}
614
615/**
616 * Base-10 logarithm.
617 */
618function log10Raw(x: Interval | IntervalResult): IntervalResult {
619 const unwrapped = unwrapOrPropagate(x);
620 if (!Array.isArray(unwrapped)) return unwrapped;
621 const [xVal] = unwrapped;
622 if (xVal.hi <= 0) {
623 return { kind: 'empty' };
624 }
625
626 if (xVal.lo > 0) {
627 return ok({ lo: Math.log10(xVal.lo), hi: Math.log10(xVal.hi) });
628 }
629
630 return {
631 kind: 'partial',
632 value: { lo: -Infinity, hi: Math.log10(xVal.hi) },
633 domainClipped: 'lo',
634 };
635}
636
637/**
638 * Base-2 logarithm.
639 */
640function log2Raw(x: Interval | IntervalResult): IntervalResult {
641 const unwrapped = unwrapOrPropagate(x);
642 if (!Array.isArray(unwrapped)) return unwrapped;
643 const [xVal] = unwrapped;
644 if (xVal.hi <= 0) {
645 return { kind: 'empty' };
646 }

Callers 1

Calls 5

unwrapOrPropagateFunction · 0.90
containsZeroFunction · 0.90
okFunction · 0.90
absMethod · 0.65
floorMethod · 0.45

Tested by

no test coverage detected