sigma  1.0.0
Loading...
Searching...
No Matches
policies.hpp
Go to the documentation of this file.
1#pragma once
2#include <boost/numeric/interval.hpp>
3#include <cmath>
4#include <limits>
5
16
17namespace sigma::detail_ {
18
56template<typename T>
58 : boost::numeric::interval_lib::rounded_arith_opp<T> {
59private:
70 static constexpr int k_error_ulps_ = 4;
71
80 static T down_(T y) {
81 constexpr auto inf = std::numeric_limits<T>::infinity();
82 for(int i = 0; i < k_error_ulps_; ++i) { y = std::nextafter(y, -inf); }
83 return y;
84 }
85
94 static T up_(T y) {
95 constexpr auto inf = std::numeric_limits<T>::infinity();
96 for(int i = 0; i < k_error_ulps_; ++i) { y = std::nextafter(y, inf); }
97 return y;
98 }
99
114 template<typename FunctionType>
115 T nearest_(FunctionType&& f) {
116 this->to_nearest();
117 T y = this->force_rounding(f());
118 this->upward();
119 return y;
120 }
121
122public:
131 T exp_down(const T& x) {
132 return down_(nearest_([&x] { return std::exp(x); }));
133 }
134
143 T exp_up(const T& x) {
144 return up_(nearest_([&x] { return std::exp(x); }));
145 }
146
155 T log_down(const T& x) {
156 return down_(nearest_([&x] { return std::log(x); }));
157 }
158
167 T log_up(const T& x) {
168 return up_(nearest_([&x] { return std::log(x); }));
169 }
170
179 T sin_down(const T& x) {
180 return down_(nearest_([&x] { return std::sin(x); }));
181 }
182
191 T sin_up(const T& x) {
192 return up_(nearest_([&x] { return std::sin(x); }));
193 }
194
203 T cos_down(const T& x) {
204 return down_(nearest_([&x] { return std::cos(x); }));
205 }
206
215 T cos_up(const T& x) {
216 return up_(nearest_([&x] { return std::cos(x); }));
217 }
218
227 T tan_down(const T& x) {
228 return down_(nearest_([&x] { return std::tan(x); }));
229 }
230
239 T tan_up(const T& x) {
240 return up_(nearest_([&x] { return std::tan(x); }));
241 }
242
251 T asin_down(const T& x) {
252 return down_(nearest_([&x] { return std::asin(x); }));
253 }
254
263 T asin_up(const T& x) {
264 return up_(nearest_([&x] { return std::asin(x); }));
265 }
266
275 T acos_down(const T& x) {
276 return down_(nearest_([&x] { return std::acos(x); }));
277 }
278
287 T acos_up(const T& x) {
288 return up_(nearest_([&x] { return std::acos(x); }));
289 }
290
299 T atan_down(const T& x) {
300 return down_(nearest_([&x] { return std::atan(x); }));
301 }
302
311 T atan_up(const T& x) {
312 return up_(nearest_([&x] { return std::atan(x); }));
313 }
314
323 T sinh_down(const T& x) {
324 return down_(nearest_([&x] { return std::sinh(x); }));
325 }
326
335 T sinh_up(const T& x) {
336 return up_(nearest_([&x] { return std::sinh(x); }));
337 }
338
347 T cosh_down(const T& x) {
348 return down_(nearest_([&x] { return std::cosh(x); }));
349 }
350
359 T cosh_up(const T& x) {
360 return up_(nearest_([&x] { return std::cosh(x); }));
361 }
362
371 T tanh_down(const T& x) {
372 return down_(nearest_([&x] { return std::tanh(x); }));
373 }
374
383 T tanh_up(const T& x) {
384 return up_(nearest_([&x] { return std::tanh(x); }));
385 }
386
395 T asinh_down(const T& x) {
396 return down_(nearest_([&x] { return std::asinh(x); }));
397 }
398
407 T asinh_up(const T& x) {
408 return up_(nearest_([&x] { return std::asinh(x); }));
409 }
410
419 T acosh_down(const T& x) {
420 return down_(nearest_([&x] { return std::acosh(x); }));
421 }
422
431 T acosh_up(const T& x) {
432 return up_(nearest_([&x] { return std::acosh(x); }));
433 }
434
443 T atanh_down(const T& x) {
444 return down_(nearest_([&x] { return std::atanh(x); }));
445 }
446
455 T atanh_up(const T& x) {
456 return up_(nearest_([&x] { return std::atanh(x); }));
457 }
458};
459
478template<typename T>
479using interval_policies_t = boost::numeric::interval_lib::policies<
480 boost::numeric::interval_lib::save_state<rounded_transc_guarded<T>>,
481 boost::numeric::interval_lib::checking_base<T>>;
482
484template<typename T>
485using boost_interval_t = boost::numeric::interval<T, interval_policies_t<T>>;
486
487} // namespace sigma::detail_
The namespace that contains the implementation details of the library.
Definition convert.hpp:18
boost::numeric::interval_lib::policies< boost::numeric::interval_lib::save_state< rounded_transc_guarded< T > >, boost::numeric::interval_lib::checking_base< T > > interval_policies_t
The policies the boost interval underlying sigma::Interval uses.
Definition policies.hpp:479
boost::numeric::interval< T, interval_policies_t< T > > boost_interval_t
The boost interval type sigma::Interval wraps.
Definition policies.hpp:485
Outward rounding for the transcendental functions.
Definition policies.hpp:58
T sinh_down(const T &x)
A lower bound for the hyperbolic sine of x.
Definition policies.hpp:323
T cosh_down(const T &x)
A lower bound for the hyperbolic cosine of x.
Definition policies.hpp:347
T asinh_up(const T &x)
A upper bound for the inverse hyperbolic sine of x.
Definition policies.hpp:407
T tanh_down(const T &x)
A lower bound for the hyperbolic tangent of x.
Definition policies.hpp:371
T atanh_down(const T &x)
A lower bound for the inverse hyperbolic tangent of x.
Definition policies.hpp:443
T acos_up(const T &x)
A upper bound for the arccosine of x.
Definition policies.hpp:287
T asin_up(const T &x)
A upper bound for the arcsine of x.
Definition policies.hpp:263
T tan_up(const T &x)
A upper bound for the tangent of x.
Definition policies.hpp:239
T atan_up(const T &x)
A upper bound for the arctangent of x.
Definition policies.hpp:311
T asin_down(const T &x)
A lower bound for the arcsine of x.
Definition policies.hpp:251
T exp_down(const T &x)
A lower bound for the exponential of x.
Definition policies.hpp:131
T sin_up(const T &x)
A upper bound for the sine of x.
Definition policies.hpp:191
T sinh_up(const T &x)
A upper bound for the hyperbolic sine of x.
Definition policies.hpp:335
T tanh_up(const T &x)
A upper bound for the hyperbolic tangent of x.
Definition policies.hpp:383
T atanh_up(const T &x)
A upper bound for the inverse hyperbolic tangent of x.
Definition policies.hpp:455
T asinh_down(const T &x)
A lower bound for the inverse hyperbolic sine of x.
Definition policies.hpp:395
T log_up(const T &x)
A upper bound for the natural logarithm of x.
Definition policies.hpp:167
T sin_down(const T &x)
A lower bound for the sine of x.
Definition policies.hpp:179
T cos_down(const T &x)
A lower bound for the cosine of x.
Definition policies.hpp:203
T tan_down(const T &x)
A lower bound for the tangent of x.
Definition policies.hpp:227
T atan_down(const T &x)
A lower bound for the arctangent of x.
Definition policies.hpp:299
T acosh_up(const T &x)
A upper bound for the inverse hyperbolic cosine of x.
Definition policies.hpp:431
T exp_up(const T &x)
A upper bound for the exponential of x.
Definition policies.hpp:143
T cosh_up(const T &x)
A upper bound for the hyperbolic cosine of x.
Definition policies.hpp:359
T cos_up(const T &x)
A upper bound for the cosine of x.
Definition policies.hpp:215
T acos_down(const T &x)
A lower bound for the arccosine of x.
Definition policies.hpp:275
T acosh_down(const T &x)
A lower bound for the inverse hyperbolic cosine of x.
Definition policies.hpp:419
T log_down(const T &x)
A lower bound for the natural logarithm of x.
Definition policies.hpp:155