1 /* Boost interval/detail/ia64_rounding_control.hpp file
3 * Copyright 2006-2007 Boris Gubenko
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE_1_0.txt or
7 * copy at http://www.boost.org/LICENSE_1_0.txt)
10 #ifndef BOOST_NUMERIC_INTERVAL_DETAIL_IA64_ROUNDING_CONTROL_HPP
11 #define BOOST_NUMERIC_INTERVAL_DETAIL_IA64_ROUNDING_CONTROL_HPP
13 #if !defined(ia64) && !defined(__ia64) && !defined(__ia64__)
14 #error This header only works on ia64 CPUs.
23 namespace interval_lib {
27 struct ia64_rounding_control
29 typedef unsigned int rounding_mode;
31 static void set_rounding_mode(const rounding_mode& mode) {
33 static void get_rounding_mode(rounding_mode& mode) { mode = fegetround(); }
35 static void downward() { set_rounding_mode(FE_DOWNWARD); }
36 static void upward() { set_rounding_mode(FE_UPWARD); }
37 static void to_nearest() { set_rounding_mode(FE_TONEAREST); }
38 static void toward_zero() { set_rounding_mode(FE_TOWARDZERO); }
46 long double rintl(long double);
50 struct rounding_control<float>:
51 detail::ia64_rounding_control
53 static float force_rounding(const float r)
54 { volatile float _r = r; return _r; }
55 static float to_int(const float& x) { return rintf(x); }
59 struct rounding_control<double>:
60 detail::ia64_rounding_control
62 static const double & force_rounding(const double& r) { return r; }
63 static double to_int(const double& r) { return rint(r); }
67 struct rounding_control<long double>:
68 detail::ia64_rounding_control
70 static const long double & force_rounding(const long double& r) { return r; }
71 static long double to_int(const long double& r) { return rintl(r); }
74 } // namespace interval_lib
75 } // namespace numeric
78 #undef BOOST_NUMERIC_INTERVAL_NO_HARDWARE
82 #endif /* BOOST_NUMERIC_INTERVAL_DETAIL_IA64_ROUNDING_CONTROL_HPP */