gen tools: add tox
authorSzabolcs Nagy <nsz@port70.net>
Fri, 24 May 2013 15:31:25 +0000 (15:31 +0000)
committerSzabolcs Nagy <nsz@port70.net>
Fri, 24 May 2013 15:31:25 +0000 (15:31 +0000)
src/math/gen/Makefile
src/math/gen/tox.c [new file with mode: 0644]

index f3c3429..7bae051 100644 (file)
@@ -2,7 +2,7 @@ CFLAGS=-I. -Wall -fno-builtin -ffloat-store -D_GNU_SOURCE
 U=mpfr
 T=$(wildcard t*.c)
 
-all: gen check mgen tof toa toe next prev rnd
+all: gen check mgen tof toa toe tox next prev rnd
 
 #tx: tx.c $(U)/lib/libmpfr.a $(U)/lib/libgmp.a
 #      musl-gcc -o $@ $(CFLAGS) -I$(U)/include $^
diff --git a/src/math/gen/tox.c b/src/math/gen/tox.c
new file mode 100644 (file)
index 0000000..195f31f
--- /dev/null
@@ -0,0 +1,28 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <errno.h>
+
+int main(int argc, char *argv[])
+{
+       int i;
+       union {float f; uint32_t i;} f;
+       union {double f; uint64_t i;} d;
+       union {long double f; struct {uint64_t m; uint16_t se;} i;} ld;
+       char *eptr;
+
+       for (i = 1; i < argc; i++) {
+               errno = 0;
+               f.f = strtof(argv[i], &eptr);
+               printf("0x%08x  (*eptr:%d errno:%d)\n", f.i, *eptr, errno);
+               errno = 0;
+               d.f = strtod(argv[i], &eptr);
+               printf("0x%08x %08x  (*eptr:%d errno:%d)\n",
+                       (unsigned)(d.i>>32), (unsigned)d.i, *eptr, errno);
+               errno = 0;
+               ld.f = strtold(argv[i], &eptr);
+               printf("0x%04x %08x %08x  (*eptr:%d errno:%d)\n",
+                       ld.i.se, (unsigned)(ld.i.m>>32), (unsigned)ld.i.m, *eptr, errno);
+       }
+       return 0;
+}