24 : gaol::interval(-oo,oo)
30 if(a == -oo || a == oo)
73 else if(l.size() == 2)
74 *
this =
Interval(*l.begin(),*std::prev(l.end()));
78 assert_release(
"'Interval' can only be defined by one or two 'double' values.");
86 if(x == -oo || x == oo)
89 gaol::interval::operator=(x);
96 gaol::interval::operator=(x);
107 return !(*
this == x);
112 return gaol::interval::left();
117 return gaol::interval::right();
122 double m = gaol::interval::midpoint();
123 gaol::round_upward();
129 return gaol::interval::mag();
134 return gaol::interval::mig();
140 return std::numeric_limits<double>::quiet_NaN();
144 double r = a + (((double)std::rand())/(double)RAND_MAX)*(b-a);
147 return std::max<double>(
lb(),std::min<double>(r,
ub()));
153 return std::numeric_limits<double>::quiet_NaN();
161 double t1 = (t-*
this).
ub();
162 double t2 = (*
this-t).
ub();
163 return (t1>t2) ? t1 : t2;
170 return std::numeric_limits<double>::quiet_NaN();
174 double d = gaol::interval::width();
175 gaol::round_upward();
197 return gaol::interval::is_empty();
202 return gaol::interval::set_contains(x);
212 return !gaol::interval::is_finite();
217 return is_empty() || gaol::interval::is_a_double();
222 return gaol::interval::is_an_int();
227 return trunc(
lb()) ==
lb() && trunc(
ub()) ==
ub();
263 (x.
lb() <
lb() && (x.
ub() == oo || x.
ub() >
ub()))
264 || (x.
ub() >
ub() && (x.
lb() == -oo || x.
lb() <
lb()))
289 return lb() < m && m <
ub();
302 return {
Interval(-oo,-std::numeric_limits<double>::max()),
Interval(-std::numeric_limits<double>::max(),
ub()) };
306 return {
Interval(
lb(),std::numeric_limits<double>::max()),
Interval(std::numeric_limits<double>::max(),oo) };
333 std::vector<Interval> l;
336 l.push_back({-oo,
lb()});
339 l.push_back({
ub(),oo});
354 std::vector<Interval> l;
371 return gaol::operator&(x,y);
376 return gaol::operator|(x,
Interval(y));
381 return gaol::operator|(x,y);
391 if(y == -oo || y == oo)
395 return gaol::operator+(x,y);
400 if(x == -oo || x == oo)
404 return gaol::operator+(x,y);
409 return gaol::operator+(x,y);
414 if(y == -oo || y == oo)
418 return gaol::operator-(x, y);
423 if(x == -oo || x == oo)
427 return gaol::operator-(x, y);
432 return gaol::operator-(x, y);
437 if(y == -oo || y == oo)
441 return gaol::operator*(x,y);
446 if(x == -oo || x == oo)
450 return gaol::operator*(x,y);
455 return gaol::operator*(x,y);
460 if(y == -oo || y == oo)
464 return gaol::operator/(x,y);
469 if(x == -oo || x == oo)
473 return gaol::operator/(x,y);
478 return gaol::operator/(x,y);
483 gaol::interval::operator|=(x);
489 gaol::interval::operator&=(x);
495 if(x == -oo || x == oo)
498 gaol::interval::operator+=(x);
504 gaol::interval::operator+=(x);
515 if(x == -oo || x == oo)
518 gaol::interval::operator-=(x);
524 gaol::interval::operator-=(x);
530 if(x == -oo || x == oo)
533 gaol::interval::operator*=(x);
539 gaol::interval::operator*=(x);
545 if(x == -oo || x == oo)
548 gaol::interval::operator/=(x);
554 gaol::interval::operator/=(x);
560 return std::numeric_limits<double>::quiet_NaN();
565 return gaol::interval::zero();
570 return gaol::interval::one();
575 return gaol::interval::half_pi();
580 return gaol::interval::pi();
585 return gaol::interval::two_pi();
590 gaol::interval::precision(os.precision());
591 gaol::operator<<(os,x);
606 return gaol::previous_float(x);
611 return gaol::next_float(x);
Interval class, for representing closed and connected subsets of .
Definition codac2_Interval.h:49
bool is_unbounded() const
Tests if one of the bounds of this is infinite.
Definition codac2_Interval_impl.h:210
Interval & operator*=(double x)
Self multiplication of this and a real x.
Definition codac2_Interval_impl.h:528
Interval & operator-=(double x)
Self substraction of this and a real x.
Definition codac2_Interval_impl.h:513
bool operator==(const Interval &x) const
Comparison (equality) between two intervals.
Definition codac2_Interval_impl.h:100
bool is_empty() const
Tests if this is empty.
Definition codac2_Interval_impl.h:195
double mig() const
Returns the mignitude of this.
Definition codac2_Interval_impl.h:132
bool is_bisectable() const
Tests if this can be bisected into two non-degenerated intervals.
Definition codac2_Interval_impl.h:284
Interval & inflate(const double &rad)
Adds [-rad,+rad] to this.
Definition codac2_Interval_impl.h:278
static Interval one()
Provides an interval for .
Definition codac2_Interval_impl.h:568
Interval & init_from_list(const std::list< double > &l)
Sets the bounds as the hull of a list of values.
Definition codac2_Interval_impl.h:68
double ub() const
Returns the upper bound of this.
Definition codac2_Interval_impl.h:115
bool intersects(const Interval &x) const
Tests if this and x intersect.
Definition codac2_Interval_impl.h:230
double volume() const
Returns the diameter of this.
Definition codac2_Interval_impl.h:180
bool interior_contains(const double &x) const
Tests if the interior of this contains x.
Definition codac2_Interval_impl.h:205
static Interval pi()
Provides an interval for .
Definition codac2_Interval_impl.h:578
double rand() const
Returns a random value inside the interval.
Definition codac2_Interval_impl.h:137
std::pair< Interval, Interval > bisect(float ratio=0.49) const
Bisects this into two subintervals.
Definition codac2_Interval_impl.h:292
bool is_integer() const
Tests if this is an integer, that is, in the form of where n is an integer.
Definition codac2_Interval_impl.h:220
std::vector< Interval > diff(const Interval &y, bool compactness=true) const
Computes the result of .
Definition codac2_Interval_impl.h:344
bool is_strict_subset(const Interval &x) const
Tests if this is a subset of x and not x itself.
Definition codac2_Interval_impl.h:250
bool is_interior_subset(const Interval &x) const
Tests if this is in the interior of x.
Definition codac2_Interval_impl.h:255
bool is_degenerated() const
Tests if this is degenerated, that is, in the form of .
Definition codac2_Interval_impl.h:215
std::vector< Interval > complementary(bool compactness=true) const
Computes the complementary of this.
Definition codac2_Interval_impl.h:328
Interval & operator/=(double x)
Self division of this and a real x.
Definition codac2_Interval_impl.h:543
double diam() const
Returns the diameter of this.
Definition codac2_Interval_impl.h:167
Interval & operator+=(double x)
Self addition of this and a real x.
Definition codac2_Interval_impl.h:493
bool is_disjoint(const Interval &x) const
Tests if this and x do not intersect.
Definition codac2_Interval_impl.h:235
Interval & operator&=(const Interval &x)
Self intersection of this and x.
Definition codac2_Interval_impl.h:487
static Interval zero()
Provides an interval for .
Definition codac2_Interval_impl.h:563
Index size() const
Returns the dimension of this (which is always )
Definition codac2_Interval_impl.h:185
bool is_superset(const Interval &x) const
Tests if this is a superset of x.
Definition codac2_Interval_impl.h:268
double rad() const
Returns the radius of this.
Definition codac2_Interval_impl.h:150
double mag() const
Returns the magnitude of this i.e. max(|lower bound|, |upper bound|).
Definition codac2_Interval_impl.h:127
bool overlaps(const Interval &x) const
Tests if this and x intersect and their intersection has a non-null volume.
Definition codac2_Interval_impl.h:240
void set_empty()
Sets this interval to the empty set.
Definition codac2_Interval_impl.h:190
bool is_subset(const Interval &x) const
Tests if this is a subset of x.
Definition codac2_Interval_impl.h:245
Interval & operator|=(const Interval &x)
Self union of this and x.
Definition codac2_Interval_impl.h:481
Interval & operator=(double x)
Sets this to x.
Definition codac2_Interval_impl.h:84
Interval()
Creates an interval .
Definition codac2_Interval_impl.h:23
bool contains(const double &x) const
Tests if this contains x.
Definition codac2_Interval_impl.h:200
bool operator!=(const Interval &x) const
Comparison (non equality) between two intervals.
Definition codac2_Interval_impl.h:105
double lb() const
Returns the lower bound of this.
Definition codac2_Interval_impl.h:110
bool has_integer_bounds() const
Checks whether the interval has integer lower and upper bounds.
Definition codac2_Interval_impl.h:225
static Interval two_pi()
Provides an interval for .
Definition codac2_Interval_impl.h:583
bool is_strict_interior_subset(const Interval &x) const
Tests if this is in the interior of x and different from x.
Definition codac2_Interval_impl.h:260
Interval & init()
Sets the value of this interval to [-oo,oo].
Definition codac2_Interval_impl.h:56
bool is_strict_superset(const Interval &x) const
Tests if this is a superset of x and different from x.
Definition codac2_Interval_impl.h:273
double mid() const
Returns the midpoint of this.
Definition codac2_Interval_impl.h:120
static Interval empty()
Provides an empty interval.
Definition codac2_Interval_impl.h:558
Interval operator-() const
Substraction of this.
Definition codac2_Interval_impl.h:508
static Interval half_pi()
Provides an interval for .
Definition codac2_Interval_impl.h:573
Definition codac2_OctaSym.h:21
Interval operator*(const Interval &x, double y)
Returns with .
Definition codac2_Interval_impl.h:435
Interval operator/(const Interval &x, double y)
Returns with .
Definition codac2_Interval_impl.h:458
Ellipsoid operator+(const Ellipsoid &e1, const Ellipsoid &e2)
Compute the Minkowski sum of two ellipsoids.
std::ostream & operator<<(std::ostream &os, const BoolInterval &x)
Streams out a BoolInterval.
Definition codac2_BoolInterval.h:64
Interval operator-(const Interval &x, double y)
Returns with .
Definition codac2_Interval_impl.h:412
double next_float(double x)
Returns the next representable double-precision floating-point value after x.
Definition codac2_Interval_impl.h:609
double previous_float(double x)
Returns the previous representable double-precision floating-point value before x.
Definition codac2_Interval_impl.h:604