]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/decimal/conversion-from-float.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / decimal / conversion-from-float.cc
1 // Copyright (C) 2009-2022 Free Software Foundation, Inc.
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
18 // { dg-require-effective-target dfp }
19
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).
23
24 #include <decimal/decimal>
25 #include <testsuite_hooks.h>
26
27 using namespace std::decimal;
28
29 void
30 conversion_from_float_32 ()
31 {
32 decimal32 d32(123);
33 decimal64 d64(234);
34 decimal128 d128(345);
35 float f = 456.F;
36 double d = 567.;
37 long double ld = 678.L;
38
39 d32 = (decimal32) d64;
40 VERIFY (d32 == make_decimal32 (234LL, 0));
41 d32 = (decimal32) d128;
42 VERIFY (d32 == make_decimal32 (345LL, 0));
43 d32 = (decimal32) f;
44 VERIFY (d32 == make_decimal32 (456LL, 0));
45 d32 = (decimal32) d;
46 VERIFY (d32 == make_decimal32 (567LL, 0));
47 d32 = (decimal32) ld;
48 VERIFY (d32 == make_decimal32 (678LL, 0));
49 }
50
51 void
52 conversion_from_float_64 ()
53 {
54 decimal32 d32(123);
55 decimal64 d64(234);
56 decimal128 d128(345);
57 float f = 456.F;
58 double d = 567.;
59 long double ld = 678.L;
60
61 d64 = d32;
62 VERIFY (d64 == make_decimal64 (123LL, 0));
63 d64 = (decimal64) d128;
64 VERIFY (d64 == make_decimal64 (345LL, 0));
65 d64 = (decimal64) f;
66 VERIFY (d64 == make_decimal64 (456LL, 0));
67 d64 = (decimal64) d;
68 VERIFY (d64 == make_decimal64 (567LL, 0));
69 d64 = (decimal64) ld;
70 VERIFY (d64 == make_decimal64 (678LL, 0));
71 }
72
73 void
74 conversion_from_float_128 ()
75 {
76 decimal32 d32(123);
77 decimal64 d64(234);
78 decimal128 d128(345);
79 float f = 456.F;
80 double d = 567.;
81 long double ld = 678.L;
82
83 d128 = d32;
84 VERIFY (d128 == make_decimal128 (123LL, 0));
85 d128 = d64;
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));
93 }
94
95 int
96 main ()
97 {
98 conversion_from_float_32 ();
99 conversion_from_float_64 ();
100 conversion_from_float_128 ();
101 }