Chris@16: /* Boost interval/detail/ia64_rounding_control.hpp file Chris@16: * Chris@16: * Copyright 2006-2007 Boris Gubenko Chris@16: * Chris@16: * Distributed under the Boost Software License, Version 1.0. Chris@16: * (See accompanying file LICENSE_1_0.txt or Chris@16: * copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_NUMERIC_INTERVAL_DETAIL_IA64_ROUNDING_CONTROL_HPP Chris@16: #define BOOST_NUMERIC_INTERVAL_DETAIL_IA64_ROUNDING_CONTROL_HPP Chris@16: Chris@16: #if !defined(ia64) && !defined(__ia64) && !defined(__ia64__) Chris@16: #error This header only works on ia64 CPUs. Chris@16: #endif Chris@16: Chris@16: #if defined(__hpux) Chris@16: Chris@16: # include Chris@16: Chris@16: namespace boost { Chris@16: namespace numeric { Chris@16: namespace interval_lib { Chris@16: namespace detail { Chris@16: Chris@16: Chris@16: struct ia64_rounding_control Chris@16: { Chris@16: typedef unsigned int rounding_mode; Chris@16: Chris@16: static void set_rounding_mode(const rounding_mode& mode) { Chris@16: fesetround(mode); } Chris@16: static void get_rounding_mode(rounding_mode& mode) { mode = fegetround(); } Chris@16: Chris@16: static void downward() { set_rounding_mode(FE_DOWNWARD); } Chris@16: static void upward() { set_rounding_mode(FE_UPWARD); } Chris@16: static void to_nearest() { set_rounding_mode(FE_TONEAREST); } Chris@16: static void toward_zero() { set_rounding_mode(FE_TOWARDZERO); } Chris@16: }; Chris@16: Chris@16: } // namespace detail Chris@16: Chris@16: extern "C" { Chris@16: float rintf(float); Chris@16: double rint(double); Chris@16: long double rintl(long double); Chris@16: } Chris@16: Chris@16: template<> Chris@16: struct rounding_control: Chris@16: detail::ia64_rounding_control Chris@16: { Chris@16: static float force_rounding(const float r) Chris@16: { volatile float _r = r; return _r; } Chris@16: static float to_int(const float& x) { return rintf(x); } Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct rounding_control: Chris@16: detail::ia64_rounding_control Chris@16: { Chris@16: static const double & force_rounding(const double& r) { return r; } Chris@16: static double to_int(const double& r) { return rint(r); } Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct rounding_control: Chris@16: detail::ia64_rounding_control Chris@16: { Chris@16: static const long double & force_rounding(const long double& r) { return r; } Chris@16: static long double to_int(const long double& r) { return rintl(r); } Chris@16: }; Chris@16: Chris@16: } // namespace interval_lib Chris@16: } // namespace numeric Chris@16: } // namespace boost Chris@16: Chris@16: #undef BOOST_NUMERIC_INTERVAL_NO_HARDWARE Chris@16: Chris@16: #endif /* __hpux */ Chris@16: Chris@16: #endif /* BOOST_NUMERIC_INTERVAL_DETAIL_IA64_ROUNDING_CONTROL_HPP */ Chris@16: