New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
msvc_rounding_control.hpp in vendors/XIOS/current/extern/boost/include/boost/numeric/interval/detail – NEMO

source: vendors/XIOS/current/extern/boost/include/boost/numeric/interval/detail/msvc_rounding_control.hpp @ 3408

Last change on this file since 3408 was 3408, checked in by rblod, 12 years ago

importing initial XIOS vendor drop

  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1/* Boost interval/detail/msvc_rounding_control.hpp file
2 *
3 * Copyright 2000 Maarten Keijzer
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_MSVC_ROUNDING_CONTROL_HPP
12#define BOOST_NUMERIC_INTERVAL_DETAIL_MSVC_ROUNDING_CONTROL_HPP
13
14#ifndef _MSC_VER
15#  error This header is only intended for MSVC, but might work for Borland as well
16#endif
17
18#include <float.h>      // MSVC rounding control
19
20// Although the function is called _control87, it seems to work for
21// other FPUs too, so it does not have to be changed to _controlfp.
22
23namespace boost {
24namespace numeric {
25namespace interval_lib {
26namespace detail {
27
28extern "C" { double rint(double); }
29
30struct x86_rounding
31{
32  static unsigned int hard2msvc(unsigned short m) {
33    unsigned int n = 0;
34    if (m & 0x01) n |= _EM_INVALID;
35    if (m & 0x02) n |= _EM_DENORMAL;
36    if (m & 0x04) n |= _EM_ZERODIVIDE;
37    if (m & 0x08) n |= _EM_OVERFLOW;
38    if (m & 0x10) n |= _EM_UNDERFLOW;
39    if (m & 0x20) n |= _EM_INEXACT;
40    switch (m & 0x300) {
41    case 0x000: n |= _PC_24; break;
42    case 0x200: n |= _PC_53; break;
43    case 0x300: n |= _PC_64; break;
44    }
45    switch (m & 0xC00) {
46    case 0x000: n |= _RC_NEAR; break;
47    case 0x400: n |= _RC_DOWN; break;
48    case 0x800: n |= _RC_UP;   break;
49    case 0xC00: n |= _RC_CHOP; break;
50    }
51    if (m & 0x1000) n |= _IC_AFFINE; // only useful on 287
52    return n;
53  }
54
55  static unsigned short msvc2hard(unsigned int n) {
56    unsigned short m = 0;
57    if (n & _EM_INVALID)    m |= 0x01;
58    if (n & _EM_DENORMAL)   m |= 0x02;
59    if (n & _EM_ZERODIVIDE) m |= 0x04;
60    if (n & _EM_OVERFLOW)   m |= 0x08;
61    if (n & _EM_UNDERFLOW)  m |= 0x10;
62    if (n & _EM_INEXACT)    m |= 0x20;
63    switch (n & _MCW_RC) {
64    case _RC_NEAR: m |= 0x000; break;
65    case _RC_DOWN: m |= 0x400; break;
66    case _RC_UP:   m |= 0x800; break;
67    case _RC_CHOP: m |= 0xC00; break;
68    }
69    switch (n & _MCW_PC) {
70    case _PC_24: m |= 0x000; break;
71    case _PC_53: m |= 0x200; break;
72    case _PC_64: m |= 0x300; break;
73    }
74    if ((n & _MCW_IC) == _IC_AFFINE) m |= 0x1000;
75    return m;
76  }
77
78  typedef unsigned short rounding_mode;
79  static void get_rounding_mode(rounding_mode& mode)
80  { mode = msvc2hard(_control87(0, 0)); }
81  static void set_rounding_mode(const rounding_mode mode)
82  { _control87(hard2msvc(mode), _MCW_EM | _MCW_RC | _MCW_PC | _MCW_IC); }
83  static double to_int(const double& x) { return rint(x); }
84};
85
86} // namespace detail
87} // namespace interval_lib
88} // namespace numeric
89} // namespace boost
90
91#endif /* BOOST_NUMERIC_INTERVAL_DETAIL_MSVC_ROUNDING_CONTROL_HPP */
Note: See TracBrowser for help on using the repository browser.