1 /* Boost interval/detail/bcc_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_BCC_ROUNDING_CONTROL_HPP 12 #define BOOST_NUMERIC_INTERVAL_DETAIL_BCC_ROUNDING_CONTROL_HPP 13 14 #ifndef __BORLANDC__ 15 # error This header is only intended for Borland C++. 16 #endif 17 18 #ifndef _M_IX86 19 # error This header only works on x86 CPUs. 20 #endif 21 22 #include <float.h> // Borland C++ rounding control 23 24 namespace boost { 25 namespace numeric { 26 namespace interval_lib { 27 namespace detail { 28 29 #ifndef BOOST_NUMERIC_INTERVAL_KEEP_EXCEPTIONS_FOR_BCC 30 extern "C" { unsigned int _RTLENTRY _fm_init(void); } 31 32 struct borland_workaround { borland_workaroundboost::numeric::interval_lib::detail::borland_workaround33 borland_workaround() { _fm_init(); } 34 }; 35 36 static borland_workaround borland_workaround_exec; 37 #endif // BOOST_NUMERIC_INTERVAL_KEEP_EXCEPTIONS_FOR_BCC 38 rint(double)39__inline double rint(double) 40 { __emit__(0xD9); __emit__(0xFC); /* asm FRNDINT */ } 41 42 struct x86_rounding 43 { 44 typedef unsigned int rounding_mode; get_rounding_modeboost::numeric::interval_lib::detail::x86_rounding45 static void get_rounding_mode(rounding_mode& mode) 46 { mode = _control87(0, 0); } set_rounding_modeboost::numeric::interval_lib::detail::x86_rounding47 static void set_rounding_mode(const rounding_mode mode) 48 { _control87(mode, 0xffff); } to_intboost::numeric::interval_lib::detail::x86_rounding49 static double to_int(const double& x) { return rint(x); } 50 }; 51 52 } // namespace detail 53 } // namespace interval_lib 54 } // namespace numeric 55 } // namespace boost 56 57 #endif /* BOOST_NUMERIC_INTERVAL_DETAIL_BCC_ROUNDING_CONTROL_HPP */ 58