]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/decimal/compound-assignment-memfunc.cc
Update copyright years in libstdc++-v3/
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / decimal / compound-assignment-memfunc.cc
1 // Copyright (C) 2009-2014 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.
8
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.
13
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/>.
17
18 // { dg-require-effective-target dfp }
19
20 // ISO/IEC TR 24733 3.2.2.6 Compound assignment (decimal32).
21 // ISO/IEC TR 24733 3.2.3.6 Compound assignment (decimal64).
22 // ISO/IEC TR 24733 3.2.4.6 Compound assignment (decimal128).
23
24 // Access member functions directly.
25
26 #include <decimal/decimal>
27 #include <testsuite_hooks.h>
28
29 using namespace std::decimal;
30
31 decimal32 d32 (5);
32 decimal64 d64 (-10);
33 decimal128 d128 (25);
34 int si = -2;
35 unsigned int ui = 5;
36 long sl = -10;
37 unsigned long ul = 20;
38 long long sll = -25;
39 unsigned long long ull = 50;
40
41 void
42 compound_assignment_add_32 (void)
43 {
44 bool test __attribute__((unused)) = true;
45 decimal32 a (1000), b;
46
47 b = a; b.operator+=(d32); VERIFY (b == 1005);
48 b = a; b.operator+=(d64); VERIFY (b == 990);
49 b = a; b.operator+=(d128); VERIFY (b == 1025);
50 b = a; b.operator+=(si); VERIFY (b == 998);
51 b = a; b.operator+=(ui); VERIFY (b == 1005);
52 b = a; b.operator+=(sl); VERIFY (b == 990);
53 b = a; b.operator+=(ul); VERIFY (b == 1020);
54 b = a; b.operator+=(sll); VERIFY (b == 975);
55 b = a; b.operator+=(ull); VERIFY (b == 1050);
56 }
57
58 void
59 compound_assignment_subtract_32 (void)
60 {
61 bool test __attribute__((unused)) = true;
62 decimal32 a (1000), b;
63
64 b = a; b.operator-=(d32); VERIFY (b == 995);
65 b = a; b.operator-=(d64); VERIFY (b == 1010);
66 b = a; b.operator-=(d128); VERIFY (b == 975);
67 b = a; b.operator-=(si); VERIFY (b == 1002);
68 b = a; b.operator-=(ui); VERIFY (b == 995);
69 b = a; b.operator-=(sl); VERIFY (b == 1010);
70 b = a; b.operator-=(ul); VERIFY (b == 980);
71 b = a; b.operator-=(sll); VERIFY (b == 1025);
72 b = a; b.operator-=(ull); VERIFY (b == 950);
73 }
74
75 void
76 compound_assignment_multiply_32 (void)
77 {
78 bool test __attribute__((unused)) = true;
79 decimal32 a (1000), b;
80
81 b = a; b.operator*=(d32); VERIFY (b == 5000);
82 b = a; b.operator*=(d64); VERIFY (b == -10000);
83 b = a; b.operator*=(d128); VERIFY (b == 25000);
84 b = a; b.operator*=(si); VERIFY (b == -2000);
85 b = a; b.operator*=(ui); VERIFY (b == 5000);
86 b = a; b.operator*=(sl); VERIFY (b == -10000);
87 b = a; b.operator*=(ul); VERIFY (b == 20000);
88 b = a; b.operator*=(sll); VERIFY (b == -25000);
89 b = a; b.operator*=(ull); VERIFY (b == 50000);
90 }
91
92 void
93 compound_assignment_divide_32 (void)
94 {
95 bool test __attribute__((unused)) = true;
96 decimal32 a (1000), b;
97
98 b = a; b.operator/=(d32); VERIFY (b == 200);
99 b = a; b.operator/=(d64); VERIFY (b == -100);
100 b = a; b.operator/=(d128); VERIFY (b == 40);
101 b = a; b.operator/=(si); VERIFY (b == -500);
102 b = a; b.operator/=(ui); VERIFY (b == 200);
103 b = a; b.operator/=(sl); VERIFY (b == -100);
104 b = a; b.operator/=(ul); VERIFY (b == 50);
105 b = a; b.operator/=(sll); VERIFY (b == -40);
106 b = a; b.operator/=(ull); VERIFY (b == 20);
107 }
108
109 void
110 compound_assignment_add_64 (void)
111 {
112 bool test __attribute__((unused)) = true;
113 decimal64 a (1000), b;
114
115 b = a; b.operator+=(d32); VERIFY (b == 1005);
116 b = a; b.operator+=(d64); VERIFY (b == 990);
117 b = a; b.operator+=(d128); VERIFY (b == 1025);
118 b = a; b.operator+=(si); VERIFY (b == 998);
119 b = a; b.operator+=(ui); VERIFY (b == 1005);
120 b = a; b.operator+=(sl); VERIFY (b == 990);
121 b = a; b.operator+=(ul); VERIFY (b == 1020);
122 b = a; b.operator+=(sll); VERIFY (b == 975);
123 b = a; b.operator+=(ull); VERIFY (b == 1050);
124 }
125
126 void
127 compound_assignment_subtract_64 (void)
128 {
129 bool test __attribute__((unused)) = true;
130 decimal64 a (1000), b;
131
132 b = a; b.operator-=(d32); VERIFY (b == 995);
133 b = a; b.operator-=(d64); VERIFY (b == 1010);
134 b = a; b.operator-=(d128); VERIFY (b == 975);
135 b = a; b.operator-=(si); VERIFY (b == 1002);
136 b = a; b.operator-=(ui); VERIFY (b == 995);
137 b = a; b.operator-=(sl); VERIFY (b == 1010);
138 b = a; b.operator-=(ul); VERIFY (b == 980);
139 b = a; b.operator-=(sll); VERIFY (b == 1025);
140 b = a; b.operator-=(ull); VERIFY (b == 950);
141 }
142
143 void
144 compound_assignment_multiply_64 (void)
145 {
146 bool test __attribute__((unused)) = true;
147 decimal64 a (1000), b;
148
149 b = a; b.operator*=(d32); VERIFY (b == 5000);
150 b = a; b.operator*=(d64); VERIFY (b == -10000);
151 b = a; b.operator*=(d128); VERIFY (b == 25000);
152 b = a; b.operator*=(si); VERIFY (b == -2000);
153 b = a; b.operator*=(ui); VERIFY (b == 5000);
154 b = a; b.operator*=(sl); VERIFY (b == -10000);
155 b = a; b.operator*=(ul); VERIFY (b == 20000);
156 b = a; b.operator*=(sll); VERIFY (b == -25000);
157 b = a; b.operator*=(ull); VERIFY (b == 50000);
158 }
159
160 void
161 compound_assignment_divide_64 (void)
162 {
163 bool test __attribute__((unused)) = true;
164 decimal64 a (1000), b;
165
166 b = a; b.operator/=(d32); VERIFY (b == 200);
167 b = a; b.operator/=(d64); VERIFY (b == -100);
168 b = a; b.operator/=(d128); VERIFY (b == 40);
169 b = a; b.operator/=(si); VERIFY (b == -500);
170 b = a; b.operator/=(ui); VERIFY (b == 200);
171 b = a; b.operator/=(sl); VERIFY (b == -100);
172 b = a; b.operator/=(ul); VERIFY (b == 50);
173 b = a; b.operator/=(sll); VERIFY (b == -40);
174 b = a; b.operator/=(ull); VERIFY (b == 20);
175 }
176
177 void
178 compound_assignment_add_128 (void)
179 {
180 bool test __attribute__((unused)) = true;
181 decimal128 a (1000), b;
182
183 b = a; b.operator+=(d32); VERIFY (b == 1005);
184 b = a; b.operator+=(d64); VERIFY (b == 990);
185 b = a; b.operator+=(d128); VERIFY (b == 1025);
186 b = a; b.operator+=(si); VERIFY (b == 998);
187 b = a; b.operator+=(ui); VERIFY (b == 1005);
188 b = a; b.operator+=(sl); VERIFY (b == 990);
189 b = a; b.operator+=(ul); VERIFY (b == 1020);
190 b = a; b.operator+=(sll); VERIFY (b == 975);
191 b = a; b.operator+=(ull); VERIFY (b == 1050);
192 }
193
194 void
195 compound_assignment_subtract_128 (void)
196 {
197 bool test __attribute__((unused)) = true;
198 decimal128 a (1000), b;
199
200 b = a; b.operator-=(d32); VERIFY (b == 995);
201 b = a; b.operator-=(d64); VERIFY (b == 1010);
202 b = a; b.operator-=(d128); VERIFY (b == 975);
203 b = a; b.operator-=(si); VERIFY (b == 1002);
204 b = a; b.operator-=(ui); VERIFY (b == 995);
205 b = a; b.operator-=(sl); VERIFY (b == 1010);
206 b = a; b.operator-=(ul); VERIFY (b == 980);
207 b = a; b.operator-=(sll); VERIFY (b == 1025);
208 b = a; b.operator-=(ull); VERIFY (b == 950);
209 }
210
211 void
212 compound_assignment_multiply_128 (void)
213 {
214 bool test __attribute__((unused)) = true;
215 decimal128 a (1000), b;
216
217 b = a; b.operator*=(d32); VERIFY (b == 5000);
218 b = a; b.operator*=(d64); VERIFY (b == -10000);
219 b = a; b.operator*=(d128); VERIFY (b == 25000);
220 b = a; b.operator*=(si); VERIFY (b == -2000);
221 b = a; b.operator*=(ui); VERIFY (b == 5000);
222 b = a; b.operator*=(sl); VERIFY (b == -10000);
223 b = a; b.operator*=(ul); VERIFY (b == 20000);
224 b = a; b.operator*=(sll); VERIFY (b == -25000);
225 b = a; b.operator*=(ull); VERIFY (b == 50000);
226 }
227
228 void
229 compound_assignment_divide_128 (void)
230 {
231 bool test __attribute__((unused)) = true;
232 decimal128 a (1000), b;
233
234 b = a; b.operator/=(d32); VERIFY (b == 200);
235 b = a; b.operator/=(d64); VERIFY (b == -100);
236 b = a; b.operator/=(d128); VERIFY (b == 40);
237 b = a; b.operator/=(si); VERIFY (b == -500);
238 b = a; b.operator/=(ui); VERIFY (b == 200);
239 b = a; b.operator/=(sl); VERIFY (b == -100);
240 b = a; b.operator/=(ul); VERIFY (b == 50);
241 b = a; b.operator/=(sll); VERIFY (b == -40);
242 b = a; b.operator/=(ull); VERIFY (b == 20);
243 }
244
245 int
246 main ()
247 {
248 compound_assignment_add_32 ();
249 compound_assignment_subtract_32 ();
250 compound_assignment_multiply_32 ();
251 compound_assignment_divide_32 ();
252
253 compound_assignment_add_64 ();
254 compound_assignment_subtract_64 ();
255 compound_assignment_multiply_64 ();
256 compound_assignment_divide_64 ();
257
258 compound_assignment_add_128 ();
259 compound_assignment_subtract_128 ();
260 compound_assignment_multiply_128 ();
261 compound_assignment_divide_128 ();
262 }