- else
- return convert_infinite (dst, fp, number);
-}
-
-/* Tries to compose NUMBER into DST in format FP by first
- formatting it with DECIMALS decimal places, then rounding off
- to as many decimal places will fit or the number specified in
- FP, whichever is fewer.
-
- Returns 1 if conversion succeeds, 0 if this try at conversion
- failed and so will any other tries (because the integer part
- of the number is too long), or -1 if this try failed but
- another with higher DECIMALS might succeed (because we'd be
- able to properly round). */
-static int
-format_and_round (char *dst, double number, const struct fmt_spec *fp,
- int decimals)
-{
- /* Number of characters before the decimal point,
- which includes digits and possibly a minus sign. */
- int predot_chars;
-
- /* Number of digits in the output fraction,
- which may be smaller than fp->d if there's not enough room. */
- int fraction_digits;
-
- /* Points to last digit that will remain in the fraction after
- rounding. */
- char *final_frac_dig;
-
- /* Round up? */
- bool round_up;
-
- char buf[128];
-
- assert (decimals > fp->d);
- if (decimals > LDBL_DIG)
- decimals = LDBL_DIG + 1;
-
- sprintf (buf, "%.*f", decimals, number);
-
- /* Omit integer part if it's 0. */
- if (!memcmp (buf, "0.", 2))
- memmove (buf, buf + 1, strlen (buf));
- else if (!memcmp (buf, "-0.", 3))
- memmove (buf + 1, buf + 2, strlen (buf + 1));
-
- predot_chars = strcspn (buf, ".");
- if (predot_chars > fp->w)
- {
- /* Can't possibly fit. */
- return 0;
- }
- else if (predot_chars == fp->w)
- {
- /* Exact fit for integer part and sign. */
- memcpy (dst, buf, fp->w);
- return 1;
- }
- else if (predot_chars + 1 == fp->w)
- {
- /* There's room for the decimal point, but not for any
- digits of the fraction.
- Right-justify the integer part and sign. */
- dst[0] = ' ';
- memcpy (dst + 1, buf, fp->w - 1);
- return 1;
- }
-
- /* It looks like we have room for at least one digit of the
- fraction. Figure out how many. */
- fraction_digits = fp->w - predot_chars - 1;
- if (fraction_digits > fp->d)
- fraction_digits = fp->d;
- final_frac_dig = buf + predot_chars + fraction_digits;
-
- /* Decide rounding direction and truncate string. */
- if (final_frac_dig[1] == '5'
- && strspn (final_frac_dig + 2, "0") == strlen (final_frac_dig + 2))