/Src/Dependencies/Boost/boost/spirit/home/support/detail/sign.hpp

http://hadesmem.googlecode.com/ · C++ Header · 71 lines · 50 code · 8 blank · 13 comment · 1 complexity · a1667415604ef4092e9dfc5ac58e1f32 MD5 · raw file

  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Copyright (c) 2001-2011 Hartmut Kaiser
  4. http://spirit.sourceforge.net/
  5. Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. =============================================================================*/
  8. #if !defined(SPIRIT_SIGN_MAR_11_2009_0734PM)
  9. #define SPIRIT_SIGN_MAR_11_2009_0734PM
  10. #if defined(_MSC_VER)
  11. #pragma once
  12. #endif
  13. #include <boost/config/no_tr1/cmath.hpp>
  14. #include <boost/version.hpp>
  15. #if BOOST_VERSION < 104000
  16. #include <boost/spirit/home/support/detail/math/fpclassify.hpp>
  17. #include <boost/spirit/home/support/detail/math/signbit.hpp>
  18. #else
  19. #include <boost/math/special_functions/fpclassify.hpp>
  20. #include <boost/math/special_functions/sign.hpp>
  21. #endif
  22. namespace boost { namespace spirit { namespace detail
  23. {
  24. #if BOOST_VERSION < 104000
  25. // signbit(-NAN) is broken for versions of Boost earlier than 1.40.0
  26. // This routine has been taken and adapted from Johan Rade's fp_traits
  27. // library
  28. template<typename T>
  29. inline bool (signbit)(T x)
  30. {
  31. return (boost::spirit::math::signbit)(x);
  32. }
  33. template<typename T>
  34. inline T (changesign)(T x)
  35. {
  36. return (boost::spirit::math::changesign)(x);
  37. }
  38. #else
  39. template<typename T>
  40. inline bool (signbit)(T x)
  41. {
  42. return (boost::math::signbit)(x) ? true : false;
  43. }
  44. // This routine has been taken and adapted from Johan Rade's fp_traits
  45. // library
  46. template<typename T>
  47. inline T (changesign)(T x)
  48. {
  49. #if defined(BOOST_MATH_USE_STD_FPCLASSIFY) && !defined(BOOST_MATH_DISABLE_STD_FPCLASSIFY)
  50. return -x;
  51. #else
  52. typedef typename math::detail::fp_traits<T>::type traits_type;
  53. typename traits_type::bits a;
  54. traits_type::get_bits(x, a);
  55. a ^= traits_type::sign;
  56. traits_type::set_bits(x, a);
  57. return x;
  58. #endif
  59. }
  60. #endif
  61. }}}
  62. #endif