bcc_rounding_control.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. #ifndef BOOST_NUMERIC_INTERVAL_DETAIL_BCC_ROUNDING_CONTROL_HPP
  11. #define BOOST_NUMERIC_INTERVAL_DETAIL_BCC_ROUNDING_CONTROL_HPP
  12. #ifndef __BORLANDC__
  13. # error This header is only intended for Borland C++.
  14. #endif
  15. #ifndef _M_IX86
  16. # error This header only works on x86 CPUs.
  17. #endif
  18. #include <float.h> // Borland C++ rounding control
  19. namespace boost {
  20. namespace numeric {
  21. namespace interval_lib {
  22. namespace detail {
  23. #ifndef BOOST_NUMERIC_INTERVAL_KEEP_EXCEPTIONS_FOR_BCC
  24. extern "C" { unsigned int _RTLENTRY _fm_init(void); }
  25. struct borland_workaround {
  26. borland_workaround() { _fm_init(); }
  27. };
  28. static borland_workaround borland_workaround_exec;
  29. #endif // BOOST_NUMERIC_INTERVAL_KEEP_EXCEPTIONS_FOR_BCC
  30. __inline double rint(double)
  31. { __emit__(0xD9); __emit__(0xFC); /* asm FRNDINT */ }
  32. struct x86_rounding
  33. {
  34. typedef unsigned int rounding_mode;
  35. static void get_rounding_mode(rounding_mode& mode)
  36. { mode = _control87(0, 0); }
  37. static void set_rounding_mode(const rounding_mode mode)
  38. { _control87(mode, 0xffff); }
  39. static double to_int(const double& x) { return rint(x); }
  40. };
  41. } // namespace detail
  42. } // namespace interval_lib
  43. } // namespace numeric
  44. } // namespace boost
  45. #endif /* BOOST_NUMERIC_INTERVAL_DETAIL_BCC_ROUNDING_CONTROL_HPP */