|
sigma
1.0.0
|
Models a closed numeric interval. More...
#include <interval.hpp>
Public Types | |
| using | value_t = ValueType |
| The numeric type of the bounds. | |
Public Member Functions | |
| Interval () | |
| Default constructor. | |
| Interval (value_t value) | |
| Construct an interval from a single value. | |
| Interval (value_t lower, value_t upper) | |
| Construct an interval from two bounds. | |
| value_t | width () const |
| Returns the distance between the interval's bounds. | |
| value_t | median () const |
| Returns the midpoint of the interval. | |
| value_t | radius () const |
| Returns the half-width of the interval. | |
| bool | empty () const |
| Is *this the empty interval? | |
| value_t | lower () const |
| Returns the lower bound of the interval. | |
| value_t | upper () const |
| Returns the upper bound of the interval. | |
| bool | contains (value_t value) const |
| Whether a scalar lies in this interval. | |
| bool | contains (const Interval &other) const |
Is other fully contained in this interval? | |
| Interval | set_union (const Interval &other) const |
| Returns the union of this interval and another interval. | |
| Interval | set_intersection (const Interval &other) const |
| Returns the intersection of this interval and another interval. | |
| Interval | operator- () const |
| Negation of an interval. | |
| Interval & | operator+= (const Interval &rhs) |
| In-place addition of another interval. | |
| Interval & | operator+= (value_t rhs) |
| In-place addition of a scalar. | |
| Interval & | operator-= (const Interval &rhs) |
| In-place subtraction of another interval. | |
| Interval & | operator-= (value_t rhs) |
| In-place subtraction of a scalar. | |
| Interval & | operator*= (const Interval &rhs) |
| In-place multiplication by another interval. | |
| Interval & | operator*= (value_t rhs) |
| In-place multiplication by a scalar. | |
| Interval & | operator/= (const Interval &rhs) |
| In-place division by another interval. | |
| Interval & | operator/= (value_t rhs) |
| In-place division by a scalar. | |
| std::string | print_interval_form () const |
| Print the interval in interval form. | |
Related Symbols | |
(Note that these are not member symbols.) | |
| template<typename ValueType> | |
| std::ostream & | operator<< (std::ostream &os, const Interval< ValueType > &i) |
| Overload stream insertion to print an interval. | |
| template<typename T1, typename T2> | |
| bool | operator== (const Interval< T1 > &lhs, const Interval< T2 > &rhs) |
| Compare two intervals for equality. | |
| template<typename T1, typename T2> | |
| bool | operator!= (const Interval< T1 > &lhs, const Interval< T2 > &rhs) |
| Compare two intervals for inequality. | |
| template<typename T> | |
| bool | operator< (const Interval< T > &lhs, const Interval< T > &rhs) |
| Orders two intervals, primarily by their median. | |
| template<typename T> | |
| bool | operator> (const Interval< T > &lhs, const Interval< T > &rhs) |
| Same ordering as operator<, with the operands reversed. | |
| template<typename T> | |
| bool | operator<= (const Interval< T > &lhs, const Interval< T > &rhs) |
| Same ordering as operator<, negated. | |
| template<typename T> | |
| bool | operator>= (const Interval< T > &lhs, const Interval< T > &rhs) |
| Same ordering as operator<, negated and reversed. | |
| template<typename T> | |
| Interval< T > | widen (const Interval< T > &a, typename Interval< T >::value_t point) |
| Widens an interval just enough to contain a point. | |
| template<typename T> | |
| Interval< T > | operator+ (Interval< T > lhs, const Interval< T > &rhs) |
| Addition of two intervals. | |
| template<typename T> | |
| Interval< T > | operator- (Interval< T > lhs, const Interval< T > &rhs) |
| Subtraction of two intervals. | |
| template<typename T> | |
| Interval< T > | operator* (Interval< T > lhs, const Interval< T > &rhs) |
| Multiplication of two intervals. | |
| template<typename T> | |
| Interval< T > | operator/ (Interval< T > lhs, const Interval< T > &rhs) |
| Division of two intervals. | |
Models a closed numeric interval.
An interval is defined by a lower and upper bound, both of which are members of the set. This class wraps boost::numeric::interval and provides a median (midpoint) and radius (half-width) interface consistent with the rest of the sigma library. An infinite bound means the interval is unbounded in that direction. Intervals whose bounds may be open are represented by GeneralInterval.
| ValueType | The floating-point type of the bounds |
|
inline |
Default constructor.
Constructs an empty interval (contains no values).
| none | No throw guarantee |
|
inline |
Construct an interval from a single value.
Constructs an interval with both bounds set to the given value.
| value | The value to set both bounds to |
| none | No throw guarantee |
|
inline |
|
inline |
Is other fully contained in this interval?
| other | The interval to test. The empty interval is contained in every interval. |
other is in *this.| none | No throw guarantee |
|
inline |
Whether a scalar lies in this interval.
An infinite bound marks an unbounded direction, not a member, so no interval contains an infinite (or NaN) value.
| value | The scalar to test |
value is finite and lower() <= value <= upper(), and false otherwise or if *this is empty.| none | No throw guarantee |
|
inline |
Is *this the empty interval?
The empty interval contains no values.
| none | No throw guarantee |
|
inline |
Returns the lower bound of the interval.
| std::domain_error | if the interval is empty |
|
inline |
Returns the midpoint of the interval.
| std::domain_error | if the interval is empty |
| Interval< ValueType > & sigma::Interval< ValueType >::operator*= | ( | const Interval< ValueType > & | rhs | ) |
In-place multiplication by another interval.
| rhs | The interval to multiply by |
| none | No throw guarantee |
|
inline |
In-place multiplication by a scalar.
| rhs | The scalar to multiply by |
| none | No throw guarantee |
| Interval< ValueType > & sigma::Interval< ValueType >::operator+= | ( | const Interval< ValueType > & | rhs | ) |
In-place addition of another interval.
| rhs | The interval to add |
| none | No throw guarantee |
|
inline |
In-place addition of a scalar.
| rhs | The scalar to add |
| none | No throw guarantee |
|
inline |
Negation of an interval.
Given the interval [a, b], the negation is [-b, -a].
| none | No throw guarantee |
|
inline |
In-place subtraction of another interval.
| rhs | The interval to subtract |
| none | No throw guarantee |
|
inline |
In-place subtraction of a scalar.
| rhs | The scalar to subtract |
| none | No throw guarantee |
| Interval< ValueType > & sigma::Interval< ValueType >::operator/= | ( | const Interval< ValueType > & | rhs | ) |
In-place division by another interval.
| rhs | The interval to divide by |
| std::domain_error | if rhs contains zero, including as a bound. Strong throw guarantee. |
|
inline |
In-place division by a scalar.
| rhs | The scalar to divide by |
| none | No throw guarantee |
| std::string sigma::Interval< ValueType >::print_interval_form | ( | ) | const |
Print the interval in interval form.
The interval is printed as "[lower, upper]".
| none | No throw guarantee |
|
inline |
| Interval< ValueType > sigma::Interval< ValueType >::set_intersection | ( | const Interval< ValueType > & | other | ) | const |
Returns the intersection of this interval and another interval.
The intersection of two intervals is the largest interval that is contained in both intervals.
| other | The interval to intersect with |
other | None | No throw guarantee. |
| Interval< ValueType > sigma::Interval< ValueType >::set_union | ( | const Interval< ValueType > & | other | ) | const |
Returns the union of this interval and another interval.
The union of two intervals is the smallest interval that contains both intervals. Because the result must be an interval, union is only defined when the intervals overlap at least at one point.
| other | The interval to union with |
other | std::domain_error | if the intervals do not overlap. Strong throw guarantee. |
|
inline |
Returns the upper bound of the interval.
| std::domain_error | if the interval is empty |
|
inline |
Returns the distance between the interval's bounds.
The width of an interval is defined by |upper() - lower()|. The width of an empty interval is undefined (and calling this member on an empty interval will cause a domain_error to be thrown)
| std::domain_error | if the interval is empty |
|
Compare two intervals for inequality.
| T1 | The numerical type of the left-hand interval |
| T2 | The numerical type of the right-hand interval |
| lhs | The first interval |
| rhs | The second interval |
Multiplication of two intervals.
| T | The numerical type of the intervals |
| lhs | The left-hand interval |
| rhs | The right-hand interval |
lhs and rhs | none | No throw guarantee |
Addition of two intervals.
| T | The numerical type of the intervals |
| lhs | The left-hand interval |
| rhs | The right-hand interval |
lhs and rhs | none | No throw guarantee |
Subtraction of two intervals.
| T | The numerical type of the intervals |
| lhs | The left-hand interval |
| rhs | The right-hand interval |
lhs and rhs | none | No throw guarantee |
Division of two intervals.
If the interval contains zero the resulting interval will loose most of its information.
| T | The numerical type of the intervals |
| lhs | The left-hand interval |
| rhs | The right-hand interval |
lhs and rhs | none | No throw guarantee |
Orders two intervals, primarily by their median.
Interval containment does not give a total order (overlapping intervals are neither less than, greater than, nor equal to one another under it), so this comparison is a deliberately weaker, total one, meant only for consumers that need some consistent ordering to sort by and not a rigorous enclosure relation. Intervals are compared lexicographically by median, then lower bound, then upper bound. The tie-breaks make the order consistent with operator==: neither of two intervals precedes the other exactly when they are equal, so, e.g., [0, 2] and [-1, 3] are ordered even though they share a median, and intervals can be keys of ordered containers. The empty interval sorts before every non-empty one.
| T | The numerical type of the bounds |
| lhs | The first interval |
| rhs | The second interval |
lhs precedes rhs.| none | No throw guarantee |
|
Overload stream insertion to print an interval.
| ValueType | The numerical type of the bounds |
| os | The ostream to write to |
| i | The interval to write |
| std::ios_base::failure | if anything goes wrong while writing. Weak throw guarantee. |
|
Compare two intervals for equality.
| T1 | The numerical type of the left-hand interval |
| T2 | The numerical type of the right-hand interval |
| lhs | The first interval |
| rhs | The second interval |
|
Widens an interval just enough to contain a point.
| T | The numerical type of the bounds |
| a | The interval to widen |
| point | The value the result must contain. An infinite or NaN value is never a member of an interval, so for one of those the result cannot contain point. |
a if it already contains point. Otherwise a with the bound on the side of point moved to point; the degenerate interval [point, point] if a is empty.| none | No throw guarantee |