Interval

An interval [a,b] along the real line, where either endpoint may be infinite.

Members

Functions

contains
bool contains(X x)

Check whether the value x is contained in the interval, i.e. whether a <= x <= b or b <= x <= a.

order
void order()

If a > b, swap the endpoints.

Properties

isInfinite
bool isInfinite [@property getter]

Determine whether the interval is infinite. This is true if:

  • a is infinite, b is finite
  • a is finite, b is infinite
  • a and b are infinite, but have opposite sign.

If T is an integer type, this is always false.

isOrdered
bool isOrdered [@property getter]

Determine whether this is an ordered interval, i.e. whether a <= b.

length
T length [@property getter]

The length of the interval, defined as b-a.

Variables

a
T a;
b
T b;

The interval endpoints.

Examples

auto i1 = interval(1, 5);
assert (i1.length == 4);

auto i2 = interval(0, real.infinity);
assert (i2.isInfinite);

Meta