projects
/
tools.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
56b8624
)
round:output without comma for integer targets
author
Jann Horn
<jann@thejh.net>
Wed, 30 Apr 2014 14:12:09 +0000
(16:12 +0200)
committer
Jann Horn
<jann@thejh.net>
Wed, 30 Apr 2014 14:12:09 +0000
(16:12 +0200)
math/round.c
patch
|
blob
|
history
diff --git
a/math/round.c
b/math/round.c
index
f87d3c1
..
f5a07b2
100644
(file)
--- a/
math/round.c
+++ b/
math/round.c
@@
-1,9
+1,11
@@
#include <jh.h>
#include <math.h>
#include <jh.h>
#include <math.h>
+#include <stdbool.h>
int main(int argc, char **argv) {
if (argc != 2) xperror("invocation: round <target>", 0);
double target = strtod(argv[1], NULL);
int main(int argc, char **argv) {
if (argc != 2) xperror("invocation: round <target>", 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");
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;
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;
}
}
return 0;
}