sigma  1.0.0
Loading...
Searching...
No Matches
convert.hpp
Go to the documentation of this file.
1#pragma once
4#include <stdexcept>
5#include <string>
6
17
18namespace sigma::detail_ {
19
30template<typename T>
34
47template<typename T>
49 if(boost::numeric::empty(x)) { return Interval<T>(); }
50 return Interval<T>(x.lower(), x.upper());
51}
52
73template<typename T>
74void assert_within_unit_(const Interval<T>& a, bool open,
75 const std::string& name) {
76 auto below = a.lower() < T(-1) || (open && a.lower() == T(-1));
77 auto above = a.upper() > T(1) || (open && a.upper() == T(1));
78 if(below || above) {
79 throw std::domain_error("Interval has values outside the domain of " +
80 name + ", " + (open ? "(-1, 1)" : "[-1, 1]") +
81 ".");
82 }
83}
84
85} // namespace sigma::detail_
Models a closed numeric interval.
Definition interval.hpp:29
value_t upper() const
Returns the upper bound of the interval.
Definition interval.hpp:127
value_t lower() const
Returns the lower bound of the interval.
Definition interval.hpp:116
Defines the Interval class.
The namespace that contains the implementation details of the library.
Definition convert.hpp:18
Interval< T > from_boost_(const boost_interval_t< T > &x)
Convert a boost interval into a sigma::Interval.
Definition convert.hpp:48
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
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
Rounding and checking policies used by the boost interval sigma wraps.