1570af302Sopenharmony_ci#include <stdio.h>
2570af302Sopenharmony_ci#include <stdlib.h>
3570af302Sopenharmony_ci#include <math.h>
4570af302Sopenharmony_ci#include "test.h"
5570af302Sopenharmony_ci
6570af302Sopenharmony_ci/* r = place to store result
7570af302Sopenharmony_ci * f = function call to test (or any expression)
8570af302Sopenharmony_ci * x = expected result
9570af302Sopenharmony_ci * m = message to print on failure (with formats for r & x)
10570af302Sopenharmony_ci */
11570af302Sopenharmony_ci
12570af302Sopenharmony_ci#define TEST(r, f, x, m) ( \
13570af302Sopenharmony_ci	((r) = (f)) == (x) || \
14570af302Sopenharmony_ci	(t_error("%s failed (" m ")\n", #f, r, x, r-x), 0) )
15570af302Sopenharmony_ci
16570af302Sopenharmony_ciint main(void)
17570af302Sopenharmony_ci{
18570af302Sopenharmony_ci	int i;
19570af302Sopenharmony_ci	double d, d2;
20570af302Sopenharmony_ci	char buf[1000];
21570af302Sopenharmony_ci
22570af302Sopenharmony_ci	for (i=0; i<100; i++) {
23570af302Sopenharmony_ci		d = sin(i);
24570af302Sopenharmony_ci		snprintf(buf, sizeof buf, "%.300f", d);
25570af302Sopenharmony_ci		TEST(d2, strtod(buf, 0), d, "round trip fail %a != %a (%a)");
26570af302Sopenharmony_ci	}
27570af302Sopenharmony_ci
28570af302Sopenharmony_ci	TEST(d, strtod("0x1p4", 0), 16.0, "hex float %a != %a");
29570af302Sopenharmony_ci	TEST(d, strtod("0x1.1p4", 0), 17.0, "hex float %a != %a");
30570af302Sopenharmony_ci	return t_status;
31570af302Sopenharmony_ci}
32570af302Sopenharmony_ci
33