Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / float_single.c.in
blob8ab0ff7069300cfb3f478df2e4c72cf1d57bab1d
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
4 */
6 #include <testfwk.h>
7 #include <math.h>
9 #if 0
10 # include <stdio.h>
11 # define DEBUG(x) x /* only for "make test-host" */
12 # ifdef SDCC
13 void _putchar(char c);
14 void putchar(char c)
16 _putchar(c);
18 # endif
19 #else
20 # define DEBUG(x)
21 #endif
23 #define {func} (1)
25 #define TOLERANCE (1e-5)
27 static float
28 dummy (float a)
30 return a;
33 static float
34 neg (float a)
36 return -a;
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:) */
45 struct
47 float_test_func f;
48 float arg, result, tolerance;
51 static const testpoint[] =
54 #if SINF
55 # if {func}_DISABLED
56 # warning {func} disabled
57 { dummy, 0.0, 0.0, TOLERANCE },
58 # else
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 },
63 # endif
64 #endif
65 #if SINHF
66 # if {func}_DISABLED
67 # warning {func} disabled
68 { dummy, 0.0, 0.0, TOLERANCE },
69 # else
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 },
74 # endif
75 #endif
76 #if ASINF
77 # if {func}_DISABLED
78 # warning {func} disabled
79 { dummy, 0.0, 0.0, TOLERANCE },
80 # else
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 },
85 # endif
86 #endif
89 #if COSF
90 # if {func}_DISABLED
91 # warning {func} disabled
92 { dummy, 0.0, 0.0, TOLERANCE },
93 # else
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 },
98 # endif
99 #endif
100 #if COSHF
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 },
105 #endif
106 #if ACOSF
107 # if {func}_DISABLED
108 # warning {func} disabled
109 { dummy, 0.0, 0.0, TOLERANCE },
110 # else
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 },
115 # endif
116 #endif
119 #if TANF
120 # if {func}_DISABLED
121 # warning {func} disabled
122 { dummy, 0.0, 0.0, TOLERANCE },
123 # else
124 { tanf, 1.0, 1.557407724, TOLERANCE },
125 { tanf, 2.0, -2.18503986, TOLERANCE },
126 { tanf, -1.5, -14.10141994, TOLERANCE },
127 # endif
128 #endif
129 #if TANHF
130 { tanhf, 1.0, 0.761594155, TOLERANCE },
131 { tanhf, 3.800201167, 0.999, TOLERANCE },
132 { tanhf, 1.5, 0.905148253, TOLERANCE },
133 #endif
134 #if ATANF
135 # if {func}_DISABLED
136 # warning {func} disabled
137 { dummy, 0.0, 0.0, TOLERANCE },
138 # else
139 { atanf, 1.0, 0.7853981633, TOLERANCE },
140 { atanf, -2.0, -1.1071487177, TOLERANCE },
141 { atanf, 42.0, 1.5469913006, TOLERANCE },
142 # endif
143 #endif
146 #if SQRTF
147 { sqrtf, 5.0, 2.23606801, TOLERANCE },
148 { sqrtf, 1522756.0, 1234.0, TOLERANCE },
149 { sqrtf, 10000.0, 100.0, TOLERANCE },
150 #endif
153 #if EXPF
154 # if {func}_DISABLED
155 # warning {func} disabled
156 { dummy, 0.0, 0.0, TOLERANCE },
157 # else
158 { expf, 2.30258509, 10.0, TOLERANCE },
159 { expf, 4.82028150, 124.0, TOLERANCE },
160 { expf, 10.0, 22026.46579, TOLERANCE },
161 # endif
162 #endif
163 #if LOGF
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 },
168 #endif
169 #if LOG10F
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 },
175 #endif
178 #if FLOORF
179 # if {func}_DISABLED
180 # warning {func} disabled
181 { dummy, 0.0, 0.0, TOLERANCE },
182 # else
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 },
188 # endif
189 #endif
192 #if CEILF
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 },
197 #endif
200 #if FABSF
201 { fabsf, -1.0e-20, 1.0e-20, TOLERANCE },
202 { fabsf, 9999999, 9999999, TOLERANCE },
203 #endif
206 #if NEG
207 # if {func}_DISABLED
208 # warning {func} disabled
209 { dummy, 0.0, 0.0, TOLERANCE },
210 # else
211 { neg, 0.0, -0.0, TOLERANCE },
212 { dummy, 0.0, -0.0, TOLERANCE },
213 # endif
214 #endif
217 #endif
219 void
220 testFloat (void)
222 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
223 unsigned char i;
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);
238 #endif