Improvements to %g pull request

This code %g is preliminary.

Fixed some code style issues to match the current code style.

Added regression tests and help file updates to printf and strprintf.

Fixed use of magic number -4: using -P instead.

Noted two problem areas with XXX comments in qio.c:

    1) need a qprintfg function
    2) re-write to not modify conf->outdigits
This commit is contained in:
Landon Curt Noll
2018-09-30 16:06:28 -07:00
parent fcfe237375
commit da6ccc146f
6 changed files with 82 additions and 39 deletions

24
qio.c
View File

@@ -97,6 +97,15 @@ qprintf(char *fmt, ...)
q = va_arg(ap, NUMBER *);
qprintfe(q, width, precision);
break;
case 'g':
q = va_arg(ap, NUMBER *);
/* XXX - we need a qprintfg function */
#if 0 /* XXX - we need a qprintfg() function */
qprintfg(q, width, precision);
#else /* XXX - use qprintfe until we have a qprintfg() function */
qprintfe(q, width, precision);
#endif /* XXX - we need a qprintfg() function */
break;
case 'r':
case 'R':
q = va_arg(ap, NUMBER *);
@@ -235,18 +244,23 @@ qprintnum(NUMBER *q, int outmode)
case MODE_REAL_AUTO:
{
/*
* XXX - re-write to not modify conf->outdigits
*
* Modifying the configuration value could be dangerious
* when a calculation is aborted within an opcode.
* Better to use qprintfg() use inline code that
* does not depend on changing conf->outdigits.
*/
const int P = conf->outdigits ? conf->outdigits : 1;
tmpval = *q;
tmpval.num.sign = 0;
exp = qilog10(&tmpval);
const long olddigits = conf->outdigits;
if(P > exp && exp >= -4)
{
if (P > exp && exp >= -P) {
conf->outdigits = P - 1 - exp;
qprintnum(q, MODE_REAL);
}
else
{
} else {
conf->outdigits = P - 1;
qprintnum(q, MODE_EXP);
}