1 // Copyright (C) 2009-2018 Free Software Foundation, Inc.
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)
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.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).
24 // Access member functions directly.
26 #include <decimal/decimal>
27 #include <testsuite_hooks.h>
29 using namespace std::decimal
;
37 unsigned long ul
= 20;
39 unsigned long long ull
= 50;
42 compound_assignment_add_32 (void)
44 decimal32
a (1000), b
;
46 b
= a
; b
.operator+=(d32
); VERIFY (b
== 1005);
47 b
= a
; b
.operator+=(d64
); VERIFY (b
== 990);
48 b
= a
; b
.operator+=(d128
); VERIFY (b
== 1025);
49 b
= a
; b
.operator+=(si
); VERIFY (b
== 998);
50 b
= a
; b
.operator+=(ui
); VERIFY (b
== 1005);
51 b
= a
; b
.operator+=(sl
); VERIFY (b
== 990);
52 b
= a
; b
.operator+=(ul
); VERIFY (b
== 1020);
53 b
= a
; b
.operator+=(sll
); VERIFY (b
== 975);
54 b
= a
; b
.operator+=(ull
); VERIFY (b
== 1050);
58 compound_assignment_subtract_32 (void)
60 decimal32
a (1000), b
;
62 b
= a
; b
.operator-=(d32
); VERIFY (b
== 995);
63 b
= a
; b
.operator-=(d64
); VERIFY (b
== 1010);
64 b
= a
; b
.operator-=(d128
); VERIFY (b
== 975);
65 b
= a
; b
.operator-=(si
); VERIFY (b
== 1002);
66 b
= a
; b
.operator-=(ui
); VERIFY (b
== 995);
67 b
= a
; b
.operator-=(sl
); VERIFY (b
== 1010);
68 b
= a
; b
.operator-=(ul
); VERIFY (b
== 980);
69 b
= a
; b
.operator-=(sll
); VERIFY (b
== 1025);
70 b
= a
; b
.operator-=(ull
); VERIFY (b
== 950);
74 compound_assignment_multiply_32 (void)
76 decimal32
a (1000), b
;
78 b
= a
; b
.operator*=(d32
); VERIFY (b
== 5000);
79 b
= a
; b
.operator*=(d64
); VERIFY (b
== -10000);
80 b
= a
; b
.operator*=(d128
); VERIFY (b
== 25000);
81 b
= a
; b
.operator*=(si
); VERIFY (b
== -2000);
82 b
= a
; b
.operator*=(ui
); VERIFY (b
== 5000);
83 b
= a
; b
.operator*=(sl
); VERIFY (b
== -10000);
84 b
= a
; b
.operator*=(ul
); VERIFY (b
== 20000);
85 b
= a
; b
.operator*=(sll
); VERIFY (b
== -25000);
86 b
= a
; b
.operator*=(ull
); VERIFY (b
== 50000);
90 compound_assignment_divide_32 (void)
92 decimal32
a (1000), b
;
94 b
= a
; b
.operator/=(d32
); VERIFY (b
== 200);
95 b
= a
; b
.operator/=(d64
); VERIFY (b
== -100);
96 b
= a
; b
.operator/=(d128
); VERIFY (b
== 40);
97 b
= a
; b
.operator/=(si
); VERIFY (b
== -500);
98 b
= a
; b
.operator/=(ui
); VERIFY (b
== 200);
99 b
= a
; b
.operator/=(sl
); VERIFY (b
== -100);
100 b
= a
; b
.operator/=(ul
); VERIFY (b
== 50);
101 b
= a
; b
.operator/=(sll
); VERIFY (b
== -40);
102 b
= a
; b
.operator/=(ull
); VERIFY (b
== 20);
106 compound_assignment_add_64 (void)
108 decimal64
a (1000), b
;
110 b
= a
; b
.operator+=(d32
); VERIFY (b
== 1005);
111 b
= a
; b
.operator+=(d64
); VERIFY (b
== 990);
112 b
= a
; b
.operator+=(d128
); VERIFY (b
== 1025);
113 b
= a
; b
.operator+=(si
); VERIFY (b
== 998);
114 b
= a
; b
.operator+=(ui
); VERIFY (b
== 1005);
115 b
= a
; b
.operator+=(sl
); VERIFY (b
== 990);
116 b
= a
; b
.operator+=(ul
); VERIFY (b
== 1020);
117 b
= a
; b
.operator+=(sll
); VERIFY (b
== 975);
118 b
= a
; b
.operator+=(ull
); VERIFY (b
== 1050);
122 compound_assignment_subtract_64 (void)
124 decimal64
a (1000), b
;
126 b
= a
; b
.operator-=(d32
); VERIFY (b
== 995);
127 b
= a
; b
.operator-=(d64
); VERIFY (b
== 1010);
128 b
= a
; b
.operator-=(d128
); VERIFY (b
== 975);
129 b
= a
; b
.operator-=(si
); VERIFY (b
== 1002);
130 b
= a
; b
.operator-=(ui
); VERIFY (b
== 995);
131 b
= a
; b
.operator-=(sl
); VERIFY (b
== 1010);
132 b
= a
; b
.operator-=(ul
); VERIFY (b
== 980);
133 b
= a
; b
.operator-=(sll
); VERIFY (b
== 1025);
134 b
= a
; b
.operator-=(ull
); VERIFY (b
== 950);
138 compound_assignment_multiply_64 (void)
140 decimal64
a (1000), b
;
142 b
= a
; b
.operator*=(d32
); VERIFY (b
== 5000);
143 b
= a
; b
.operator*=(d64
); VERIFY (b
== -10000);
144 b
= a
; b
.operator*=(d128
); VERIFY (b
== 25000);
145 b
= a
; b
.operator*=(si
); VERIFY (b
== -2000);
146 b
= a
; b
.operator*=(ui
); VERIFY (b
== 5000);
147 b
= a
; b
.operator*=(sl
); VERIFY (b
== -10000);
148 b
= a
; b
.operator*=(ul
); VERIFY (b
== 20000);
149 b
= a
; b
.operator*=(sll
); VERIFY (b
== -25000);
150 b
= a
; b
.operator*=(ull
); VERIFY (b
== 50000);
154 compound_assignment_divide_64 (void)
156 decimal64
a (1000), b
;
158 b
= a
; b
.operator/=(d32
); VERIFY (b
== 200);
159 b
= a
; b
.operator/=(d64
); VERIFY (b
== -100);
160 b
= a
; b
.operator/=(d128
); VERIFY (b
== 40);
161 b
= a
; b
.operator/=(si
); VERIFY (b
== -500);
162 b
= a
; b
.operator/=(ui
); VERIFY (b
== 200);
163 b
= a
; b
.operator/=(sl
); VERIFY (b
== -100);
164 b
= a
; b
.operator/=(ul
); VERIFY (b
== 50);
165 b
= a
; b
.operator/=(sll
); VERIFY (b
== -40);
166 b
= a
; b
.operator/=(ull
); VERIFY (b
== 20);
170 compound_assignment_add_128 (void)
172 decimal128
a (1000), b
;
174 b
= a
; b
.operator+=(d32
); VERIFY (b
== 1005);
175 b
= a
; b
.operator+=(d64
); VERIFY (b
== 990);
176 b
= a
; b
.operator+=(d128
); VERIFY (b
== 1025);
177 b
= a
; b
.operator+=(si
); VERIFY (b
== 998);
178 b
= a
; b
.operator+=(ui
); VERIFY (b
== 1005);
179 b
= a
; b
.operator+=(sl
); VERIFY (b
== 990);
180 b
= a
; b
.operator+=(ul
); VERIFY (b
== 1020);
181 b
= a
; b
.operator+=(sll
); VERIFY (b
== 975);
182 b
= a
; b
.operator+=(ull
); VERIFY (b
== 1050);
186 compound_assignment_subtract_128 (void)
188 decimal128
a (1000), b
;
190 b
= a
; b
.operator-=(d32
); VERIFY (b
== 995);
191 b
= a
; b
.operator-=(d64
); VERIFY (b
== 1010);
192 b
= a
; b
.operator-=(d128
); VERIFY (b
== 975);
193 b
= a
; b
.operator-=(si
); VERIFY (b
== 1002);
194 b
= a
; b
.operator-=(ui
); VERIFY (b
== 995);
195 b
= a
; b
.operator-=(sl
); VERIFY (b
== 1010);
196 b
= a
; b
.operator-=(ul
); VERIFY (b
== 980);
197 b
= a
; b
.operator-=(sll
); VERIFY (b
== 1025);
198 b
= a
; b
.operator-=(ull
); VERIFY (b
== 950);
202 compound_assignment_multiply_128 (void)
204 decimal128
a (1000), b
;
206 b
= a
; b
.operator*=(d32
); VERIFY (b
== 5000);
207 b
= a
; b
.operator*=(d64
); VERIFY (b
== -10000);
208 b
= a
; b
.operator*=(d128
); VERIFY (b
== 25000);
209 b
= a
; b
.operator*=(si
); VERIFY (b
== -2000);
210 b
= a
; b
.operator*=(ui
); VERIFY (b
== 5000);
211 b
= a
; b
.operator*=(sl
); VERIFY (b
== -10000);
212 b
= a
; b
.operator*=(ul
); VERIFY (b
== 20000);
213 b
= a
; b
.operator*=(sll
); VERIFY (b
== -25000);
214 b
= a
; b
.operator*=(ull
); VERIFY (b
== 50000);
218 compound_assignment_divide_128 (void)
220 decimal128
a (1000), b
;
222 b
= a
; b
.operator/=(d32
); VERIFY (b
== 200);
223 b
= a
; b
.operator/=(d64
); VERIFY (b
== -100);
224 b
= a
; b
.operator/=(d128
); VERIFY (b
== 40);
225 b
= a
; b
.operator/=(si
); VERIFY (b
== -500);
226 b
= a
; b
.operator/=(ui
); VERIFY (b
== 200);
227 b
= a
; b
.operator/=(sl
); VERIFY (b
== -100);
228 b
= a
; b
.operator/=(ul
); VERIFY (b
== 50);
229 b
= a
; b
.operator/=(sll
); VERIFY (b
== -40);
230 b
= a
; b
.operator/=(ull
); VERIFY (b
== 20);
236 compound_assignment_add_32 ();
237 compound_assignment_subtract_32 ();
238 compound_assignment_multiply_32 ();
239 compound_assignment_divide_32 ();
241 compound_assignment_add_64 ();
242 compound_assignment_subtract_64 ();
243 compound_assignment_multiply_64 ();
244 compound_assignment_divide_64 ();
246 compound_assignment_add_128 ();
247 compound_assignment_subtract_128 ();
248 compound_assignment_multiply_128 ();
249 compound_assignment_divide_128 ();