mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-11 07:12:16 +00:00
Add Printf extension %H
- This conversion has behavior similar to %g: It automatically behaves like %f or %e based on the number of output characters. However, unlike %g, this decision is also based on what will produce the smallest string without truncating the output. The precision field (the * in %.*f) is ignored. Converting a double to text with %H and then back to a double should be lossless.
This commit is contained in:
parent
0fb9f98a96
commit
1948642758
1 changed files with 23 additions and 1 deletions
|
@ -638,6 +638,12 @@ namespace StringFormat
|
||||||
}
|
}
|
||||||
goto fp_begin;
|
goto fp_begin;
|
||||||
}
|
}
|
||||||
|
else if (type == 'H')
|
||||||
|
{ // %H is an extension that behaves similarly to %g, except it automatically
|
||||||
|
// selects precision based on whatever will produce the smallest string.
|
||||||
|
expchar = 'e';
|
||||||
|
goto fp_begin;
|
||||||
|
}
|
||||||
#if 0
|
#if 0
|
||||||
// The hdtoa function provided with FreeBSD uses a hexadecimal FP constant.
|
// The hdtoa function provided with FreeBSD uses a hexadecimal FP constant.
|
||||||
// Microsoft's compiler does not support these, so I would need to hack it
|
// Microsoft's compiler does not support these, so I would need to hack it
|
||||||
|
@ -690,7 +696,7 @@ fp_begin:
|
||||||
precision = DEFPREC;
|
precision = DEFPREC;
|
||||||
}
|
}
|
||||||
dblarg = va_arg(arglist, double);
|
dblarg = va_arg(arglist, double);
|
||||||
obuff = dtoaresult = dtoa(dblarg, expchar ? 2 : 3, precision, &expt, &signflag, &dtoaend);
|
obuff = dtoaresult = dtoa(dblarg, type != 'H' ? (expchar ? 2 : 3) : 0, precision, &expt, &signflag, &dtoaend);
|
||||||
//fp_common:
|
//fp_common:
|
||||||
decimal_point = localeconv()->decimal_point;
|
decimal_point = localeconv()->decimal_point;
|
||||||
flags |= F_SIGNED;
|
flags |= F_SIGNED;
|
||||||
|
@ -742,6 +748,22 @@ fp_begin:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (type == 'H')
|
||||||
|
{
|
||||||
|
if (expt > -(ndig + 2) && expt <= (ndig + 4))
|
||||||
|
{ // Make %H smell like %f
|
||||||
|
expchar = '\0';
|
||||||
|
precision = ndig - expt;
|
||||||
|
if (precision < 0)
|
||||||
|
{
|
||||||
|
precision = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{// Make %H smell like %e
|
||||||
|
precision = ndig;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (expchar)
|
if (expchar)
|
||||||
{
|
{
|
||||||
expsize = exponent(expstr, expt - 1, expchar);
|
expsize = exponent(expstr, expt - 1, expchar);
|
||||||
|
|
Loading…
Reference in a new issue