diff --git a/src/math/gen/Makefile b/src/math/gen/Makefile index f3c3429..7bae051 100644 --- a/src/math/gen/Makefile +++ b/src/math/gen/Makefile @@ -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 index 0000000..195f31f --- /dev/null +++ b/src/math/gen/tox.c @@ -0,0 +1,28 @@ +#include +#include +#include +#include + +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; +}