[Bug 217149] seq(1) inconsistently omits 'last' when using float increment

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Sun Feb 25 18:26:33 UTC 2018


https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=217149

--- Comment #10 from fernando.apesteguia at gmail.com ---
(In reply to Conrad Meyer from comment #9)

Do you mean something like this?

Index: seq.c
===================================================================
--- seq.c       (revisión: 329385)
+++ seq.c       (copia de trabajo)
@@ -80,7 +80,10 @@
        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";
@@ -163,23 +166,19 @@
                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 + (step/2) : cur >=
last;
+           cur = first + incr * step++) {
+               printf(fmt, cur);
+               fputs(sep, stdout);
+               last_shown_value = cur;
        }
+
        if (term != NULL)
                fputs(term, stdout);

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the freebsd-bugs mailing list