2 * Copyright (c) 2014 Martin Decky
3 * Copyright (c) 2015 Jiri Svoboda
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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.
35 #include "../tester.h"
38 #define PRECISIONF 10000
39 #define PRECISION 100000000
41 static double arguments
[OPERANDS
] = {
42 3.5, -2.1, 100.0, 50.0, -1024.0, 0.0, 768.3156, 1080.499999, -600.0, 1.0
45 static double results_cos
[OPERANDS
] = {
46 -0.936456687291, -0.504846104600, 0.862318872288, 0.964966028492,
47 0.987353618220, 1.0, -0.194939922623, 0.978471923925, -0.999023478833,
51 static double results_sin
[OPERANDS
] = {
52 -0.350783227690, -0.863209366649, -0.506365641110, -0.262374853704,
53 0.158533380044, 0.0, 0.980815184715, -0.206379975025, -0.044182448332,
57 static double results_trunc
[OPERANDS
] = {
58 3.0, -2.0, 100.0, 50.0, -1024.0, 0.0, 768.0, 1080.0, -600.0, 1.0
61 static bool cmp_float(float a
, float b
)
65 /* XXX Need fabsf() */
66 if (b
< 1.0 / PRECISIONF
&& b
> -1.0 / PRECISIONF
)
71 /* XXX Need fabsf() */
75 return r
< 1.0 / PRECISIONF
;
78 static bool cmp_double(double a
, double b
)
83 if (b
< 1.0 / PRECISION
&& b
> -1.0 / PRECISION
)
92 return r
< 1.0 / PRECISION
;
95 const char *test_float2(void)
99 for (unsigned int i
= 0; i
< OPERANDS
; i
++) {
100 double res
= cos(arguments
[i
]);
102 if (!cmp_double(res
, results_cos
[i
])) {
103 TPRINTF("Double precision cos failed "
104 "(%lf != %lf, arg %u)\n", res
, results_cos
[i
], i
);
109 for (unsigned int i
= 0; i
< OPERANDS
; i
++) {
110 float res
= cosf(arguments
[i
]);
112 if (!cmp_float(res
, results_cos
[i
])) {
113 TPRINTF("Single precision cos failed "
114 "(%f != %lf, arg %u)\n", res
, results_cos
[i
], i
);
119 for (unsigned int i
= 0; i
< OPERANDS
; i
++) {
120 double res
= sin(arguments
[i
]);
122 if (!cmp_double(res
, results_sin
[i
])) {
123 TPRINTF("Double precision sin failed "
124 "(%lf != %lf, arg %u)\n", res
, results_sin
[i
], i
);
129 for (unsigned int i
= 0; i
< OPERANDS
; i
++) {
130 float res
= sinf(arguments
[i
]);
132 if (!cmp_float(res
, results_sin
[i
])) {
133 TPRINTF("Single precision sin failed "
134 "(%f != %lf, arg %u)\n", res
, results_sin
[i
], i
);
139 for (unsigned int i
= 0; i
< OPERANDS
; i
++) {
140 double res
= trunc(arguments
[i
]);
142 if (!cmp_double(res
, results_trunc
[i
])) {
143 TPRINTF("Double precision trunc failed "
144 "(%lf != %lf, arg %u)\n", res
, results_trunc
[i
], i
);
149 for (unsigned int i
= 0; i
< OPERANDS
; i
++) {
150 float res
= truncf(arguments
[i
]);
152 if (!cmp_float(res
, results_trunc
[i
])) {
153 TPRINTF("Single precision trunc failed "
154 "(%f != %lf, arg %u)\n", res
, results_trunc
[i
], i
);
160 return "Floating point imprecision";