fp-test.c revision 90075
120253Sjoerg/* fp-test.c - Check that all floating-point operations are available.
220302Sjoerg   Copyright (C) 1995, 2000 Free Software Foundation, Inc.
320302Sjoerg   Contributed by Ronald F. Guilmette <rfg@monkeys.com>.
420253Sjoerg
520253Sjoerg   This file is part of GCC.
620253Sjoerg
720253Sjoerg   GCC is free software; you can redistribute it and/or modify it
820253Sjoerg   under the terms of the GNU General Public License as published by
920302Sjoerg   the Free Software Foundation; either version 2, or (at your option)
1020253Sjoerg   any later version.
1120253Sjoerg
1220253Sjoerg   GCC is distributed in the hope that it will be useful, but WITHOUT
1320253Sjoerg   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
1420302Sjoerg   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
1520253Sjoerg   License for more details.
1620253Sjoerg
1720302Sjoerg   You should have received a copy of the GNU General Public License
1820253Sjoerg   along with GCC; see the file COPYING.  If not, write to the Free
1920253Sjoerg   Software Foundation, 59 Temple Place - Suite 330, Boston, MA
2020253Sjoerg   02111-1307, USA.  */
2120253Sjoerg
2220253Sjoerg/* This is a trivial test program which may be useful to people who are
2320253Sjoerg   porting the GCC or G++ compilers to a new system.  The intent here is
2420253Sjoerg   merely to check that all floating-point operations have been provided
2544229Sdavidn   by the port. (Note that I say ``provided'' rather than ``implemented''.)
2620253Sjoerg
2720253Sjoerg   To use this file, simply compile it (with GCC or G++) and then try to
2830259Scharnier   link it in the normal way (also using GCC or G++ respectively).  If
2930259Scharnier   all of the floating -point operations (including conversions) have
3050479Speter   been provided, then this file will link without incident.  If however
3130259Scharnier   one or more of the primitive floating-point operations have not been
3230259Scharnier   properly provided, you will get link-time errors indicating which
3330259Scharnier   floating-point operations are unavailable.
3430259Scharnier
3520253Sjoerg   This file will typically be used when porting the GNU compilers to
3620253Sjoerg   some system which lacks floating-point hardware, and for which
3720253Sjoerg   software emulation routines (for FP ops) are needed in order to
3830259Scharnier   complete the port.  */
3920253Sjoerg
4020555Sdavidn#if 0
4120555Sdavidn#include <math.h>
4220555Sdavidn#endif
4364918Sgreen
44242349Sbaptextern double acos (double);
45242349Sbaptextern double asin (double);
46242349Sbaptextern double atan (double);
4720253Sjoergextern double atan2 (double, double);
4820253Sjoergextern double cos (double);
4920253Sjoergextern double sin (double);
5023318Sacheextern double tan (double);
5122394Sdavidnextern double cosh (double);
5252512Sdavidnextern double sinh (double);
5324214Sacheextern double tanh (double);
54285401Sbaptextern double exp (double);
55284124Sbaptextern double frexp (double, int *);
56284133Sbaptextern double ldexp (double, int);
57284118Sbaptextern double log (double);
5820253Sjoergextern double log10 (double);
5920253Sjoergextern double modf (double, double *);
6020253Sjoergextern double pow (double, double);
6120253Sjoergextern double sqrt (double);
62285409Sbaptextern double ceil (double);
6320253Sjoergextern double fabs (double);
6420253Sjoergextern double floor (double);
6585145Sacheextern double fmod (double, double);
6620253Sjoerg
67283961Sbaptint i1, i2 = 2;
68285403Sbapt
69283961Sbaptvolatile signed char sc;
70284118Sbaptvolatile unsigned char uc;
71285430Sbapt
72285430Sbaptvolatile signed short ss;
73283961Sbaptvolatile unsigned short us;
74285430Sbapt
75283961Sbaptvolatile signed int si;
76285430Sbaptvolatile unsigned int ui;
77285430Sbapt
78285430Sbaptvolatile signed long sl;
79283961Sbaptvolatile unsigned long ul;
80283961Sbapt
81285430Sbaptvolatile float f1 = 1.0, f2 = 1.0, f3 = 1.0;
82285430Sbaptvolatile double d1 = 1.0, d2 = 1.0, d3 = 1.0;
83285403Sbaptvolatile long double D1 = 1.0, D2 = 1.0, D3 = 1.0;
84283961Sbapt
85283961Sbaptint
86283961Sbaptmain ()
87285133Sbapt{
88285137Sbapt  /* TYPE: float */
89285133Sbapt
90285133Sbapt  f1 = -f2;
91285133Sbapt  f1 = f2 + f3;
92285133Sbapt  f1 = f2 - f3;
93285133Sbapt  f1 = f2 * f3;
94285133Sbapt  f1 = f2 / f3;
95285133Sbapt  f1 += f2;
96285133Sbapt  f1 -= f2;
97285133Sbapt  f1 *= f2;
98285133Sbapt  f1 /= f2;
99285133Sbapt
100285133Sbapt  si = f1 == f2;
101285133Sbapt  si = f1 != f2;
102285133Sbapt  si = f1 > f2;
103285133Sbapt  si = f1 < f2;
104285133Sbapt  si = f1 >= f2;
105285133Sbapt  si = f1 <= f2;
106285133Sbapt
107285133Sbapt  si = __builtin_isgreater (f1, f2);
108285137Sbapt  si = __builtin_isgreaterequal (f1, f2);
109285133Sbapt  si = __builtin_isless (f1, f2);
110285133Sbapt  si = __builtin_islessequal (f1, f2);
111285133Sbapt  si = __builtin_islessgreater (f1, f2);
112285133Sbapt  si = __builtin_isunordered (f1, f2);
113285133Sbapt
114285133Sbapt  sc = f1;
115285133Sbapt  uc = f1;
116285133Sbapt  ss = f1;
117285133Sbapt  us = f1;
118285133Sbapt  si = f1;
119285133Sbapt  ui = f1;
120285133Sbapt  sl = f1;
121285133Sbapt  ul = f1;
122285133Sbapt  d1 = f1;
123285133Sbapt  D1 = f1;
124285133Sbapt
125285133Sbapt  f1 = sc;
126285133Sbapt  f1 = uc;
127285133Sbapt  f1 = ss;
128285133Sbapt  f1 = us;
129285133Sbapt  f1 = si;
130285133Sbapt  f1 = ui;
131285133Sbapt  f1 = sl;
132285133Sbapt  f1 = ul;
133285133Sbapt  f1 = d1;
134285133Sbapt  f1 = D1;
135285133Sbapt
136285137Sbapt  d1 = -d2;
137285133Sbapt  d1 = d2 + d3;
138285133Sbapt  d1 = d2 - d3;
139285133Sbapt  d1 = d2 * d3;
140285133Sbapt  d1 = d2 / d3;
141285133Sbapt  d1 += d2;
142285133Sbapt  d1 -= d2;
143285133Sbapt  d1 *= d2;
144285133Sbapt  d1 /= d2;
145285133Sbapt
146285133Sbapt  si = d1 == d2;
147285133Sbapt  si = d1 != d2;
148285133Sbapt  si = d1 > d2;
149285395Sbapt  si = d1 < d2;
150285395Sbapt  si = d1 >= d2;
151285395Sbapt  si = d1 <= d2;
152285395Sbapt
153285395Sbapt  si = __builtin_isgreater (d1, d2);
154285395Sbapt  si = __builtin_isgreaterequal (d1, d2);
155285395Sbapt  si = __builtin_isless (d1, d2);
156285395Sbapt  si = __builtin_islessequal (d1, d2);
157285395Sbapt  si = __builtin_islessgreater (d1, d2);
158285395Sbapt  si = __builtin_isunordered (d1, d2);
159285395Sbapt
160285395Sbapt  sc = d1;
161285395Sbapt  uc = d1;
162285395Sbapt  ss = d1;
163285398Sbapt  us = d1;
164285398Sbapt  si = d1;
165285398Sbapt  ui = d1;
166285398Sbapt  sl = d1;
167285398Sbapt  ul = d1;
168285398Sbapt  f1 = d1;
169285398Sbapt  D1 = d1;
170285398Sbapt
171285398Sbapt  d1 = sc;
172285398Sbapt  d1 = uc;
173285398Sbapt  d1 = ss;
174285398Sbapt  d1 = us;
175285398Sbapt  d1 = si;
176285398Sbapt  d1 = ui;
177285398Sbapt  d1 = sl;
178285398Sbapt  d1 = ul;
179285398Sbapt  d1 = f1;
180285398Sbapt  d1 = D1;
181285398Sbapt
182285398Sbapt  D1 = -D2;
183285398Sbapt  D1 = D2 + D3;
184285398Sbapt  D1 = D2 - D3;
185285398Sbapt  D1 = D2 * D3;
186285398Sbapt  D1 = D2 / D3;
187285398Sbapt  D1 += D2;
188285398Sbapt  D1 -= D2;
189285398Sbapt  D1 *= D2;
190285398Sbapt  D1 /= D2;
191285398Sbapt
192285398Sbapt  si = D1 == D2;
193285405Sbapt  si = D1 != D2;
194285405Sbapt  si = D1 > D2;
195285405Sbapt  si = D1 < D2;
196285405Sbapt  si = D1 >= D2;
197285405Sbapt  si = D1 <= D2;
198285405Sbapt
199285405Sbapt  si = __builtin_isgreater (D1, D2);
200285405Sbapt  si = __builtin_isgreaterequal (D1, D2);
201285405Sbapt  si = __builtin_isless (D1, D2);
202285405Sbapt  si = __builtin_islessequal (D1, D2);
203285405Sbapt  si = __builtin_islessgreater (D1, D2);
204285405Sbapt  si = __builtin_isunordered (D1, D2);
205285405Sbapt
206285405Sbapt  sc = D1;
207285405Sbapt  uc = D1;
208285405Sbapt  ss = D1;
209285405Sbapt  us = D1;
210285405Sbapt  si = D1;
211285405Sbapt  ui = D1;
212285405Sbapt  sl = D1;
213285405Sbapt  ul = D1;
214285405Sbapt  f1 = D1;
215285405Sbapt  d1 = D1;
216285405Sbapt
217285405Sbapt  D1 = sc;
218285405Sbapt  D1 = uc;
219285405Sbapt  D1 = ss;
220285405Sbapt  D1 = us;
221285405Sbapt  D1 = si;
222285405Sbapt  D1 = ui;
223285405Sbapt  D1 = sl;
224285405Sbapt  D1 = ul;
225285405Sbapt  D1 = f1;
226285405Sbapt  D1 = d1;
227285405Sbapt
228285405Sbapt  d1 = acos (d2);
229285405Sbapt  d1 = asin (d2);
230285405Sbapt  d1 = atan (d2);
231285405Sbapt  d1 = atan2 (d2, d3);
232285405Sbapt  d1 = cos (d2);
233285405Sbapt  d1 = sin (d2);
234285405Sbapt  d1 = tan (d2);
235285405Sbapt  d1 = cosh (d2);
236285405Sbapt  d1 = sinh (d2);
237285405Sbapt  d1 = tanh (d2);
238285405Sbapt  d1 = exp (d2);
239285405Sbapt  d1 = frexp (d2, &i1);
240285405Sbapt  d1 = ldexp (d2, i2);
241285405Sbapt  d1 = log (d2);
242285405Sbapt  d1 = log10 (d2);
243285405Sbapt  d1 = modf (d2, &d3);
244285405Sbapt  d1 = pow (d2, d3);
245285405Sbapt  d1 = sqrt (d2);
246285405Sbapt  d1 = ceil (d2);
247285405Sbapt  d1 = fabs (d2);
248285405Sbapt  d1 = floor (d2);
249285405Sbapt  d1 = fmod (d2, d3);
250285405Sbapt
251285405Sbapt  return 0;
252285405Sbapt}
253285405Sbapt