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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since ac96b11 was 7a9ef81, checked in by Martin Decky <martin@…>, 11 years ago

make the float2 test more informative

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/*
2 * Copyright (c) 2014 Martin Decky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <stdio.h>
30#include <stdlib.h>
31#include <math.h>
32#include "../tester.h"
33
34#define OPERANDS 10
35#define PRECISION 100000000
36
37static double arguments[OPERANDS] = {
38 3.5, -2.1, 100.0, 50.0, -1024.0, 0.0, 768.3156, 1080.499999, -600.0, 1.0
39};
40
41static double results_trunc[OPERANDS] = {
42 3.0, -2.0, 100.0, 50.0, -1024.0, 0.0, 768.0, 1080.0, -600.0, 1.0
43};
44
45static double results_sin[OPERANDS] = {
46 -0.350783227690, -0.863209366649, -0.506365641110, -0.262374853704,
47 0.158533380044, 0.0, 0.980815184715, -0.206379975025, -0.044182448332,
48 0.841470984808
49};
50
51static double results_cos[OPERANDS] = {
52 -0.936456687291, -0.504846104600, 0.862318872288, 0.964966028492,
53 0.987353618220, 1.0, -0.194939922623, 0.978471923925, -0.999023478833,
54 0.540302305868
55};
56
57const char *test_float2(void)
58{
59 bool fail = false;
60
61 for (unsigned int i = 0; i < OPERANDS; i++) {
62 double res = trunc(arguments[i]);
63 int64_t res_int = (int64_t) (res * PRECISION);
64 int64_t corr_int = (int64_t) (results_trunc[i] * PRECISION);
65
66 if (res_int != corr_int) {
67 TPRINTF("Double truncation failed (%" PRId64 " != %" PRId64
68 ", arg %u)\n", res_int, corr_int, i);
69 fail = true;
70 }
71 }
72
73 for (unsigned int i = 0; i < OPERANDS; i++) {
74 double res = sin(arguments[i]);
75 int64_t res_int = (int64_t) (res * PRECISION);
76 int64_t corr_int = (int64_t) (results_sin[i] * PRECISION);
77
78 if (res_int != corr_int) {
79 TPRINTF("Double sine failed (%" PRId64 " != %" PRId64
80 ", arg %u)\n", res_int, corr_int, i);
81 fail = true;
82 }
83 }
84
85 for (unsigned int i = 0; i < OPERANDS; i++) {
86 double res = cos(arguments[i]);
87 int64_t res_int = (int64_t) (res * PRECISION);
88 int64_t corr_int = (int64_t) (results_cos[i] * PRECISION);
89
90 if (res_int != corr_int) {
91 TPRINTF("Double cosine failed (%" PRId64 " != %" PRId64
92 ", arg %u)\n", res_int, corr_int, i);
93 fail = true;
94 }
95 }
96
97 if (fail)
98 return "Floating point imprecision";
99
100 return NULL;
101}
Note: See TracBrowser for help on using the repository browser.