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