ratio_add_pass.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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_add
  14. #include <boost/ratio/ratio.hpp>
  15. #if !defined(BOOST_NO_CXX11_STATIC_ASSERT)
  16. #define NOTHING ""
  17. #endif
  18. void test()
  19. {
  20. {
  21. typedef boost::ratio<0> R1;
  22. typedef boost::ratio<0> R2;
  23. typedef boost::ratio_add<R1, R2> R;
  24. BOOST_RATIO_STATIC_ASSERT(R::num == 0 && R::den == 1, NOTHING, ());
  25. }
  26. {
  27. typedef boost::ratio<1, 1> R1;
  28. typedef boost::ratio<1, 1> R2;
  29. typedef boost::ratio_add<R1, R2> R;
  30. BOOST_RATIO_STATIC_ASSERT(R::num == 2 && R::den == 1, NOTHING, ());
  31. typedef boost::ratio_add<R, R2> RR;
  32. BOOST_RATIO_STATIC_ASSERT(RR::num == 3 && RR::den == 1, NOTHING, ());
  33. }
  34. {
  35. typedef boost::ratio<1, 2> R1;
  36. typedef boost::ratio<1, 1> R2;
  37. typedef boost::ratio_add<R1, R2> R;
  38. BOOST_RATIO_STATIC_ASSERT(R::num == 3 && R::den == 2, NOTHING, ());
  39. }
  40. {
  41. typedef boost::ratio<-1, 2> R1;
  42. typedef boost::ratio<1, 1> R2;
  43. typedef boost::ratio_add<R1, R2> R;
  44. BOOST_RATIO_STATIC_ASSERT(R::num == 1 && R::den == 2, NOTHING, ());
  45. }
  46. {
  47. typedef boost::ratio<1, -2> R1;
  48. typedef boost::ratio<1, 1> R2;
  49. typedef boost::ratio_add<R1, R2> R;
  50. BOOST_RATIO_STATIC_ASSERT(R::num == 1 && R::den == 2, NOTHING, ());
  51. }
  52. {
  53. typedef boost::ratio<1, 2> R1;
  54. typedef boost::ratio<-1, 1> R2;
  55. typedef boost::ratio_add<R1, R2> R;
  56. BOOST_RATIO_STATIC_ASSERT(R::num == -1 && R::den == 2, NOTHING, ());
  57. }
  58. {
  59. typedef boost::ratio<1, 2> R1;
  60. typedef boost::ratio<1, -1> R2;
  61. typedef boost::ratio_add<R1, R2> R;
  62. BOOST_RATIO_STATIC_ASSERT(R::num == -1 && R::den == 2, NOTHING, ());
  63. }
  64. {
  65. typedef boost::ratio<56987354, 467584654> R1;
  66. typedef boost::ratio<544668, 22145> R2;
  67. typedef boost::ratio_add<R1, R2> R;
  68. BOOST_RATIO_STATIC_ASSERT(R::num == 127970191639601LL && R::den == 5177331081415LL, NOTHING, ());
  69. }
  70. {
  71. typedef boost::ratio<BOOST_RATIO_INTMAX_T_MAX, 1> R1;
  72. typedef boost::ratio<-1, 1> R2;
  73. typedef boost::ratio_add<R1, R2>::type RT;
  74. }
  75. }
  76. boost::intmax_t func(boost::ratio<5,6> s) {
  77. return s.num;
  78. }
  79. boost::intmax_t test_conversion() {
  80. return func(
  81. boost::ratio_add<
  82. boost::ratio<1,2>,
  83. boost::ratio<1,3>
  84. >
  85. ()
  86. );
  87. }