On 12/12/2016 05:06 PM, Martin Sebor wrote:
+ /* The lower bound when precision isn't specified is 8 bytes
+ ("1.23456" since precision is taken to be 6). When precision
+ is zero, the lower bound is 1 byte (e.g., "1"). Otherwise,
+ when precision is greater than zero, then the lower bound
+ is 2 plus precision (plus flags). */
+ res.range.min = (flagmin
+ + (prec != INT_MIN) /* for decimal point */
+ + (prec == INT_MIN
+ ? 0 : prec < 0 ? 6 : prec ? prec : -1));
Note for the future, nest/chained ternary operators can sometimes just
be hard to visually parse when they're squashed on a single line.
Formatting like this has often been used in the past to help clarify the
intent:
(flagmin
+ (prec != INT_MIN)
+ (prec == INT_MIN ? 0
: prec < 0 ? 6
: prec ? prec
: -1)
Okay.
If we ignore the flagmin component, I get the following evaluations for
PREC.
PREC RESULT
INTMIN 0
0 0
negative (but not INTMIN) 7
positive prec + 1
That doesn't seem in-line with the comment.
Sorry, I think I need a hint. Which part doesn't seem in line with
which part of the comment? The numbers you have look correct to me
and I don't see anything wrong with the comment either.
Flagmin is always at least 1 and so RESULT above is 1 when precision
is used and either zero or unknown (because printf ("%.0f", 0) returns
1), and it's 8 when precision is negative because it's taken as if had
been omitted (i.e., it's 6 and printf ("%f", 0) formats "0.000000" and
returns 8), and it's prec + 2 when precision is positive because the 2
accounts for the leading "0." (when argument is zero) and precision is
the number of fractional digits.
So I think it's another case me mis-parsing the comment and conflating
unknown vs unspecified in my mind I took the "plus flags" as applying
to all cases, but re-reading it with the additional context you've
provided, it seems like it actually applies to just the last case.
Try to give the comment a light respin to see if you can clarify. OK
with that update.
Jeff