bug-coreutils
[Top][All Lists]
Advanced

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

Re: [PATCH] SEQ BUG


From: Pádraig Brady
Subject: Re: [PATCH] SEQ BUG
Date: Fri, 08 Jun 2007 12:26:49 +0100
User-agent: Thunderbird 1.5.0.8 (X11/20061116)

Andreas Schwab wrote:
> Pádraig Brady <address@hidden> writes:
> 
>> Yes you could use gmp, but for normal uses of `seq`
>> you could just use appropriate comparisons?
>> How about the following patch, and we can also
>> remove the workaround info from the docs.
>>
>> Pádraig.
>>
>> --- seq.orig.c  2007-06-08 07:50:24.000000000 +0000
>> +++ seq.c       2007-06-08 09:05:23.000000000 +0000
>> @@ -357,6 +357,10 @@
>>         }
>>      }
>>
>> +  /* perhaps can use nextafterl? */
>> +  #define PRECISION 1.0E-15
>> +  last.value += step.value + (step.value>0?-PRECISION:PRECISION);
> 
> That won't be enough, since the error adds up, so if you have a small
> step but a big range you can still overshoot.  And if the error of your
> step value is negative you may print more than expected.

Sure, but for *normal uses* of seq we can do better.
I'm just throwing out patches here to illustrate the general point.
I'm too busy at the moment to polish off a patch for inclusion.

The last patch would not work well for `seq 0.1 0.1 100000.9 | tail` as you 
suggest.
How about the following:

--- seq.orig.c  2007-06-08 07:50:24.000000000 +0000
+++ seq.c       2007-06-08 11:23:34.000000000 +0000
@@ -21,6 +21,7 @@
 #include <getopt.h>
 #include <stdio.h>
 #include <sys/types.h>
+#include <math.h>

 #include "system.h"
 #include "c-strtod.h"
@@ -357,6 +358,10 @@
        }
     }

+  int prec = MAX (first.precision, step.precision);
+  long double margin = powl(10,-prec)/2;
+  last.value += (step.value>0?margin:-margin);
+
   if (format_str != NULL && equal_width)
     {
       error (0, 0, _("\




reply via email to

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