new test framework (one main per test)
[libc-test] / src / stdlib / strtod.c
index 49766ea..c6967ac 100644 (file)
@@ -1,61 +1,10 @@
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
 #include <math.h>
 #include "test.h"
 
-/* r = place to store result
- * f = function call to test (or any expression)
- * x = expected result
- * m = message to print on failure (with formats for r & x)
-**/
+#define length(x) (sizeof(x) / sizeof *(x))
 
-#define TEST(r, f, x, m) ( \
-       ((r) = (f)) == (x) || \
-       (error("%s failed (" m ")\n", #f, r, x, r-x), 0) )
-
-void test_strtod_simple(void) {
-       int i;
-       double d, d2;
-       char buf[1000];
-
-       for (i=0; i<100; i++) {
-               d = sin(i);
-               snprintf(buf, sizeof buf, "%.300f", d);
-               TEST(d2, strtod(buf, 0), d, "round trip fail %a != %a (%a)");
-       }
-
-       TEST(d, strtod("0x1p4", 0), 16.0, "hex float %a != %a");
-       TEST(d, strtod("0x1.1p4", 0), 17.0, "hex float %a != %a");
-}
-
-#define length(x) (sizeof(x) / sizeof(*(x)))
-
-/* TODO: float exceptions, rounding mode, endptr check */
-
-static struct {
-       char *s;
-       long double f;
-} tl[] = {
-       {"12.345", 12.345L},
-       {"1.2345e1", 12.345L},
-       // 2^-16445 * 0.5 - eps
-       {".1822599765941237301264202966809709908199525407846781671860490243514185844316698e-4950", 0},
-       // 2^-16445 * 0.5 + eps
-       {".1822599765941237301264202966809709908199525407846781671860490243514185844316699e-4950", 0x1p-16445L},
-       // 2^-16445 * 1.5 - eps
-       {".5467799297823711903792608900429129724598576223540345015581470730542557532950096e-4950", 0x1p-16445L},
-       // 2^-16445 * 1.5 + eps
-       {".5467799297823711903792608900429129724598576223540345015581470730542557532950097e-4950", 0x1p-16444L},
-       // 2^-16382 + 2^-16446 - eps
-       {".3362103143112093506444937793915876332724499641527442230928779770593420866576777e-4931", 0x1p-16382L},
-       // 2^-16382 + 2^-16446 + eps
-       {".3362103143112093506444937793915876332724499641527442230928779770593420866576778e-4931", 0x1.0000000000000002p-16382L},
-       // 2^16384 - 2^16319 - eps
-       {"118973149535723176505351158982948.86679662540046955672e4900", 0x1.fffffffffffffffep16383L},
-       // 2^16384 - 2^16319 + eps
-       {"118973149535723176505351158982948.86679662540046955673e4900", INFINITY},
-};
 static struct {
        char *s;
        double f;
@@ -109,43 +58,8 @@ static struct {
        {"0.9709481716420048341897258980454298205278e8", 97094817.164200485}, // 0x1.7263284a8242cp+26
        {"0.4996908522051874110779982354932499499602e9", 499690852.20518744}, // 0x1.dc8ad6434872ap+28
 };
-static struct {
-       char *s;
-       float f;
-} tf[] = {
-       // 2^-149 * 0.5 - eps
-       {".7006492321624085354618647916449580656401309709382578858785341419448955413429303e-45", 0},
-       // 2^-149 * 0.5 + eps
-       {".7006492321624085354618647916449580656401309709382578858785341419448955413429304e-45", 0x1p-149},
-       // 2^-149 * 0.5 - eps
-       {".2101947696487225606385594374934874196920392912814773657635602425834686624028790e-44", 0x1p-149},
-       // 2^-149 * 0.5 + eps
-       {".2101947696487225606385594374934874196920392912814773657635602425834686624028791e-44", 0x1p-148},
-       // 2^-126 + 2^-150 - eps
-       {".1175494420887210724209590083408724842314472120785184615334540294131831453944281e-37", 0x1p-126},
-       // 2^-126 + 2^-150 + eps
-       {".1175494420887210724209590083408724842314472120785184615334540294131831453944282e-37", 0x1.000002p-126},
-       // 2^128 - 2^103 - eps
-       {"340282356779733661637539395458142568447.9999999999999999999", 0x1.fffffep127},
-       // 2^128 - 2^103
-       {"340282356779733661637539395458142568448", INFINITY},
-};
-
 
-void test_strtold()
-{
-       int i;
-       long double x;
-       char *p;
-
-       for (i = 0; i < length(tl); i++) {
-               x = strtold(tl[i].s, &p);
-               if (x != tl[i].f)
-                       error("strtold(\"%s\") want %La got %La\n", tl[i].s, tl[i].f, x);
-       }
-}
-
-void test_strtod()
+int main(void)
 {
        int i;
        double x;
@@ -156,39 +70,6 @@ void test_strtod()
                if (x != t[i].f)
                        error("strtod(\"%s\") want %a got %a\n", t[i].s, t[i].f, x);
        }
-}
-
-void test_strtof()
-{
-       int i;
-       float x;
-       char *p;
-
-       for (i = 0; i < length(tf); i++) {
-               x = strtof(tf[i].s, &p);
-               if (x != tf[i].f)
-                       error("strtof(\"%s\") want %a got %a\n", tf[i].s, tf[i].f, x);
-       }
-}
-
-void bench_strtod(int N)
-{
-       volatile double y;
-       char *p;
-       int i;
-
-       for (i = 0; i < N; i++)
-               y = strtod("2740037.230228005325852424697698331177377e-7", &p);
-}
-
-
-void bench_strtold_big(int N)
-{
-       volatile long double y;
-       char *p;
-       int i;
-
-       for (i = 0; i < N; i++)
-               y = strtold("118973149535723176505351158982948.86679662540046955672e4900", &p);
+       return test_status;
 }