ratio_subtract.pass.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // test ratio_subtract
  9. #include <ratio>
  10. #include "test_macros.h"
  11. int main(int, char**)
  12. {
  13. {
  14. typedef std::ratio<1, 1> R1;
  15. typedef std::ratio<1, 1> R2;
  16. typedef std::ratio_subtract<R1, R2>::type R;
  17. static_assert(R::num == 0 && R::den == 1, "");
  18. }
  19. {
  20. typedef std::ratio<1, 2> R1;
  21. typedef std::ratio<1, 1> R2;
  22. typedef std::ratio_subtract<R1, R2>::type R;
  23. static_assert(R::num == -1 && R::den == 2, "");
  24. }
  25. {
  26. typedef std::ratio<-1, 2> R1;
  27. typedef std::ratio<1, 1> R2;
  28. typedef std::ratio_subtract<R1, R2>::type R;
  29. static_assert(R::num == -3 && R::den == 2, "");
  30. }
  31. {
  32. typedef std::ratio<1, -2> R1;
  33. typedef std::ratio<1, 1> R2;
  34. typedef std::ratio_subtract<R1, R2>::type R;
  35. static_assert(R::num == -3 && R::den == 2, "");
  36. }
  37. {
  38. typedef std::ratio<1, 2> R1;
  39. typedef std::ratio<-1, 1> R2;
  40. typedef std::ratio_subtract<R1, R2>::type R;
  41. static_assert(R::num == 3 && R::den == 2, "");
  42. }
  43. {
  44. typedef std::ratio<1, 2> R1;
  45. typedef std::ratio<1, -1> R2;
  46. typedef std::ratio_subtract<R1, R2>::type R;
  47. static_assert(R::num == 3 && R::den == 2, "");
  48. }
  49. {
  50. typedef std::ratio<56987354, 467584654> R1;
  51. typedef std::ratio<544668, 22145> R2;
  52. typedef std::ratio_subtract<R1, R2>::type R;
  53. static_assert(R::num == -126708206685271LL && R::den == 5177331081415LL, "");
  54. }
  55. {
  56. typedef std::ratio<0> R1;
  57. typedef std::ratio<0> R2;
  58. typedef std::ratio_subtract<R1, R2>::type R;
  59. static_assert(R::num == 0 && R::den == 1, "");
  60. }
  61. {
  62. typedef std::ratio<1> R1;
  63. typedef std::ratio<0> R2;
  64. typedef std::ratio_subtract<R1, R2>::type R;
  65. static_assert(R::num == 1 && R::den == 1, "");
  66. }
  67. {
  68. typedef std::ratio<0> R1;
  69. typedef std::ratio<1> R2;
  70. typedef std::ratio_subtract<R1, R2>::type R;
  71. static_assert(R::num == -1 && R::den == 1, "");
  72. }
  73. return 0;
  74. }