intrvals
intrvals is a generic intervals library with basic
arithmetic (+, -, *)
and sets (union, intersect, complement) operations support.
Its main structure is an Interval which represents
a single-dimensioned (possibly unbounded) span of values instantiated by any type T.
macro syntax
Allows to simplify the defintions of an interval in common inequality and ranges terms.
For the half-open intervals, the inclusive bound is marked with = symbol;
for the closed interval both [a, b] and (=a, =b) defintions are possible.
use ;
let i0: = interval!;
assert_eq!;
let igt2: = interval!;
assert_eq!;
let igt10: = interval!;
assert_eq!;
let i_2to10_incl: = interval!;
assert_eq!;
let i5to20_excl: = interval!;
assert_eq!;
let iuni: = interval!;
assert_eq!;
common functions
use Ordering;
use ;
assert!;
assert!;
assert!;
assert!;
assert!;
let igt10 = interval!;
assert!;
assert!;
assert!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
let i_left_open = interval!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
scalar arithmetic
Add, subtract or multiply the interval bounds with a scalar value of type U
if the underlying type T: {Add, Sub, Mult}<U>:
use ;
// negation changes the sign and flips the bounds
assert_eq!;
assert_eq!;
// full and empy does not change with scalars
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
// however, multiplying by 0 is different
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
// multiplying/dividing by negative flips the bounds
assert_eq!;
assert_eq!;
interval arithmetic
Add, subtract or multiply an Interval<T> with an Interval<U>
to produce another Interval<Z>
if the underlying type T: {Add, Sub, Mult}<U, Output=Z>:
use interval;
let i0 = interval!;
let igt10 = interval!;
let i_2to10_incl = interval!;
let i5to20_excl = interval!;
let iuni = interval!;
assert_eq!;
// adding degenerate does not change the normal one
assert_eq!;
assert_eq!;
assert_eq!;
// subtracting degenerate does not change the normal one
assert_eq!;
// subtracting _from_ degenerate negates the normal one
assert_eq!;
// Interval::Empty is neutral over multiplication
assert_eq!;
// positive (+inf) times positive is positive
assert_eq!;
// positive (+inf) times (negative and positive) is (-inf, +inf)
assert_eq!;
assert_eq!;
// Interval::Full is neutral over multiplication
assert_eq!;
set operations
use ;
let igt2 = interval!;
let igt10 = interval!;
assert_eq!;
// `.complement` is aliased with `!`
assert_eq!;
assert_eq!;
// `.intersect` is aliased with `&` (falling back to Interval::Empty)
assert!;
assert_eq!;
assert_eq!;
// `.union` is aliased with `|` (falling back to the first non-empty if possible)
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;