boost_no_fenv_h.ipp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // (C) Copyright John Maddock 2001.
  2. // (C) Copyright Bryce Lelbach 2010.
  3. // Use, modification and distribution are subject to the
  4. // Boost Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. // See http://www.boost.org/libs/config for most recent version.
  7. // MACRO: BOOST_NO_FENV_H
  8. // TITLE: fenv.h
  9. // DESCRIPTION: There is no standard <fenv.h> available. If <fenv.h> is
  10. // available, <boost/detail/fenv.hpp> should be included
  11. // instead of directly including <fenv.h>.
  12. #include <fenv.h>
  13. namespace boost_no_fenv_h {
  14. int test()
  15. {
  16. /// C++0x required typedefs
  17. typedef ::fenv_t has_fenv_t;
  18. typedef ::fexcept_t has_fexcept_t;
  19. /// C++0x required macros
  20. #if !defined(FE_DIVBYZERO)
  21. #error platform does not define FE_DIVBYZERO
  22. #endif
  23. #if !defined(FE_INEXACT)
  24. #error platform does not define FE_INEXACT
  25. #endif
  26. #if !defined(FE_ALL_EXCEPT)
  27. #error platform does not define FE_ALL_EXCEPT
  28. #endif
  29. int i;
  30. has_fexcept_t fe;
  31. has_fenv_t env;
  32. i = feclearexcept(FE_ALL_EXCEPT);
  33. i += fetestexcept(FE_ALL_EXCEPT); // All flags should be zero
  34. i += fegetexceptflag(&fe, FE_ALL_EXCEPT);
  35. i += fesetexceptflag(&fe, FE_ALL_EXCEPT);
  36. i += feraiseexcept(0);
  37. i += fesetround(fegetround());
  38. i += fegetenv(&env);
  39. i += fesetenv(&env);
  40. i += feholdexcept(&env);
  41. if(i)
  42. i += feupdateenv(&env);
  43. return i;
  44. }
  45. }