]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/ratio/operations/47913.cc
1 // { dg-do run { target c++11 } }
3 // Copyright (C) 2011-2021 Free Software Foundation, Inc.
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)
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.
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/>.
22 #include <testsuite_hooks.h>
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) );
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 );
41 typedef ratio_add
<ratio
<m2
/ 7 * 5 - 1, 5>,
42 ratio
<-m2
+ 2, 7> > ra_type3
;
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
;
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 );