summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.target/i386/excess-precision-1.c
blob: bd825d628e10f257e536112ce01a956b90bff71c (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
/* Excess precision tests.  Test that excess precision is carried
   through various operations.  */
/* { dg-do run } */
/* { dg-options "-O2 -mfpmath=387 -fexcess-precision=standard" } */

#include <float.h>

extern void abort (void);
extern void exit (int);

volatile float f1 = 1.0f;
volatile float f2 = 0x1.0p-30f;
volatile float f3 = 0x1.0p-60f;
volatile double d1 = 1.0;
volatile double d2 = 0x1.0p-30;
volatile double d3 = 0x1.0p-60;
volatile float fadd1 = 1.0f + 0x1.0p-30f;
volatile double dadd2 = 1.0 + 0x1.0p-30 + 0x1.0p-60;
volatile long double ldadd1 = 1.0l + 0x1.0p-30l;
volatile long double ldadd2 = 1.0l + 0x1.0p-30l + 0x1.0p-60l;

void
test_add (void)
{
  if (f1 + f2 != ldadd1)
    abort ();
  if (f1 + f2 + f3 != ldadd2)
    abort ();
  if (d1 + d2 != ldadd1)
    abort ();
  if (d1 + d2 + d3 != ldadd2)
    abort ();
  if (f1 + d2 + f3 != ldadd2)
    abort ();
  if (f1 + f2 == fadd1)
    abort ();
  if (f1 + f2 <= fadd1)
    abort ();
  if (f1 + f2 < fadd1)
    abort ();
  if (d1 + d2 + d3 == dadd2)
    abort ();
  if (!(d1 + d2 + d3 > dadd2))
    abort ();
  if (!(d1 + d2 + d3 >= dadd2))
    abort ();
}

volatile long double ldsub1 = 1.0l - 0x1.0p-30l;
volatile long double ldsub2 = 1.0l - 0x1.0p-30l - 0x1.0p-60l;

void
test_sub (void)
{
  if (f1 - f2 != ldsub1)
    abort ();
  if (f1 - f2 - f3 != ldsub2)
    abort ();
  if (d1 - d2 != ldsub1)
    abort ();
  if (d1 - d2 - d3 != ldsub2)
    abort ();
  if (f1 - d2 - f3 != ldsub2)
    abort ();
  if (+(f1 - d2 - f3) != ldsub2)
    abort ();
  if (-(f1 - d2 - f3) != -ldsub2)
    abort ();
}

volatile float flt_min = FLT_MIN;
volatile double dbl_min = DBL_MIN;
volatile long double flt_min2 = (long double)FLT_MIN * (long double)FLT_MIN;
volatile long double dbl_min3 = (long double)DBL_MIN * (long double)DBL_MIN * (long double)DBL_MIN;

void
test_mul (void)
{
  if (flt_min * flt_min != flt_min2)
    abort ();
  if (flt_min * flt_min == 0)
    abort ();
  if (flt_min * flt_min == 0)
    abort ();
  if (!(flt_min * flt_min))
    abort ();
  if (dbl_min * dbl_min * dbl_min != dbl_min3)
    abort ();
  if ((long double)(dbl_min * dbl_min * dbl_min) != dbl_min3)
    abort ();
  if ((0, dbl_min * dbl_min * dbl_min) != dbl_min3)
    abort ();
  if (dbl_min * dbl_min * dbl_min == 0)
    abort ();
  if ((flt_min * flt_min ? dbl_min * dbl_min * dbl_min : 0) == 0)
    abort ();
  if ((flt_min * flt_min ? : 0) == 0)
    abort ();
}

volatile float f4 = 0x1.0p100f;
volatile double d4 = 0x1.0p100;
volatile long double flt_div = 0x1.0p100l / (long double) FLT_MIN;
volatile long double dbl_div = 0x1.0p100l / (long double) DBL_MIN;

void
test_div (void)
{
  if (f4 / flt_min != flt_div)
    abort ();
  if (d4 / dbl_min != dbl_div)
    abort ();
}

volatile float f5 = 0x1.0p30;

void
test_cast (void)
{
  if ((int)(f1 + f5) != 0x40000001)
    abort ();
}

volatile float _Complex f1c = 1.0f + 1.0if;
volatile float _Complex f2c = 0x1.0p-30f + 0x1.0p-31if;
volatile float _Complex f3c = 0x1.0p-60f + 0x1.0p-59if;
volatile double _Complex d1c = 1.0 + 1.0i;
volatile double _Complex d2c = 0x1.0p-30 + 0x1.0p-31i;
volatile double _Complex d3c = 0x1.0p-60 + 0x1.0p-59i;
volatile long double _Complex ldadd1c = 1.0l + 0x1.0p-30l + 1.0il + 0x1.0p-31il;
volatile long double _Complex ldadd2c = 1.0l + 0x1.0p-30l + 0x1.0p-60l + 1.0il + 0x1.0p-31il + 0x1.0p-59il;
volatile long double _Complex ldadd2cc = 1.0l + 0x1.0p-30l + 0x1.0p-60l - 1.0il - 0x1.0p-31il - 0x1.0p-59il;
volatile float _Complex flt_minc = FLT_MIN;
volatile double _Complex dbl_minc = DBL_MIN;
volatile float _Complex f4c = 0x1.0p100f;
volatile double _Complex d4c = 0x1.0p100;

void
test_complex (void)
{
  if (f1c + f2c != ldadd1c)
    abort ();
  if (f1c + f2c + f3c != ldadd2c)
    abort ();
  if (d1c + d2c != ldadd1c)
    abort ();
  if (d1c + d2c + d3c != ldadd2c)
    abort ();
  if (__real__ (f1c + f2c + f3c) != ldadd2)
    abort ();
  if (__imag__ (d1c + d2c + d3c) != __imag__ ldadd2c)
    abort ();
  if (~(d1c + d2c + d3c) != ldadd2cc)
    abort ();
  /* The following call libgcc functions and so would fail unless they
     call those for long double.  */
  if (flt_minc * flt_minc != flt_min2)
    abort ();
  if (dbl_minc * dbl_minc * dbl_minc != dbl_min3)
    abort ();
  if (f4c / flt_minc != flt_div)
    abort ();
  if (d4c / dbl_minc != dbl_div)
    abort ();
  if (f4 / flt_minc != flt_div)
    abort ();
  if (d4 / dbl_minc != dbl_div)
    abort ();
  if (f4c / flt_min != flt_div)
    abort ();
  if (d4c / dbl_min != dbl_div)
    abort ();
}

int
main (void)
{
  test_add ();
  test_sub ();
  test_mul ();
  test_div ();
  test_cast ();
  test_complex ();
  exit (0);
}