From 4e9b6af8ed612763fe31bd466f3e7719ac9ab0e7 Mon Sep 17 00:00:00 2001 From: hjp Date: Tue, 8 Feb 2000 17:04:37 +0000 Subject: [PATCH] Added -f and -d options to force input to be float or double format. --- ieeefloat/ieeefloat.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/ieeefloat/ieeefloat.c b/ieeefloat/ieeefloat.c index 866c76e..3af609b 100644 --- a/ieeefloat/ieeefloat.c +++ b/ieeefloat/ieeefloat.c @@ -1,9 +1,12 @@ char ieeefloat_c_rcs_id[] = - "$Id: ieeefloat.c,v 1.1 1998-03-20 20:09:53 hjp Exp $"; + "$Id: ieeefloat.c,v 1.2 2000-02-08 17:04:37 hjp Exp $"; /* ieeefloat: print binary representations of IEEE 754 FP numbers. * * $Log: ieeefloat.c,v $ - * Revision 1.1 1998-03-20 20:09:53 hjp + * Revision 1.2 2000-02-08 17:04:37 hjp + * Added -f and -d options to force input to be float or double format. + * + * Revision 1.1 1998/03/20 20:09:53 hjp * Initial release: * prints arguments as strings, floats, and doubles decimal and binary. * @@ -49,7 +52,7 @@ char *cmnd; static void usage(void) { - fprintf(stderr, "Usage: %s fp-number ...\n", cmnd); + fprintf(stderr, "Usage: %s [-f|-d] fp-number ...\n", cmnd); exit(1); } @@ -152,12 +155,28 @@ static void sanitychecks(void) { int main(int argc, char**argv) { int i; + int convfloat = 0; + char *p; cmnd = argv[0]; sanitychecks(); for (i = 1; i < argc; i++) { - double d = strtod(argv[i], NULL); + double d; + if (strcmp(argv[i], "-f") == 0) { + convfloat = 1; + continue; + } else if (strcmp(argv[i], "-d") == 0) { + convfloat = 0; + continue; + } + + d = strtod(argv[i], &p); + if (p && *p) usage(); + + if (convfloat) { + d = (float) d; + } printf("%s\n", argv[i]); printdouble(d); printfloat(d);