]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/fp-test.c
Initial revision
[thirdparty/gcc.git] / gcc / fp-test.c
CommitLineData
5870d23d 1/* fp-test.c - Check that all floating-point operations are available.
2 Copyright (C) 1995 Free Software Foundation, Inc.
3 Contributed by Ronald F. Guilmette <rfg@monkeys.com>.
4
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GNU CC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING. If not, write to
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, 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 ()
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 sc = f1;
108 uc = f1;
109 ss = f1;
110 us = f1;
111 si = f1;
112 ui = f1;
113 sl = f1;
114 ul = f1;
115 d1 = f1;
116 D1 = f1;
117
118 f1 = sc;
119 f1 = uc;
120 f1 = ss;
121 f1 = us;
122 f1 = si;
123 f1 = ui;
124 f1 = sl;
125 f1 = ul;
126 f1 = d1;
127 f1 = D1;
128
129 d1 = -d2;
130 d1 = d2 + d3;
131 d1 = d2 - d3;
132 d1 = d2 * d3;
133 d1 = d2 / d3;
134 d1 += d2;
135 d1 -= d2;
136 d1 *= d2;
137 d1 /= d2;
138
139 si = d1 == d2;
140 si = d1 != d2;
141 si = d1 > d2;
142 si = d1 < d2;
143 si = d1 >= d2;
144 si = d1 <= d2;
145
146 sc = d1;
147 uc = d1;
148 ss = d1;
149 us = d1;
150 si = d1;
151 ui = d1;
152 sl = d1;
153 ul = d1;
154 f1 = d1;
155 D1 = d1;
156
157 d1 = sc;
158 d1 = uc;
159 d1 = ss;
160 d1 = us;
161 d1 = si;
162 d1 = ui;
163 d1 = sl;
164 d1 = ul;
165 d1 = f1;
166 d1 = D1;
167
168 D1 = -D2;
169 D1 = D2 + D3;
170 D1 = D2 - D3;
171 D1 = D2 * D3;
172 D1 = D2 / D3;
173 D1 += D2;
174 D1 -= D2;
175 D1 *= D2;
176 D1 /= D2;
177
178 si = D1 == D2;
179 si = D1 != D2;
180 si = D1 > D2;
181 si = D1 < D2;
182 si = D1 >= D2;
183 si = D1 <= D2;
184
185 sc = D1;
186 uc = D1;
187 ss = D1;
188 us = D1;
189 si = D1;
190 ui = D1;
191 sl = D1;
192 ul = D1;
193 f1 = D1;
194 d1 = D1;
195
196 D1 = sc;
197 D1 = uc;
198 D1 = ss;
199 D1 = us;
200 D1 = si;
201 D1 = ui;
202 D1 = sl;
203 D1 = ul;
204 D1 = f1;
205 D1 = d1;
206
207 d1 = acos (d2);
208 d1 = asin (d2);
209 d1 = atan (d2);
210 d1 = atan2 (d2, d3);
211 d1 = cos (d2);
212 d1 = sin (d2);
213 d1 = tan (d2);
214 d1 = cosh (d2);
215 d1 = sinh (d2);
216 d1 = tanh (d2);
217 d1 = exp (d2);
218 d1 = frexp (d2, &i1);
219 d1 = ldexp (d2, i2);
220 d1 = log (d2);
221 d1 = log10 (d2);
222 d1 = modf (d2, &d3);
223 d1 = pow (d2, d3);
224 d1 = sqrt (d2);
225 d1 = ceil (d2);
226 d1 = fabs (d2);
227 d1 = floor (d2);
228 d1 = fmod (d2, d3);
229
230 return 0;
231}