Red Hat Bugzilla – Bug 463556
Weird output of seq command for some sequences of floats
Last modified: 2008-10-15 22:00:59 EDT
Program doesn't work as it should:
$ seq -0.01 0.1 1
seq [OPTION]... FIRST INCREMENT LAST
What is the expected output? I can't see the bug...
> man page:
> seq [OPTION]... FIRST INCREMENT LAST
The last number should be LAST.
Ok, last number should be LAST, but increment should be INCREMENT... therefore you are in deadlock and there is no way out. Info pages are usually more complex than man pages in the case of coreutils and they are recommended in coreutils man pages. So please consider to use them... They say "`seq' prints the numbers from FIRST to LAST by INCREMENT." That's exactly what is the output. I really can't see a bug. It simply did what you requested - sequence from -0.01 to 1 with increment 0.1 - next number would be bigger than 1 so seq stopped. NOTABUG for me, please provide any relevant informations why should seq work like you want.
Then why this:
$ seq -0.1 0.1 1
$ seq -0.1 0.1 2
Thanks, that one report makes sense, but is about different thing. It seems to be about handling floats on some architectures/systems ... I guess that issue was already fixed by upstream (in middle april this year, http://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=commitdiff;h=4827dd27b0c655a685947aaa01426a5ecba179f3) and should be fixed in Fedora Rawhide, but unfortunately I can't check it at the moment. Will check it tomorrow (10PM here now) and possibly make an update for F-9.
I'm able to reproduce the issue on i386 architecture even with the latest upstream seq. Solution is quite easy - to simply add/substract DBL_EPSILON when deciding if the number is out of range. Solution proposed to upstream, we will see if it is harmless...
Thanks to Ondrej for discovering that it's locale-dependent:
$ LC_ALL=C seq -0.1 0.1 2|grep 2.0 || echo bug
$ LC_ALL=cs_CZ.UTF-8 seq -0.1 0.1 2|grep 2.0 || echo bug
Here's the fix I expect to use:
diff --git a/src/seq.c b/src/seq.c
index 55518df..b5f0651 100644
@@ -309 +309 @@ print_numbers (char const *fmt, struct layout layout,
- if (xstrtold (x_str + layout.prefix_len, NULL, &x_val, c_strtold)
+ if (xstrtold (x_str + layout.prefix_len, NULL, &x_val, strtold)
Patch and test case pushed and posted upstream:
coreutils-6.10-31.fc9 has been submitted as an update for Fedora 9.
coreutils-6.10-33.fc9 has been pushed to the Fedora 9 stable repository. If problems still persist, please make note of it in this bug report.