]>
Commit | Line | Data |
---|---|---|
4cdc8761 BK |
1 | // Copyright (C) 2009 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.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). | |
23 | ||
24 | #include <decimal/decimal> | |
25 | #include <testsuite_hooks.h> | |
26 | ||
27 | using namespace std::decimal; | |
28 | ||
29 | void | |
30 | conversion_from_integral_p32 () | |
31 | { | |
32 | decimal32 d; | |
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); | |
39 | ||
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); | |
46 | ||
47 | from_si = 7; | |
48 | d++; VERIFY (from_si == d); | |
49 | from_ui = 8U; | |
50 | d++; VERIFY (from_ui == d); | |
51 | from_sl = 9L; | |
52 | d++; VERIFY (from_sl == d); | |
53 | from_ul = 10UL; | |
54 | d++; VERIFY (from_ul == d); | |
55 | from_sll = 11LL; | |
56 | d++; VERIFY (from_sll == d); | |
57 | from_ull = 12ULL; | |
58 | d++; VERIFY (from_ull == d); | |
59 | } | |
60 | ||
61 | void | |
62 | conversion_from_integral_m32 () | |
63 | { | |
64 | decimal32 d; | |
65 | decimal32 from_si (-1); | |
66 | decimal32 from_sl (-2L); | |
67 | decimal32 from_sll (-3LL); | |
68 | ||
69 | d--; VERIFY (from_si == d); | |
70 | d--; VERIFY (from_sl == d); | |
71 | d--; VERIFY (from_sll == d); | |
72 | ||
73 | from_si = -4; | |
74 | d--; VERIFY (from_si == d); | |
75 | from_sl = -5L; | |
76 | d--; VERIFY (from_sl == d); | |
77 | from_sll = -6LL; | |
78 | d--; VERIFY (from_sll == d); | |
79 | } | |
80 | ||
81 | void | |
82 | conversion_from_integral_p64 () | |
83 | { | |
84 | decimal64 d; | |
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); | |
91 | ||
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); | |
98 | ||
99 | from_si = 7; | |
100 | d++; VERIFY (from_si == d); | |
101 | from_ui = 8U; | |
102 | d++; VERIFY (from_ui == d); | |
103 | from_sl = 9L; | |
104 | d++; VERIFY (from_sl == d); | |
105 | from_ul = 10UL; | |
106 | d++; VERIFY (from_ul == d); | |
107 | from_sll = 11LL; | |
108 | d++; VERIFY (from_sll == d); | |
109 | from_ull = 12ULL; | |
110 | d++; VERIFY (from_ull == d); | |
111 | } | |
112 | ||
113 | void | |
114 | conversion_from_integral_m64 () | |
115 | { | |
116 | decimal64 d; | |
117 | decimal64 from_si (-1); | |
118 | decimal64 from_sl (-2L); | |
119 | decimal64 from_sll (-3LL); | |
120 | ||
121 | d--; VERIFY (from_si == d); | |
122 | d--; VERIFY (from_sl == d); | |
123 | d--; VERIFY (from_sll == d); | |
124 | ||
125 | from_si = -4; | |
126 | d--; VERIFY (from_si == d); | |
127 | from_sl = -5L; | |
128 | d--; VERIFY (from_sl == d); | |
129 | from_sll = -6LL; | |
130 | d--; VERIFY (from_sll == d); | |
131 | } | |
132 | ||
133 | void | |
134 | conversion_from_integral_p128 () | |
135 | { | |
136 | decimal128 d; | |
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); | |
143 | ||
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); | |
150 | ||
151 | from_si = 7; | |
152 | d++; VERIFY (from_si == d); | |
153 | from_ui = 8U; | |
154 | d++; VERIFY (from_ui == d); | |
155 | from_sl = 9L; | |
156 | d++; VERIFY (from_sl == d); | |
157 | from_ul = 10UL; | |
158 | d++; VERIFY (from_ul == d); | |
159 | from_sll = 11LL; | |
160 | d++; VERIFY (from_sll == d); | |
161 | from_ull = 12ULL; | |
162 | } | |
163 | ||
164 | void | |
165 | conversion_from_integral_m128 () | |
166 | { | |
167 | decimal128 d; | |
168 | decimal128 from_si (-1); | |
169 | decimal128 from_sl (-2L); | |
170 | decimal128 from_sll (-3LL); | |
171 | ||
172 | d--; VERIFY (from_si == d); | |
173 | d--; VERIFY (from_sl == d); | |
174 | d--; VERIFY (from_sll == d); | |
175 | ||
176 | from_si = -4; | |
177 | d--; VERIFY (from_si == d); | |
178 | from_sl = -5L; | |
179 | d--; VERIFY (from_sl == d); | |
180 | from_sll = -6LL; | |
181 | d--; VERIFY (from_sll == d); | |
182 | } | |
183 | ||
184 | int | |
185 | main () | |
186 | { | |
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 (); | |
193 | } |