interval<R>DescriptionA closed arithmetic interval represented by a pair of elements of
type R. In principle, one should be able to use Boost.Interval library for
this. But the functions in this library are not constexpr.
Also, this Boost.Interval is more complex and does not support certain
operations such bit operations. Perhaps some time in the future,
Boost.Interval will be used instead of this interval<R>
type.Template ParametersR must model the type requirements of Numeric. Note this in principle
includes any numeric type including floating point numbers and instances
of checked_result<R>.NotationSymbolDescriptionIAn interval typei, jAn instance of interval typeRNumeric types which can be used to make an intervalrAn instance of type RpAn instance of std::pair<R, R>l, uLowermost and uppermost values in an intervalosstd::basic_ostream<class CharT, class Traits =
std::char_traits<CharT>>Associated Typeschecked_resultholds either the result of an operation or information as
to why it failedValid ExpressionsNote that all expressions are constexpr.ExpressionReturn TypeSemanticsinterval<R>(l, u)interval<R>construct a new interval from a pair of limitsinterval<R>(p)interval<R>construct a new interval from a pair of limitsinterval<R>(i)interval<R>copy constructormake_interval<R>()interval<R>return new interval with
std::numric_limits<R>::min() and
std::numric_limits<R>::max()make_interval<R>(const R
&r)interval<R>return new interval with
std::numric_limits<R>::min() and
std::numric_limits<R>::max()i.lRlowermost value in the interval ii.uRuppermost value in the interval ii.includes(j)boost::logic::triboolreturn true if interval i includes interval ji.excludes(j)boost::logic::triboolreturn true if interval i includes interval ji.includes(t)boolreturn true if interval i includes value ti.excludes(t)boolreturn true if interval i includes value ti + jinterval<R>add two intervals and return the resulti - jinterval<R>subtract two intervals and return the resulti * jinterval<R>multiply two intervals and return the resulti / jinterval<R>divide one interval by another and return the
resulti % jinterval<R>calculate modulus of one interval by another and return
the resulti << jinterval<R>calculate the range that would result from shifting one
interval by anotheri >> jinterval<R>calculate the range that would result from shifting one
interval by anotheri | jinterval<R>range of values which can result from applying | to any
pair of operands from I and ji & jinterval<R>range of values which can result from applying & to
any pair of operands from I and ji ^ jinterval<R>range of values which can result from applying ^ to any
pair of operands from I and jt < uboost::logic::tribooltrue if every element in t is less than every element in
ut > uboost::logic::tribooltrue if every element in t is greater than every element
in ut <= uboost::logic::tribooltrue if every element in t is less than or equal to every
element in ut >= uboost::logic::tribooltrue if every element in t is greater than or equal to
every element in ut == ubooltrue if limits are equalt != ubooltrue if limits are not equalos << ios &print interval to output streamExample of use#include <iostream>
#include <cstdint>
#include <cassert>
#include <boost/numeric/safe_numerics/interval.hpp>
int main(){
std::cout << "test1" << std::endl;
interval<std::int16_t> x = {-64, 63};
std::cout << "x = " << x << std::endl;
interval<std::int16_t> y(-128, 126);
std::cout << "y = " << y << std::endl;
assert(static_cast<interval<std::int16_t>>(add<std::int16_t>(x,x)) == y);
std::cout << "x + x =" << add<std::int16_t>(x, x) << std::endl;
std::cout << "x - x = " << subtract<std::int16_t>(x, x) << std::endl;
return 0;
}Header#include
<boost/numeric/safe_numerics/interval.hpp>