1 // Copyright (C) 2009 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.3 Conversion from integral type (decimal32).
21 // ISO/IEC TR 24733 3.2.3.3 Conversion from integral type (decimal64).
22 // ISO/IEC TR 24733 3.2.4.3 Conversion from integral type (decimal128).
24 #include <decimal/decimal>
25 #include <testsuite_hooks.h>
27 using namespace std::decimal
;
30 conversion_from_integral_p32 ()
33 decimal32
from_si (1);
34 decimal32
from_ui (2U);
35 decimal32
from_sl (3L);
36 decimal32
from_ul (4UL);
37 decimal32
from_sll (5LL);
38 decimal32
from_ull (6ULL);
40 d
++; VERIFY (from_si
== d
);
41 d
++; VERIFY (from_ui
== d
);
42 d
++; VERIFY (from_sl
== d
);
43 d
++; VERIFY (from_ul
== d
);
44 d
++; VERIFY (from_sll
== d
);
45 d
++; VERIFY (from_ull
== d
);
48 d
++; VERIFY (from_si
== d
);
50 d
++; VERIFY (from_ui
== d
);
52 d
++; VERIFY (from_sl
== d
);
54 d
++; VERIFY (from_ul
== d
);
56 d
++; VERIFY (from_sll
== d
);
58 d
++; VERIFY (from_ull
== d
);
62 conversion_from_integral_m32 ()
65 decimal32
from_si (-1);
66 decimal32
from_sl (-2L);
67 decimal32
from_sll (-3LL);
69 d
--; VERIFY (from_si
== d
);
70 d
--; VERIFY (from_sl
== d
);
71 d
--; VERIFY (from_sll
== d
);
74 d
--; VERIFY (from_si
== d
);
76 d
--; VERIFY (from_sl
== d
);
78 d
--; VERIFY (from_sll
== d
);
82 conversion_from_integral_p64 ()
85 decimal64
from_si (1);
86 decimal64
from_ui (2U);
87 decimal64
from_sl (3L);
88 decimal64
from_ul (4UL);
89 decimal64
from_sll (5LL);
90 decimal64
from_ull (6ULL);
92 d
++; VERIFY (from_si
== d
);
93 d
++; VERIFY (from_ui
== d
);
94 d
++; VERIFY (from_sl
== d
);
95 d
++; VERIFY (from_ul
== d
);
96 d
++; VERIFY (from_sll
== d
);
97 d
++; VERIFY (from_ull
== d
);
100 d
++; VERIFY (from_si
== d
);
102 d
++; VERIFY (from_ui
== d
);
104 d
++; VERIFY (from_sl
== d
);
106 d
++; VERIFY (from_ul
== d
);
108 d
++; VERIFY (from_sll
== d
);
110 d
++; VERIFY (from_ull
== d
);
114 conversion_from_integral_m64 ()
117 decimal64
from_si (-1);
118 decimal64
from_sl (-2L);
119 decimal64
from_sll (-3LL);
121 d
--; VERIFY (from_si
== d
);
122 d
--; VERIFY (from_sl
== d
);
123 d
--; VERIFY (from_sll
== d
);
126 d
--; VERIFY (from_si
== d
);
128 d
--; VERIFY (from_sl
== d
);
130 d
--; VERIFY (from_sll
== d
);
134 conversion_from_integral_p128 ()
137 decimal128
from_si (1);
138 decimal128
from_ui (2U);
139 decimal128
from_sl (3L);
140 decimal128
from_ul (4UL);
141 decimal128
from_sll (5LL);
142 decimal128
from_ull (6ULL);
144 d
++; VERIFY (from_si
== d
);
145 d
++; VERIFY (from_ui
== d
);
146 d
++; VERIFY (from_sl
== d
);
147 d
++; VERIFY (from_ul
== d
);
148 d
++; VERIFY (from_sll
== d
);
149 d
++; VERIFY (from_ull
== d
);
152 d
++; VERIFY (from_si
== d
);
154 d
++; VERIFY (from_ui
== d
);
156 d
++; VERIFY (from_sl
== d
);
158 d
++; VERIFY (from_ul
== d
);
160 d
++; VERIFY (from_sll
== d
);
165 conversion_from_integral_m128 ()
168 decimal128
from_si (-1);
169 decimal128
from_sl (-2L);
170 decimal128
from_sll (-3LL);
172 d
--; VERIFY (from_si
== d
);
173 d
--; VERIFY (from_sl
== d
);
174 d
--; VERIFY (from_sll
== d
);
177 d
--; VERIFY (from_si
== d
);
179 d
--; VERIFY (from_sl
== d
);
181 d
--; VERIFY (from_sll
== d
);
187 conversion_from_integral_p32 ();
188 conversion_from_integral_m32 ();
189 conversion_from_integral_p64 ();
190 conversion_from_integral_m64 ();
191 conversion_from_integral_p128 ();
192 conversion_from_integral_m128 ();