- /* You should note that this is pos-5.0.91 semantics, -- FK. */
- if (first < last ? increment > 0 : increment < 0) {
- for (i = first;
- (first < last) ? (i <= last) : (i >= last);
- i += increment)
- {
- printf("%g\n", i);
- }
+#if ENABLE_LOCALE_SUPPORT
+ setlocale(LC_NUMERIC, "");
+#endif
+
+ /* Last checked to be compatible with: coreutils-6.10 */
+ width = 0;
+ frac_part = 0;
+ while (1) {
+ char *dot = strchrnul(*argv, '.');
+ int w = (dot - *argv);
+ int f = strlen(dot);
+ if (width < w)
+ width = w;
+ argv++;
+ if (!*argv)
+ break;
+ /* Why do the above _before_ frac check below?
+ * Try "seq 1 2.0" and "seq 1.0 2.0":
+ * coreutils never pay attention to the number
+ * of fractional digits in last arg. */
+ if (frac_part < f)
+ frac_part = f;
+ }
+ if (frac_part) {
+ frac_part--;
+ if (frac_part)
+ width += frac_part + 1;
+ }
+ if (!(opt & OPT_w))
+ width = 0;
+
+ sep = "";
+ v = first;
+ n = 0;
+ while (increment >= 0 ? v <= last : v >= last) {
+ if (printf("%s%0*.*f", sep, width, frac_part, v) < 0)
+ break; /* I/O error, bail out (yes, this really happens) */
+ sep = opt_s;
+ /* v += increment; - would accumulate floating point errors */
+ n++;
+ v = first + n * increment;