Line | |
---|
1 | /* Boost interval/detail/c99sub_rounding_control.hpp file
|
---|
2 | *
|
---|
3 | * Copyright 2000 Jens Maurer
|
---|
4 | * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion
|
---|
5 | *
|
---|
6 | * Distributed under the Boost Software License, Version 1.0.
|
---|
7 | * (See accompanying file LICENSE_1_0.txt or
|
---|
8 | * copy at http://www.boost.org/LICENSE_1_0.txt)
|
---|
9 | */
|
---|
10 |
|
---|
11 | #ifndef BOOST_NUMERIC_INTERVAL_DETAIL_C99SUB_ROUNDING_CONTROL_HPP
|
---|
12 | #define BOOST_NUMERIC_INTERVAL_DETAIL_C99SUB_ROUNDING_CONTROL_HPP
|
---|
13 |
|
---|
14 | #include <fenv.h> // ISO C 99 rounding mode control
|
---|
15 |
|
---|
16 | namespace boost {
|
---|
17 | namespace numeric {
|
---|
18 | namespace interval_lib {
|
---|
19 | namespace detail {
|
---|
20 |
|
---|
21 | extern "C" { double rint(double); }
|
---|
22 |
|
---|
23 | struct c99_rounding
|
---|
24 | {
|
---|
25 | typedef int rounding_mode;
|
---|
26 |
|
---|
27 | static void set_rounding_mode(const rounding_mode mode) { fesetround(mode); }
|
---|
28 | static void get_rounding_mode(rounding_mode &mode) { mode = fegetround(); }
|
---|
29 | static void downward() { set_rounding_mode(FE_DOWNWARD); }
|
---|
30 | static void upward() { set_rounding_mode(FE_UPWARD); }
|
---|
31 | static void to_nearest() { set_rounding_mode(FE_TONEAREST); }
|
---|
32 | static void toward_zero() { set_rounding_mode(FE_TOWARDZERO); }
|
---|
33 |
|
---|
34 | template<class T>
|
---|
35 | static T to_int(const T& r) { return rint(r); }
|
---|
36 | };
|
---|
37 |
|
---|
38 | } // namespace detail
|
---|
39 | } // namespace interval_lib
|
---|
40 | } // namespace numeric
|
---|
41 | } // namespace boost
|
---|
42 |
|
---|
43 | #endif // BOOST_NUMERIC_INTERVAL_DETAIL_C99SUB_ROUBDING_CONTROL_HPP
|
---|
Note: See
TracBrowser
for help on using the repository browser.