1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <math.h>
4 #include "test.h"
5
6 /* r = place to store result
7 * f = function call to test (or any expression)
8 * x = expected result
9 * m = message to print on failure (with formats for r & x)
10 */
11
12 #define TEST(r, f, x, m) ( \
13 ((r) = (f)) == (x) || \
14 (t_error("%s failed (" m ")\n", #f, r, x, r-x), 0) )
15
main(void)16 int main(void)
17 {
18 int i;
19 double d, d2;
20 char buf[1000];
21
22 for (i=0; i<100; i++) {
23 d = sin(i);
24 snprintf(buf, sizeof buf, "%.300f", d);
25 TEST(d2, strtod(buf, 0), d, "round trip fail %a != %a (%a)");
26 }
27
28 TEST(d, strtod("0x1p4", 0), 16.0, "hex float %a != %a");
29 TEST(d, strtod("0x1.1p4", 0), 17.0, "hex float %a != %a");
30 return t_status;
31 }
32
33