ratio_pass.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // Adaptation to Boost of the libcxx
  10. // Copyright 2010 Vicente J. Botet Escriba
  11. // Distributed under the Boost Software License, Version 1.0.
  12. // See http://www.boost.org/LICENSE_1_0.txt
  13. // test ratio: The static data members num and den shall have thcommon
  14. // divisor of the absolute values of N and D:
  15. #include <boost/ratio/ratio.hpp>
  16. #if !defined(BOOST_NO_CXX11_STATIC_ASSERT)
  17. #define NOTHING ""
  18. #endif
  19. template <long long N, long long D, long long eN, long long eD>
  20. void test()
  21. {
  22. BOOST_RATIO_STATIC_ASSERT((boost::ratio<N, D>::num == eN), NOTHING, (boost::mpl::integral_c<boost::intmax_t,boost::ratio<N, D>::num>));
  23. BOOST_RATIO_STATIC_ASSERT((boost::ratio<N, D>::den == eD), NOTHING, (boost::mpl::integral_c<boost::intmax_t,boost::ratio<N, D>::den>));
  24. }
  25. int main()
  26. {
  27. test<1, 1, 1, 1>();
  28. test<1, 10, 1, 10>();
  29. test<10, 10, 1, 1>();
  30. test<10, 1, 10, 1>();
  31. test<12, 4, 3, 1>();
  32. test<12, -4, -3, 1>();
  33. test<-12, 4, -3, 1>();
  34. test<-12, -4, 3, 1>();
  35. test<4, 12, 1, 3>();
  36. test<4, -12, -1, 3>();
  37. test<-4, 12, -1, 3>();
  38. test<-4, -12, 1, 3>();
  39. test<222, 333, 2, 3>();
  40. test<222, -333, -2, 3>();
  41. test<-222, 333, -2, 3>();
  42. test<-222, -333, 2, 3>();
  43. //test<BOOST_RATIO_INTMAX_T_MAX, 127, 72624976668147841LL, 1>();
  44. //test<-BOOST_RATIO_INTMAX_T_MAX, 127, -72624976668147841LL, 1>();
  45. //test<BOOST_RATIO_INTMAX_T_MAX, -127, -72624976668147841LL, 1>();
  46. //test<-BOOST_RATIO_INTMAX_T_MAX, -127, 72624976668147841LL, 1>();
  47. //~ test<BOOST_RATIO_INTMAX_T_MAX, 127, BOOST_RATIO_INTMAX_T_MAX, 127>();
  48. //~ test<-BOOST_RATIO_INTMAX_T_MAX, 127, -BOOST_RATIO_INTMAX_T_MAX, 127>();
  49. //~ test<BOOST_RATIO_INTMAX_T_MAX, -127, -BOOST_RATIO_INTMAX_T_MAX, 127>();
  50. //~ test<-BOOST_RATIO_INTMAX_T_MAX, -127, BOOST_RATIO_INTMAX_T_MAX, 127>();
  51. }