On 7/11/2016 1:24 PM, Ethan Furman wrote:
On 07/11/2016 09:28 AM, Steven D'Aprano wrote:
On Tue, 12 Jul 2016 01:04 am, Ian Kelly wrote:

Er, what? I count *five* digits in "00123", not three.

You seem to be assuming that "precision" can only refer to digits
after the
decimal place, but that's a dubious proposition.

I will readily admit to not having a maths degree, and so of course to
me saying the integer 123 has a precision of 5, 10, or 99 digits seems
like hogwash to me.

I do have an undergraduate degree in math and a career in statistics, and I cannot remember seen 'precision' used in relation to integers. So I would call it a 'non-standard extension' of the notion.

But I'm always willing to learn.  So please explain what 123 with a
precision of five integer digits means,

What it could mean is that we have an count selected from the range 00000 to 99999 inclusive. But what I just said is the usual way of saying that, as it does not limit the lower and upper limits to 0s and 9s.

and what to do we gain by saying such a thing?

Confusion.

Precision is usually used in reference to measurement, and while measurement is based on counting, it is not the same thing. If 123 is a count, then its precision is 1 count, not k digits. Or one could say that all digits are precise. What is ambiguous without context is whether counts with trailing 0s, like 120 or 100 are exact or rounded. 100, as a cound, could have a precision of 1, 2, or 3 (significant) digits. Context sometimes says things like 'to the nearest hundred thousand'.

In any case, I think it an improvement to say that '0x00123' has a field width of 7 rather than a 'precision' of 5.

>>> '{:#07x}'.format(0x123)  # specifiy field width
'0x00123'
>>> "%#0.5x" % 0x123  # specify int precision
'0x00123'

Thus, my title for a post noting the same change might be "Upgrade in new-style formats".
(format and If one want leading 0s,

--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to