Struct Interval

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

struct Interval(T)
  
if (isSigned!T);

Fields

NameTypeDescription
a TThe interval endpoints.
b TThe interval endpoints.

Properties

NameTypeDescription
isInfinite[get] boolDetermine 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[get] boolDetermine whether this is an ordered interval, i.e. whether a <= b.
length[get] TThe length of the interval, defined as b-a.

Methods

NameDescription
contains Check whether the value x is contained in the interval, i.e. whether a <= x <= b or b <= x <= a.
order If a > b, swap the endpoints.

Examples

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

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