FreeBSD Bugzilla – Attachment 190550 Details for
Bug 217149
seq(1) inconsistently omits 'last' when using float increment
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
patch to /usr.bin/seq/seq.c
handle_last_value.patch (text/plain), 2.00 KB, created by
Fernando Apesteguía
on 2018-02-12 18:40:27 UTC
(
hide
)
Description:
patch to /usr.bin/seq/seq.c
Filename:
MIME Type:
Creator:
Fernando Apesteguía
Created:
2018-02-12 18:40:27 UTC
Size:
2.00 KB
patch
obsolete
>Index: seq.c >=================================================================== >--- seq.c (revisión: 329106) >+++ seq.c (copia de trabajo) >@@ -80,12 +80,17 @@ > int equalize = 0; > double first = 1.0; > double last = 0.0; >+ double last_shown_value = 0.0; >+ double cur; > double incr = 0.0; >+ double step; > struct lconv *locale; > char *fmt = NULL; > const char *sep = "\n"; > const char *term = NULL; > char pad = ZERO; >+ char *cur_print; >+ char *last_print; > > /* Determine the locale's decimal point. */ > locale = localeconv(); >@@ -163,23 +168,40 @@ > if (!valid_format(fmt)) > errx(1, "invalid format string"); > /* >- * XXX to be bug for bug compatible with Plan 9 add a >+ * XXX to be bug for bug compatible with Plan 9 add a > * newline if none found at the end of the format string. > */ > } else > fmt = generate_format(first, incr, last, equalize, pad); > >- if (incr > 0) { >- for (; first <= last; first += incr) { >- printf(fmt, first); >- fputs(sep, stdout); >- } >- } else { >- for (; first >= last; first += incr) { >- printf(fmt, first); >- fputs(sep, stdout); >- } >+ for (step = 1, cur = first; incr > 0 ? cur <= last : cur >= last; >+ cur = first + incr * step++) { >+ printf(fmt, cur); >+ fputs(sep, stdout); >+ last_shown_value = cur; > } >+ >+ /* >+ * 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 computed value ('cur', that _might_ have not be printed) >+ * and 'last' (the only number possibly missing in the generated list) >+ * are equal. It they are but 'cur' and 'last_shown_value' are not equal, >+ * than means the exit condition of the loop held true due to a >+ * rounding error so we need to print 'last'. >+ */ >+ asprintf(&cur_print, fmt, cur); >+ asprintf(&last_print, fmt, last); >+ >+ if (strcmp(cur_print, last_print) == 0 && (cur != last_shown_value)) { >+ printf(fmt, last); >+ fputs(sep, stdout); >+ } >+ >+ free(cur_print); >+ free(last_print); >+ > if (term != NULL) > fputs(term, stdout); >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 217149
:
189755
|
189760
| 190550 |
190656
|
190657
|
190658
|
190999