From ff1a08c16ea49fa2bd3260a3b327b5dcaa5d13a6 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Mon, 27 Jan 2014 14:15:56 +0100 Subject: [PATCH] math/gen: yet another little decimal formatting tool --- src/math/gen/Makefile | 4 ++-- src/math/gen/tog.c | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 src/math/gen/tog.c diff --git a/src/math/gen/Makefile b/src/math/gen/Makefile index 9be541d..ad1e280 100644 --- a/src/math/gen/Makefile +++ b/src/math/gen/Makefile @@ -8,7 +8,7 @@ T=$(wildcard t*.c) CC=musl-gcc #CC=gcc -all: gen check mgen tof toa toe tox next prev rnd +all: gen check mgen tof toa toe tog tox next prev rnd %:%.o %:%.c @@ -24,5 +24,5 @@ mgen: gen.c util.c mplibm.c $(CC) -o $@ $(CFLAGS) -lm $^ clean: - rm -f gen check mgen tof toa toe tox next prev rnd + rm -f gen check mgen tof toa toe tog tox next prev rnd diff --git a/src/math/gen/tog.c b/src/math/gen/tog.c new file mode 100644 index 0000000..ec0f687 --- /dev/null +++ b/src/math/gen/tog.c @@ -0,0 +1,25 @@ +#include +#include +#include + +int main(int argc, char *argv[]) +{ + int i; + float f; + double d; + long double ld; + char *eptr; + + for (i = 1; i < argc; i++) { + errno = 0; + f = strtof(argv[i], &eptr); + printf("%.42g (*eptr:%d errno:%d)\n", f, *eptr, errno); + errno = 0; + d = strtod(argv[i], &eptr); + printf("%.42g (*eptr:%d errno:%d)\n", d, *eptr, errno); + errno = 0; + ld = strtold(argv[i], &eptr); + printf("%.42Lg (*eptr:%d errno:%d)\n", ld, *eptr, errno); + } + return 0; +} -- 2.11.4.GIT