summaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/dfp/convert-int.c
blob: 1525d5760a44d10bf181eb4da838ffccc045a2c0 (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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/* { dg-options "-O0" } */

/* N1150 5.1 Conversion between decimal floating types and integer.
   C99 6.3.1.4(1a) New.  */

#include "dfp-dbg.h"

#ifdef __cplusplus
#define BOOL bool
#else
#define BOOL _Bool
#endif

_Decimal32 d32;
_Decimal64 d64;
_Decimal128 d128;
unsigned int ui;
unsigned long ul;
unsigned long long ull;
int si;
long sl;
long long sll;
BOOL b;

void
init_dfp_1 (void)
{
  d32 = 456.789df;
  d64 = 23.456789dd;
  d128 = 1234.5678dl;
}
void
init_dfp_2 (void)
{
  d32 = 1.23df;
  d64 = -3.4dd;
  d128 = 0.00003dl;
}

void
init_dfp_3 (void)
{
  d32 = 0.0DF;
  d64 = 0.0DD;
  d128 = 0.0DL;
}

void
init_unsigned_int (void)
{
  ui = 987U;
  ul = 345678UL;
  ull = 1234567ULL;
}

void
init_signed_int (void)
{
  si = -987;
  sl = -345678;
  sll = -1234567;
}

int
main ()
{
  /* C99 Section 6.7.2 Type specifiers.  Type _Bool is 
     mentioned in this section.  Conversions between 
     BOOL and DFP types.  */

  /* Decimal float to unsigned integer.  */
  init_dfp_1 ();

  ui = d32;
  if (ui != 456U)
    FAILURE
  ul = d32;
  if (ul != 456UL)
    FAILURE
  ull = d32;
  if (ull != 456ULL)
    FAILURE

  ui = d64;
  if (ui != 23U)
    FAILURE
  ul = d64;
  if (ul != 23UL)
    FAILURE
  ull = d64;
  if (ull != 23ULL)
    FAILURE

  ui = d128;
  if (ui != 1234U)
    FAILURE
  ul = d128;
  if (ul != 1234UL)
    FAILURE
  ull = d128;
  if (ull != 1234ULL)
    FAILURE

  /* Decimal float to signed integer.  */

  /* Decimal float to BOOL.  */
  init_dfp_2 ();

  b = d32;
  if (!b)
    FAILURE
  b = d64;
  if (!b)
    FAILURE
  b = d128;
  if (!b)
    FAILURE

  /* Unsigned integer to decimal float.  */
  init_unsigned_int ();

  d32 = ui;
  if (d32 != 987.0df)
    FAILURE
  d32 = ul;
  if (d32 != 345678.0df)
    FAILURE
  d32 = ull;
  if (d32 != 1234567.df)
    FAILURE

  d64 = ui;
  if (d64 != 987.0dd)
    FAILURE
  d64 = ul;
  if (d64 != 345678.0dd)
    FAILURE
  d64 = ull;
  if (d64 != 1234567.dd)
    FAILURE

  d128 = ui;
  if (d128 != 987.0dl)
    FAILURE
  d128 = ul;
  if (d128 != 345678.0dl)
    FAILURE
  d128 = ull;
  if (d128 != 1234567.dl)
    FAILURE

  /* Signed integer to decimal float.  */
  init_signed_int ();

  d32 = si;
  if (d32 != -987.0df)
    FAILURE
  d32 = sl;
  if (d32 != -345678.0df)
    FAILURE
  d32 = sll;
  if (d32 != -1234567.df)
    FAILURE

  d64 = si;
  if (d64 != -987.0dd)
    FAILURE
  d64 = sl;
  if (d64 != -345678.0dd)
    FAILURE
  d64 = sll;
  if (d64 != -1234567.dd)
    FAILURE

  d128 = si;
  if (d128 != -987.0dl)
    FAILURE
  d128 = sl;
  if (d128 != -345678.0dl)
    FAILURE
  d128 = sll;
  if (d128 != -1234567.dl)
    FAILURE

  /* BOOL to decimal float.  */
  init_dfp_3 ();
  
  b = d32;
  if (b)
    FAILURE
  b = d64;
  if (b)
    FAILURE
  b = d128;
  if (b)
    FAILURE

  FINISH
}