sigma  1.0.0
Loading...
Searching...
No Matches
general_convert.hpp
Go to the documentation of this file.
1#pragma once
4#include <stdexcept>
5#include <string>
6
30
31namespace sigma::detail_ {
32
44template<typename T>
48
64template<typename T>
66 bool left_open = false,
67 bool right_open = false) {
68 if(boost::numeric::empty(x)) { return GeneralInterval<T>(); }
69 return GeneralInterval<T>(x.lower(), x.upper(), left_open, right_open);
70}
71
92template<typename T>
93void assert_within_unit_(const GeneralInterval<T>& a, bool open,
94 const std::string& name) {
95 auto below =
96 a.lower() < T(-1) || (open && a.lower() == T(-1) && a.left_closed());
97 auto above =
98 a.upper() > T(1) || (open && a.upper() == T(1) && a.right_closed());
99 if(below || above) {
100 throw std::domain_error("Interval has values outside the domain of " +
101 name + ", " + (open ? "(-1, 1)" : "[-1, 1]") +
102 ".");
103 }
104}
105
106} // namespace sigma::detail_
Models an interval whose bounds may be open.
Definition general_interval.hpp:36
const closure_t & closure() const
Returns the closure of the interval.
Definition general_interval.hpp:189
bool right_closed() const
Is upper() contained in the interval?
Definition general_interval.hpp:161
bool left_closed() const
Is lower() contained in the interval?
Definition general_interval.hpp:144
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
Conversions between sigma::Interval and the boost interval it wraps.
Defines the GeneralInterval class.
The namespace that contains the implementation details of the library.
Definition convert.hpp:18
void assert_within_unit_(const Interval< T > &a, bool open, const std::string &name)
Throws unless every value in a lies in the unit interval.
Definition convert.hpp:74
GeneralInterval< T > general_from_boost_(const boost_interval_t< T > &x, bool left_open=false, bool right_open=false)
Convert a boost interval into a sigma::GeneralInterval.
Definition general_convert.hpp:65
boost_interval_t< T > to_boost_(const Interval< T > &a)
Convert a sigma::Interval into the boost interval it wraps.
Definition convert.hpp:31
boost::numeric::interval< T, interval_policies_t< T > > boost_interval_t
The boost interval type sigma::Interval wraps.
Definition policies.hpp:485