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 Interval<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 Interval<T>(0, abs_high, false, a.right_open());
21 } else if(abs_low > abs_high) {
22 return Interval<T>(0, abs_low, false, a.left_open());
23 } else { // Equal in magnitude
24 return Interval<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 a numeric interval.
Definition interval.hpp:23
value_t upper() const
Returns the upper bound of the interval.
Definition interval.hpp:157
bool left_open() const
Is lower() NOT contained in the interval?
Definition interval.hpp:114
value_t lower() const
Returns the lower bound of the interval.
Definition interval.hpp:146
bool right_open() const
Is upper() NOT contained in the interval?
Definition interval.hpp:130
bool empty() const
Is *this the empty interval?
Definition interval.hpp:106
Defines the Interval 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:8
Affine< T > fabs(const Affine< T > &a)
Absolute Value of an affine form.
Definition basic.ipp:25