• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Copyright (c) 2010      Bryce Lelbach
3 
4     Distributed under the Boost Software License, Version 1.0. (See accompanying
5     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 =============================================================================*/
7 
8 #include <boost/config.hpp>
9 
10 #if defined(BOOST_NO_FENV_H)
11   #error This platform does not have a floating point environment
12 #endif
13 
14 #if !defined(BOOST_DETAIL_FENV_HPP)
15 #define BOOST_DETAIL_FENV_HPP
16 
17 /* If we're using clang + glibc, we have to get hacky.
18  * See http://llvm.org/bugs/show_bug.cgi?id=6907 */
19 #if defined(__clang__)       &&  (__clang_major__ < 3) &&    \
20     defined(__GNU_LIBRARY__) && /* up to version 5 */ \
21     defined(__GLIBC__) &&         /* version 6 + */ \
22     !defined(_FENV_H)
23   #define _FENV_H
24 
25   #include <features.h>
26   #include <bits/fenv.h>
27 
28   extern "C" {
29     extern int fegetexceptflag (fexcept_t*, int) __THROW;
30     extern int fesetexceptflag (__const fexcept_t*, int) __THROW;
31     extern int feclearexcept (int) __THROW;
32     extern int feraiseexcept (int) __THROW;
33     extern int fetestexcept (int) __THROW;
34     extern int fegetround (void) __THROW;
35     extern int fesetround (int) __THROW;
36     extern int fegetenv (fenv_t*) __THROW;
37     extern int fesetenv (__const fenv_t*) __THROW;
38     extern int feupdateenv (__const fenv_t*) __THROW;
39     extern int feholdexcept (fenv_t*) __THROW;
40 
41     #ifdef __USE_GNU
42       extern int feenableexcept (int) __THROW;
43       extern int fedisableexcept (int) __THROW;
44       extern int fegetexcept (void) __THROW;
45     #endif
46   }
47 
48   namespace std { namespace tr1 {
49     using ::fenv_t;
50     using ::fexcept_t;
51     using ::fegetexceptflag;
52     using ::fesetexceptflag;
53     using ::feclearexcept;
54     using ::feraiseexcept;
55     using ::fetestexcept;
56     using ::fegetround;
57     using ::fesetround;
58     using ::fegetenv;
59     using ::fesetenv;
60     using ::feupdateenv;
61     using ::feholdexcept;
62   } }
63 
64 #elif defined(__MINGW32__) && defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 408
65 
66   // MinGW (32-bit) has a bug in mingw32/bits/c++config.h, it does not define _GLIBCXX_HAVE_FENV_H,
67   // which prevents the C fenv.h header contents to be included in the C++ wrapper header fenv.h. This is at least
68   // the case with gcc 4.8.1 packages tested so far, up to 4.8.1-4. Note that there is no issue with
69   // MinGW-w64.
70   // To work around the bug we avoid including the C++ wrapper header and include the C header directly
71   // and import all relevant symbols into std:: ourselves.
72 
73   #include <../include/fenv.h>
74 
75   namespace std {
76     using ::fenv_t;
77     using ::fexcept_t;
78     using ::fegetexceptflag;
79     using ::fesetexceptflag;
80     using ::feclearexcept;
81     using ::feraiseexcept;
82     using ::fetestexcept;
83     using ::fegetround;
84     using ::fesetround;
85     using ::fegetenv;
86     using ::fesetenv;
87     using ::feupdateenv;
88     using ::feholdexcept;
89   }
90 
91 #else /* if we're not using GNU's C stdlib, fenv.h should work with clang */
92 
93   #if defined(__SUNPRO_CC) /* lol suncc */
94     #include <stdio.h>
95   #endif
96 
97   #include <fenv.h>
98 
99 #endif
100 
101 #endif /* BOOST_DETAIL_FENV_HPP */
102