* Tight enclosure of an integer-valued binary function over the integer grid * spanned by two intervals, by enumerating every grid point. Returns `null` * when the grid is too large to enumerate (caller supplies a conservative * fallback). Corner sampling is unsound here: these functions are not
( a: Interval, b: Interval, f: (x: number, y: number) => number )
| 909 | } |
| 910 | |
| 911 | if (xVal.lo > 0) { |
| 912 | return ok({ lo: Math.log2(xVal.lo), hi: Math.log2(xVal.hi) }); |
| 913 | } |
| 914 | |
| 915 | return { |
| 916 | kind: 'partial', |
| 917 | value: { lo: -Infinity, hi: Math.log2(xVal.hi) }, |
| 918 | domainClipped: 'lo', |
| 919 | }; |
| 920 | } |
| 921 | |
| 922 | /** |
| 923 | * Absolute value of an interval. |
| 924 | */ |
| 925 | function absRaw(x: Interval | IntervalResult): IntervalResult { |
| 926 | const unwrapped = unwrapOrPropagate(x); |
| 927 | if (!Array.isArray(unwrapped)) return unwrapped; |
| 928 | const [xVal] = unwrapped; |
| 929 | if (isNaNInterval(xVal)) return ok(NAN_INTERVAL); |
| 930 | if (xVal.lo >= 0) { |
| 931 | return ok(xVal); |
| 932 | } |
| 933 | if (xVal.hi <= 0) { |
| 934 | return ok({ lo: -xVal.hi, hi: -xVal.lo }); |