OSDN Git Service

64b0054d2d3bac662d6344fdd2537b72cee29789
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / dfp / constants-zero.c
1 /* { dg-options "-O0" } */
2
3 /* Decimal float values can have significant trailing zeroes.  This is
4    true for zero values as well.  Check that various representations of
5    zero are handled correctly when specified as literal constants.  */
6
7 #include "dfp-dbg.h"
8
9 int big_endian;
10
11 typedef union U32 {
12   unsigned int i;
13   _Decimal32 d;
14   unsigned char b[4];
15 } u32_t;
16
17 typedef union U64 {
18   unsigned long long i;
19   _Decimal64 d;
20 } u64_t;
21
22 typedef union U128 {
23   unsigned long long i[2];
24   _Decimal128 d;
25 } u128_t;
26
27 int
28 compare32 (_Decimal32 d, unsigned int i)
29 {
30   u32_t u;
31
32   u.d = d;
33   return (u.i == i);
34 }
35
36 int
37 compare64 (_Decimal64 d, unsigned long long i)
38 {
39   u64_t u;
40
41   u.d = d;
42   return (u.i == i);
43 }
44
45 int
46 compare128 (_Decimal64 d, unsigned long long i, unsigned long long j)
47 {
48   u128_t u;
49
50   u.d = d;
51   if (big_endian)
52     return (u.i[0] == i && u.i[1] == j);
53   else
54     return (u.i[1] == i && u.i[0] == j);
55 }
56
57 void
58 dpd_tests (void)
59 {
60   if (! compare32 (0.DF, 0x22500000U))
61     FAILURE
62   if (! compare32 (-0.DF, 0xa2500000U))
63     FAILURE
64   if (! compare32 (0.E-4DF, 0x22100000U))
65     FAILURE
66   if (! compare32 (0.E-7DF, 0x21e00000U))
67     FAILURE
68   if (! compare32 (0.E+3DF, 0x22800000U))
69     FAILURE
70
71   if (! compare64 (0.DD, 0x2238000000000000ULL))
72     FAILURE
73   if (! compare64 (-0.DD, 0xa238000000000000ULL))
74     FAILURE
75   if (! compare64 (0.E-6DD, 0x2220000000000000ULL))
76     FAILURE
77   if (! compare64 (0.E-7DD, 0x221c000000000000ULL))
78     FAILURE
79   if (! compare64 (0.E+2DD, 0x2240000000000000ULL))
80     FAILURE
81
82   if (! compare128 (0.DL, 0x2208000000000000ULL, 0x0000000000000000ULL))
83     FAILURE
84   if (! compare128 (-0.DL, 0xa208000000000000ULL, 0x0000000000000000ULL))
85     FAILURE
86   if (! compare128 (0.E-3DL, 0x2207400000000000ULL, 0x0000000000000000ULL))
87     FAILURE
88   if (! compare128 (0.E-8DL, 0x2206000000000000ULL, 0x0000000000000000ULL))
89     FAILURE
90   if (! compare128 (0.E+2DL, 0x2208800000000000ULL, 0x0000000000000000ULL))
91     FAILURE
92 }
93
94 void
95 bid_tests (void)
96 {
97   if (! compare32 (0.DF, 0x32800000U))
98     FAILURE
99   if (! compare32 (-0.DF, 0xb2800000U))
100     FAILURE
101   if (! compare32 (0.E-4DF, 0x30800000U))
102     FAILURE
103   if (! compare32 (0.E-7DF, 0x2f000000U))
104     FAILURE
105   if (! compare32 (0.E+3DF, 0x34000000U))
106     FAILURE
107
108   if (! compare64 (0.DD, 0x31c0000000000000ULL))
109     FAILURE
110   if (! compare64 (-0.DD, 0xb1c0000000000000ULL))
111     FAILURE
112   if (! compare64 (0.E-6DD, 0x3100000000000000ULL))
113     FAILURE
114   if (! compare64 (0.E-7DD, 0x30e0000000000000ULL))
115     FAILURE
116   if (! compare64 (0.E+2DD, 0x3200000000000000ULL))
117     FAILURE
118
119   if (! compare128 (0.DL, 0x3040000000000000ULL, 0x0000000000000000ULL))
120     FAILURE
121   if (! compare128 (-0.DL, 0xb040000000000000ULL, 0x0000000000000000ULL))
122     FAILURE
123   if (! compare128 (0.E-3DL, 0x303a000000000000ULL, 0x0000000000000000ULL))
124     FAILURE
125   if (! compare128 (0.E-8DL, 0x3030000000000000ULL, 0x0000000000000000ULL))
126     FAILURE
127   if (! compare128 (0.E+2DL, 0x3044000000000000ULL, 0x0000000000000000ULL))
128     FAILURE
129 }
130
131 int
132 main ()
133 {
134   u32_t u32;
135   
136   /* These sizes are probably always true for targets that support decimal
137      float types, but check anyway.  Abort so we can fix the test.  */
138   if ((sizeof (_Decimal64) != sizeof (long long))
139       || (sizeof (_Decimal128) != 2 * sizeof (long long))
140       || (sizeof (_Decimal32) != sizeof (_Decimal32)))
141     FAILURE
142
143   u32.d = 1.DF;
144
145   if (u32.i == 0x22500001)
146     {
147       big_endian = (u32.b[0] == 0x22);
148       dpd_tests ();
149     }
150   else if (u32.i == 0x32800001)
151     {
152        big_endian = (u32.b[0] == 0x32);
153        bid_tests ();
154     }
155   else
156     FAILURE             /* unknown format; test problem  */
157
158   FINISH
159 }