sigma  1.0.0
Loading...
Searching...
No Matches
sigma::Interval< ValueType > Class Template Reference

Models a 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 lower and upper bounds.
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 (endpoints included).
value_t median () const
 Returns the midpoint of the interval.
value_t radius () const
 Returns the half-width of the interval.
Intervaloperator+= (const Interval &rhs)
 In-place addition of another interval.
Intervaloperator+= (value_t rhs)
 In-place addition of a scalar.
Intervaloperator-= (const Interval &rhs)
 In-place subtraction of another interval.
Intervaloperator-= (value_t rhs)
 In-place subtraction of a scalar.
Intervaloperator*= (const Interval &rhs)
 In-place multiplication by another interval.
Intervaloperator*= (value_t rhs)
 In-place multiplication by a scalar.
Intervaloperator/= (const Interval &rhs)
 In-place division by another interval.
Intervaloperator/= (value_t rhs)
 In-place division by a scalar.

(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 T1, typename T2>
bool operator< (const Interval< T1 > &lhs, const Interval< T2 > &rhs)
 Whether one interval is certainly less than another.
template<typename T1, typename T2>
bool operator> (const Interval< T1 > &lhs, const Interval< T2 > &rhs)
 Whether one interval is greater than another.
template<typename T1, typename T2>
bool operator<= (const Interval< T1 > &lhs, const Interval< T2 > &rhs)
 Whether one interval is less than or equal to another.
template<typename T1, typename T2>
bool operator>= (const Interval< T1 > &lhs, const Interval< T2 > &rhs)
 Whether one interval is greater than or equal to another.
template<typename T>
Interval< T > operator- (const Interval< T > &a)
 Negation of an interval.
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.

Detailed Description

template<typename ValueType>
class sigma::Interval< ValueType >

Models a numeric interval.

An interval is defined by a lower and upper bound. This class wraps boost::numeric::interval and provides a median (midpoint) and radius (half-width) interface consistent with the rest of the sigma library.

Template Parameters
ValueTypeThe floating-point type of the bounds

Constructor & Destructor Documentation

◆ Interval() [1/3]

template<typename ValueType>
sigma::Interval< ValueType >::Interval ( )
inline

Default constructor.

Constructs an interval with both bounds set to 0.0.

Exceptions
noneNo throw guarantee

◆ Interval() [2/3]

template<typename ValueType>
sigma::Interval< ValueType >::Interval ( value_t value)
inline

Construct an interval from a single value.

Constructs an interval with both bounds set to the given value.

Parameters
valueThe value to set both bounds to
Exceptions
noneNo throw guarantee

◆ Interval() [3/3]

template<typename ValueType>
sigma::Interval< ValueType >::Interval ( value_t lower,
value_t upper )
inline

Construct an interval from lower and upper bounds.

Parameters
lowerThe lower bound of the interval
upperThe upper bound of the interval
Exceptions
noneNo throw guarantee

Member Function Documentation

◆ contains()

template<typename ValueType>
bool sigma::Interval< ValueType >::contains ( value_t value) const
inline

Whether a scalar lies in this interval (endpoints included).

Returns true if lower() <= value <= upper(). Boundary values are considered contained.

Parameters
valueThe scalar to test
Returns
True if value lies in the closed interval from lower() to upper()
Exceptions
noneNo throw guarantee

◆ lower()

template<typename ValueType>
value_t sigma::Interval< ValueType >::lower ( ) const
inline

Returns the lower bound of the interval.

Returns
The lower bound value
Exceptions
noneNo throw guarantee

◆ median()

template<typename ValueType>
value_t sigma::Interval< ValueType >::median ( ) const
inline

Returns the midpoint of the interval.

Returns
The midpoint value
Exceptions
noneNo throw guarantee

◆ operator*=() [1/2]

template<typename ValueType>
Interval & sigma::Interval< ValueType >::operator*= ( const Interval< ValueType > & rhs)
inline

In-place multiplication by another interval.

Parameters
rhsThe interval to multiply by
Returns
Reference to this interval after multiplication
Exceptions
noneNo throw guarantee

◆ operator*=() [2/2]

template<typename ValueType>
Interval & sigma::Interval< ValueType >::operator*= ( value_t rhs)
inline

In-place multiplication by a scalar.

Parameters
rhsThe scalar to multiply by
Returns
Reference to this interval after multiplication
Exceptions
noneNo throw guarantee

◆ operator+=() [1/2]

template<typename ValueType>
Interval & sigma::Interval< ValueType >::operator+= ( const Interval< ValueType > & rhs)
inline

In-place addition of another interval.

Parameters
rhsThe interval to add
Returns
Reference to this interval after addition
Exceptions
noneNo throw guarantee

◆ operator+=() [2/2]

template<typename ValueType>
Interval & sigma::Interval< ValueType >::operator+= ( value_t rhs)
inline

In-place addition of a scalar.

Parameters
rhsThe scalar to add
Returns
Reference to this interval after addition
Exceptions
noneNo throw guarantee

◆ operator-=() [1/2]

template<typename ValueType>
Interval & sigma::Interval< ValueType >::operator-= ( const Interval< ValueType > & rhs)
inline

In-place subtraction of another interval.

Parameters
rhsThe interval to subtract
Returns
Reference to this interval after subtraction
Exceptions
noneNo throw guarantee

◆ operator-=() [2/2]

template<typename ValueType>
Interval & sigma::Interval< ValueType >::operator-= ( value_t rhs)
inline

In-place subtraction of a scalar.

Parameters
rhsThe scalar to subtract
Returns
Reference to this interval after subtraction
Exceptions
noneNo throw guarantee

◆ operator/=() [1/2]

template<typename ValueType>
Interval & sigma::Interval< ValueType >::operator/= ( const Interval< ValueType > & rhs)
inline

In-place division by another interval.

Parameters
rhsThe interval to divide by
Returns
Reference to this interval after division
Exceptions
noneNo throw guarantee

◆ operator/=() [2/2]

template<typename ValueType>
Interval & sigma::Interval< ValueType >::operator/= ( value_t rhs)
inline

In-place division by a scalar.

Parameters
rhsThe scalar to divide by
Returns
Reference to this interval after division
Exceptions
noneNo throw guarantee

◆ radius()

template<typename ValueType>
value_t sigma::Interval< ValueType >::radius ( ) const
inline

Returns the half-width of the interval.

This is the distance from the median to either endpoint.

Returns
The half-width value
Exceptions
noneNo throw guarantee

◆ upper()

template<typename ValueType>
value_t sigma::Interval< ValueType >::upper ( ) const
inline

Returns the upper bound of the interval.

Returns
The upper bound value
Exceptions
noneNo throw guarantee

◆ operator!=()

template<typename T1, typename T2>
bool operator!= ( const Interval< T1 > & lhs,
const Interval< T2 > & rhs )
related

Compare two intervals for inequality.

Template Parameters
T1The numerical type of the left-hand interval
T2The numerical type of the right-hand interval
Parameters
lhsThe first interval
rhsThe second interval
Returns
Whether the instances are not equivalent

◆ operator*()

template<typename T>
Interval< T > operator* ( Interval< T > lhs,
const Interval< T > & rhs )
related

Multiplication of two intervals.

Template Parameters
TThe numerical type of the intervals
Parameters
lhsThe left-hand interval
rhsThe right-hand interval
Returns
A new interval that is the product of lhs and rhs
Exceptions
noneNo throw guarantee

◆ operator+()

template<typename T>
Interval< T > operator+ ( Interval< T > lhs,
const Interval< T > & rhs )
related

Addition of two intervals.

Template Parameters
TThe numerical type of the intervals
Parameters
lhsThe left-hand interval
rhsThe right-hand interval
Returns
A new interval that is the sum of lhs and rhs
Exceptions
noneNo throw guarantee

◆ operator-() [1/2]

template<typename T>
Interval< T > operator- ( const Interval< T > & a)
related

Negation of an interval.

Template Parameters
TThe numerical type of the interval
Parameters
aThe interval to negate
Returns
A new interval with negated bounds
Exceptions
noneNo throw guarantee

◆ operator-() [2/2]

template<typename T>
Interval< T > operator- ( Interval< T > lhs,
const Interval< T > & rhs )
related

Subtraction of two intervals.

Template Parameters
TThe numerical type of the intervals
Parameters
lhsThe left-hand interval
rhsThe right-hand interval
Returns
A new interval that is the difference of lhs and rhs
Exceptions
noneNo throw guarantee

◆ operator/()

template<typename T>
Interval< T > operator/ ( Interval< T > lhs,
const Interval< T > & rhs )
related

Division of two intervals.

If the interval contains zero the resulting interval will loose most of its information.

Template Parameters
TThe numerical type of the intervals
Parameters
lhsThe left-hand interval
rhsThe right-hand interval
Returns
A new interval that is the quotient of lhs and rhs
Exceptions
noneNo throw guarantee

◆ operator<()

template<typename T1, typename T2>
bool operator< ( const Interval< T1 > & lhs,
const Interval< T2 > & rhs )
related

Whether one interval is certainly less than another.

Returns true only when lhs lies entirely below rhs, i.e. lhs.upper() < rhs.lower().

Template Parameters
T1The numerical type of the left-hand interval
T2The numerical type of the right-hand interval
Parameters
lhsThe first interval
rhsThe second interval
Returns
Whether lhs is certainly less than rhs

◆ operator<<()

template<typename ValueType>
std::ostream & operator<< ( std::ostream & os,
const Interval< ValueType > & i )
related

Overload stream insertion to print an interval.

Template Parameters
ValueTypeThe numerical type of the bounds
Parameters
osThe ostream to write to
iThe interval to write
Returns
The modified ostream instance
Exceptions
std::ios_base::failureif anything goes wrong while writing. Weak throw guarantee.

◆ operator<=()

template<typename T1, typename T2>
bool operator<= ( const Interval< T1 > & lhs,
const Interval< T2 > & rhs )
related

Whether one interval is less than or equal to another.

Template Parameters
T1The numerical type of the left-hand interval
T2The numerical type of the right-hand interval
Parameters
lhsThe first interval
rhsThe second interval
Returns
Whether lhs is less than or equal to rhs

◆ operator==()

template<typename T1, typename T2>
bool operator== ( const Interval< T1 > & lhs,
const Interval< T2 > & rhs )
related

Compare two intervals for equality.

Template Parameters
T1The numerical type of the left-hand interval
T2The numerical type of the right-hand interval
Parameters
lhsThe first interval
rhsThe second interval
Returns
Whether the instances are equivalent

◆ operator>()

template<typename T1, typename T2>
bool operator> ( const Interval< T1 > & lhs,
const Interval< T2 > & rhs )
related

Whether one interval is greater than another.

Template Parameters
T1The numerical type of the left-hand interval
T2The numerical type of the right-hand interval
Parameters
lhsThe first interval
rhsThe second interval
Returns
Whether lhs is certainly greater than rhs

◆ operator>=()

template<typename T1, typename T2>
bool operator>= ( const Interval< T1 > & lhs,
const Interval< T2 > & rhs )
related

Whether one interval is greater than or equal to another.

Template Parameters
T1The numerical type of the left-hand interval
T2The numerical type of the right-hand interval
Parameters
lhsThe first interval
rhsThe second interval
Returns
Whether lhs is greater than or equal to rhs

The documentation for this class was generated from the following files: