Blame src/functional/strtod_simple.c

nsz 462b4f
#include <stdio.h>
nsz 462b4f
#include <stdlib.h>
nsz 462b4f
#include <math.h>
nsz 462b4f
#include "test.h"
nsz 462b4f
nsz 462b4f
/* r = place to store result
nsz 462b4f
 * f = function call to test (or any expression)
nsz 462b4f
 * x = expected result
nsz 462b4f
 * m = message to print on failure (with formats for r & x)
Szabolcs Nagy cfa23c
 */
nsz 462b4f
nsz 462b4f
#define TEST(r, f, x, m) ( \
nsz 462b4f
	((r) = (f)) == (x) || \
Szabolcs Nagy cfa23c
	(t_error("%s failed (" m ")\n", #f, r, x, r-x), 0) )
nsz 462b4f
nsz 462b4f
int main(void)
nsz 462b4f
{
nsz 462b4f
	int i;
nsz 462b4f
	double d, d2;
nsz 462b4f
	char buf[1000];
nsz 462b4f
nsz 462b4f
	for (i=0; i<100; i++) {
nsz 462b4f
		d = sin(i);
nsz 462b4f
		snprintf(buf, sizeof buf, "%.300f", d);
nsz 462b4f
		TEST(d2, strtod(buf, 0), d, "round trip fail %a != %a (%a)");
nsz 462b4f
	}
nsz 462b4f
nsz 462b4f
	TEST(d, strtod("0x1p4", 0), 16.0, "hex float %a != %a");
nsz 462b4f
	TEST(d, strtod("0x1.1p4", 0), 17.0, "hex float %a != %a");
Szabolcs Nagy cfa23c
	return t_status;
nsz 462b4f
}
nsz 462b4f