]>
Commit | Line | Data |
---|---|---|
f1717362 | 1 | // Copyright (C) 2009-2016 Free Software Foundation, Inc. |
a9c001cb | 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 | ||
5adf1dac | 18 | // { dg-require-effective-target dfp } |
a9c001cb | 19 | |
20 | // ISO/IEC TR 24733 3.2.2.4 Conversion to integral type (decimal32). | |
21 | // ISO/IEC TR 24733 3.2.3.4 Conversion to integral type (decimal64). | |
22 | // ISO/IEC TR 24733 3.2.4.4 Conversion to integral type (decimal128). | |
23 | ||
24 | #include <decimal/decimal> | |
25 | #include <climits> | |
a9c001cb | 26 | #include <testsuite_hooks.h> |
27 | ||
28 | // Use extension to replace implicit long long conversion with function call. | |
29 | #define LONGLONG(X) decimal_to_long_long(X) | |
30 | ||
31 | using namespace std::decimal; | |
32 | ||
33 | void | |
34 | conversion_to_integral_32 (void) | |
35 | { | |
36 | #undef MAXVAL | |
37 | #define MAXVAL 999999LL | |
0b42d8d9 | 38 | bool test __attribute__((unused)) = true; |
a9c001cb | 39 | decimal32 a, b (1), c (-1), d (MAXVAL), e (-MAXVAL); |
40 | long long ll; | |
41 | ||
42 | ll = LONGLONG (a); VERIFY (ll == 0LL); | |
43 | ll = LONGLONG (b); VERIFY (ll == 1LL); | |
44 | ll = LONGLONG (c); VERIFY (ll == -1LL); | |
45 | ll = LONGLONG (d); VERIFY (ll == MAXVAL); | |
46 | ll = LONGLONG (e); VERIFY (ll == -MAXVAL); | |
47 | } | |
48 | ||
49 | void | |
50 | conversion_to_integral_64 (void) | |
51 | { | |
52 | #undef MAXVAL | |
53 | #define MAXVAL 999999999999999LL | |
0b42d8d9 | 54 | bool test __attribute__((unused)) = true; |
a9c001cb | 55 | decimal64 a, b (1), c (-1), d (MAXVAL), e (-MAXVAL); |
56 | long long ll; | |
57 | ||
58 | ll = LONGLONG (a); VERIFY (ll == 0LL); | |
59 | ll = LONGLONG (b); VERIFY (ll == 1LL); | |
60 | ll = LONGLONG (c); VERIFY (ll == -1LL); | |
61 | ll = LONGLONG (d); VERIFY (ll == MAXVAL); | |
62 | ll = LONGLONG (e); VERIFY (ll == -MAXVAL); | |
63 | } | |
64 | ||
65 | void | |
66 | conversion_to_integral_128 (void) | |
67 | { | |
68 | #undef MAXVAL | |
69 | #define MAXVAL LONG_LONG_MAX | |
0b42d8d9 | 70 | bool test __attribute__((unused)) = true; |
a9c001cb | 71 | decimal128 a, b (1), c (-1), d (MAXVAL), e (-MAXVAL); |
72 | long long ll; | |
73 | ||
74 | ll = LONGLONG (a); VERIFY (ll == 0LL); | |
75 | ll = LONGLONG (b); VERIFY (ll == 1LL); | |
76 | ll = LONGLONG (c); VERIFY (ll == -1LL); | |
77 | ll = LONGLONG (d); VERIFY (ll == MAXVAL); | |
78 | ll = LONGLONG (e); VERIFY (ll == -MAXVAL); | |
79 | } | |
80 | ||
81 | int | |
82 | main () | |
83 | { | |
84 | conversion_to_integral_32 (); | |
85 | conversion_to_integral_64 (); | |
86 | conversion_to_integral_128 (); | |
87 | } |