]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/decimal/conversion-from-float.cc
1 // Copyright (C) 2009-2012 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 ()
32 bool test
__attribute__((unused
)) = true;
38 long double ld
= 678.L
;
40 d32
= (decimal32
) d64
;
41 VERIFY (d32
== make_decimal32 (234LL, 0));
42 d32
= (decimal32
) d128
;
43 VERIFY (d32
== make_decimal32 (345LL, 0));
45 VERIFY (d32
== make_decimal32 (456LL, 0));
47 VERIFY (d32
== make_decimal32 (567LL, 0));
49 VERIFY (d32
== make_decimal32 (678LL, 0));
53 conversion_from_float_64 ()
55 bool test
__attribute__((unused
)) = true;
61 long double ld
= 678.L
;
64 VERIFY (d64
== make_decimal64 (123LL, 0));
65 d64
= (decimal64
) d128
;
66 VERIFY (d64
== make_decimal64 (345LL, 0));
68 VERIFY (d64
== make_decimal64 (456LL, 0));
70 VERIFY (d64
== make_decimal64 (567LL, 0));
72 VERIFY (d64
== make_decimal64 (678LL, 0));
76 conversion_from_float_128 ()
78 bool test
__attribute__((unused
)) = true;
84 long double ld
= 678.L
;
87 VERIFY (d128
== make_decimal128 (123LL, 0));
89 VERIFY (d128
== make_decimal128 (234LL, 0));
90 d128
= (decimal128
) f
;
91 VERIFY (d128
== make_decimal128 (456LL, 0));
92 d128
= (decimal128
) d
;
93 VERIFY (d128
== make_decimal128 (567LL, 0));
94 d128
= (decimal128
) ld
;
95 VERIFY (d128
== make_decimal128 (678LL, 0));
101 conversion_from_float_32 ();
102 conversion_from_float_64 ();
103 conversion_from_float_128 ();