22 : gaol::interval(-oo,oo)
28 if(a == -oo || a == oo)
71 else if(l.size() == 2)
72 *
this =
Interval(*l.begin(),*std::prev(l.end()));
76 assert_release(
"'Interval' can only be defined by one or two 'double' values.");
84 if(x == -oo || x == oo)
87 gaol::interval::operator=(x);
94 gaol::interval::operator=(x);
105 return !(*
this == x);
110 return gaol::interval::left();
115 return gaol::interval::right();
120 double m = gaol::interval::midpoint();
121 gaol::round_upward();
127 return gaol::interval::mag();
132 return gaol::interval::mig();
138 return std::numeric_limits<double>::quiet_NaN();
140 double a = std::max<double>(next_float(-oo),
lb());
141 double b = std::min<double>(previous_float(oo),
ub());
142 double r = a + (((double)std::rand())/(double)RAND_MAX)*(b-a);
145 return std::max<double>(
lb(),std::min<double>(r,
ub()));
151 return std::numeric_limits<double>::quiet_NaN();
159 double t1 = (t-*
this).
ub();
160 double t2 = (*
this-t).
ub();
161 return (t1>t2) ? t1 : t2;
168 return std::numeric_limits<double>::quiet_NaN();
172 double d = gaol::interval::width();
173 gaol::round_upward();
195 return gaol::interval::is_empty();
200 return gaol::interval::set_contains(x);
210 return !gaol::interval::is_finite();
215 return is_empty() || gaol::interval::is_a_double();
220 return gaol::interval::is_an_int();
256 (x.
lb() <
lb() && (x.
ub() == oo || x.
ub() >
ub()))
257 || (x.
ub() >
ub() && (x.
lb() == -oo || x.
lb() <
lb()))
282 return lb() < m && m <
ub();
295 return {
Interval(-oo,-std::numeric_limits<double>::max()),
Interval(-std::numeric_limits<double>::max(),
ub()) };
299 return {
Interval(
lb(),std::numeric_limits<double>::max()),
Interval(std::numeric_limits<double>::max(),oo) };
312 m = next_float(
lb());
326 std::vector<Interval> l;
329 l.push_back({-oo,
lb()});
332 l.push_back({
ub(),oo});
347 std::vector<Interval> l;
364 return gaol::operator&(x,y);
369 return gaol::operator|(x,
Interval(y));
374 return gaol::operator|(x,y);
384 if(y == -oo || y == oo)
388 return gaol::operator+(x,y);
393 if(x == -oo || x == oo)
397 return gaol::operator+(x,y);
402 return gaol::operator+(x,y);
407 if(y == -oo || y == oo)
411 return gaol::operator-(x, y);
416 if(x == -oo || x == oo)
420 return gaol::operator-(x, y);
425 return gaol::operator-(x, y);
430 if(y == -oo || y == oo)
434 return gaol::operator*(x,y);
439 if(x == -oo || x == oo)
443 return gaol::operator*(x,y);
448 return gaol::operator*(x,y);
453 if(y == -oo || y == oo)
457 return gaol::operator/(x,y);
462 if(x == -oo || x == oo)
466 return gaol::operator/(x,y);
471 return gaol::operator/(x,y);
476 gaol::interval::operator|=(x);
482 gaol::interval::operator&=(x);
488 if(x == -oo || x == oo)
491 gaol::interval::operator+=(x);
497 gaol::interval::operator+=(x);
508 if(x == -oo || x == oo)
511 gaol::interval::operator-=(x);
517 gaol::interval::operator-=(x);
523 if(x == -oo || x == oo)
526 gaol::interval::operator*=(x);
532 gaol::interval::operator*=(x);
538 if(x == -oo || x == oo)
541 gaol::interval::operator/=(x);
547 gaol::interval::operator/=(x);
553 return std::numeric_limits<double>::quiet_NaN();
558 return gaol::interval::zero();
563 return gaol::interval::one();
568 return gaol::interval::half_pi();
573 return gaol::interval::pi();
578 return gaol::interval::two_pi();
583 gaol::interval::precision(os.precision());
584 gaol::operator<<(os,x);
597 inline double previous_float(
double x)
599 return gaol::previous_float(x);
602 inline double next_float(
double x)
604 return gaol::next_float(x);
Interval class, for representing closed and connected subsets of .
Definition codac2_Interval.h:62
bool is_unbounded() const
Tests if one of the bounds of this is infinite.
Definition codac2_Interval_impl.h:208
Interval & operator*=(double x)
Self multiplication of this and a real x.
Definition codac2_Interval_impl.h:521
Interval & operator-=(double x)
Self substraction of this and a real x.
Definition codac2_Interval_impl.h:506
bool operator==(const Interval &x) const
Comparison (equality) between two intervals.
Definition codac2_Interval_impl.h:98
bool is_empty() const
Tests if this is empty.
Definition codac2_Interval_impl.h:193
double mig() const
Returns the mignitude of this.
Definition codac2_Interval_impl.h:130
bool is_bisectable() const
Tests if this can be bisected into two non-degenerated intervals.
Definition codac2_Interval_impl.h:277
Interval & inflate(const double &rad)
Adds [-rad,+rad] to this.
Definition codac2_Interval_impl.h:271
static Interval one()
Provides an interval for .
Definition codac2_Interval_impl.h:561
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:66
double ub() const
Returns the upper bound of this.
Definition codac2_Interval_impl.h:113
bool intersects(const Interval &x) const
Tests if this and x intersect.
Definition codac2_Interval_impl.h:223
double volume() const
Returns the diameter of this.
Definition codac2_Interval_impl.h:178
bool interior_contains(const double &x) const
Tests if the interior of this contains x.
Definition codac2_Interval_impl.h:203
static Interval pi()
Provides an interval for .
Definition codac2_Interval_impl.h:571
double rand() const
Returns a random value inside the interval.
Definition codac2_Interval_impl.h:135
std::pair< Interval, Interval > bisect(float ratio=0.49) const
Bisects this into two subintervals.
Definition codac2_Interval_impl.h:285
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:218
friend std::ostream & operator<<(std::ostream &os, const Interval &x)
Streams out this.
Definition codac2_Interval_impl.h:581
std::vector< Interval > diff(const Interval &y, bool compactness=true) const
Computes the result of .
Definition codac2_Interval_impl.h:337
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:243
bool is_interior_subset(const Interval &x) const
Tests if this is in the interior of x.
Definition codac2_Interval_impl.h:248
bool is_degenerated() const
Tests if this is degenerated, that is, in the form of .
Definition codac2_Interval_impl.h:213
std::vector< Interval > complementary(bool compactness=true) const
Computes the complementary of this.
Definition codac2_Interval_impl.h:321
Interval & operator/=(double x)
Self division of this and a real x.
Definition codac2_Interval_impl.h:536
double diam() const
Returns the diameter of this.
Definition codac2_Interval_impl.h:165
Interval & operator+=(double x)
Self addition of this and a real x.
Definition codac2_Interval_impl.h:486
bool is_disjoint(const Interval &x) const
Tests if this and x do not intersect.
Definition codac2_Interval_impl.h:228
Interval & operator&=(const Interval &x)
Self intersection of this and x.
Definition codac2_Interval_impl.h:480
static Interval zero()
Provides an interval for .
Definition codac2_Interval_impl.h:556
Index size() const
Returns the dimension of this (which is always )
Definition codac2_Interval_impl.h:183
bool is_superset(const Interval &x) const
Tests if this is a superset of x.
Definition codac2_Interval_impl.h:261
double rad() const
Returns the radius of this.
Definition codac2_Interval_impl.h:148
double mag() const
Returns the magnitude of this i.e. max(|lower bound|, |upper bound|).
Definition codac2_Interval_impl.h:125
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:233
void set_empty()
Sets this interval to the empty set.
Definition codac2_Interval_impl.h:188
bool is_subset(const Interval &x) const
Tests if this is a subset of x.
Definition codac2_Interval_impl.h:238
Interval & operator|=(const Interval &x)
Self union of this and x.
Definition codac2_Interval_impl.h:474
Interval & operator=(double x)
Sets this to x.
Definition codac2_Interval_impl.h:82
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:198
bool operator!=(const Interval &x) const
Comparison (non equality) between two intervals.
Definition codac2_Interval_impl.h:103
double lb() const
Returns the lower bound of this.
Definition codac2_Interval_impl.h:108
static Interval two_pi()
Provides an interval for .
Definition codac2_Interval_impl.h:576
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:253
Interval & init()
Sets the value of this interval to [-oo,oo].
Definition codac2_Interval_impl.h:54
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:266
double mid() const
Returns the midpoint of this.
Definition codac2_Interval_impl.h:118
static Interval empty()
Provides an empty interval.
Definition codac2_Interval_impl.h:551
Interval operator-() const
Substraction of this.
Definition codac2_Interval_impl.h:501
static Interval half_pi()
Provides an interval for .
Definition codac2_Interval_impl.h:566
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:428
Interval operator/(const Interval &x, double y)
Returns with .
Definition codac2_Interval_impl.h:451
Interval operator-(const Interval &x, double y)
Returns with .
Definition codac2_Interval_impl.h:405