summaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/dfp/convert-int-max-fold.c
blob: 3f6faae34cc42ff57834ed1fcf0eef4f292e030d (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
/* { dg-options "-O2 -w" } */

/* N1150 5.1 Conversions from decimal float to integer.  */

/* Test decimal float to integer conversions for values at the limit of
   what will fit into the destination type.  This assumes 32-bit int and
   64-bit long long (there's a check for that below).  This version tests
   conversions during compilation.  */

#include "dfp-dbg.h"

extern void link_error (void);

void
doit ()
{
  _Decimal32 d32;
  _Decimal64 d64;
  _Decimal128 d128;
  int si;
  unsigned int ui;
  long long sll;
  unsigned long long ull;

  /* _Decimal32 to int.  */

  d32 = 2147483.E3DF;
  si = d32;
  if (si != 2147483000)
    link_error ();

  d32 = -2147483.E3DF;
  si = d32;
  if (si != -2147483000)
    link_error ();

  /* _Decimal32 to unsigned int.  */

  d32 = 4.294967E9DF;
  ui = d32;
  if (ui != 4294967000U)
    link_error ();

  /* _Decimal32 to long long.  */

  d32 = 922.3372E16DF;
  sll = d32;
  if (sll != 9223372000000000000LL)
    link_error ();

  d32 = -92233.72E14DF;
  sll = d32;
  if (sll != -9223372000000000000LL)
    link_error ();

  /* _Decimal32 to unsigned long long.  */

  d32 = 0.1844674E20DF;
  ull = d32;
  if (ull != 18446740000000000000ULL)
    link_error ();

  /* _Decimal64 to int.  */

  d64 = 2.147483647E9DD;
  si = d64;
  if (si != 2147483647)
    link_error ();

  d64 = -2147483648.DD;
  si = d64;
  if (si != -2147483648)
    link_error ();

  /* _Decimal64 to unsigned int.  */

  d64 = 42949.67295E5DD;
  ui = d64;
  if (ui != 4294967295)
    link_error ();

  /* _Decimal64 to long long.  */

  d64 = 9.223372036854775E18DD;
  sll = d64;
  if (sll != 9223372036854775000LL)
    link_error (); 

  d64 = -92233720.36854775E11DD;
  sll = d64;
  if (sll != -9223372036854775000LL)
    link_error ();

  /* _Decimal64 to unsigned long long.  */
  d64 = 1844674407370955.E4DD;
  ull = d64;
  if (ull != 18446744073709550000ULL)
    link_error ();

  /* _Decimal128 to int.  */

  d128 = 2.147483647E9DL;
  si = d128;
  if (si != 2147483647)
    link_error ();

  d128 = -2147483648.DL;
  si = d128;
  if (si != -2147483648)
    link_error ();

  /* _Decimal128 to unsigned int.  */

  d128 = 4294.967295E6DL;
  ui = d128;
  if (ui != 4294967295)
    link_error ();

  /* _Decimal128 to long long.  */

  d128 = 9223372036854775807.DL;
  sll = d128;
  if (sll != 9223372036854775807LL)
    link_error (); 

  d128 = -9.223372036854775808E19DL;
  sll = d128;
  if (sll != -9223372036854775807LL - 1LL)
    link_error ();

  /* _Decimal128 to unsigned long long.  */
  d128 = 18446744073709551615.DL;
  ull = d128;
  if (ull != 18446744073709551615ULL)
    link_error ();
}

int
main ()
{
  /* This test assumes 32-bit int and 64-bit long long.  */

  if (sizeof (int) != 4 || sizeof (long long) != 8)
    return 0;

  doit ();
  return 0;
}