round: ignore empty lines
[tools.git] / math / round.c
1 #include <jh.h>
2 #include <math.h>
3
4 int main(int argc, char **argv) {
5   if (argc != 2) xperror("invocation: round <target>", 0);
6   double target = strtod(argv[1], NULL);
7   char line[128];
8   while (fgets(line, sizeof(line), stdin)) {
9     trim_end(line, "\r\n \t");
10     if (!*line) continue;
11     double n = strtod(line, NULL);
12     double quot = n / target;
13     quot = round(quot);
14     n = quot * target;
15     printf("%f\n", n);
16   }
17   return 0;
18 }