Library Documentation Index

Safe Numerics

PrevUpHomeNext

interval<typename R>

Description
Template Parameters
Notation
Associated Types
Valid Expressions
Header
Example of use

Description

A closed arithmetic interval represented by a pair of elements of type R.

Template Parameters

R must model the type requirements Numeric

Notation

Symbol Description
I An interval type
i, j An interval
R, T Numeric types which can be used to make an interval
l, u lower and upper Numeric limits of an interval
C checked_result<interval<R>>
os std::basic_ostream<Char, CharT>

Associated Types

checked_result holds either the result of an operation or information as to why it failed

Valid Expressions

Note that all expressions are constexpr .

Expression Return Type Semantics
interval<R>(l, u) interval<R> construct a new interval from a pair of limits
interval<R>(p) interval<R> construct a new interval from a pair of limits
interval<R>(i) interval<R> copy constructor
i.includes(j) bool return true if interval i includes interval j
i.includes(t) bool return true if interval i includes value t
add<R>(i, j) C add two intervals and return the result
subtract<R>(i, j) C subtract two intervals and return the result
multiply<R>(i, j) C multiply two intervals and return the result
divide_nz<R>(i, j) C divide one interval by another excluding the value zero and return the result
divide<R>(i, j) C divide one interval by another and return the result
modulus_nz<R>(i, j) C calculate modulus of one interval by another excluding the value zero and return the result
modulus<R>(i, j) C calculate modulus of one interval by another and return the result
left_shift<R>(i, j) C calculate the range that would result from shifting one interval by another
right_shift<R>(i, j) C calculate the range that would result from shifting one interval by another
t < u boost::logic::tribool true if every element in t is less than every element in u
t > u boost::logic::tribool true if every element in t is greater than every element in u
t <= u boost::logic::tribool true if every element in t is less than or equal to every element in u
t >= u boost::logic::tribool true if every element in t is greater than or equal to every element in u
t == u bool true if limits are equal
t != u bool true if limits are not equal
os << i os & print interval to output stream

Header

#include "interval.hpp"

Example of use

#include <iostream>
#include <cstdint>
#include <cassert>
#include <boost/numeric/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;
}

PrevUpHomeNext