trange(1): allow negative numbers in range - numtools - perform numerical opera… | |
git clone git://src.adamsgaard.dk/numtools | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 4e01195c6096ced645b0f533565700537a208a5b | |
parent e9477a50184a9679dc571a1e22194e4d0e672a4d | |
Author: Anders Damsgaard <[email protected]> | |
Date: Mon, 2 May 2022 15:02:46 +0200 | |
range(1): allow negative numbers in range | |
Diffstat: | |
M range.1 | 12 ++++++++++++ | |
M range.c | 6 ++---- | |
2 files changed, 14 insertions(+), 4 deletions(-) | |
--- | |
diff --git a/range.1 b/range.1 | |
t@@ -30,6 +30,11 @@ is not specified, it is 1. | |
If | |
.Ar min_val | |
is not specified, it is 0. | |
+If | |
+.Ar min_val | |
+and/or | |
+.Ar max_val | |
+are negative, they must be prefixed with the '--' option. | |
.Pp | |
The options are as follows: | |
.Bl -tag -width Ds | |
t@@ -113,6 +118,13 @@ Generate three numbers evenly distributed in logspace fro… | |
.Dl 1 | |
.Dl 10 | |
.Dl 100 | |
+.Pp | |
+Generate three numbers in the range [-2;-1]: | |
+.Pp | |
+.Dl $ range -n 3 -- -2 -1 | |
+.Dl -2 | |
+.Dl -1.5 | |
+.Dl -1 | |
.Sh SEE ALSO | |
.Xr max 1 , | |
.Xr mean 1 , | |
diff --git a/range.c b/range.c | |
t@@ -13,7 +13,7 @@ char *argv0; | |
static void | |
usage(void) | |
{ | |
- errx(1, "usage: %s [-b] [-e] [-f fmtstr] [-h] [-l] [-n num] [-s]" | |
+ errx(1, "usage: %s [-b] [-e] [-f fmtstr] [-h] [-l] [-n num] [-s] " | |
"[[min_val] max_val]\n", argv0); | |
} | |
t@@ -61,13 +61,11 @@ main(int argc, char *argv[]) | |
} else if (argc == 1) | |
maxv = atof(argv[0]); | |
- dx = (maxv - minv)/(n - 1 + openend + openstart); | |
+ dx = (maxv - minv) / (n - 1 + openend + openstart); | |
if (reportdx) { | |
printf(fmtstr, dx); | |
return 0; | |
} | |
- if (minv >= maxv) | |
- errx(1, "min_val must be smaller than max_val"); | |
for (i = 0 + openstart; i < n + openstart; i++) { | |
if (logrange) | |
printf(fmtstr, pow(10, minv + i * dx)); |