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.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).
24 #include <decimal/decimal>
27 #include <testsuite_hooks.h>
29 // Use extension to replace implicit long long conversion with function call.
30 #define LONGLONG(X) decimal_to_long_long(X)
32 using namespace std::decimal
;
35 conversion_to_integral_32 (void)
38 #define MAXVAL 999999LL
39 decimal32 a
, b (1), c (-1), d (MAXVAL
), e (-MAXVAL
);
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
);
50 conversion_to_integral_64 (void)
53 #define MAXVAL 999999999999999LL
54 decimal64 a
, b (1), c (-1), d (MAXVAL
), e (-MAXVAL
);
57 ll
= LONGLONG (a
); VERIFY (ll
== 0LL);
58 ll
= LONGLONG (b
); VERIFY (ll
== 1LL);
59 ll
= LONGLONG (c
); VERIFY (ll
== -1LL);
60 ll
= LONGLONG (d
); VERIFY (ll
== MAXVAL
);
61 ll
= LONGLONG (e
); VERIFY (ll
== -MAXVAL
);
65 conversion_to_integral_128 (void)
68 #define MAXVAL LONG_LONG_MAX
69 decimal128 a
, b (1), c (-1), d (MAXVAL
), e (-MAXVAL
);
72 ll
= LONGLONG (a
); VERIFY (ll
== 0LL);
73 ll
= LONGLONG (b
); VERIFY (ll
== 1LL);
74 ll
= LONGLONG (c
); VERIFY (ll
== -1LL);
75 ll
= LONGLONG (d
); VERIFY (ll
== MAXVAL
);
76 ll
= LONGLONG (e
); VERIFY (ll
== -MAXVAL
);
82 conversion_to_integral_32 ();
83 conversion_to_integral_64 ();
84 conversion_to_integral_128 ();