bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: seq -w floating point incorrect formating


From: Pádraig Brady
Subject: Re: seq -w floating point incorrect formating
Date: Sat, 14 Feb 2009 17:23:16 +0000
User-agent: Thunderbird 2.0.0.6 (X11/20071008)

Samuel Hapák wrote:
> Hello,
> I think that seq is not behaving correctly on this input:
> seq -w 9 0.5 10
> 
> I obtain the output:
> 9.0
> 9.5
> 10.0
> 
> While I think I should obtain:
> 09.0
> 09.5
> 10.0

Looks like a bug alright.
I'm thinking of applying the attached to fix it.

thanks!
Pádraig.

>From b350141cfefdd68f663c8ea3efa47ed81bcaba03 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?P=C3=A1draig=20Brady?= <address@hidden>
Date: Sat, 14 Feb 2009 17:20:37 +0000
Subject: [PATCH] 
=?utf-8?q?seq:=20Fix=20equal=20width=20calculation=20when=20'.'=20added=20to=20last=20number
=20Issue=20reported=20by=20Samuel=20Hap=C3=A1k.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

* src/seq.c: Account for '.' added to "last".
* tests/misc/seq: Add corresponding test.
---
 src/seq.c      |    2 ++
 tests/misc/seq |    1 +
 2 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/src/seq.c b/src/seq.c
index 5f9da96..76dd015 100644
--- a/src/seq.c
+++ b/src/seq.c
@@ -317,6 +317,8 @@ get_default_format (operand first, operand step, operand 
last)
          size_t last_width = last.width + (prec - last.precision);
          if (last.precision && prec == 0)
            last_width--;  /* don't include space for '.' */
+         if (last.precision == 0 && prec != 0)
+           last_width++;  /* include space for '.' */
          size_t width = MAX (first_width, last_width);
          if (width <= INT_MAX)
            {
diff --git a/tests/misc/seq b/tests/misc/seq
index 7f808cf..cd78bd1 100755
--- a/tests/misc/seq
+++ b/tests/misc/seq
@@ -64,6 +64,7 @@ my @Tests =
    ['eq-wid-5',        qw(-w 1 .5 2),  {OUT => [qw(1.0 1.5 2.0)]}],
    ['eq-wid-6',        qw(-w +1 2),  {OUT => [qw(1 2)]}],
    ['eq-wid-7',        qw(-w "    .1"  "    .1"),  {OUT => [qw(0.1)]}],
+   ['eq-wid-8',        qw(-w 9 0.5 10),  {OUT => [qw(09.0 09.5 10.0)]}],
 
    # Prior to coreutils-4.5.11, some of these were not accepted.
    ['fmt-1',   qw(-f %2.1f 1.5 .5 2),{OUT => [qw(1.5 2.0)]}],
-- 
1.5.3.6


reply via email to

[Prev in Thread] Current Thread [Next in Thread]