diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2007-06-23 09:27:11 +0200 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2007-06-23 09:43:59 +0200 |
commit | a0304574e96916f0444b04f301f8e5191615f800 (patch) | |
tree | 9613fac65c5f5a4687a67d91212ba0ec4d03676d /doc/coreutils.texi | |
parent | 01616c9404b1c66bb395a0438ce28b9e2cb559b7 (diff) | |
download | coreutils-a0304574e96916f0444b04f301f8e5191615f800.tar.xz |
seq no longer mishandles cases like "seq 0 0.000001 0.000003",
where it would not print the desired last number.
* doc/coreutils.texi (seq invocation): Remove advice about workaround
for seq off-by-one problem, since the bug is fixed now. Replace
it with more-generic advice about rounding errors.
* src/seq.c (long_double_format, print_numbers):
New arg NUMERIC_FORMAT. All uses changed.
Diffstat (limited to 'doc/coreutils.texi')
-rw-r--r-- | doc/coreutils.texi | 30 |
1 files changed, 6 insertions, 24 deletions
diff --git a/doc/coreutils.texi b/doc/coreutils.texi index 7290ab27f..42558a3ae 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -14052,34 +14052,16 @@ $ seq 18446744073709551616 1 18446744073709551618 18446744073709551618 @end example -Be careful when using @command{seq} with a fractional @var{increment}; -otherwise you may see surprising results. Most people would expect to -see @code{0.000003} printed as the last number in this example: +Be careful when using @command{seq} with outlandish values: otherwise +you may see surprising results, as @command{seq} uses floating point +internally. For example, on the x86 platform, where the internal +representation uses a 64-bit fraction, the command: @example -$ seq -s ' ' 0 0.000001 0.000003 -0.000000 0.000001 0.000002 +seq 1 0.0000000000000000001 1.0000000000000000009 @end example -But that doesn't happen on many systems because @command{seq} is -implemented using binary floating point arithmetic (via the C -@code{long double} type)---which means decimal fractions like @code{0.000001} -cannot be represented exactly. That in turn means some nonintuitive -conditions like @w{@code{0.000001 * 3 > 0.000003}} will end up being true. - -To work around that in the above example, use a slightly larger number as -the @var{last} value: - -@example -$ seq -s ' ' 0 0.000001 0.0000031 -0.000000 0.000001 0.000002 0.000003 -@end example - -In general, when using an @var{increment} with a fractional part, where -(@var{last} - @var{first}) / @var{increment} is (mathematically) a whole -number, specify a slightly larger (or smaller, if @var{increment} is negative) -value for @var{last} to ensure that @var{last} is the final value printed -by seq. +outputs 1.0000000000000000007 twice and skips 1.0000000000000000008. @exitstatus |