1// Copyright (C) 2009-2015 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.6 Conversion to generic floating-point type. 21 22#include <decimal/decimal> 23#include <testsuite_hooks.h> 24 25using namespace std::decimal; 26 27void 28conversion_to_generic_float_32 () 29{ 30 bool test __attribute__((unused)) = true; 31 decimal32 d32(123); 32 float f; 33 double d; 34 long double ld; 35 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); 42 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); 50} 51 52void 53conversion_to_generic_float_64 () 54{ 55 bool test __attribute__((unused)) = true; 56 decimal64 d64(234); 57 float f; 58 double d; 59 long double ld; 60 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); 67 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); 75} 76 77void 78conversion_to_generic_float_128 () 79{ 80 bool test __attribute__((unused)) = true; 81 decimal128 d128(345); 82 float f; 83 double d; 84 long double ld; 85 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); 92 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); 100} 101 102int 103main () 104{ 105 conversion_to_generic_float_32 (); 106 conversion_to_generic_float_64 (); 107 conversion_to_generic_float_128 (); 108} 109