seq.c does this: for (i = 0; /* empty */; i++) { long double x = first + i * step;
if (step < 0 ? x < last : last < x) and for an invocation of "./seq .1 .1", it would print nothing (surprise!) on FreeBSD 6.1. Why? Because with i == 0, it had last < x (gdb) p last $4 = 0.10000000000000000000135525271560688 (gdb) p x $5 = 0.1000000000000000055511151231257827 I fixed it like this: [and realized while typing this that the last < first conjunct, while right for this test case, was wrong for e.g., seq 1 -1 3. Another patch below. ] diff --git a/ChangeLog b/ChangeLog index 0e6c87a..d563ae9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2007-11-17 Jim Meyering <[EMAIL PROTECTED]> + + "seq .1 .1" would mistakenly generate no output on some systems + * NEWS: Say this. + * src/seq.c (print_numbers): Handle another floating point corner case. + This avoids failure of seq's eq-wid-7 test on FreeBSD 6.1. + 2007-11-16 Paul Eggert <[EMAIL PROTECTED]> Port tests/rmdir/ignore away from GNU/Linux. diff --git a/NEWS b/NEWS index a8434c5..11efa75 100644 --- a/NEWS +++ b/NEWS @@ -142,6 +142,8 @@ GNU coreutils NEWS -*- outline -*- seq would mistakenly reject some valid format strings containing %%, and would mistakenly accept some invalid ones. e.g., %g%% and %%g, resp. + "seq .1 .1" would mistakenly generate no output on some systems + Obsolete sort usage with an invalid ordering-option character, e.g., "env _POSIX2_VERSION=199209 sort +1x" no longer makes sort free an invalid pointer [introduced in coreutils-6.5] diff --git a/src/seq.c b/src/seq.c index d7d2521..77d5586 100644 --- a/src/seq.c +++ b/src/seq.c @@ -280,7 +280,13 @@ print_numbers (char const *fmt, struct layout layout, free (x_str); } - break; + /* With floating point arithmetic, we may well reach this point + with i == 0 and first == last. E.g., ./seq .1 .1 on FreeBSD 6.1. + Hence the first conjunct: don't break out of this loop when + i == 0. *unless* first and last themselves are out of order, + in which case we must print nothing, e.g. for ./seq -1 */ + if (i || last < first) + break; } if (i) -- 1.5.3.5.726.g41a7a diff --git a/ChangeLog b/ChangeLog index d563ae9..6e6f713 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2007-11-17 Jim Meyering <[EMAIL PROTECTED]> + Correct preceding patch. + * src/seq.c (print_numbers): Also handle first < last && step < 0. + * tests/misc/seq [empty-rev]: New test for this case. + "seq .1 .1" would mistakenly generate no output on some systems * NEWS: Say this. * src/seq.c (print_numbers): Handle another floating point corner case. diff --git a/src/seq.c b/src/seq.c index 77d5586..eec5ed5 100644 --- a/src/seq.c +++ b/src/seq.c @@ -285,7 +285,7 @@ print_numbers (char const *fmt, struct layout layout, Hence the first conjunct: don't break out of this loop when i == 0. *unless* first and last themselves are out of order, in which case we must print nothing, e.g. for ./seq -1 */ - if (i || last < first) + if (i || (0 < step && last < first) || (step < 0 && first < last)) break; } diff --git a/tests/misc/seq b/tests/misc/seq index 17c8f0c..3365d95 100755 --- a/tests/misc/seq +++ b/tests/misc/seq @@ -42,6 +42,7 @@ my @Tests = ( ['onearg-1', qw(10), {OUT => [(1..10)]}], ['onearg-2', qw(-1)], + ['empty-rev', qw(1 -1 3)], ['neg-1', qw(-10 10 10), {OUT => [qw(-10 0 10)]}], # ['neg-2', qw(-.1 .1 .11), {OUT => [qw(-0.1 0.0 0.1)]}], ['neg-3', qw(1 -1 0), {OUT => [qw(1 0)]}], -- 1.5.3.5.726.g41a7a _______________________________________________ Bug-coreutils mailing list Bug-coreutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-coreutils