1 /** Test of float functions with a single float argument
3 func: SINF, SINHF, ASINF, COSF, COSHF, ACOSF, TANF, TANHF, ATANF, SQRTF, EXPF, LOGF, LOG10F, FLOORF, CEILF, FABSF
11 # define DEBUG(x) x /* only for "make test-host" */
18 #define TOLERANCE (1e-5)
21 # define STORAGE __code
28 # define REENTRANT reentrant
35 /* now exceptions for targets/functions which would not pass */
36 #if defined(SDCC_ds390)
37 # define ACOSF_DISABLED (1)
40 #if defined(SDCC_hc08)
41 # define ACOSF_DISABLED (1)
42 # define EXPF_DISABLED (1)
43 # define SINHF_DISABLED (1)
44 # define TANF_DISABLED (1)
47 #if defined(SDCC_mcs51) && defined(SDCC_USE_XSTACK)
48 # define SINF_DISABLED (1)
49 # define ACOSF_DISABLED (1)
50 # define COSF_DISABLED (1)
54 # define ACOSF_DISABLED (1)
55 # define ASINF_DISABLED (1)
56 # define ATANF_DISABLED (1)
60 static float dummy(float a)
65 typedef float (*float_test_func)(float) REENTRANT;
67 /* the table with functions, their argument, expected result, tolerance.
68 For most 8-bitters each testpoint uses 14 bytes so we could have a few:) */
72 float arg, result, tolerance;
74 static const STORAGE testpoint[] =
79 # warning {func} disabled
80 { dummy, 0.0, 0.0, TOLERANCE },
82 { sinf, 1.0, 0.841470984, TOLERANCE },
83 { sinf, -2.0, -0.909297426, TOLERANCE },
84 { sinf, 3.14159265/6.0, 0.5, TOLERANCE },
85 { sinf, 3.14159265+2.0, -0.909297426, TOLERANCE },
90 # warning {func} disabled
91 { dummy, 0.0, 0.0, TOLERANCE },
93 { sinhf, 1.0, 1.175201193, TOLERANCE },
94 { sinhf, -2.0, -3.626860407, TOLERANCE },
95 { sinhf, 3.14159265/6.0, 0.547853473, TOLERANCE },
96 { sinhf, 3.14159265+2.0, 85.49101383, TOLERANCE },
101 # warning {func} disabled
102 { dummy, 0.0, 0.0, TOLERANCE },
104 { asinf, 0.5, 3.14159265/6.0, TOLERANCE },
105 { asinf, 0.99749498, 1.5, TOLERANCE },
106 { asinf, -0.84147098, -1.0, TOLERANCE },
107 { asinf, 0.29552020, 0.3, TOLERANCE },
114 # warning {func} disabled
115 { dummy, 0.0, 0.0, TOLERANCE },
117 { cosf, 1.0, 0.540302305, TOLERANCE },
118 { cosf, 2.0, -0.416146836, TOLERANCE },
119 { cosf, 3.14159265/3.0, 0.5, TOLERANCE },
120 { cosf, 3.14159265+2.0, +0.416146836, TOLERANCE },
124 { coshf, 1.0, 1.543080634, TOLERANCE },
125 { coshf, 2.0, 3.7621956910, TOLERANCE },
126 { coshf, 3.0, 10.06766199, TOLERANCE },
127 { coshf, 4.0, 27.30823283, TOLERANCE },
131 # warning {func} disabled
132 { dummy, 0.0, 0.0, TOLERANCE },
134 { acosf, 0.1, 1.470628905, TOLERANCE },
135 { acosf, 0.5, 1.047197551, TOLERANCE },
136 { acosf, -0.9, 2.690565841, TOLERANCE },
137 { acosf, 0.999, 0.044725087, TOLERANCE },
144 # warning {func} disabled
145 { dummy, 0.0, 0.0, TOLERANCE },
147 { tanf, 1.0, 1.557407724, TOLERANCE },
148 { tanf, 2.0, -2.18503986, TOLERANCE },
149 { tanf, -1.5, -14.10141994, TOLERANCE },
153 { tanhf, 1.0, 0.761594155, TOLERANCE },
154 { tanhf, 3.800201167, 0.999, TOLERANCE },
155 { tanhf, 1.5, 0.905148253, TOLERANCE },
159 # warning {func} disabled
160 { dummy, 0.0, 0.0, TOLERANCE },
162 { atanf, 1.0, 0.7853981633, TOLERANCE },
163 { atanf, -2.0, -1.1071487177, TOLERANCE },
164 { atanf, 42.0, 1.5469913006, TOLERANCE },
170 { sqrtf, 5.0, 2.23606801, TOLERANCE },
171 { sqrtf, 1522756.0, 1234.0, TOLERANCE },
172 { sqrtf, 10000.0, 100.0, TOLERANCE },
178 # warning {func} disabled
179 { dummy, 0.0, 0.0, TOLERANCE },
181 { expf, 2.30258509, 10.0, TOLERANCE },
182 { expf, 4.82028150, 124.0, TOLERANCE },
183 { expf, 10.0, 22026.46579, TOLERANCE },
187 { logf, 2.06115362e-9, -20.0, TOLERANCE },
188 { logf, 10.0, 2.30258509, TOLERANCE },
189 { logf, 124.0, 4.82028150, TOLERANCE },
190 { logf, 22026.46579, 10.0, TOLERANCE },
193 { log10f, 0.000001, -6.0, TOLERANCE },
194 { log10f, 3.16227766e-4, -3.5, TOLERANCE },
195 { log10f, 3.16227766, 0.5, TOLERANCE },
196 { log10f, 10.0, 1.0, TOLERANCE },
197 { log10f, 1E6, 6.0, TOLERANCE },
203 # warning {func} disabled
204 { dummy, 0.0, 0.0, TOLERANCE },
206 { floorf, 1.0+0.000001, 1.0, TOLERANCE },
207 { floorf, 1.0-0.000001, 0.0, TOLERANCE },
208 //{ floorf, 1.0-0.000001, -0.0, TOLERANCE }, /* oops */
209 //{ dummy, 0.0, -0.0, TOLERANCE }, /* oops */
210 { floorf, -1.0+0.000001, -1.0, TOLERANCE },
211 { floorf, -1.0-0.000001, -2.0, TOLERANCE },
217 { ceilf, 1.0+0.000001, 2.0, TOLERANCE },
218 { ceilf, 1.0-0.000001, 1.0, TOLERANCE },
219 { ceilf, -1.0+0.000001, 0.0, TOLERANCE },
220 { ceilf, -1.0-0.000001, -1.0, TOLERANCE },
225 { fabsf, -1.0e-20, 1.0e-20, TOLERANCE },
226 { fabsf, 9999999, 9999999, TOLERANCE },
236 float result, rel_error;
238 for( i = 0; i < sizeof testpoint / sizeof testpoint[0]; i++ ) {
240 result = testpoint[i].f(testpoint[i].arg);
242 rel_error = testpoint[i].result ? result/testpoint[i].result - 1.0 : 0.0;
244 DEBUG(printf ("Test No: %d f(%f) = %f should: %f rel_error: %f %s\n",
245 i, testpoint[i].arg, result, testpoint[i].result, rel_error,
246 (fabsf(rel_error) < testpoint[i].tolerance) ? "Ok" : "Fail");)
248 ASSERT(fabsf(rel_error) < testpoint[i].tolerance);