1 | // decimal classes -*- C++ -*-
|
---|
2 |
|
---|
3 | // Copyright (C) 2009-2021 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 | // Under Section 7 of GPL version 3, you are granted additional
|
---|
17 | // permissions described in the GCC Runtime Library Exception, version
|
---|
18 | // 3.1, as published by the Free Software Foundation.
|
---|
19 |
|
---|
20 | // You should have received a copy of the GNU General Public License and
|
---|
21 | // a copy of the GCC Runtime Library Exception along with this program;
|
---|
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
---|
23 | // <http://www.gnu.org/licenses/>.
|
---|
24 |
|
---|
25 | /** @file decimal/decimal.h
|
---|
26 | * This is an internal header file, included by other library headers.
|
---|
27 | * Do not attempt to use it directly. @headername{decimal}
|
---|
28 | */
|
---|
29 |
|
---|
30 | // ISO/IEC TR 24733
|
---|
31 | // Written by Janis Johnson <janis187@us.ibm.com>
|
---|
32 |
|
---|
33 | #ifndef _GLIBCXX_DECIMAL_IMPL
|
---|
34 | #define _GLIBCXX_DECIMAL_IMPL 1
|
---|
35 |
|
---|
36 | #pragma GCC system_header
|
---|
37 |
|
---|
38 | namespace std _GLIBCXX_VISIBILITY(default)
|
---|
39 | {
|
---|
40 | _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
---|
41 |
|
---|
42 | namespace decimal
|
---|
43 | {
|
---|
44 | // ISO/IEC TR 24733 3.2.[234].1 Construct/copy/destroy.
|
---|
45 |
|
---|
46 | inline decimal32::decimal32(decimal64 __r) : __val(__r.__getval()) {}
|
---|
47 | inline decimal32::decimal32(decimal128 __r) : __val(__r.__getval()) {}
|
---|
48 | inline decimal64::decimal64(decimal32 __r) : __val(__r.__getval()) {}
|
---|
49 | inline decimal64::decimal64(decimal128 __r) : __val(__r.__getval()) {}
|
---|
50 | inline decimal128::decimal128(decimal32 __r) : __val(__r.__getval()) {}
|
---|
51 | inline decimal128::decimal128(decimal64 __r) : __val(__r.__getval()) {}
|
---|
52 |
|
---|
53 | // ISO/IEC TR 24733 3.2.[234].6 Compound assignment.
|
---|
54 |
|
---|
55 | #define _DEFINE_DECIMAL_COMPOUND_ASSIGNMENT_DEC(_Op1, _Op2, _T1, _T2) \
|
---|
56 | inline _T1& _T1::operator _Op1(_T2 __rhs) \
|
---|
57 | { \
|
---|
58 | __setval(__getval() _Op2 __rhs.__getval()); \
|
---|
59 | return *this; \
|
---|
60 | }
|
---|
61 |
|
---|
62 | #define _DEFINE_DECIMAL_COMPOUND_ASSIGNMENT_INT(_Op1, _Op2, _T1, _T2) \
|
---|
63 | inline _T1& _T1::operator _Op1(_T2 __rhs) \
|
---|
64 | { \
|
---|
65 | __setval(__getval() _Op2 __rhs); \
|
---|
66 | return *this; \
|
---|
67 | }
|
---|
68 |
|
---|
69 | #define _DEFINE_DECIMAL_COMPOUND_ASSIGNMENTS(_Op1, _Op2, _T1) \
|
---|
70 | _DEFINE_DECIMAL_COMPOUND_ASSIGNMENT_DEC(_Op1, _Op2, _T1, decimal32) \
|
---|
71 | _DEFINE_DECIMAL_COMPOUND_ASSIGNMENT_DEC(_Op1, _Op2, _T1, decimal64) \
|
---|
72 | _DEFINE_DECIMAL_COMPOUND_ASSIGNMENT_DEC(_Op1, _Op2, _T1, decimal128) \
|
---|
73 | _DEFINE_DECIMAL_COMPOUND_ASSIGNMENT_INT(_Op1, _Op2, _T1, int) \
|
---|
74 | _DEFINE_DECIMAL_COMPOUND_ASSIGNMENT_INT(_Op1, _Op2, _T1, unsigned int) \
|
---|
75 | _DEFINE_DECIMAL_COMPOUND_ASSIGNMENT_INT(_Op1, _Op2, _T1, long) \
|
---|
76 | _DEFINE_DECIMAL_COMPOUND_ASSIGNMENT_INT(_Op1, _Op2, _T1, unsigned long)\
|
---|
77 | _DEFINE_DECIMAL_COMPOUND_ASSIGNMENT_INT(_Op1, _Op2, _T1, long long) \
|
---|
78 | _DEFINE_DECIMAL_COMPOUND_ASSIGNMENT_INT(_Op1, _Op2, _T1, unsigned long long)
|
---|
79 |
|
---|
80 | _DEFINE_DECIMAL_COMPOUND_ASSIGNMENTS(+=, +, decimal32)
|
---|
81 | _DEFINE_DECIMAL_COMPOUND_ASSIGNMENTS(-=, -, decimal32)
|
---|
82 | _DEFINE_DECIMAL_COMPOUND_ASSIGNMENTS(*=, *, decimal32)
|
---|
83 | _DEFINE_DECIMAL_COMPOUND_ASSIGNMENTS(/=, /, decimal32)
|
---|
84 |
|
---|
85 | _DEFINE_DECIMAL_COMPOUND_ASSIGNMENTS(+=, +, decimal64)
|
---|
86 | _DEFINE_DECIMAL_COMPOUND_ASSIGNMENTS(-=, -, decimal64)
|
---|
87 | _DEFINE_DECIMAL_COMPOUND_ASSIGNMENTS(*=, *, decimal64)
|
---|
88 | _DEFINE_DECIMAL_COMPOUND_ASSIGNMENTS(/=, /, decimal64)
|
---|
89 |
|
---|
90 | _DEFINE_DECIMAL_COMPOUND_ASSIGNMENTS(+=, +, decimal128)
|
---|
91 | _DEFINE_DECIMAL_COMPOUND_ASSIGNMENTS(-=, -, decimal128)
|
---|
92 | _DEFINE_DECIMAL_COMPOUND_ASSIGNMENTS(*=, *, decimal128)
|
---|
93 | _DEFINE_DECIMAL_COMPOUND_ASSIGNMENTS(/=, /, decimal128)
|
---|
94 |
|
---|
95 | #undef _DEFINE_DECIMAL_COMPOUND_ASSIGNMENT_DEC
|
---|
96 | #undef _DEFINE_DECIMAL_COMPOUND_ASSIGNMENT_INT
|
---|
97 | #undef _DEFINE_DECIMAL_COMPOUND_ASSIGNMENTS
|
---|
98 |
|
---|
99 | // Extension: Conversion to integral type.
|
---|
100 |
|
---|
101 | inline long long decimal32_to_long_long(decimal32 __d)
|
---|
102 | { return (long long)__d.__getval(); }
|
---|
103 |
|
---|
104 | inline long long decimal64_to_long_long(decimal64 __d)
|
---|
105 | { return (long long)__d.__getval(); }
|
---|
106 |
|
---|
107 | inline long long decimal128_to_long_long(decimal128 __d)
|
---|
108 | { return (long long)__d.__getval(); }
|
---|
109 |
|
---|
110 | inline long long decimal_to_long_long(decimal32 __d)
|
---|
111 | { return (long long)__d.__getval(); }
|
---|
112 |
|
---|
113 | inline long long decimal_to_long_long(decimal64 __d)
|
---|
114 | { return (long long)__d.__getval(); }
|
---|
115 |
|
---|
116 | inline long long decimal_to_long_long(decimal128 __d)
|
---|
117 | { return (long long)__d.__getval(); }
|
---|
118 |
|
---|
119 | // ISO/IEC TR 24733 3.2.5 Initialization from coefficient and exponent.
|
---|
120 |
|
---|
121 | static decimal32 make_decimal32(long long __coeff, int __exponent)
|
---|
122 | {
|
---|
123 | decimal32 __decexp = 1, __multiplier;
|
---|
124 |
|
---|
125 | if (__exponent < 0)
|
---|
126 | {
|
---|
127 | __multiplier = 1.E-1DF;
|
---|
128 | __exponent = -__exponent;
|
---|
129 | }
|
---|
130 | else
|
---|
131 | __multiplier = 1.E1DF;
|
---|
132 |
|
---|
133 | for (int __i = 0; __i < __exponent; ++__i)
|
---|
134 | __decexp *= __multiplier;
|
---|
135 |
|
---|
136 | return __coeff * __decexp;
|
---|
137 | }
|
---|
138 |
|
---|
139 | static decimal32 make_decimal32(unsigned long long __coeff, int __exponent)
|
---|
140 | {
|
---|
141 | decimal32 __decexp = 1, __multiplier;
|
---|
142 |
|
---|
143 | if (__exponent < 0)
|
---|
144 | {
|
---|
145 | __multiplier = 1.E-1DF;
|
---|
146 | __exponent = -__exponent;
|
---|
147 | }
|
---|
148 | else
|
---|
149 | __multiplier = 1.E1DF;
|
---|
150 |
|
---|
151 | for (int __i = 0; __i < __exponent; ++__i)
|
---|
152 | __decexp *= __multiplier;
|
---|
153 |
|
---|
154 | return __coeff * __decexp;
|
---|
155 | }
|
---|
156 |
|
---|
157 | static decimal64 make_decimal64(long long __coeff, int __exponent)
|
---|
158 | {
|
---|
159 | decimal64 __decexp = 1, __multiplier;
|
---|
160 |
|
---|
161 | if (__exponent < 0)
|
---|
162 | {
|
---|
163 | __multiplier = 1.E-1DD;
|
---|
164 | __exponent = -__exponent;
|
---|
165 | }
|
---|
166 | else
|
---|
167 | __multiplier = 1.E1DD;
|
---|
168 |
|
---|
169 | for (int __i = 0; __i < __exponent; ++__i)
|
---|
170 | __decexp *= __multiplier;
|
---|
171 |
|
---|
172 | return __coeff * __decexp;
|
---|
173 | }
|
---|
174 |
|
---|
175 | static decimal64 make_decimal64(unsigned long long __coeff, int __exponent)
|
---|
176 | {
|
---|
177 | decimal64 __decexp = 1, __multiplier;
|
---|
178 |
|
---|
179 | if (__exponent < 0)
|
---|
180 | {
|
---|
181 | __multiplier = 1.E-1DD;
|
---|
182 | __exponent = -__exponent;
|
---|
183 | }
|
---|
184 | else
|
---|
185 | __multiplier = 1.E1DD;
|
---|
186 |
|
---|
187 | for (int __i = 0; __i < __exponent; ++__i)
|
---|
188 | __decexp *= __multiplier;
|
---|
189 |
|
---|
190 | return __coeff * __decexp;
|
---|
191 | }
|
---|
192 |
|
---|
193 | static decimal128 make_decimal128(long long __coeff, int __exponent)
|
---|
194 | {
|
---|
195 | decimal128 __decexp = 1, __multiplier;
|
---|
196 |
|
---|
197 | if (__exponent < 0)
|
---|
198 | {
|
---|
199 | __multiplier = 1.E-1DL;
|
---|
200 | __exponent = -__exponent;
|
---|
201 | }
|
---|
202 | else
|
---|
203 | __multiplier = 1.E1DL;
|
---|
204 |
|
---|
205 | for (int __i = 0; __i < __exponent; ++__i)
|
---|
206 | __decexp *= __multiplier;
|
---|
207 |
|
---|
208 | return __coeff * __decexp;
|
---|
209 | }
|
---|
210 |
|
---|
211 | static decimal128 make_decimal128(unsigned long long __coeff, int __exponent)
|
---|
212 | {
|
---|
213 | decimal128 __decexp = 1, __multiplier;
|
---|
214 |
|
---|
215 | if (__exponent < 0)
|
---|
216 | {
|
---|
217 | __multiplier = 1.E-1DL;
|
---|
218 | __exponent = -__exponent;
|
---|
219 | }
|
---|
220 | else
|
---|
221 | __multiplier = 1.E1DL;
|
---|
222 |
|
---|
223 | for (int __i = 0; __i < __exponent; ++__i)
|
---|
224 | __decexp *= __multiplier;
|
---|
225 |
|
---|
226 | return __coeff * __decexp;
|
---|
227 | }
|
---|
228 |
|
---|
229 | // ISO/IEC TR 24733 3.2.6 Conversion to generic floating-point type.
|
---|
230 |
|
---|
231 | inline float decimal32_to_float(decimal32 __d)
|
---|
232 | { return (float)__d.__getval(); }
|
---|
233 |
|
---|
234 | inline float decimal64_to_float(decimal64 __d)
|
---|
235 | { return (float)__d.__getval(); }
|
---|
236 |
|
---|
237 | inline float decimal128_to_float(decimal128 __d)
|
---|
238 | { return (float)__d.__getval(); }
|
---|
239 |
|
---|
240 | inline float decimal_to_float(decimal32 __d)
|
---|
241 | { return (float)__d.__getval(); }
|
---|
242 |
|
---|
243 | inline float decimal_to_float(decimal64 __d)
|
---|
244 | { return (float)__d.__getval(); }
|
---|
245 |
|
---|
246 | inline float decimal_to_float(decimal128 __d)
|
---|
247 | { return (float)__d.__getval(); }
|
---|
248 |
|
---|
249 | inline double decimal32_to_double(decimal32 __d)
|
---|
250 | { return (double)__d.__getval(); }
|
---|
251 |
|
---|
252 | inline double decimal64_to_double(decimal64 __d)
|
---|
253 | { return (double)__d.__getval(); }
|
---|
254 |
|
---|
255 | inline double decimal128_to_double(decimal128 __d)
|
---|
256 | { return (double)__d.__getval(); }
|
---|
257 |
|
---|
258 | inline double decimal_to_double(decimal32 __d)
|
---|
259 | { return (double)__d.__getval(); }
|
---|
260 |
|
---|
261 | inline double decimal_to_double(decimal64 __d)
|
---|
262 | { return (double)__d.__getval(); }
|
---|
263 |
|
---|
264 | inline double decimal_to_double(decimal128 __d)
|
---|
265 | { return (double)__d.__getval(); }
|
---|
266 |
|
---|
267 | inline long double decimal32_to_long_double(decimal32 __d)
|
---|
268 | { return (long double)__d.__getval(); }
|
---|
269 |
|
---|
270 | inline long double decimal64_to_long_double(decimal64 __d)
|
---|
271 | { return (long double)__d.__getval(); }
|
---|
272 |
|
---|
273 | inline long double decimal128_to_long_double(decimal128 __d)
|
---|
274 | { return (long double)__d.__getval(); }
|
---|
275 |
|
---|
276 | inline long double decimal_to_long_double(decimal32 __d)
|
---|
277 | { return (long double)__d.__getval(); }
|
---|
278 |
|
---|
279 | inline long double decimal_to_long_double(decimal64 __d)
|
---|
280 | { return (long double)__d.__getval(); }
|
---|
281 |
|
---|
282 | inline long double decimal_to_long_double(decimal128 __d)
|
---|
283 | { return (long double)__d.__getval(); }
|
---|
284 |
|
---|
285 | // ISO/IEC TR 24733 3.2.7 Unary arithmetic operators.
|
---|
286 |
|
---|
287 | #define _DEFINE_DECIMAL_UNARY_OP(_Op, _Tp) \
|
---|
288 | inline _Tp operator _Op(_Tp __rhs) \
|
---|
289 | { \
|
---|
290 | _Tp __tmp; \
|
---|
291 | __tmp.__setval(_Op __rhs.__getval()); \
|
---|
292 | return __tmp; \
|
---|
293 | }
|
---|
294 |
|
---|
295 | _DEFINE_DECIMAL_UNARY_OP(+, decimal32)
|
---|
296 | _DEFINE_DECIMAL_UNARY_OP(+, decimal64)
|
---|
297 | _DEFINE_DECIMAL_UNARY_OP(+, decimal128)
|
---|
298 | _DEFINE_DECIMAL_UNARY_OP(-, decimal32)
|
---|
299 | _DEFINE_DECIMAL_UNARY_OP(-, decimal64)
|
---|
300 | _DEFINE_DECIMAL_UNARY_OP(-, decimal128)
|
---|
301 |
|
---|
302 | #undef _DEFINE_DECIMAL_UNARY_OP
|
---|
303 |
|
---|
304 | // ISO/IEC TR 24733 3.2.8 Binary arithmetic operators.
|
---|
305 |
|
---|
306 | #define _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(_Op, _T1, _T2, _T3) \
|
---|
307 | inline _T1 operator _Op(_T2 __lhs, _T3 __rhs) \
|
---|
308 | { \
|
---|
309 | _T1 __retval; \
|
---|
310 | __retval.__setval(__lhs.__getval() _Op __rhs.__getval()); \
|
---|
311 | return __retval; \
|
---|
312 | }
|
---|
313 |
|
---|
314 | #define _DEFINE_DECIMAL_BINARY_OP_BOTH(_Op, _T1, _T2, _T3) \
|
---|
315 | inline _T1 operator _Op(_T2 __lhs, _T3 __rhs) \
|
---|
316 | { \
|
---|
317 | _T1 __retval; \
|
---|
318 | __retval.__setval(__lhs.__getval() _Op __rhs.__getval()); \
|
---|
319 | return __retval; \
|
---|
320 | }
|
---|
321 |
|
---|
322 | #define _DEFINE_DECIMAL_BINARY_OP_LHS(_Op, _T1, _T2) \
|
---|
323 | inline _T1 operator _Op(_T1 __lhs, _T2 __rhs) \
|
---|
324 | { \
|
---|
325 | _T1 __retval; \
|
---|
326 | __retval.__setval(__lhs.__getval() _Op __rhs); \
|
---|
327 | return __retval; \
|
---|
328 | }
|
---|
329 |
|
---|
330 | #define _DEFINE_DECIMAL_BINARY_OP_RHS(_Op, _T1, _T2) \
|
---|
331 | inline _T1 operator _Op(_T2 __lhs, _T1 __rhs) \
|
---|
332 | { \
|
---|
333 | _T1 __retval; \
|
---|
334 | __retval.__setval(__lhs _Op __rhs.__getval()); \
|
---|
335 | return __retval; \
|
---|
336 | }
|
---|
337 |
|
---|
338 | #define _DEFINE_DECIMAL_BINARY_OP_WITH_INT(_Op, _T1) \
|
---|
339 | _DEFINE_DECIMAL_BINARY_OP_LHS(_Op, _T1, int); \
|
---|
340 | _DEFINE_DECIMAL_BINARY_OP_LHS(_Op, _T1, unsigned int); \
|
---|
341 | _DEFINE_DECIMAL_BINARY_OP_LHS(_Op, _T1, long); \
|
---|
342 | _DEFINE_DECIMAL_BINARY_OP_LHS(_Op, _T1, unsigned long); \
|
---|
343 | _DEFINE_DECIMAL_BINARY_OP_LHS(_Op, _T1, long long); \
|
---|
344 | _DEFINE_DECIMAL_BINARY_OP_LHS(_Op, _T1, unsigned long long); \
|
---|
345 | _DEFINE_DECIMAL_BINARY_OP_RHS(_Op, _T1, int); \
|
---|
346 | _DEFINE_DECIMAL_BINARY_OP_RHS(_Op, _T1, unsigned int); \
|
---|
347 | _DEFINE_DECIMAL_BINARY_OP_RHS(_Op, _T1, long); \
|
---|
348 | _DEFINE_DECIMAL_BINARY_OP_RHS(_Op, _T1, unsigned long); \
|
---|
349 | _DEFINE_DECIMAL_BINARY_OP_RHS(_Op, _T1, long long); \
|
---|
350 | _DEFINE_DECIMAL_BINARY_OP_RHS(_Op, _T1, unsigned long long); \
|
---|
351 |
|
---|
352 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(+, decimal32, decimal32, decimal32)
|
---|
353 | _DEFINE_DECIMAL_BINARY_OP_WITH_INT(+, decimal32)
|
---|
354 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(+, decimal64, decimal32, decimal64)
|
---|
355 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(+, decimal64, decimal64, decimal32)
|
---|
356 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(+, decimal64, decimal64, decimal64)
|
---|
357 | _DEFINE_DECIMAL_BINARY_OP_WITH_INT(+, decimal64)
|
---|
358 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(+, decimal128, decimal32, decimal128)
|
---|
359 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(+, decimal128, decimal64, decimal128)
|
---|
360 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(+, decimal128, decimal128, decimal32)
|
---|
361 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(+, decimal128, decimal128, decimal64)
|
---|
362 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(+, decimal128, decimal128, decimal128)
|
---|
363 | _DEFINE_DECIMAL_BINARY_OP_WITH_INT(+, decimal128)
|
---|
364 |
|
---|
365 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(-, decimal32, decimal32, decimal32)
|
---|
366 | _DEFINE_DECIMAL_BINARY_OP_WITH_INT(-, decimal32)
|
---|
367 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(-, decimal64, decimal32, decimal64)
|
---|
368 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(-, decimal64, decimal64, decimal32)
|
---|
369 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(-, decimal64, decimal64, decimal64)
|
---|
370 | _DEFINE_DECIMAL_BINARY_OP_WITH_INT(-, decimal64)
|
---|
371 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(-, decimal128, decimal32, decimal128)
|
---|
372 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(-, decimal128, decimal64, decimal128)
|
---|
373 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(-, decimal128, decimal128, decimal32)
|
---|
374 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(-, decimal128, decimal128, decimal64)
|
---|
375 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(-, decimal128, decimal128, decimal128)
|
---|
376 | _DEFINE_DECIMAL_BINARY_OP_WITH_INT(-, decimal128)
|
---|
377 |
|
---|
378 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(*, decimal32, decimal32, decimal32)
|
---|
379 | _DEFINE_DECIMAL_BINARY_OP_WITH_INT(*, decimal32)
|
---|
380 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(*, decimal64, decimal32, decimal64)
|
---|
381 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(*, decimal64, decimal64, decimal32)
|
---|
382 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(*, decimal64, decimal64, decimal64)
|
---|
383 | _DEFINE_DECIMAL_BINARY_OP_WITH_INT(*, decimal64)
|
---|
384 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(*, decimal128, decimal32, decimal128)
|
---|
385 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(*, decimal128, decimal64, decimal128)
|
---|
386 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(*, decimal128, decimal128, decimal32)
|
---|
387 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(*, decimal128, decimal128, decimal64)
|
---|
388 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(*, decimal128, decimal128, decimal128)
|
---|
389 | _DEFINE_DECIMAL_BINARY_OP_WITH_INT(*, decimal128)
|
---|
390 |
|
---|
391 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(/, decimal32, decimal32, decimal32)
|
---|
392 | _DEFINE_DECIMAL_BINARY_OP_WITH_INT(/, decimal32)
|
---|
393 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(/, decimal64, decimal32, decimal64)
|
---|
394 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(/, decimal64, decimal64, decimal32)
|
---|
395 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(/, decimal64, decimal64, decimal64)
|
---|
396 | _DEFINE_DECIMAL_BINARY_OP_WITH_INT(/, decimal64)
|
---|
397 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(/, decimal128, decimal32, decimal128)
|
---|
398 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(/, decimal128, decimal64, decimal128)
|
---|
399 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(/, decimal128, decimal128, decimal32)
|
---|
400 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(/, decimal128, decimal128, decimal64)
|
---|
401 | _DEFINE_DECIMAL_BINARY_OP_WITH_DEC(/, decimal128, decimal128, decimal128)
|
---|
402 | _DEFINE_DECIMAL_BINARY_OP_WITH_INT(/, decimal128)
|
---|
403 |
|
---|
404 | #undef _DEFINE_DECIMAL_BINARY_OP_WITH_DEC
|
---|
405 | #undef _DEFINE_DECIMAL_BINARY_OP_BOTH
|
---|
406 | #undef _DEFINE_DECIMAL_BINARY_OP_LHS
|
---|
407 | #undef _DEFINE_DECIMAL_BINARY_OP_RHS
|
---|
408 | #undef _DEFINE_DECIMAL_BINARY_OP_WITH_INT
|
---|
409 |
|
---|
410 | // ISO/IEC TR 24733 3.2.9 Comparison operators.
|
---|
411 |
|
---|
412 | #define _DEFINE_DECIMAL_COMPARISON_BOTH(_Op, _T1, _T2) \
|
---|
413 | inline bool operator _Op(_T1 __lhs, _T2 __rhs) \
|
---|
414 | { return __lhs.__getval() _Op __rhs.__getval(); }
|
---|
415 |
|
---|
416 | #define _DEFINE_DECIMAL_COMPARISON_LHS(_Op, _T1, _T2) \
|
---|
417 | inline bool operator _Op(_T1 __lhs, _T2 __rhs) \
|
---|
418 | { return __lhs.__getval() _Op __rhs; }
|
---|
419 |
|
---|
420 | #define _DEFINE_DECIMAL_COMPARISON_RHS(_Op, _T1, _T2) \
|
---|
421 | inline bool operator _Op(_T1 __lhs, _T2 __rhs) \
|
---|
422 | { return __lhs _Op __rhs.__getval(); }
|
---|
423 |
|
---|
424 | #define _DEFINE_DECIMAL_COMPARISONS(_Op, _Tp) \
|
---|
425 | _DEFINE_DECIMAL_COMPARISON_BOTH(_Op, _Tp, decimal32) \
|
---|
426 | _DEFINE_DECIMAL_COMPARISON_BOTH(_Op, _Tp, decimal64) \
|
---|
427 | _DEFINE_DECIMAL_COMPARISON_BOTH(_Op, _Tp, decimal128) \
|
---|
428 | _DEFINE_DECIMAL_COMPARISON_LHS(_Op, _Tp, int) \
|
---|
429 | _DEFINE_DECIMAL_COMPARISON_LHS(_Op, _Tp, unsigned int) \
|
---|
430 | _DEFINE_DECIMAL_COMPARISON_LHS(_Op, _Tp, long) \
|
---|
431 | _DEFINE_DECIMAL_COMPARISON_LHS(_Op, _Tp, unsigned long) \
|
---|
432 | _DEFINE_DECIMAL_COMPARISON_LHS(_Op, _Tp, long long) \
|
---|
433 | _DEFINE_DECIMAL_COMPARISON_LHS(_Op, _Tp, unsigned long long) \
|
---|
434 | _DEFINE_DECIMAL_COMPARISON_RHS(_Op, int, _Tp) \
|
---|
435 | _DEFINE_DECIMAL_COMPARISON_RHS(_Op, unsigned int, _Tp) \
|
---|
436 | _DEFINE_DECIMAL_COMPARISON_RHS(_Op, long, _Tp) \
|
---|
437 | _DEFINE_DECIMAL_COMPARISON_RHS(_Op, unsigned long, _Tp) \
|
---|
438 | _DEFINE_DECIMAL_COMPARISON_RHS(_Op, long long, _Tp) \
|
---|
439 | _DEFINE_DECIMAL_COMPARISON_RHS(_Op, unsigned long long, _Tp)
|
---|
440 |
|
---|
441 | _DEFINE_DECIMAL_COMPARISONS(==, decimal32)
|
---|
442 | _DEFINE_DECIMAL_COMPARISONS(==, decimal64)
|
---|
443 | _DEFINE_DECIMAL_COMPARISONS(==, decimal128)
|
---|
444 | _DEFINE_DECIMAL_COMPARISONS(!=, decimal32)
|
---|
445 | _DEFINE_DECIMAL_COMPARISONS(!=, decimal64)
|
---|
446 | _DEFINE_DECIMAL_COMPARISONS(!=, decimal128)
|
---|
447 | _DEFINE_DECIMAL_COMPARISONS(<, decimal32)
|
---|
448 | _DEFINE_DECIMAL_COMPARISONS(<, decimal64)
|
---|
449 | _DEFINE_DECIMAL_COMPARISONS(<, decimal128)
|
---|
450 | _DEFINE_DECIMAL_COMPARISONS(<=, decimal32)
|
---|
451 | _DEFINE_DECIMAL_COMPARISONS(<=, decimal64)
|
---|
452 | _DEFINE_DECIMAL_COMPARISONS(<=, decimal128)
|
---|
453 | _DEFINE_DECIMAL_COMPARISONS(>, decimal32)
|
---|
454 | _DEFINE_DECIMAL_COMPARISONS(>, decimal64)
|
---|
455 | _DEFINE_DECIMAL_COMPARISONS(>, decimal128)
|
---|
456 | _DEFINE_DECIMAL_COMPARISONS(>=, decimal32)
|
---|
457 | _DEFINE_DECIMAL_COMPARISONS(>=, decimal64)
|
---|
458 | _DEFINE_DECIMAL_COMPARISONS(>=, decimal128)
|
---|
459 |
|
---|
460 | #undef _DEFINE_DECIMAL_COMPARISON_BOTH
|
---|
461 | #undef _DEFINE_DECIMAL_COMPARISON_LHS
|
---|
462 | #undef _DEFINE_DECIMAL_COMPARISON_RHS
|
---|
463 | #undef _DEFINE_DECIMAL_COMPARISONS
|
---|
464 | } // namespace decimal
|
---|
465 |
|
---|
466 | _GLIBCXX_END_NAMESPACE_VERSION
|
---|
467 | } // namespace std
|
---|
468 |
|
---|
469 | #endif /* _GLIBCXX_DECIMAL_IMPL */
|
---|