Interval arithmetic over conforming Quantities. An interval denotes every value between its endpoints; arithmetic yields the tightest interval containing every result (the interval-inclusion property). Endpoints are Quantities (or plain numbers), kept exact.
Two shapes, unified by the IInterval protocol (lo/hi/main-value):
Interval2 [lo hi] — a plain range.Interval3 [lo main hi] — a range with a main value (Frink's mainValue): a
best-known estimate that need not be the center. It propagates through arithmetic (the
same op applied to the operands' mains) and is dropped the moment any operand lacks one,
so [2,2.5,3] * [7,8.2,9.4] = [14, 20.5, 28.2].Per Frink, a bare number/Quantity is not an interval. Only the two records implement
IInterval; the *-or-identity accessors add the degenerate case (mainValue[5]=5) by
returning a non-interval unchanged (its own bound), which is why the arithmetic and the
comparison operators need no scalar 'promotion'. interval? is false for a scalar.
An interval prints as its raw record (endpoints as their own #commensura/quantity
literals) — no bespoke tagged literal — which is readable and round-trips losslessly.
The commensura.core verbs (by/per/plus/minus/pow/to/ratio) accept intervals
transparently.
Interval arithmetic over conforming Quantities. An interval denotes every value between
its endpoints; arithmetic yields the tightest interval containing every result (the
interval-inclusion property). Endpoints are Quantities (or plain numbers), kept exact.
Two shapes, unified by the `IInterval` protocol (`lo`/`hi`/`main-value`):
* `Interval2 [lo hi]` — a plain range.
* `Interval3 [lo main hi]` — a range with a *main value* (Frink's `mainValue`): a
best-known estimate that need not be the center. It propagates through arithmetic (the
same op applied to the operands' mains) and is dropped the moment any operand lacks one,
so `[2,2.5,3] * [7,8.2,9.4] = [14, 20.5, 28.2]`.
Per Frink, a bare number/Quantity is *not* an interval. Only the two records implement
`IInterval`; the `*-or-identity` accessors add the degenerate case (`mainValue[5]=5`) by
returning a non-interval unchanged (its own bound), which is why the arithmetic and the
comparison operators need no scalar 'promotion'. `interval?` is false for a scalar.
An interval prints as its raw record (endpoints as their own `#commensura/quantity`
literals) — no bespoke tagged literal — which is readable and round-trips losslessly.
The `commensura.core` verbs (`by`/`per`/`plus`/`minus`/`pow`/`to`/`ratio`) accept intervals
transparently.(hi-or-identity x)An interval's upper bound; any other value is returned as-is.
An interval's upper bound; any other value is returned as-is.
(hi x)Upper bound.
Upper bound.
(lo x)Lower bound (a bare value is its own bound).
Lower bound (a bare value is its own bound).
(main-value x)Best-known estimate (Frink's mainValue), or nil for a plain interval.
Best-known estimate (Frink's `mainValue`), or nil for a plain interval.
(interval a b)(interval a m b)Construct from two conforming endpoints (auto-ordered by magnitude; bare decimals are
rationalized, like the rest of commensura). The 3-arity adds a main value m — the
best-known estimate; it must conform and lie within [lo, hi], but need not be the center,
and propagates through arithmetic.
Construct from two conforming endpoints (auto-ordered by magnitude; bare decimals are rationalized, like the rest of commensura). The 3-arity adds a *main value* `m` — the best-known estimate; it must conform and lie within [lo, hi], but need not be the center, and propagates through arithmetic.
(lo-or-identity x)An interval's lower bound; any other value is returned as-is (a point is its own bound).
An interval's lower bound; any other value is returned as-is (a point is its own bound).
(main-value-or-identity x)An interval's main value (nil for a plain Interval2); any other value is returned as-is.
An interval's main value (nil for a plain Interval2); any other value is returned as-is.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |