version 1.6, 2022/02/25 16:00:39 |
version 1.7, 2023/06/12 20:15:06 |
|
|
double first = 1.0; |
double first = 1.0; |
double last = 0.0; |
double last = 0.0; |
double incr = 0.0; |
double incr = 0.0; |
double last_shown_value = 0.0; |
double prev = 0.0; |
double cur, step; |
double cur, step; |
struct lconv *locale; |
struct lconv *locale; |
char *fmt = NULL; |
char *fmt = NULL; |
const char *sep = "\n"; |
const char *sep = "\n"; |
const char *term = "\n"; |
const char *term = "\n"; |
char *cur_print, *last_print; |
char *cur_print, *last_print, *prev_print; |
char pad = ZERO; |
char pad = ZERO; |
|
|
if (pledge("stdio", NULL) == -1) |
if (pledge("stdio", NULL) == -1) |
|
|
} else |
} else |
fmt = generate_format(first, incr, last, equalize, pad); |
fmt = generate_format(first, incr, last, equalize, pad); |
|
|
|
warnx("first: %f, incr: %f", first, incr); |
for (step = 1, cur = first; incr > 0 ? cur <= last : cur >= last; |
for (step = 1, cur = first; incr > 0 ? cur <= last : cur >= last; |
cur = first + incr * step++) { |
cur = first + incr * step++) { |
if (cur != first) |
if (cur != first) |
fputs(sep, stdout); |
fputs(sep, stdout); |
printf(fmt, cur); |
printf(fmt, cur); |
last_shown_value = cur; |
prev = cur; |
} |
} |
|
|
/* |
/* |
* Did we miss the last value of the range in the loop above? |
* Did we miss the last value of the range in the loop above? |
* |
* |
* We might have, so check if the printable version of the last |
* We might have, so check if the printable version of the last |
* computed value ('cur') and desired 'last' value are equal. If they |
* computed value ('cur') and desired 'last' value are equal. If |
* are equal after formatting truncation, but 'cur' and |
* they are equal after formatting truncation, but 'cur' and 'prev' |
* 'last_shown_value' are not equal, it means the exit condition of the |
* are different, it means the exit condition of the loop held true |
* loop held true due to a rounding error and we still need to print |
* due to a rounding error and we still need to print 'last'. |
* 'last'. |
|
*/ |
*/ |
if (asprintf(&cur_print, fmt, cur) == -1 || |
if (asprintf(&cur_print, fmt, cur) == -1 || |
asprintf(&last_print, fmt, last) == -1) |
asprintf(&last_print, fmt, last) == -1 || |
|
asprintf(&prev_print, fmt, prev) == -1) |
err(1, "asprintf"); |
err(1, "asprintf"); |
if (strcmp(cur_print, last_print) == 0 && cur != last_shown_value) { |
if (strcmp(cur_print, last_print) == 0 && |
|
strcmp(cur_print, prev_print) != 0) { |
if (cur != first) |
if (cur != first) |
fputs(sep, stdout); |
fputs(sep, stdout); |
fputs(last_print, stdout); |
fputs(last_print, stdout); |
} |
} |
free(cur_print); |
free(cur_print); |
free(last_print); |
free(last_print); |
|
free(prev_print); |
|
|
fputs(term, stdout); |
fputs(term, stdout); |
|
|