(x: Interval | IntervalResult)
| 399 | * Absolute value of an interval. |
| 400 | */ |
| 401 | export function abs(x: Interval | IntervalResult): IntervalResult { |
| 402 | const unwrapped = unwrapOrPropagate(x); |
| 403 | if (!Array.isArray(unwrapped)) return unwrapped; |
| 404 | const [xVal] = unwrapped; |
| 405 | if (xVal.lo >= 0) { |
| 406 | return ok(xVal); |
| 407 | } |
| 408 | if (xVal.hi <= 0) { |
| 409 | return ok({ lo: -xVal.hi, hi: -xVal.lo }); |
| 410 | } |
| 411 | // Interval straddles zero - minimum is 0 |
| 412 | return ok({ lo: 0, hi: Math.max(-xVal.lo, xVal.hi) }); |
| 413 | } |
| 414 | |
| 415 | /** |
| 416 | * Floor function (greatest integer <= x). |
no test coverage detected