2 * This file is Copyright (c) 2010 by the GPSD project
3 * BSD terms apply: see the file COPYING in the distribution root for details.
8 * Copyright (c) 2006 Chris Kuethe <chris.kuethe@gmail.com>
10 * Permission to use, copy, modify, and distribute this software for any
11 * purpose with or without fee is hereby granted, provided that the above
12 * copyright notice and this permission notice appear in all copies.
14 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
15 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
17 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 * this simple program tests to see whether your system can do proper
25 * single and double precision floating point. This is apparently Very
26 * Hard To Do(tm) on embedded systems, judging by the number of broken
27 * ARM toolchains I've seen... :(
29 * compile with: gcc -O -o test_float test_float.c
30 * (use whatever -O level you like)
34 int test_single( void );
35 int test_double( void );
40 if ((i = test_single()))
41 printf("WARNING: Single-precision "
42 "floating point math might be broken\n");
44 if ((j = test_double()))
45 printf("WARNING: Double-precision "
46 "floating point math might be broken\n");
50 printf("floating point math appears to work\n");
61 for(i = 0; i < 10; i++)
68 /* subtraction test */
70 for(i = 0; i < 10; i++)
77 /* multiplication test */
79 for(i = 1; i < 10; i++)
88 for(i = 1; i < 10; i++)
95 /* multiply-accumulate test */
97 for(i = 1; i < 1000000; i++) {
106 /* divide-subtract test */
108 for(i = 1; i < 1000000; i++) {
117 /* add-multiply-subtract-divide test */
119 for(i = 1; i < 1000000; i++)
120 f = ((((f + 1.5) * 0.5) - 1.25) / 0.5);
126 /* multiply-add-divide-subtract test */
128 for(i = 1; i < 1000000; i++)
129 f = ((((f * 5.0) + 3.0) / 2.0) - 3.0);
133 /* subtract-divide-add-multiply test */
135 for(i = 1; i < 1000000; i++)
136 f = ((((f - 5.0) / 2.0) + 2.5) * 2.0);
142 /* divide-subtract-multiply-add test */
144 for(i = 1; i < 1000000; i++)
145 f = ((((f / 6.0) - 5.0) * 19.75 ) + 2.5);
165 for(i = 0; i < 10; i++)
172 /* subtraction test */
174 for(i = 0; i < 10; i++)
181 /* multiplication test */
183 for(i = 1; i < 10; i++)
192 for(i = 1; i < 10; i++)
199 /* multiply-accumulate test */
201 for(i = 1; i < 1000000; i++) {
210 /* divide-subtract test */
212 for(i = 1; i < 1000000; i++) {
221 /* add-multiply-subtract-divide test */
223 for(i = 1; i < 1000000; i++)
224 f = ((((f + 1.5) * 0.5) - 1.25) / 0.5);
230 /* multiply-add-divide-subtract test */
232 for(i = 1; i < 1000000; i++)
233 f = ((((f * 5.0) + 3.0) / 2.0) - 3.0);
237 /* subtract-divide-add-multiply test */
239 for(i = 1; i < 1000000; i++)
240 f = ((((f - 5.0) / 2.0) + 2.5) * 2.0);
246 /* divide-subtract-multiply-add test */
248 for(i = 1; i < 1000000; i++)
249 f = ((((f / 6.0) - 5.0) * 19.75 ) + 2.5);