Date: Sun, 25 Feb 2018 19:08:19 +0000 From: bugzilla-noreply@freebsd.org To: freebsd-bugs@FreeBSD.org Subject: [Bug 217149] seq(1) inconsistently omits 'last' when using float increment Message-ID: <bug-217149-8-42wSI7b63A@https.bugs.freebsd.org/bugzilla/> In-Reply-To: <bug-217149-8@https.bugs.freebsd.org/bugzilla/> References: <bug-217149-8@https.bugs.freebsd.org/bugzilla/>
next in thread | previous in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D217149 --- Comment #12 from fernando.apesteguia@gmail.com --- (In reply to Conrad Meyer from comment #11) OK, this is the new approach: Index: seq.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- seq.c (revisi=C3=B3n: 329385) +++ seq.c (copia de trabajo) @@ -80,7 +80,10 @@ int equalize =3D 0; double first =3D 1.0; double last =3D 0.0; + double last_shown_value =3D 0.0; + double cur; double incr =3D 0.0; + double step; struct lconv *locale; char *fmt =3D NULL; const char *sep =3D "\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 =3D generate_format(first, incr, last, equalize, pad); - if (incr > 0) { - for (; first <=3D last; first +=3D incr) { - printf(fmt, first); - fputs(sep, stdout); - } - } else { - for (; first >=3D last; first +=3D incr) { - printf(fmt, first); - fputs(sep, stdout); - } + for (step =3D 1, cur =3D first; incr > 0 ? cur <=3D last + (incr / = 2) : cur >=3D last - (incr / 2); + cur =3D first + incr * step++) { + printf(fmt, cur); + fputs(sep, stdout); + last_shown_value =3D cur; } + if (term !=3D NULL) fputs(term, stdout); The problem with this one is that in some cases, we are not stopping when we should. For example: $ seq 1.7 .7 10 1.7 2.4 3.1 3.8 4.5 5.2 5.9 6.6 7.3 8 8.7 9.4 <--- Should have stopped here 10.1=20 $ seq 1.07 .07 10 ... ... 9.96 <--- Should have stopped here 10.03 I attached a new test file "output_incr_over_two.txt" --=20 You are receiving this mail because: You are the assignee for the bug.=
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-217149-8-42wSI7b63A>