9
3

fenv.hpp 3.1 KB

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