Fix addvdi3 and subvdi3 patterns
[official-gcc.git] / libstdc++-v3 / testsuite / decimal / incdec-memfunc.cc
blob95f0d1efb90e2ea583b2596bfec3dc5a7f7bd2c3
1 // Copyright (C) 2009-2022 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-require-effective-target dfp }
20 // ISO/IEC TR 24733 3.2.2.5 Increment and decrement operators (decimal32).
21 // ISO/IEC TR 24733 3.2.3.5 Increment and decrement operators (decimal64).
22 // ISO/IEC TR 24733 3.2.4.5 Increment and decrement operators (decimal128).
24 // Access member functions directly.
26 #include <decimal/decimal>
27 #include <testsuite_hooks.h>
29 // Use extension to replace implicit long long conversion with function call.
30 #define LONGLONG(X) decimal_to_long_long(X)
32 using namespace std::decimal;
34 void
35 incdec32 (void)
37 int ival;
38 decimal32 a(11), b, c;
40 // Verify that we get the expected value of b after assignment.
41 b = a;
42 ival = LONGLONG (b); VERIFY (ival == 11);
44 // Check that the increment and decrement operators change the value
45 // of the original class.
46 b = a;
47 b.operator++();
48 ival = LONGLONG (b); VERIFY (ival == 12);
50 b = a;
51 b.operator++(1);
52 ival = LONGLONG (b); VERIFY (ival == 12);
54 b = a;
55 b.operator--();
56 ival = LONGLONG (b); VERIFY (ival == 10);
58 b = a;
59 b.operator--(1);
60 ival = LONGLONG (b); VERIFY (ival == 10);
62 // Check that the increment and decrement operators return the
63 // correct value.
64 b = a;
65 c = b.operator++();
66 ival = LONGLONG (c); VERIFY (ival == 12);
68 b = a;
69 c = b.operator++(1);
70 ival = LONGLONG (c); VERIFY (ival == 11);
72 b = a;
73 c = b.operator--();
74 ival = LONGLONG (c); VERIFY (ival == 10);
76 b = a;
77 c = b.operator--(1);
78 ival = LONGLONG (c); VERIFY (ival == 11);
81 void
82 incdec64 (void)
84 int ival;
85 decimal64 a(11), b, c;
87 // Verify that we get the expected value of b after assignment.
88 b = a;
89 ival = LONGLONG (b); VERIFY (ival == 11);
91 // Check that the increment and decrement operators change the value
92 // of the original class.
93 b = a;
94 b.operator++();
95 ival = LONGLONG (b); VERIFY (ival == 12);
97 b = a;
98 b.operator++(1);
99 ival = LONGLONG (b); VERIFY (ival == 12);
101 b = a;
102 b.operator--();
103 ival = LONGLONG (b); VERIFY (ival == 10);
105 b = a;
106 b.operator--(1);
107 ival = LONGLONG (b); VERIFY (ival == 10);
109 // Check that the increment and decrement operators return the
110 // correct value.
111 b = a;
112 c = b.operator++();
113 ival = LONGLONG (c); VERIFY (ival == 12);
115 b = a;
116 c = b.operator++(1);
117 ival = LONGLONG (c); VERIFY (ival == 11);
119 b = a;
120 c = b.operator--();
121 ival = LONGLONG (c); VERIFY (ival == 10);
123 b = a;
124 c = b.operator--(1);
125 ival = LONGLONG (c); VERIFY (ival == 11);
128 void
129 incdec128 (void)
131 int ival;
132 decimal128 a(11), b, c;
134 // Verify that we get the expected value of b after assignment.
135 b = a;
136 ival = LONGLONG (b); VERIFY (ival == 11);
138 // Check that the increment and decrement operators change the value
139 // of the original class.
140 b = a;
141 b.operator++();
142 ival = LONGLONG (b); VERIFY (ival == 12);
144 b = a;
145 b.operator++(1);
146 ival = LONGLONG (b); VERIFY (ival == 12);
148 b = a;
149 b.operator--();
150 ival = LONGLONG (b); VERIFY (ival == 10);
152 b = a;
153 b.operator--(1);
154 ival = LONGLONG (b); VERIFY (ival == 10);
156 // Check that the increment and decrement operators return the
157 // correct value.
158 b = a;
159 c = b.operator++();
160 ival = LONGLONG (c); VERIFY (ival == 12);
162 b = a;
163 c = b.operator++(1);
164 ival = LONGLONG (c); VERIFY (ival == 11);
166 b = a;
167 c = b.operator--();
168 ival = LONGLONG (c); VERIFY (ival == 10);
170 b = a;
171 c = b.operator--(1);
172 ival = LONGLONG (c); VERIFY (ival == 11);
176 main ()
178 incdec32 ();
179 incdec64 ();
180 incdec128 ();