1/* fp-test.c - Check that all floating-point operations are available.
2   Copyright (C) 1995, 2000, 2003 Free Software Foundation, Inc.
3   Contributed by Ronald F. Guilmette <rfg@monkeys.com>.
4
5   This file is part of GCC.
6
7   GCC is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by
9   the Free Software Foundation; either version 2, or (at your option)
10   any later version.
11
12   GCC is distributed in the hope that it will be useful, but WITHOUT
13   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
15   License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with GCC; see the file COPYING.  If not, write to the Free
19   Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
20   02110-1301, USA.  */
21
22/* This is a trivial test program which may be useful to people who are
23   porting the GCC or G++ compilers to a new system.  The intent here is
24   merely to check that all floating-point operations have been provided
25   by the port. (Note that I say ``provided'' rather than ``implemented''.)
26
27   To use this file, simply compile it (with GCC or G++) and then try to
28   link it in the normal way (also using GCC or G++ respectively).  If
29   all of the floating -point operations (including conversions) have
30   been provided, then this file will link without incident.  If however
31   one or more of the primitive floating-point operations have not been
32   properly provided, you will get link-time errors indicating which
33   floating-point operations are unavailable.
34
35   This file will typically be used when porting the GNU compilers to
36   some system which lacks floating-point hardware, and for which
37   software emulation routines (for FP ops) are needed in order to
38   complete the port.  */
39
40#if 0
41#include <math.h>
42#endif
43
44extern double acos (double);
45extern double asin (double);
46extern double atan (double);
47extern double atan2 (double, double);
48extern double cos (double);
49extern double sin (double);
50extern double tan (double);
51extern double cosh (double);
52extern double sinh (double);
53extern double tanh (double);
54extern double exp (double);
55extern double frexp (double, int *);
56extern double ldexp (double, int);
57extern double log (double);
58extern double log10 (double);
59extern double modf (double, double *);
60extern double pow (double, double);
61extern double sqrt (double);
62extern double ceil (double);
63extern double fabs (double);
64extern double floor (double);
65extern double fmod (double, double);
66
67int i1, i2 = 2;
68
69volatile signed char sc;
70volatile unsigned char uc;
71
72volatile signed short ss;
73volatile unsigned short us;
74
75volatile signed int si;
76volatile unsigned int ui;
77
78volatile signed long sl;
79volatile unsigned long ul;
80
81volatile float f1 = 1.0, f2 = 1.0, f3 = 1.0;
82volatile double d1 = 1.0, d2 = 1.0, d3 = 1.0;
83volatile long double D1 = 1.0, D2 = 1.0, D3 = 1.0;
84
85int
86main (void)
87{
88  /* TYPE: float */
89
90  f1 = -f2;
91  f1 = f2 + f3;
92  f1 = f2 - f3;
93  f1 = f2 * f3;
94  f1 = f2 / f3;
95  f1 += f2;
96  f1 -= f2;
97  f1 *= f2;
98  f1 /= f2;
99
100  si = f1 == f2;
101  si = f1 != f2;
102  si = f1 > f2;
103  si = f1 < f2;
104  si = f1 >= f2;
105  si = f1 <= f2;
106
107  si = __builtin_isgreater (f1, f2);
108  si = __builtin_isgreaterequal (f1, f2);
109  si = __builtin_isless (f1, f2);
110  si = __builtin_islessequal (f1, f2);
111  si = __builtin_islessgreater (f1, f2);
112  si = __builtin_isunordered (f1, f2);
113
114  sc = f1;
115  uc = f1;
116  ss = f1;
117  us = f1;
118  si = f1;
119  ui = f1;
120  sl = f1;
121  ul = f1;
122  d1 = f1;
123  D1 = f1;
124
125  f1 = sc;
126  f1 = uc;
127  f1 = ss;
128  f1 = us;
129  f1 = si;
130  f1 = ui;
131  f1 = sl;
132  f1 = ul;
133  f1 = d1;
134  f1 = D1;
135
136  d1 = -d2;
137  d1 = d2 + d3;
138  d1 = d2 - d3;
139  d1 = d2 * d3;
140  d1 = d2 / d3;
141  d1 += d2;
142  d1 -= d2;
143  d1 *= d2;
144  d1 /= d2;
145
146  si = d1 == d2;
147  si = d1 != d2;
148  si = d1 > d2;
149  si = d1 < d2;
150  si = d1 >= d2;
151  si = d1 <= d2;
152
153  si = __builtin_isgreater (d1, d2);
154  si = __builtin_isgreaterequal (d1, d2);
155  si = __builtin_isless (d1, d2);
156  si = __builtin_islessequal (d1, d2);
157  si = __builtin_islessgreater (d1, d2);
158  si = __builtin_isunordered (d1, d2);
159
160  sc = d1;
161  uc = d1;
162  ss = d1;
163  us = d1;
164  si = d1;
165  ui = d1;
166  sl = d1;
167  ul = d1;
168  f1 = d1;
169  D1 = d1;
170
171  d1 = sc;
172  d1 = uc;
173  d1 = ss;
174  d1 = us;
175  d1 = si;
176  d1 = ui;
177  d1 = sl;
178  d1 = ul;
179  d1 = f1;
180  d1 = D1;
181
182  D1 = -D2;
183  D1 = D2 + D3;
184  D1 = D2 - D3;
185  D1 = D2 * D3;
186  D1 = D2 / D3;
187  D1 += D2;
188  D1 -= D2;
189  D1 *= D2;
190  D1 /= D2;
191
192  si = D1 == D2;
193  si = D1 != D2;
194  si = D1 > D2;
195  si = D1 < D2;
196  si = D1 >= D2;
197  si = D1 <= D2;
198
199  si = __builtin_isgreater (D1, D2);
200  si = __builtin_isgreaterequal (D1, D2);
201  si = __builtin_isless (D1, D2);
202  si = __builtin_islessequal (D1, D2);
203  si = __builtin_islessgreater (D1, D2);
204  si = __builtin_isunordered (D1, D2);
205
206  sc = D1;
207  uc = D1;
208  ss = D1;
209  us = D1;
210  si = D1;
211  ui = D1;
212  sl = D1;
213  ul = D1;
214  f1 = D1;
215  d1 = D1;
216
217  D1 = sc;
218  D1 = uc;
219  D1 = ss;
220  D1 = us;
221  D1 = si;
222  D1 = ui;
223  D1 = sl;
224  D1 = ul;
225  D1 = f1;
226  D1 = d1;
227
228  d1 = acos (d2);
229  d1 = asin (d2);
230  d1 = atan (d2);
231  d1 = atan2 (d2, d3);
232  d1 = cos (d2);
233  d1 = sin (d2);
234  d1 = tan (d2);
235  d1 = cosh (d2);
236  d1 = sinh (d2);
237  d1 = tanh (d2);
238  d1 = exp (d2);
239  d1 = frexp (d2, &i1);
240  d1 = ldexp (d2, i2);
241  d1 = log (d2);
242  d1 = log10 (d2);
243  d1 = modf (d2, &d3);
244  d1 = pow (d2, d3);
245  d1 = sqrt (d2);
246  d1 = ceil (d2);
247  d1 = fabs (d2);
248  d1 = floor (d2);
249  d1 = fmod (d2, d3);
250
251  return 0;
252}
253