X-Git-Url: http://git.thejh.net/?p=tools.git;a=blobdiff_plain;f=math%2Fround.c;h=f5a07b28dae5b6229144e649b6ebff8982084d88;hp=f87d3c109841cb9e87248f5761cb78282e8fb208;hb=384ee75e98daccfb078ee084edfdfa0b3188b79e;hpb=56b86248a393e3dd5073189ca50cb262046839ac diff --git a/math/round.c b/math/round.c index f87d3c1..f5a07b2 100644 --- a/math/round.c +++ b/math/round.c @@ -1,9 +1,11 @@ #include #include +#include int main(int argc, char **argv) { if (argc != 2) xperror("invocation: round ", 0); double target = strtod(argv[1], NULL); + bool intmode = (target == floor(target)); char line[128]; while (fgets(line, sizeof(line), stdin)) { trim_end(line, "\r\n \t"); @@ -12,7 +14,11 @@ int main(int argc, char **argv) { double quot = n / target; quot = round(quot); n = quot * target; - printf("%f\n", n); + if (intmode) { + printf("%lld\n", (long long)n); + } else { + printf("%f\n", n); + } } return 0; }