aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/decimal/conversion-to-generic-float.cc
blob: bac0c820ee6fafcc296f9ed90e85c022e06afb20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright (C) 2009 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3.  If not see
// <http://www.gnu.org/licenses/>.

// { dg-require-effective-target dfp }

// ISO/IEC TR 24733  3.2.6  Conversion to generic floating-point type.

#include <decimal/decimal>
#include <testsuite_hooks.h>

using namespace std::decimal;

void
conversion_to_generic_float_32 ()
{
  std::decimal::decimal32 d32(123);
  float f;
  double d;
  long double ld;

  f = decimal32_to_float (d32);
  VERIFY (f == 123.F);
  d = decimal32_to_double (d32);
  VERIFY (d == 123.);
  ld = decimal32_to_long_double (d32);
  VERIFY (ld == 123.L);

  d32++;
  f = decimal_to_float (d32);
  VERIFY (f == 124.F);
  d = decimal_to_double (d32);
  VERIFY (d == 124.);
  ld = decimal_to_long_double (d32);
  VERIFY (ld == 124.L);
}

void
conversion_to_generic_float_64 ()
{
  std::decimal::decimal64 d64(234);
  float f;
  double d;
  long double ld;

  f = decimal64_to_float (d64);
  VERIFY (f == 234.F);
  d = decimal64_to_double (d64);
  VERIFY (d == 234.);
  ld = decimal64_to_long_double (d64);
  VERIFY (ld == 234.L);

  d64++;
  f = decimal_to_float (d64);
  VERIFY (f == 235.F);
  d = decimal_to_double (d64);
  VERIFY (d == 235.);
  ld = decimal_to_long_double (d64);
  VERIFY (ld == 235.L);
}

void
conversion_to_generic_float_128 ()
{
  std::decimal::decimal128 d128(345);
  float f;
  double d;
  long double ld;

  f = decimal128_to_float (d128);
  VERIFY (f == 345.F);
  d = decimal128_to_double (d128);
  VERIFY (d == 345.);
  ld = decimal128_to_long_double (d128);
  VERIFY (ld == 345.L);

  d128++;
  f = decimal_to_float (d128);
  VERIFY (f == 346.F);
  d = decimal_to_double (d128);
  VERIFY (d == 346.);
  ld = decimal_to_long_double (d128);
  VERIFY (ld == 346.L);
}

int
main ()
{
  conversion_to_generic_float_32 ();
  conversion_to_generic_float_64 ();
  conversion_to_generic_float_128 ();
}