--- seq.c.orig Wed Sep 19 21:24:02 2001 +++ seq.c Wed Sep 19 21:24:33 2001 @@ -21,6 +21,7 @@ #include #include #include +#include #include #include "system.h" @@ -177,6 +178,7 @@ if (first > last) { int i; + double threshold; if (step >= 0) { @@ -186,12 +188,21 @@ usage (1); } + /* Don't assume that floating-point values will be exact. + Use an error margin which is relative to the magnitude + of the numbers being compared. */ + + if ( last != 0.0 ) + threshold = last - fabs(last) * sqrt(DBL_EPSILON); + else + threshold = last - fabs(step) * sqrt(DBL_EPSILON); + printf (fmt, first); for (i = 1; /* empty */; i++) { double x = first + i * step; - if (x < last) + if (x < threshold) break; fputs (separator, stdout); @@ -201,6 +212,7 @@ else { int i; + double threshold; if (step <= 0) { @@ -210,12 +222,21 @@ usage (1); } + /* Don't assume that floating-point values will be exact. + Use an error margin which is relative to the magnitude + of the numbers being compared. */ + + if ( last != 0.0 ) + threshold = last + fabs(last) * sqrt(DBL_EPSILON); + else + threshold = last + fabs(step) * sqrt(DBL_EPSILON); + printf (fmt, first); for (i = 1; /* empty */; i++) { double x = first + i * step; - if (x > last) + if (x > threshold) break; fputs (separator, stdout);