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, NEG
11 # define DEBUG(x) x /* only for "make test-host" */
13 void _putchar(char c
);
25 #define TOLERANCE (1e-5)
39 typedef float (*float_test_func
)(float) __reentrant
;
41 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
43 /* the table with functions, their argument, expected result, tolerance.
44 For most 8-bitters each testpoint uses 14 bytes so we could have a few:) */
48 float arg
, result
, tolerance
;
51 static const testpoint
[] =
56 # warning {func} disabled
57 { dummy
, 0.0, 0.0, TOLERANCE
},
59 { sinf
, 1.0, 0.841470984, TOLERANCE
},
60 { sinf
, -2.0, -0.909297426, TOLERANCE
},
61 { sinf
, 3.14159265/6.0, 0.5, TOLERANCE
},
62 { sinf
, 3.14159265+2.0, -0.909297426, TOLERANCE
},
67 # warning {func} disabled
68 { dummy
, 0.0, 0.0, TOLERANCE
},
70 { sinhf
, 1.0, 1.175201193, TOLERANCE
},
71 { sinhf
, -2.0, -3.626860407, TOLERANCE
},
72 { sinhf
, 3.14159265/6.0, 0.547853473, TOLERANCE
},
73 { sinhf
, 3.14159265+2.0, 85.49101383, TOLERANCE
},
78 # warning {func} disabled
79 { dummy
, 0.0, 0.0, TOLERANCE
},
81 { asinf
, 0.5, 3.14159265/6.0, TOLERANCE
},
82 { asinf
, 0.99749498, 1.5, TOLERANCE
},
83 { asinf
, -0.84147098, -1.0, TOLERANCE
},
84 { asinf
, 0.29552020, 0.3, TOLERANCE
},
91 # warning {func} disabled
92 { dummy
, 0.0, 0.0, TOLERANCE
},
94 { cosf
, 1.0, 0.540302305, TOLERANCE
},
95 { cosf
, 2.0, -0.416146836, TOLERANCE
},
96 { cosf
, 3.14159265/3.0, 0.5, TOLERANCE
},
97 { cosf
, 3.14159265+2.0, +0.416146836, TOLERANCE
},
101 { coshf
, 1.0, 1.543080634, TOLERANCE
},
102 { coshf
, 2.0, 3.7621956910, TOLERANCE
},
103 { coshf
, 3.0, 10.06766199, TOLERANCE
},
104 { coshf
, 4.0, 27.30823283, TOLERANCE
},
108 # warning {func} disabled
109 { dummy
, 0.0, 0.0, TOLERANCE
},
111 { acosf
, 0.1, 1.470628905, TOLERANCE
},
112 { acosf
, 0.5, 1.047197551, TOLERANCE
},
113 { acosf
, -0.9, 2.690565841, TOLERANCE
},
114 { acosf
, 0.999, 0.044725087, TOLERANCE
},
121 # warning {func} disabled
122 { dummy
, 0.0, 0.0, TOLERANCE
},
124 { tanf
, 1.0, 1.557407724, TOLERANCE
},
125 { tanf
, 2.0, -2.18503986, TOLERANCE
},
126 { tanf
, -1.5, -14.10141994, TOLERANCE
},
130 { tanhf
, 1.0, 0.761594155, TOLERANCE
},
131 { tanhf
, 3.800201167, 0.999, TOLERANCE
},
132 { tanhf
, 1.5, 0.905148253, TOLERANCE
},
136 # warning {func} disabled
137 { dummy
, 0.0, 0.0, TOLERANCE
},
139 { atanf
, 1.0, 0.7853981633, TOLERANCE
},
140 { atanf
, -2.0, -1.1071487177, TOLERANCE
},
141 { atanf
, 42.0, 1.5469913006, TOLERANCE
},
147 { sqrtf
, 5.0, 2.23606801, TOLERANCE
},
148 { sqrtf
, 1522756.0, 1234.0, TOLERANCE
},
149 { sqrtf
, 10000.0, 100.0, TOLERANCE
},
155 # warning {func} disabled
156 { dummy
, 0.0, 0.0, TOLERANCE
},
158 { expf
, 2.30258509, 10.0, TOLERANCE
},
159 { expf
, 4.82028150, 124.0, TOLERANCE
},
160 { expf
, 10.0, 22026.46579, TOLERANCE
},
164 { logf
, 2.06115362e-9, -20.0, TOLERANCE
},
165 { logf
, 10.0, 2.30258509, TOLERANCE
},
166 { logf
, 124.0, 4.82028150, TOLERANCE
},
167 { logf
, 22026.46579, 10.0, TOLERANCE
},
170 { log10f
, 0.000001, -6.0, TOLERANCE
},
171 { log10f
, 3.16227766e-4, -3.5, TOLERANCE
},
172 { log10f
, 3.16227766, 0.5, TOLERANCE
},
173 { log10f
, 10.0, 1.0, TOLERANCE
},
174 { log10f
, 1E6
, 6.0, TOLERANCE
},
180 # warning {func} disabled
181 { dummy
, 0.0, 0.0, TOLERANCE
},
183 { floorf
, 1.0+0.000001, 1.0, TOLERANCE
},
184 { floorf
, 1.0-0.000001, 0.0, TOLERANCE
},
185 { floorf
, 1.0-0.000001, -0.0, TOLERANCE
},
186 { floorf
, -1.0+0.000001, -1.0, TOLERANCE
},
187 { floorf
, -1.0-0.000001, -2.0, TOLERANCE
},
193 { ceilf
, 1.0+0.000001, 2.0, TOLERANCE
},
194 { ceilf
, 1.0-0.000001, 1.0, TOLERANCE
},
195 { ceilf
, -1.0+0.000001, 0.0, TOLERANCE
},
196 { ceilf
, -1.0-0.000001, -1.0, TOLERANCE
},
201 { fabsf
, -1.0e-20, 1.0e-20, TOLERANCE
},
202 { fabsf
, 9999999, 9999999, TOLERANCE
},
208 # warning {func} disabled
209 { dummy
, 0.0, 0.0, TOLERANCE
},
211 { neg
, 0.0, -0.0, TOLERANCE
},
212 { dummy
, 0.0, -0.0, TOLERANCE
},
222 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
224 float result
, rel_error
;
226 for ( i
= 0; i
< sizeof testpoint
/ sizeof testpoint
[0]; i
++ )
228 result
= testpoint
[i
].f (testpoint
[i
].arg
);
230 rel_error
= testpoint
[i
].result
? result
/testpoint
[i
].result
- 1.0 : result
;
232 DEBUG (printf ("Test No: %d f(%f) = %f should: %f rel_error: %f %s\n",
233 i
, testpoint
[i
].arg
, result
, testpoint
[i
].result
, rel_error
,
234 (fabsf (rel_error
) < testpoint
[i
].tolerance
) ? "Ok" : "Fail");)
236 ASSERT (fabsf (rel_error
) < testpoint
[i
].tolerance
);