source: mainline/uspace/app/tester/float/float2.c@ 18b6a88

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 18b6a88 was 18b6a88, checked in by Jiri Svoboda <jiri@…>, 7 years ago

More ccheck fixes, sometimes with manual intervention.

  • Property mode set to 100644
File size: 15.0 KB
Line 
1/*
2 * Copyright (c) 2014 Martin Decky
3 * Copyright (c) 2015 Jiri Svoboda
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#include <stdbool.h>
31#include <stdio.h>
32#include <stdlib.h>
33#include <stddef.h>
34#include <math.h>
35#include "../tester.h"
36
37#define OPERANDS 10
38#define PRECISIONF 10000
39#define PRECISION 100000000
40
41static double arguments[OPERANDS] = {
42 3.5, -2.1, 100.0, 50.0, -1024.0, 0.0, 768.3156, 1080.499999, -600.0, 1.0
43};
44
45static double arguments_acos[OPERANDS] = {
46 -0.936456687291, -0.504846104600, 0.862318872288, 0.964966028492,
47 0.987353618220, 1.0, -0.194939922623, 0.978471923925, -0.999023478833,
48 0.540302305868
49};
50
51static double arguments_asin[OPERANDS] = {
52 -0.350783227690, -0.863209366649, -0.506365641110, -0.262374853704,
53 0.158533380044, 0.0, 0.980815184715, -0.206379975025, -0.044182448332,
54 0.841470984808
55};
56
57static double arguments_atan[OPERANDS] = {
58 3.5, 100.0, 50.0, 768.3156, 1080.499999, 1.0, 66.0,
59 2.718281828459045, 9.9, 0.001
60};
61
62static double arguments_exp[OPERANDS] = {
63 3.5, -2.1, 50.0, 0.0, 1.0, 13.2, -1.1, -5.5, 0.1, -66.0
64};
65
66static double arguments_log[OPERANDS] = {
67 3.5, 100.0, 50.0, 768.3156, 1080.499999, 1.0, 66.0,
68 2.718281828459045, 9.9, 0.001
69};
70
71static double arguments_sqrt[OPERANDS] = {
72 3.5, 100.0, 50.0, 768.3156, 1080.499999, 1.0, 66.0,
73 2.718281828459045, 9.9, 0.001
74};
75
76static double arguments_tanh[OPERANDS] = {
77 3.5, -2.1, 50.0, 0.0, 1.0, 13.2, -1.1, -5.5, 0.000001, -66000000.0
78};
79
80static double results_acos[OPERANDS] = {
81 2.783185307180, 2.100000000000, 0.530964914873, 0.265482457437,
82 0.159205070272, 0.000000000000, 1.766992524091, 0.207873834887,
83 3.097395817941, 1.000000000000
84};
85
86static double results_asin[OPERANDS] = {
87 -0.358407346411, -1.041592653590, -0.530964914874, -0.265482457437,
88 0.159205070273, 0.000000000000, 1.374600129498, -0.207873834889,
89 -0.044196835651, 1.000000000000
90};
91
92static double results_atan[OPERANDS] = {
93 1.292496667790, 1.560796660108, 1.550798992822, 1.569494779052,
94 1.569870829603, 0.785398163397, 1.555645970920, 1.218282905017,
95 1.470127674637, 0.000999999667
96};
97
98static double results_ceil[OPERANDS] = {
99 4.0, -2.0, 100.0, 50.0, -1024.0, 0.0, 769.0, 1081.0, -600.0, 1.0
100};
101
102static double results_cos[OPERANDS] = {
103 -0.936456687291, -0.504846104600, 0.862318872288, 0.964966028492,
104 0.987353618220, 1.0, -0.194939922623, 0.978471923925, -0.999023478833,
105 0.540302305868
106};
107
108static double results_cosh[OPERANDS] = {
109 16.572824671057, 4.144313170410, 2592352764293536022528.000000000000,
110 1.000000000000, 1.543080634815, 270182.468624271103, 1.668518553822,
111 122.348009517829, 1.005004168056, 23035933171656458903220125696.0
112};
113
114static double results_fabs[OPERANDS] = {
115 3.5, 2.1, 100.0, 50.0, 1024.0, 0.0, 768.3156, 1080.499999, 600.0, 1.0
116};
117
118static double results_floor[OPERANDS] = {
119 3.0, -3.0, 100.0, 50.0, -1024.0, 0.0, 768.0, 1080.0, -600.0, 1.0
120};
121
122static double results_exp[OPERANDS] = {
123 33.115451958692, 0.122456428253, 5184705528587072045056.0,
124 1.000000000000, 2.718281828459, 540364.937246691552, 0.332871083698,
125 0.004086771438, 1.105170918076, 0.000000000000
126};
127
128static double results_log[OPERANDS] = {
129 1.252762968495, 4.605170185988, 3.912023005428, 6.644200586236,
130 6.985179175021, 0.000000000000, 4.189654742026, 1.000000000000,
131 2.292534757141, -6.907755278982
132};
133
134static double results_log10[OPERANDS] = {
135 0.544068044350, 2.000000000000, 1.698970004336, 2.885539651261,
136 3.033624770817, 0.000000000000, 1.819543935542, 0.434294481903,
137 0.995635194598, -3.000000000000
138};
139
140static double results_sin[OPERANDS] = {
141 -0.350783227690, -0.863209366649, -0.506365641110, -0.262374853704,
142 0.158533380044, 0.0, 0.980815184715, -0.206379975025, -0.044182448332,
143 0.841470984808
144};
145
146static double results_sinh[OPERANDS] = {
147 16.542627287635, -4.021856742157, 2592352764293536022528.000000000000,
148 0.000000000000, 1.175201193644, 270182.468622420449, -1.335647470124,
149 -122.343922746391, 0.100166750020, -23035933171656458903220125696.0
150};
151
152static double results_sqrt[OPERANDS] = {
153 1.870828693387, 10.000000000000, 7.071067811865, 27.718506453271,
154 32.870959812576, 1.000000000000, 8.124038404636, 1.648721270700,
155 3.146426544510, 0.031622776602
156};
157
158static double results_tan[OPERANDS] = {
159 0.374585640159, 1.709846542905, -0.587213915157, -0.271900611998,
160 0.160563932839, 0.000000000000, -5.031371570891, -0.210920691722,
161 0.044225635601, 1.557407724655
162};
163
164static double results_tanh[OPERANDS] = {
165 0.998177897611, -0.970451936613, 1.000000000000, 0.000000000000,
166 0.761594155956, 0.999999999993, -0.800499021761, -0.999966597156,
167 0.000001000000, -1.000000000000
168};
169
170static double results_trunc[OPERANDS] = {
171 3.0, -2.0, 100.0, 50.0, -1024.0, 0.0, 768.0, 1080.0, -600.0, 1.0
172};
173
174static bool cmp_float(float a, float b)
175{
176 float r;
177
178 /* XXX Need fabsf() */
179 if (b < 1.0 / PRECISIONF && b > -1.0 / PRECISIONF)
180 r = a;
181 else
182 r = a / b - 1.0;
183
184 /* XXX Need fabsf() */
185 if (r < 0.0)
186 r = -r;
187
188 return r < 1.0 / PRECISIONF;
189}
190
191static bool cmp_double(double a, double b)
192{
193 double r;
194
195 /* XXX Need fabs() */
196 if (b < 1.0 / PRECISION && b > -1.0 / PRECISION)
197 r = a;
198 else
199 r = a / b - 1.0;
200
201 /* XXX Need fabs() */
202 if (r < 0.0)
203 r = -r;
204
205 return r < 1.0 / PRECISION;
206}
207
208const char *test_float2(void)
209{
210 bool fail = false;
211#if 0
212 for (unsigned int i = 0; i < OPERANDS; i++) {
213 double res = acos(arguments_acos[i]);
214
215 if (!cmp_double(res, results_acos[i])) {
216 TPRINTF("Double precision acos failed "
217 "(%lf != %lf, arg %u)\n", res, results_acos[i], i);
218 fail = true;
219 }
220 }
221
222 for (unsigned int i = 0; i < OPERANDS; i++) {
223 float res = acosf(arguments_acos[i]);
224
225 if (!cmp_float(res, results_acos[i])) {
226 TPRINTF("Single precision acos failed "
227 "(%f != %lf, arg %u)\n", res, results_acos[i], i);
228 fail = true;
229 }
230 }
231
232 for (unsigned int i = 0; i < OPERANDS; i++) {
233 double res = asin(arguments_asin[i]);
234
235 if (!cmp_double(res, results_asin[i])) {
236 TPRINTF("Double precision asin failed "
237 "(%lf != %lf, arg %u)\n", res, results_asin[i], i);
238 fail = true;
239 }
240 }
241
242 for (unsigned int i = 0; i < OPERANDS; i++) {
243 float res = asinf(arguments_asin[i]);
244
245 if (!cmp_float(res, results_asin[i])) {
246 TPRINTF("Single precision asin failed "
247 "(%f != %lf, arg %u)\n", res, results_asin[i], i);
248 fail = true;
249 }
250 }
251#endif
252 for (unsigned int i = 0; i < OPERANDS; i++) {
253 double res = atan(arguments_atan[i]);
254
255 if (!cmp_double(res, results_atan[i])) {
256 TPRINTF("Double precision atan failed "
257 "(%.12lf != %.12lf, arg %u)\n", res, results_atan[i], i);
258 fail = true;
259 }
260 }
261
262 for (unsigned int i = 0; i < OPERANDS; i++) {
263 float res = atanf(arguments_atan[i]);
264
265 if (!cmp_float(res, results_atan[i])) {
266 TPRINTF("Single precision atan failed "
267 "(%f != %lf, arg %u)\n", res, results_atan[i], i);
268 fail = true;
269 }
270 }
271
272 for (unsigned int i = 0; i < OPERANDS; i++) {
273 double res = ceil(arguments[i]);
274
275 if (!cmp_double(res, results_ceil[i])) {
276 TPRINTF("Double precision ceil failed "
277 "(%lf != %lf, arg %u)\n", res, results_ceil[i], i);
278 fail = true;
279 }
280 }
281
282 for (unsigned int i = 0; i < OPERANDS; i++) {
283 float res = ceilf(arguments[i]);
284
285 if (!cmp_float(res, results_ceil[i])) {
286 TPRINTF("Single precision ceil failed "
287 "(%f != %lf, arg %u)\n", res, results_ceil[i], i);
288 fail = true;
289 }
290 }
291
292 for (unsigned int i = 0; i < OPERANDS; i++) {
293 double res = cos(arguments[i]);
294
295 if (!cmp_double(res, results_cos[i])) {
296 TPRINTF("Double precision cos failed "
297 "(%lf != %lf, arg %u)\n", res, results_cos[i], i);
298 fail = true;
299 }
300 }
301
302 for (unsigned int i = 0; i < OPERANDS; i++) {
303 float res = cosf(arguments[i]);
304
305 if (!cmp_float(res, results_cos[i])) {
306 TPRINTF("Single precision cos failed "
307 "(%f != %lf, arg %u)\n", res, results_cos[i], i);
308 fail = true;
309 }
310 }
311
312 for (unsigned int i = 0; i < OPERANDS; i++) {
313 double res = cosh(arguments_exp[i]);
314
315 if (!cmp_double(res, results_cosh[i])) {
316 TPRINTF("Double precision cosh failed "
317 "(%lf != %lf, arg %u)\n", res, results_cosh[i], i);
318 fail = true;
319 }
320 }
321
322 for (unsigned int i = 0; i < OPERANDS; i++) {
323 float res = coshf(arguments_exp[i]);
324
325 if (!cmp_float(res, results_cosh[i])) {
326 TPRINTF("Single precision cosh failed "
327 "(%f != %lf, arg %u)\n", res, results_cosh[i], i);
328 fail = true;
329 }
330 }
331
332 for (unsigned int i = 0; i < OPERANDS; i++) {
333 double res = exp(arguments_exp[i]);
334
335 if (!cmp_double(res, results_exp[i])) {
336 TPRINTF("Double precision exp failed "
337 "(%lf != %lf, arg %u)\n", res, results_exp[i], i);
338 fail = true;
339 }
340 }
341
342 for (unsigned int i = 0; i < OPERANDS; i++) {
343 float res = expf(arguments_exp[i]);
344
345 if (!cmp_float(res, results_exp[i])) {
346 TPRINTF("Single precision exp failed "
347 "(%f != %lf, arg %u)\n", res, results_exp[i], i);
348 fail = true;
349 }
350 }
351
352 for (unsigned int i = 0; i < OPERANDS; i++) {
353 double res = fabs(arguments[i]);
354
355 if (!cmp_double(res, results_fabs[i])) {
356 TPRINTF("Double precision fabs failed "
357 "(%lf != %lf, arg %u)\n", res, results_fabs[i], i);
358 fail = true;
359 }
360 }
361
362 for (unsigned int i = 0; i < OPERANDS; i++) {
363 float res = fabsf(arguments[i]);
364
365 if (!cmp_float(res, results_fabs[i])) {
366 TPRINTF("Single precision fabs failed "
367 "(%f != %lf, arg %u)\n", res, results_fabs[i], i);
368 fail = true;
369 }
370 }
371
372 for (unsigned int i = 0; i < OPERANDS; i++) {
373 double res = floor(arguments[i]);
374
375 if (!cmp_double(res, results_floor[i])) {
376 TPRINTF("Double precision floor failed "
377 "(%lf != %lf, arg %u)\n", res, results_floor[i], i);
378 fail = true;
379 }
380 }
381
382 for (unsigned int i = 0; i < OPERANDS; i++) {
383 float res = floorf(arguments[i]);
384
385 if (!cmp_float(res, results_floor[i])) {
386 TPRINTF("Single precision floor failed "
387 "(%f != %lf, arg %u)\n", res, results_floor[i], i);
388 fail = true;
389 }
390 }
391
392 for (unsigned int i = 0; i < OPERANDS; i++) {
393 double res = log(arguments_log[i]);
394
395 if (!cmp_double(res, results_log[i])) {
396 TPRINTF("Double precision log failed "
397 "(%lf != %lf, arg %u)\n", res, results_log[i], i);
398 fail = true;
399 }
400 }
401
402 for (unsigned int i = 0; i < OPERANDS; i++) {
403 float res = logf(arguments_log[i]);
404
405 if (!cmp_float(res, results_log[i])) {
406 TPRINTF("Single precision log failed "
407 "(%f != %lf, arg %u)\n", res, results_log[i], i);
408 fail = true;
409 }
410 }
411
412 for (unsigned int i = 0; i < OPERANDS; i++) {
413 double res = log10(arguments_log[i]);
414
415 if (!cmp_double(res, results_log10[i])) {
416 TPRINTF("Double precision log10 failed "
417 "(%lf != %lf, arg %u)\n", res, results_log10[i], i);
418 fail = true;
419 }
420 }
421
422 for (unsigned int i = 0; i < OPERANDS; i++) {
423 float res = log10f(arguments_log[i]);
424
425 if (!cmp_float(res, results_log10[i])) {
426 TPRINTF("Single precision log10 failed "
427 "(%f != %lf, arg %u)\n", res, results_log10[i], i);
428 fail = true;
429 }
430 }
431
432 for (unsigned int i = 0; i < OPERANDS; i++) {
433 double res = sin(arguments[i]);
434
435 if (!cmp_double(res, results_sin[i])) {
436 TPRINTF("Double precision sin failed "
437 "(%lf != %lf, arg %u)\n", res, results_sin[i], i);
438 fail = true;
439 }
440 }
441
442 for (unsigned int i = 0; i < OPERANDS; i++) {
443 float res = sinf(arguments[i]);
444
445 if (!cmp_float(res, results_sin[i])) {
446 TPRINTF("Single precision sin failed "
447 "(%f != %lf, arg %u)\n", res, results_sin[i], i);
448 fail = true;
449 }
450 }
451
452 for (unsigned int i = 0; i < OPERANDS; i++) {
453 double res = sinh(arguments_exp[i]);
454
455 if (!cmp_double(res, results_sinh[i])) {
456 TPRINTF("Double precision sinh failed "
457 "(%lf != %lf, arg %u)\n", res, results_sinh[i], i);
458 fail = true;
459 }
460 }
461
462 for (unsigned int i = 0; i < OPERANDS; i++) {
463 float res = sinhf(arguments_exp[i]);
464
465 if (!cmp_float(res, results_sinh[i])) {
466 TPRINTF("Single precision sinh failed "
467 "(%f != %lf, arg %u)\n", res, results_sinh[i], i);
468 fail = true;
469 }
470 }
471
472 for (unsigned int i = 0; i < OPERANDS; i++) {
473 double res = sqrt(arguments_sqrt[i]);
474
475 if (!cmp_double(res, results_sqrt[i])) {
476 TPRINTF("Double precision sqrt failed "
477 "(%lf != %lf, arg %u)\n", res, results_sqrt[i], i);
478 fail = true;
479 }
480 }
481
482 for (unsigned int i = 0; i < OPERANDS; i++) {
483 float res = sqrtf(arguments_sqrt[i]);
484
485 if (!cmp_float(res, results_sqrt[i])) {
486 TPRINTF("Single precision sqrt failed "
487 "(%f != %lf, arg %u)\n", res, results_sqrt[i], i);
488 fail = true;
489 }
490 }
491
492 for (unsigned int i = 0; i < OPERANDS; i++) {
493 double res = tan(arguments[i]);
494
495 if (!cmp_double(res, results_tan[i])) {
496 TPRINTF("Double precision tan failed "
497 "(%lf != %lf, arg %u)\n", res, results_tan[i], i);
498 fail = true;
499 }
500 }
501
502 for (unsigned int i = 0; i < OPERANDS; i++) {
503 float res = tanf(arguments[i]);
504
505 if (!cmp_float(res, results_tan[i])) {
506 TPRINTF("Single precision tan failed "
507 "(%f != %lf, arg %u)\n", res, results_tan[i], i);
508 fail = true;
509 }
510 }
511
512 for (unsigned int i = 0; i < OPERANDS; i++) {
513 double res = tanh(arguments_tanh[i]);
514
515 if (!cmp_double(res, results_tanh[i])) {
516 TPRINTF("Double precision tanh failed "
517 "(%lf != %lf, arg %u)\n", res, results_tanh[i], i);
518 fail = true;
519 }
520 }
521
522 for (unsigned int i = 0; i < OPERANDS; i++) {
523 float res = tanhf(arguments_tanh[i]);
524
525 if (!cmp_float(res, results_tanh[i])) {
526 TPRINTF("Single precision tanh failed "
527 "(%f != %lf, arg %u)\n", res, results_tanh[i], i);
528 fail = true;
529 }
530 }
531
532 for (unsigned int i = 0; i < OPERANDS; i++) {
533 double res = trunc(arguments[i]);
534
535 if (!cmp_double(res, results_trunc[i])) {
536 TPRINTF("Double precision trunc failed "
537 "(%lf != %lf, arg %u)\n", res, results_trunc[i], i);
538 fail = true;
539 }
540 }
541
542 for (unsigned int i = 0; i < OPERANDS; i++) {
543 float res = truncf(arguments[i]);
544
545 if (!cmp_float(res, results_trunc[i])) {
546 TPRINTF("Single precision trunc failed "
547 "(%f != %lf, arg %u)\n", res, results_trunc[i], i);
548 fail = true;
549 }
550 }
551
552 if (fail)
553 return "Floating point imprecision";
554
555 return NULL;
556}
Note: See TracBrowser for help on using the repository browser.