Lines 80-91
Link Here
|
80 |
int equalize = 0; |
80 |
int equalize = 0; |
81 |
double first = 1.0; |
81 |
double first = 1.0; |
82 |
double last = 0.0; |
82 |
double last = 0.0; |
|
|
83 |
double last_shown_value = 0.0; |
84 |
double cur; |
83 |
double incr = 0.0; |
85 |
double incr = 0.0; |
|
|
86 |
double step; |
84 |
struct lconv *locale; |
87 |
struct lconv *locale; |
85 |
char *fmt = NULL; |
88 |
char *fmt = NULL; |
86 |
const char *sep = "\n"; |
89 |
const char *sep = "\n"; |
87 |
const char *term = NULL; |
90 |
const char *term = NULL; |
88 |
char pad = ZERO; |
91 |
char pad = ZERO; |
|
|
92 |
char *cur_print; |
93 |
char *last_print; |
89 |
|
94 |
|
90 |
/* Determine the locale's decimal point. */ |
95 |
/* Determine the locale's decimal point. */ |
91 |
locale = localeconv(); |
96 |
locale = localeconv(); |
Lines 163-185
Link Here
|
163 |
if (!valid_format(fmt)) |
168 |
if (!valid_format(fmt)) |
164 |
errx(1, "invalid format string"); |
169 |
errx(1, "invalid format string"); |
165 |
/* |
170 |
/* |
166 |
* XXX to be bug for bug compatible with Plan 9 add a |
171 |
* XXX to be bug for bug compatible with Plan 9 add a |
167 |
* newline if none found at the end of the format string. |
172 |
* newline if none found at the end of the format string. |
168 |
*/ |
173 |
*/ |
169 |
} else |
174 |
} else |
170 |
fmt = generate_format(first, incr, last, equalize, pad); |
175 |
fmt = generate_format(first, incr, last, equalize, pad); |
171 |
|
176 |
|
172 |
if (incr > 0) { |
177 |
for (step = 1, cur = first; incr > 0 ? cur <= last : cur >= last; |
173 |
for (; first <= last; first += incr) { |
178 |
cur = first + incr * step++) { |
174 |
printf(fmt, first); |
179 |
printf(fmt, cur); |
175 |
fputs(sep, stdout); |
180 |
fputs(sep, stdout); |
176 |
} |
181 |
last_shown_value = cur; |
177 |
} else { |
|
|
178 |
for (; first >= last; first += incr) { |
179 |
printf(fmt, first); |
180 |
fputs(sep, stdout); |
181 |
} |
182 |
} |
182 |
} |
|
|
183 |
|
184 |
/* |
185 |
* Did we miss the last value of the range in the loop above? |
186 |
* |
187 |
* We might have, so check if the printable version |
188 |
* of the last computed value ('cur', that _might_ have not be printed) |
189 |
* and 'last' (the only number possibly missing in the generated list) |
190 |
* are equal. It they are but 'cur' and 'last_shown_value' are not equal, |
191 |
* than means the exit condition of the loop held true due to a |
192 |
* rounding error so we need to print 'last'. |
193 |
*/ |
194 |
asprintf(&cur_print, fmt, cur); |
195 |
asprintf(&last_print, fmt, last); |
196 |
|
197 |
if (strcmp(cur_print, last_print) == 0 && (cur != last_shown_value)) { |
198 |
printf(fmt, last); |
199 |
fputs(sep, stdout); |
200 |
} |
201 |
|
202 |
free(cur_print); |
203 |
free(last_print); |
204 |
|
183 |
if (term != NULL) |
205 |
if (term != NULL) |
184 |
fputs(term, stdout); |
206 |
fputs(term, stdout); |
185 |
|
207 |
|