check_float_funcs.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2012 Daniel James.
  2. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  3. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #include <boost/static_assert.hpp>
  5. #include <boost/type_traits/is_same.hpp>
  6. #include <boost/type_traits/is_convertible.hpp>
  7. #include <cmath>
  8. namespace test
  9. {
  10. template <class T1>
  11. struct check_return_type
  12. {
  13. template <class T2>
  14. static void equals(T2)
  15. {
  16. BOOST_STATIC_ASSERT((boost::is_same<T1, T2>::value));
  17. }
  18. template <class T2>
  19. static void equals_ref(T2&)
  20. {
  21. BOOST_STATIC_ASSERT((boost::is_same<T1, T2>::value));
  22. }
  23. template <class T2>
  24. static void convertible(T2)
  25. {
  26. BOOST_STATIC_ASSERT((boost::is_convertible<T2, T1>::value));
  27. }
  28. };
  29. }
  30. int main() {
  31. float f = 0;
  32. double d = 0;
  33. long double l = 0;
  34. test::check_return_type<float>::equals(std::ldexp(f, 0));
  35. test::check_return_type<double>::equals(std::ldexp(d, 0));
  36. test::check_return_type<long double>::equals(std::ldexp(l, 0));
  37. int dummy = 0;
  38. test::check_return_type<float>::equals(std::frexp(f, &dummy));
  39. test::check_return_type<double>::equals(std::frexp(d, &dummy));
  40. test::check_return_type<long double>::equals(std::frexp(l, &dummy));
  41. #if BOOST_HASH_USE_FPCLASSIFY
  42. int (*fpc1)(float) = std::fpclassify;
  43. int (*fpc2)(double) = std::fpclassify;
  44. int (*fpc3)(long double) = std::fpclassify;
  45. #endif
  46. }