template class Interval <typename BoundType, typename Rounding = BoundType>
typedef capd::intervals::Interval< double, capd::rounding::DoubleRounding> DInterval;
typedef capd::intervals::Interval< int, capd::rounding::IntRounding> IntInterval;
typedef capd::intervals::Interval< capd::multiPrec::MpfrClass> MpfrInterval;
Because most of the functions are common for intervals with
arbitrary endpoints we use general type interval in the following
sections.
For an example it can be defined as follows
typedef DInterval interval;
Remark: if you include file "capd/interval/DoubleInterval.h" then interval is already defined as Interval< double, DoubleRounding>.
interval a; |
// a is in general not initialized |
The state of interval a depends on
flag __INTERVAL_INIT_0__.
If this flag is set in file include/capd/interval/intervalSettings.h than a
= [0.0, 0.0],
otherwise a is not initialized (this is the default behaviour).
interval c(2.0, 3.0); |
|
c.left(); |
// or |
c = interval(1.0, c.rightBound());In this way e.g. you can force constructor to check if interval endpoints are in good order (see Interval Options).
interval a(1.0, 2.0); |
|
interval a;
std::istringstream myStr("[3.21312312, 4.324324324]");
myStr >> a;
Operator | True if |
b==c; |
both end points are the same |
b!=c; |
at least one end point differs |
b>c; |
it is true for any two points from intervals b and c. For example: b>c if leftBound(b) > rightBound(c) |
True if | |
c.contains(b); |
c contains b c contains number 2.5 |
c.containsInInterior(b); |
c contains b in the interior |
c.subset(b); |
c is subset of b |
c.subsetInterior(b); |
c is subset of the interior of b |
interval a(-1,0, 2.0), b(1.0, 2.0);then
Operation | Code | Result |
Sum |
a + b; |
[0.0, 4.0] |
Substraction |
a - b; |
[-3.0, 1.0] |
Product |
a * b; |
[-2.0, 4.0] |
Division |
a / b; |
[-1.0, 2.0] |
a = a + b;can be also shorten to
a = a - b;
a = a * b;
a = a / b;
a += b;
a -= b;
a *= b;
a /= b;
Function | For an interval x it returns: |
---|---|
power(x, n) | xn, where n is an integer |
power(x, a) | xa, where a is an interval |
sqrt(x) | square root of x |
sin(x), cos(x), tan(x), cot(x) | sinus of x, etc. |
sinh(x), cosh(x), tanh(x), coth(x) | hyperbolic sinus of x, etc. |
exp(x) | exponens of x |
log(x) | natural logarithm of x |
interval a(1.0, 5.0);
std::cout << a.mid(); // displays on the screen [3.0,3.0] (the middle point of interval [1.0, 5.0])
std::cout << mid(a);
interval a(1.0, 5.0);
std::cout << diam(a); // displays on the screen [4.0, 4.0]
interval a(1.0, 3.0), b(2.0, 4.0), c(5.0, 6.0), r1, r2;
intersection(a, b, r1);
if(!intersection(a,c,r2))
std::cout << "intersection is empty";
// r1 is equal to [2.0, 3.0], r2 is not initialized
interval a(1.0, 3.0), b(5.0, 6.0), result;
result = intervalHull(a, b);
// result is equal to [1.0, 6.0]
interval a(1.0,3.0);then
interval center, remainder, radius;
double r;
Command | Result |
a.split(center,remainder); |
a = [1.0, 3.0] center = [2.0, 2.0] remainder = [-1.0, 1.0] |
a.split(remainder); |
a = [2.0, 2.0] remainder = [-1.0, 1.0] |
split(a, center,radius); |
a = [1.0, 3.0] center = [2.0, 2.0] radius = [1.0, 1.0] !!! |
split(a, center,r); |
a = [1.0, 3.0] center = [2.0, 2.0] radius = 1.0 |
// returns interval that contains pi constantNote that an output is an interval that containts true value of the constant,
interval::pi();
// returns interval that contains euler constant
interval::euler();
Flag | If switched on | Default |
__DEBUGGING__ | it turns on debugging mode. We check intervals during each operation and throw exception if interval is not valid. | off |
__INTERVAL_INIT_0__ |
default constructor initializes intervals to be [0.0,
0.0]. By default this option is switched off and an interval is not initialized. |
off |
__INTERVAL_SPEED_OPTIMIZED__ | it speeds up computations but enlarges programm size. It couses many functions to be defined as inline |
on |
__INTERVAL_DEPRECATED__ |
it allows use of deprecated functions for backward compatibility. | off |