mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
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:
24
qio.c
24
qio.c
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user