math_overloads.hpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // (C) Copyright John Maddock 2005.
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_TR1_MATH_OVERLOADS_HPP_INCLUDED
  6. # define BOOST_TR1_MATH_OVERLOADS_HPP_INCLUDED
  7. # include <boost/config.hpp>
  8. # ifndef BOOST_NO_SFINAE
  9. # include <boost/utility/enable_if.hpp>
  10. # include <boost/type_traits/is_convertible.hpp>
  11. # define BOOST_TR1_MATH_RETURN(RET) typename ::boost::enable_if< ::boost::is_convertible<T,double>, RET >::type
  12. # else
  13. # define BOOST_TR1_MATH_RETURN(RET) RET
  14. # endif
  15. # include <boost/type_traits/is_floating_point.hpp>
  16. # include <boost/type_traits/is_same.hpp>
  17. # include <boost/mpl/if.hpp>
  18. namespace boost{ namespace tr1_detail{
  19. template <class T, class U>
  20. struct largest_real
  21. {
  22. typedef typename boost::mpl::if_<
  23. boost::is_same<long double, T>,
  24. long double,
  25. typename boost::mpl::if_<
  26. boost::is_same<long double, U>,
  27. long double,
  28. typename boost::mpl::if_<
  29. boost::is_same<double, T>,
  30. double,
  31. typename boost::mpl::if_<
  32. boost::is_same<double, U>,
  33. double,
  34. float
  35. >::type
  36. >::type
  37. >::type
  38. >::type type;
  39. };
  40. template <class T, class U>
  41. struct promote_to_real
  42. {
  43. typedef typename largest_real<
  44. typename boost::mpl::if_< boost::is_floating_point<T>, T, double>::type,
  45. typename boost::mpl::if_< boost::is_floating_point<U>, U, double>::type
  46. >::type type;
  47. };
  48. } }
  49. #endif