Return the default format given FIRST, STEP, and LAST. */
| 370 | |
| 371 | /* Return the default format given FIRST, STEP, and LAST. */ |
| 372 | static char const * |
| 373 | get_default_format (operand first, operand step, operand last) |
| 374 | { |
| 375 | static char format_buf[sizeof "%0.Lf" + 2 * INT_STRLEN_BOUND (int)]; |
| 376 | |
| 377 | int prec = MAX (first.precision, step.precision); |
| 378 | |
| 379 | if (prec != INT_MAX && last.precision != INT_MAX) |
| 380 | { |
| 381 | if (equal_width) |
| 382 | { |
| 383 | /* increase first_width by any increased precision in step */ |
| 384 | size_t first_width = first.width + (prec - first.precision); |
| 385 | /* adjust last_width to use precision from first/step */ |
| 386 | size_t last_width = last.width + (prec - last.precision); |
| 387 | if (last.precision && prec == 0) |
| 388 | last_width--; /* don't include space for '.' */ |
| 389 | if (last.precision == 0 && prec) |
| 390 | last_width++; /* include space for '.' */ |
| 391 | if (first.precision == 0 && prec) |
| 392 | first_width++; /* include space for '.' */ |
| 393 | size_t width = MAX (first_width, last_width); |
| 394 | if (width <= INT_MAX) |
| 395 | { |
| 396 | int w = width; |
| 397 | sprintf (format_buf, "%%0%d.%dLf", w, prec); |
| 398 | return format_buf; |
| 399 | } |
| 400 | } |
| 401 | else |
| 402 | { |
| 403 | sprintf (format_buf, "%%.%dLf", prec); |
| 404 | return format_buf; |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | return "%Lg"; |
| 409 | } |
| 410 | |
| 411 | /* The nonempty char array P represents a valid non-negative decimal integer. |
| 412 | ENDP points just after the last char in P. |