2008-05-30 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / testsuite / gcc.dg / dfp / constants-zero.c
blobe0db28cc38f9ec27b05c5ff4a5e8e8444bfbc3b8
1 /* { dg-options "-std=gnu99 -O0" } */
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. */
7 extern void abort (void);
9 int big_endian;
11 typedef union U32 {
12 unsigned int i;
13 _Decimal32 d;
14 unsigned char b[4];
15 } u32_t;
17 typedef union U64 {
18 unsigned long long i;
19 _Decimal64 d;
20 } u64_t;
22 typedef union U128 {
23 unsigned long long i[2];
24 _Decimal128 d;
25 } u128_t;
27 int
28 compare32 (_Decimal32 d, unsigned int i)
30 u32_t u;
32 u.d = d;
33 return (u.i == i);
36 int
37 compare64 (_Decimal64 d, unsigned long long i)
39 u64_t u;
41 u.d = d;
42 return (u.i == i);
45 int
46 compare128 (_Decimal64 d, unsigned long long i, unsigned long long j)
48 u128_t u;
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);
57 void
58 dpd_tests (void)
60 if (! compare32 (0.DF, 0x22500000U))
61 abort ();
62 if (! compare32 (-0.DF, 0xa2500000U))
63 abort ();
64 if (! compare32 (0.E-4DF, 0x22100000U))
65 abort ();
66 if (! compare32 (0.E-7DF, 0x21e00000U))
67 abort ();
68 if (! compare32 (0.E+3DF, 0x22800000U))
69 abort ();
71 if (! compare64 (0.DD, 0x2238000000000000ULL))
72 abort ();
73 if (! compare64 (-0.DD, 0xa238000000000000ULL))
74 abort ();
75 if (! compare64 (0.E-6DD, 0x2220000000000000ULL))
76 abort ();
77 if (! compare64 (0.E-7DD, 0x221c000000000000ULL))
78 abort ();
79 if (! compare64 (0.E+2DD, 0x2240000000000000ULL))
80 abort ();
82 if (! compare128 (0.DL, 0x2208000000000000ULL, 0x0000000000000000ULL))
83 abort ();
84 if (! compare128 (-0.DL, 0xa208000000000000ULL, 0x0000000000000000ULL))
85 abort ();
86 if (! compare128 (0.E-3DL, 0x2207400000000000ULL, 0x0000000000000000ULL))
87 abort ();
88 if (! compare128 (0.E-8DL, 0x2206000000000000ULL, 0x0000000000000000ULL))
89 abort ();
90 if (! compare128 (0.E+2DL, 0x2208800000000000ULL, 0x0000000000000000ULL))
91 abort ();
94 void
95 bid_tests (void)
97 if (! compare32 (0.DF, 0x32800000U))
98 abort ();
99 if (! compare32 (-0.DF, 0xb2800000U))
100 abort ();
101 if (! compare32 (0.E-4DF, 0x30800000U))
102 abort ();
103 if (! compare32 (0.E-7DF, 0x2f000000U))
104 abort ();
105 if (! compare32 (0.E+3DF, 0x34000000U))
106 abort ();
108 if (! compare64 (0.DD, 0x31c0000000000000ULL))
109 abort ();
110 if (! compare64 (-0.DD, 0xb1c0000000000000ULL))
111 abort ();
112 if (! compare64 (0.E-6DD, 0x3100000000000000ULL))
113 abort ();
114 if (! compare64 (0.E-7DD, 0x30e0000000000000ULL))
115 abort ();
116 if (! compare64 (0.E+2DD, 0x3200000000000000ULL))
117 abort ();
119 if (! compare128 (0.DL, 0x3040000000000000ULL, 0x0000000000000000ULL))
120 abort ();
121 if (! compare128 (-0.DL, 0xb040000000000000ULL, 0x0000000000000000ULL))
122 abort ();
123 if (! compare128 (0.E-3DL, 0x303a000000000000ULL, 0x0000000000000000ULL))
124 abort ();
125 if (! compare128 (0.E-8DL, 0x3030000000000000ULL, 0x0000000000000000ULL))
126 abort ();
127 if (! compare128 (0.E+2DL, 0x3044000000000000ULL, 0x0000000000000000ULL))
128 abort ();
132 main ()
134 u32_t u32;
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 abort ();
143 u32.d = 1.DF;
145 if (u32.i == 0x22500001)
147 big_endian = (u32.b[0] == 0x22);
148 dpd_tests ();
150 else if (u32.i == 0x32800001)
152 big_endian = (u32.b[0] == 0x32);
153 bid_tests ();
155 else
156 abort (); /* unknown format; test problem */
158 return 0;