]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/decimal/conversion-to-integral.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / decimal / conversion-to-integral.cc
CommitLineData
99dee823 1// Copyright (C) 2009-2021 Free Software Foundation, Inc.
4cdc8761
BK
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
02ebbe2f 18// { dg-require-effective-target dfp }
4cdc8761
BK
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>
4cdc8761
BK
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
31using namespace std::decimal;
32
33void
34conversion_to_integral_32 (void)
35{
36 #undef MAXVAL
37 #define MAXVAL 999999LL
38 decimal32 a, b (1), c (-1), d (MAXVAL), e (-MAXVAL);
39 long long ll;
40
41 ll = LONGLONG (a); VERIFY (ll == 0LL);
42 ll = LONGLONG (b); VERIFY (ll == 1LL);
43 ll = LONGLONG (c); VERIFY (ll == -1LL);
44 ll = LONGLONG (d); VERIFY (ll == MAXVAL);
45 ll = LONGLONG (e); VERIFY (ll == -MAXVAL);
46}
47
48void
49conversion_to_integral_64 (void)
50{
51 #undef MAXVAL
52 #define MAXVAL 999999999999999LL
53 decimal64 a, b (1), c (-1), d (MAXVAL), e (-MAXVAL);
54 long long ll;
55
56 ll = LONGLONG (a); VERIFY (ll == 0LL);
57 ll = LONGLONG (b); VERIFY (ll == 1LL);
58 ll = LONGLONG (c); VERIFY (ll == -1LL);
59 ll = LONGLONG (d); VERIFY (ll == MAXVAL);
60 ll = LONGLONG (e); VERIFY (ll == -MAXVAL);
61}
62
63void
64conversion_to_integral_128 (void)
65{
66 #undef MAXVAL
af23b26a 67 #define MAXVAL __LONG_LONG_MAX__
4cdc8761
BK
68 decimal128 a, b (1), c (-1), d (MAXVAL), e (-MAXVAL);
69 long long ll;
70
71 ll = LONGLONG (a); VERIFY (ll == 0LL);
72 ll = LONGLONG (b); VERIFY (ll == 1LL);
73 ll = LONGLONG (c); VERIFY (ll == -1LL);
74 ll = LONGLONG (d); VERIFY (ll == MAXVAL);
75 ll = LONGLONG (e); VERIFY (ll == -MAXVAL);
76}
77
78int
79main ()
80{
81 conversion_to_integral_32 ();
82 conversion_to_integral_64 ();
83 conversion_to_integral_128 ();
84}