sigma  1.0.0
Loading...
Searching...
No Matches
basic.ipp
1#pragma once
3#include <cmath>
4
5namespace sigma {
6
7template<typename T>
9 if(a.empty()) { return GeneralInterval<T>(); }
10 // If interval is positive already, just return it.
11 if(a.lower() >= 0) { return a; }
12
13 // If interval is completely negative, return the negative of it.
14 if(a.upper() <= 0) { return -a; }
15
16 // We know it straddles zero.
17 auto abs_low = std::abs(a.lower());
18 auto abs_high = std::abs(a.upper());
19 if(abs_low < abs_high) {
20 return GeneralInterval<T>(0, abs_high, false, a.right_open());
21 } else if(abs_low > abs_high) {
22 return GeneralInterval<T>(0, abs_low, false, a.left_open());
23 } else { // Equal in magnitude
24 return GeneralInterval<T>(0, abs_low, false, a.left_open() && a.right_open());
25 }
26}
27
28template<typename T>
30 return abs(a);
31}
32
33} // namespace sigma
Models an interval whose bounds may be open.
Definition general_interval.hpp:36
bool empty() const
Is *this the empty interval?
Definition general_interval.hpp:127
bool left_open() const
Is lower() NOT contained in the interval?
Definition general_interval.hpp:136
bool right_open() const
Is upper() NOT contained in the interval?
Definition general_interval.hpp:153
value_t lower() const
Returns the lower bound of the interval.
Definition general_interval.hpp:169
value_t upper() const
Returns the upper bound of the interval.
Definition general_interval.hpp:177
Defines the GeneralInterval class.
The primary namespace for the sigma library.
Definition affine.hpp:12
Affine< T > abs(const Affine< T > &a)
Absolute Value of an affine form.
Definition basic.ipp:9
Affine< T > fabs(const Affine< T > &a)
Absolute Value of an affine form.
Definition basic.ipp:22