| 1 | // { dg-do run { target c++11 } } |
| 2 | |
| 3 | // Copyright (C) 2011-2025 Free Software Foundation, Inc. |
| 4 | // |
| 5 | // This file is part of the GNU ISO C++ Library. This library is free |
| 6 | // software; you can redistribute it and/or modify it under the |
| 7 | // terms of the GNU General Public License as published by the |
| 8 | // Free Software Foundation; either version 3, or (at your option) |
| 9 | // any later version. |
| 10 | |
| 11 | // This library is distributed in the hope that it will be useful, |
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | // GNU General Public License for more details. |
| 15 | |
| 16 | // You should have received a copy of the GNU General Public License |
| 17 | // along with this library; see the file COPYING3. If not see |
| 18 | // <http://www.gnu.org/licenses/>. |
| 19 | |
| 20 | #include <ratio> |
| 21 | #include <limits> |
| 22 | #include <testsuite_hooks.h> |
| 23 | |
| 24 | // libstdc++/47913 |
| 25 | void test01() |
| 26 | { |
| 27 | using namespace std; |
| 28 | |
| 29 | const intmax_t m1 = (intmax_t)1 << (4 * sizeof(intmax_t) - 1); |
| 30 | typedef ratio_add<ratio<1, (m1 - 1) * (m1 - 2)>, |
| 31 | ratio<1, (m1 - 3) * (m1 - 2)> > ra_type1; |
| 32 | VERIFY( ra_type1::num == 2 ); |
| 33 | VERIFY( ra_type1::den == (m1 - 1) * (m1 - 3) ); |
| 34 | |
| 35 | const intmax_t m2 = numeric_limits<intmax_t>::max(); |
| 36 | typedef ratio_add<ratio<m2, 2>, |
| 37 | ratio<-m2, 3> > ra_type2; |
| 38 | VERIFY( ra_type2::num == m2 ); |
| 39 | VERIFY( ra_type2::den == 6 ); |
| 40 | |
| 41 | typedef ratio_add<ratio<m2 / 7 * 5 - 1, 5>, |
| 42 | ratio<-m2 + 2, 7> > ra_type3; |
| 43 | ra_type3(); |
| 44 | |
| 45 | const intmax_t m3 = numeric_limits<intmax_t>::max() - 1; |
| 46 | typedef ratio_add<ratio<-m3 / 7 * 5 - 1, 5>, |
| 47 | ratio<m3, 7> > ra_type4; |
| 48 | ra_type4(); |
| 49 | |
| 50 | const intmax_t m4 = numeric_limits<intmax_t>::max() / 2; |
| 51 | typedef ratio_add<ratio<m4 - 5, 15>, |
| 52 | ratio<m4, 35> > ra_type5; |
| 53 | VERIFY( ra_type5::num == (2 * m4 - 7) ); |
| 54 | VERIFY( ra_type5::den == 21 ); |
| 55 | } |
| 56 | |
| 57 | int main() |
| 58 | { |
| 59 | test01(); |
| 60 | return 0; |
| 61 | } |