Reverting merge from trunk
[official-gcc.git] / libstdc++-v3 / testsuite / decimal / conversion-to-generic-float.cc
blobe42a771f28632a903347674f8c7ad0a298e368ca
1 // Copyright (C) 2009-2013 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.
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.6 Conversion to generic floating-point type.
22 #include <decimal/decimal>
23 #include <testsuite_hooks.h>
25 using namespace std::decimal;
27 void
28 conversion_to_generic_float_32 ()
30 bool test __attribute__((unused)) = true;
31 decimal32 d32(123);
32 float f;
33 double d;
34 long double ld;
36 f = decimal32_to_float (d32);
37 VERIFY (f == 123.F);
38 d = decimal32_to_double (d32);
39 VERIFY (d == 123.);
40 ld = decimal32_to_long_double (d32);
41 VERIFY (ld == 123.L);
43 d32++;
44 f = decimal_to_float (d32);
45 VERIFY (f == 124.F);
46 d = decimal_to_double (d32);
47 VERIFY (d == 124.);
48 ld = decimal_to_long_double (d32);
49 VERIFY (ld == 124.L);
52 void
53 conversion_to_generic_float_64 ()
55 bool test __attribute__((unused)) = true;
56 decimal64 d64(234);
57 float f;
58 double d;
59 long double ld;
61 f = decimal64_to_float (d64);
62 VERIFY (f == 234.F);
63 d = decimal64_to_double (d64);
64 VERIFY (d == 234.);
65 ld = decimal64_to_long_double (d64);
66 VERIFY (ld == 234.L);
68 d64++;
69 f = decimal_to_float (d64);
70 VERIFY (f == 235.F);
71 d = decimal_to_double (d64);
72 VERIFY (d == 235.);
73 ld = decimal_to_long_double (d64);
74 VERIFY (ld == 235.L);
77 void
78 conversion_to_generic_float_128 ()
80 bool test __attribute__((unused)) = true;
81 decimal128 d128(345);
82 float f;
83 double d;
84 long double ld;
86 f = decimal128_to_float (d128);
87 VERIFY (f == 345.F);
88 d = decimal128_to_double (d128);
89 VERIFY (d == 345.);
90 ld = decimal128_to_long_double (d128);
91 VERIFY (ld == 345.L);
93 d128++;
94 f = decimal_to_float (d128);
95 VERIFY (f == 346.F);
96 d = decimal_to_double (d128);
97 VERIFY (d == 346.);
98 ld = decimal_to_long_double (d128);
99 VERIFY (ld == 346.L);
103 main ()
105 conversion_to_generic_float_32 ();
106 conversion_to_generic_float_64 ();
107 conversion_to_generic_float_128 ();