1 // Copyright (C) 2009-2018 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.2 Conversion from floating-point type (decimal32).
21 // ISO/IEC TR 24733 3.2.3.2 Conversion from floating-point type (decimal64).
22 // ISO/IEC TR 24733 3.2.4.2 Conversion from floating-point type (decimal128).
24 #include <decimal/decimal>
25 #include <testsuite_hooks.h>
27 using namespace std::decimal
;
30 conversion_from_float_32 ()
37 long double ld
= 678.L
;
39 d32
= (decimal32
) d64
;
40 VERIFY (d32
== make_decimal32 (234LL, 0));
41 d32
= (decimal32
) d128
;
42 VERIFY (d32
== make_decimal32 (345LL, 0));
44 VERIFY (d32
== make_decimal32 (456LL, 0));
46 VERIFY (d32
== make_decimal32 (567LL, 0));
48 VERIFY (d32
== make_decimal32 (678LL, 0));
52 conversion_from_float_64 ()
59 long double ld
= 678.L
;
62 VERIFY (d64
== make_decimal64 (123LL, 0));
63 d64
= (decimal64
) d128
;
64 VERIFY (d64
== make_decimal64 (345LL, 0));
66 VERIFY (d64
== make_decimal64 (456LL, 0));
68 VERIFY (d64
== make_decimal64 (567LL, 0));
70 VERIFY (d64
== make_decimal64 (678LL, 0));
74 conversion_from_float_128 ()
81 long double ld
= 678.L
;
84 VERIFY (d128
== make_decimal128 (123LL, 0));
86 VERIFY (d128
== make_decimal128 (234LL, 0));
87 d128
= (decimal128
) f
;
88 VERIFY (d128
== make_decimal128 (456LL, 0));
89 d128
= (decimal128
) d
;
90 VERIFY (d128
== make_decimal128 (567LL, 0));
91 d128
= (decimal128
) ld
;
92 VERIFY (d128
== make_decimal128 (678LL, 0));
98 conversion_from_float_32 ();
99 conversion_from_float_64 ();
100 conversion_from_float_128 ();