22 : gaol::interval(-oo,oo)
28 if(a == -oo || a == oo)
65 else if(l.size() == 2)
66 *
this =
Interval(*l.begin(),*std::prev(l.end()));
70 assert_release(
"'Interval' can only be defined by one or two 'double' values.");
78 if(x == -oo || x == oo)
81 gaol::interval::operator=(x);
88 gaol::interval::operator=(x);
104 return gaol::interval::left();
109 return gaol::interval::right();
114 double m = gaol::interval::midpoint();
115 gaol::round_upward();
121 return gaol::interval::mag();
126 return gaol::interval::mig();
132 return std::numeric_limits<double>::quiet_NaN();
134 double a = std::max<double>(next_float(-oo),
lb());
135 double b = std::min<double>(previous_float(oo),
ub());
136 double r = a + (((double)std::rand())/(double)RAND_MAX)*(b-a);
139 return std::max<double>(
lb(),std::min<double>(r,
ub()));
145 return std::numeric_limits<double>::quiet_NaN();
153 double t1 = (t-*
this).
ub();
154 double t2 = (*
this-t).
ub();
155 return (t1>t2) ? t1 : t2;
162 return std::numeric_limits<double>::quiet_NaN();
166 double d = gaol::interval::width();
167 gaol::round_upward();
189 return gaol::interval::is_empty();
194 return gaol::interval::set_contains(x);
204 return !gaol::interval::is_finite();
209 return is_empty() || gaol::interval::is_a_double();
245 (x.
lb() <
lb() && (x.
ub() == oo || x.
ub() >
ub()))
246 || (x.
ub() >
ub() && (x.
lb() == -oo || x.
lb() <
lb()))
271 return lb() < m && m <
ub();
284 return {
Interval(-oo,-std::numeric_limits<double>::max()),
Interval(-std::numeric_limits<double>::max(),
ub()) };
288 return {
Interval(
lb(),std::numeric_limits<double>::max()),
Interval(std::numeric_limits<double>::max(),oo) };
301 m = next_float(
lb());
315 std::vector<Interval> l;
318 l.push_back({-oo,
lb()});
321 l.push_back({
ub(),oo});
336 std::vector<Interval> l;
353 return gaol::operator&(x,y);
358 return gaol::operator|(x,y);
368 if(y == -oo || y == oo)
372 return gaol::operator+(x,y);
377 if(x == -oo || x == oo)
381 return gaol::operator+(x,y);
386 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 gaol::interval::operator|=(x);
466 gaol::interval::operator&=(x);
472 if(x == -oo || x == oo)
475 gaol::interval::operator+=(x);
481 gaol::interval::operator+=(x);
492 if(x == -oo || x == oo)
495 gaol::interval::operator-=(x);
501 gaol::interval::operator-=(x);
507 if(x == -oo || x == oo)
510 gaol::interval::operator*=(x);
516 gaol::interval::operator*=(x);
522 if(x == -oo || x == oo)
525 gaol::interval::operator/=(x);
531 gaol::interval::operator/=(x);
537 return std::numeric_limits<double>::quiet_NaN();
542 return gaol::interval::zero();
547 return gaol::interval::one();
552 return gaol::interval::half_pi();
557 return gaol::interval::pi();
562 return gaol::interval::two_pi();
567 gaol::interval::precision(os.precision());
568 gaol::operator<<(os,x);
581 inline double previous_float(
double x)
583 return gaol::previous_float(x);
586 inline double next_float(
double x)
588 return gaol::next_float(x);
Interval class, for representing closed and connected subsets of .
Definition codac2_Interval.h:62
Interval & init(const Interval &x)
Sets the value of this interval to x.
Definition codac2_Interval_impl.h:54
bool is_unbounded() const
Tests if one of the bounds of this is infinite.
Definition codac2_Interval_impl.h:202
Interval & operator*=(double x)
Self multiplication of this and a real x.
Definition codac2_Interval_impl.h:505
Interval & operator-=(double x)
Self substraction of this and a real x.
Definition codac2_Interval_impl.h:490
bool operator==(const Interval &x) const
Comparison (equality) between two intervals.
Definition codac2_Interval_impl.h:92
bool is_empty() const
Tests if this is empty.
Definition codac2_Interval_impl.h:187
double mig() const
Returns the mignitude of this.
Definition codac2_Interval_impl.h:124
bool is_bisectable() const
Tests if this can be bisected into two non-degenerated intervals.
Definition codac2_Interval_impl.h:266
Interval & inflate(const double &rad)
Adds [-rad,+rad] to this.
Definition codac2_Interval_impl.h:260
static Interval one()
Provides an interval for .
Definition codac2_Interval_impl.h:545
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:60
double ub() const
Returns the upper bound of this.
Definition codac2_Interval_impl.h:107
bool intersects(const Interval &x) const
Tests if this and x intersect.
Definition codac2_Interval_impl.h:212
double volume() const
Returns the diameter of this.
Definition codac2_Interval_impl.h:172
bool interior_contains(const double &x) const
Tests if the interior of this contains x.
Definition codac2_Interval_impl.h:197
static Interval pi()
Provides an interval for .
Definition codac2_Interval_impl.h:555
double rand() const
Returns a random value inside the interval.
Definition codac2_Interval_impl.h:129
std::pair< Interval, Interval > bisect(float ratio=0.49) const
Bisects this into two subintervals.
Definition codac2_Interval_impl.h:274
friend std::ostream & operator<<(std::ostream &os, const Interval &x)
Streams out this.
Definition codac2_Interval_impl.h:565
std::vector< Interval > diff(const Interval &y, bool compactness=true) const
Computes the result of .
Definition codac2_Interval_impl.h:326
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:232
bool is_interior_subset(const Interval &x) const
Tests if this is in the interior of x.
Definition codac2_Interval_impl.h:237
bool is_degenerated() const
Tests if this is degenerated, that is, in the form of .
Definition codac2_Interval_impl.h:207
std::vector< Interval > complementary(bool compactness=true) const
Computes the complementary of this.
Definition codac2_Interval_impl.h:310
Interval & operator/=(double x)
Self division of this and a real x.
Definition codac2_Interval_impl.h:520
double diam() const
Returns the diameter of this.
Definition codac2_Interval_impl.h:159
Interval & operator+=(double x)
Self addition of this and a real x.
Definition codac2_Interval_impl.h:470
bool is_disjoint(const Interval &x) const
Tests if this and x do not intersect.
Definition codac2_Interval_impl.h:217
Interval & operator&=(const Interval &x)
Self intersection of this and x.
Definition codac2_Interval_impl.h:464
static Interval zero()
Provides an interval for .
Definition codac2_Interval_impl.h:540
Index size() const
Returns the dimension of this (which is always )
Definition codac2_Interval_impl.h:177
bool is_superset(const Interval &x) const
Tests if this is a superset of x.
Definition codac2_Interval_impl.h:250
double rad() const
Returns the radius of this.
Definition codac2_Interval_impl.h:142
double mag() const
Returns the magnitude of this i.e. max(|lower bound|, |upper bound|).
Definition codac2_Interval_impl.h:119
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:222
void set_empty()
Sets this interval to the empty set.
Definition codac2_Interval_impl.h:182
bool is_subset(const Interval &x) const
Tests if this is a subset of x.
Definition codac2_Interval_impl.h:227
Interval & operator|=(const Interval &x)
Self union of this and x.
Definition codac2_Interval_impl.h:458
Interval & operator=(double x)
Sets this to x.
Definition codac2_Interval_impl.h:76
Interval()
Creates an interval .
Definition codac2_Interval_impl.h:21
bool contains(const double &x) const
Tests if this contains x.
Definition codac2_Interval_impl.h:192
bool operator!=(const Interval &x) const
Comparison (non equality) between two intervals.
Definition codac2_Interval_impl.h:97
double lb() const
Returns the lower bound of this.
Definition codac2_Interval_impl.h:102
static Interval two_pi()
Provides an interval for .
Definition codac2_Interval_impl.h:560
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:242
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:255
double mid() const
Returns the midpoint of this.
Definition codac2_Interval_impl.h:112
static Interval empty()
Provides an empty interval.
Definition codac2_Interval_impl.h:535
Interval operator-() const
Substraction of this.
Definition codac2_Interval_impl.h:485
static Interval half_pi()
Provides an interval for .
Definition codac2_Interval_impl.h:550
Ellipsoid operator+(const Ellipsoid &e1, const Ellipsoid &e2)
Compute the Minkowski sum of two ellipsoids.
Interval operator*(const Interval &x, double y)
Returns with .
Definition codac2_Interval_impl.h:412
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:389