summaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/dfp/convert-bfp-6.c
blob: 64198a95f2ad01ed50c8fadc6bba4fc4cb91de58 (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/* { dg-xfail-run-if "" { lax_strtofp } "*" "" } */
/* { dg-options "-w" } */

/* This test assumes IEEE float and double.  */

#define __STDC_WANT_DEC_FP__
#include <float.h>

#include "convert.h"

volatile _Decimal32 sd;
volatile _Decimal64 dd;
volatile _Decimal128 td;
volatile float sf;
volatile double df;
volatile long double tf;

CONVERT_VALID (101, td, sf, 0.000488281251dl, 0.00048828125f, 0.f)

/* 2**(-25) = 0.298023223876953125E-7.  */
CONVERT_VALID (102, td, sf, 2.98023223876953125e-8dl, 2.9802322387695312e-08f,
               01.e-13f)

/* Fractional part doesn't fit.  */
CONVERT_VALID (103, df, sd, 1.0e-20, 1.0e-20df, 0.df)

/* Exact power of 2.  */
CONVERT_VALID (104, df, sd, 0.00048828125, 0.00048828125df, 0.df)
CONVERT_VALID (105, df, sd, 1.0e-96, 0.dd, DEC32_MIN)

/* A value slightly less than FLT_MAX can be converted in both directions.  */
CONVERT_VALID (201, sf, sd, 3.402819e+38f, 3.402819e+38df, 0.df)
CONVERT_VALID (202, sd, sf, 3.402819e+38df, 3.402819e+38f, 0.f)
CONVERT_VALID (203, sf, dd, 3.402819e+38f, 3.402819e+38dd, 1.e+30dd)
CONVERT_VALID (204, dd, sf, 3.402819e+38dd, 3.402819e+38f, 0.f)
CONVERT_VALID (205, sf, td, 3.402819e+38f, 3.402819e+38dl, 1.e+30dl)
CONVERT_VALID (206, td, sf, 3.402819e+38dl, 3.402819e+38f, 0.f)

/* A value slightly less than DEC32_MAX can be converted in both directions.  */
CONVERT_VALID (211, sd, df, 9.999998e96df, 9.999998e96, 0.)
CONVERT_VALID (212, df, sd, 9.999998e96, 9.999998e96df, 0.df)

/* A value slightly less than DBL_MAX can be converted in both directions.  */
CONVERT_VALID (221, df, dd, 1.79768e+308, 1.79768e+308dd, 0.dd)
CONVERT_VALID (222, dd, df, 1.79768e+308dd, 1.79768e+308, 0.)
CONVERT_VALID (223, df, td, 1.79768e+308, 1.79768e+308dl, 1.e292dl)
CONVERT_VALID (224, td, df, 1.79768e+308dl, 1.79768e+308, 0.)

/* An integral value with 6 digits (FLT_DIG) can be converted between float
   and _Decimal32 in both directions.  */
CONVERT_VALID (301, sd, sf, 100000.DF, 100000.F, 0.F)
CONVERT_VALID (302, sf, sd, 100000.F, 100000.DF, 0.DF)
CONVERT_VALID (303, sd, sf, 999999.DF, 999999.F, 0.F)
CONVERT_VALID (304, sf, sd, 999999.F, 999999.DF, 0.DF)

/* An integral value with 7 digits (DEC32_MANT_DIG) can be converted between
   _Decimal32 and double in both directions.  */
CONVERT_VALID (311, sd, df, 1000000.DF, 1000000., 0.)
CONVERT_VALID (312, df, sd, 1000000., 1000000.DF, 0.DF)
CONVERT_VALID (313, sd, df, 9999999.DF, 9999999., 0.)
CONVERT_VALID (314, df, sd, 9999999., 9999999.DF, 0.DF)

/* An integral value with 15 digits (DBL_DIG) can be converted between
   double and _Decimal64 in both directions.  */
CONVERT_VALID (321, dd, df, 100000000000000.DD, 100000000000000., 0.)
CONVERT_VALID (322, df, dd, 100000000000000., 100000000000000.DD, 0.DD);
CONVERT_VALID (323, dd, df, 999999999999999.DD, 999999999999999., 0.);
CONVERT_VALID (324, df, dd, 999999999999999., 999999999999999.DD, 0.DD);

/* If LDBL_DIG is at least 16, an integral value with 16 digits can be
   converted between _Decimal64 and long double in both directions.  */
CONVERT_VALID (331, dd, tf, 1000000000000000.DD, 1000000000000000.L, 0.L)
CONVERT_VALID (332, td, dd, 1000000000000000.L, 1000000000000000.DD, 0.DD)
CONVERT_VALID (333, dd, tf, 9999999999999999.DD, 9999999999999999.L, 0.L)
CONVERT_VALID (334, td, dd, 9999999999999999.L, 9999999999999999.DD, 0.DD)

/* If LDBL_DIG is at least 18, an integral value with 18 digits can be
   converted between long double and _Decimal128 in both directions.  */
CONVERT_VALID (341, td, tf, 100000000000000000.DL, 100000000000000000.L, 0.L)
CONVERT_VALID (342, tf, td, 100000000000000000.L, 100000000000000000.DL, 0.DL)
CONVERT_VALID (343, td, tf, 999999999999999999.DL, 999999999999999999.L, 0.L)
CONVERT_VALID (344, tf, td, 999999999999999999.L, 999999999999999999.DL, 0.DL)

/* If LDBL_DIG is at least 31, an integral value with 31 digits can be
   converted between long double and _Decimal128 in both directions.  */
CONVERT_VALID (351, td, tf, 1000000000000000000000000000000.DL,
			    1000000000000000000000000000000.L, 0.L)
CONVERT_VALID (352, tf, td, 1000000000000000000000000000000.L,
			    1000000000000000000000000000000.DL, 0.DL)
CONVERT_VALID (353, td, tf, 9999999999999999999999999999999.DL,
			    9999999999999999999999999999999.L, 0.L)
CONVERT_VALID (354, tf, td, 9999999999999999999999999999999.L,
			    9999999999999999999999999999999.DL, 0.DL)

/* If LDBL_DIG is at least 33, an integral value with 33 digits can be
   converted between long double and _Decimal128 in both directions.  */
CONVERT_VALID (361, td, tf, 100000000000000000000000000000000.DL,
			    100000000000000000000000000000000.L, 0.L)
CONVERT_VALID (362, tf, td, 100000000000000000000000000000000.L,
			    100000000000000000000000000000000.DL, 0.DL)
CONVERT_VALID (363, td, tf, 999999999999999999999999999999999.DL,
			    999999999999999999999999999999999.L, 0.L)
CONVERT_VALID (364, tf, td, 999999999999999999999999999999999.L,
			    999999999999999999999999999999999.DL, 0.DL)

int
main ()
{
  convert_101 ();
  convert_102 ();
  convert_103 ();
  convert_104 ();
  convert_105 ();

  convert_201 ();
  convert_202 ();
  convert_203 ();
  convert_204 ();
  convert_205 ();
  convert_206 ();

  convert_211 ();
  convert_212 ();

  convert_221 ();
  convert_222 ();
  convert_223 ();
  convert_224 ();

  convert_301 ();
  convert_302 ();
  convert_303 ();
  convert_304 ();

  convert_311 ();
  convert_312 ();
  convert_313 ();
  convert_314 ();

  convert_321 ();
  convert_322 ();
  convert_323 ();
  convert_324 ();

  if (LDBL_DIG >= 16)
    {
      convert_331 ();
      convert_332 ();
      convert_333 ();
      convert_334 ();
    }

  if (LDBL_DIG >= 18)
    {
      convert_341 ();
      convert_342 ();
      convert_343 ();
      convert_344 ();
    }

  if (LDBL_DIG >= 31)
    {
      convert_351 ();
      convert_352 ();
      convert_353 ();
      convert_354 ();
    }

  if (LDBL_DIG >= 33)
    {
      convert_361 ();
      convert_362 ();
      convert_363 ();
      convert_364 ();
    }

  FINISH
}