[issue34273] %f is confusingly associated with fixed point format
New submission from Michael Fischer <michael-fischer89@web.de>: In section "7.1.3.1. Format Specification Mini-Language" of the documentation (https://docs.python.org/2/library/string.html) both %f and %F are labelled "Fixed point". This is confusing for someone who a) transitions over from C or variants or b) knows the difference between fixed and floating point numbers. I suggest either changing the "Fixed" to "Floating" or explaining what is meant by "Fixed Point" (because I'm sure there's a reason why someone has named it like that in the first place). ---------- assignee: docs@python components: Documentation messages: 322644 nosy: MikeFoxtrot, docs@python priority: normal severity: normal status: open title: %f is confusingly associated with fixed point format type: enhancement _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34273> _______________________________________
Mark Dickinson <dickinsm@gmail.com> added the comment: FTR, here "fixed point" refers to the output representation (a decimal string) rather than the input (a floating-point binary value). The output of %f gives a *fixed* number of places after the decimal point (6 by default). Contrast with %e, which gives a floating-point output representation. But yes, there are probably less confusing ways to word this. Did you have a particular alternative wording in mind? Here's the behaviour of %f for different scale values: note that the output always has the same number of digits after the point, but the number of significant digits varies.
"%f" % math.pi '3.141593' "%f" % (100.0 * math.pi) '314.159265' "%f" % (0.01 * math.pi) '0.031416'
And here's %e. Now it's the other way around: the number of significant digits stays the same, but the exponent changes to reflect the magnitude.
"%e" % math.pi '3.141593e+00' "%e" % (100 * math.pi) '3.141593e+02' "%e" % (0.01 * math.pi) '3.141593e-02'
---------- nosy: +mark.dickinson _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34273> _______________________________________
Michael Fischer <michael-fischer89@web.de> added the comment: Thank you for your quick reply. I understand why you chose this description better now. However in C %f behaves exactly the same as in Python (for floating-point numbers) and you will mostly find the description for it along the lines of: '%f' Print a floating-point number in normal (fixed-point) notation. [The GNU C Library Reference Manual - https://www.gnu.org/software/libc/manual/pdf/libc.pdf] For the sake of simplicity I suggest the following wording: Fixed point notation. Displays the (floating-point) number as a fixed-point number. The default precision is 6. In my opinion this emphasizes the intent (fixed precision representation) and hints at the independence of input type, by putting the floating-point in brackets. ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34273> _______________________________________
Terry J. Reedy <tjreedy@udel.edu> added the comment: The closest anchor is https://docs.python.org/3.8/library/string.html#format-specification-mini-la.... The table title is "The available presentation types for floating point and decimal values are:". This is slightly confusing to me. Does this mean instances of 'float' and 'decimal' classes? or 'floating point numbers (floats and decimals) and integral numbers, sometimes called decimals since usually written with decimal digits'? Within the table, 'number' refers to whatever the title refers to. So I think adding '(floating point)' would be confusing and wrong, as it excludes 'decimals' whatever they are. On the other hand, changing 'Fixed point' to 'Fixed point notation', in parallel with 'Exponential notation', is correct and should be helpful. ---------- nosy: +terry.reedy stage: -> needs patch versions: +Python 2.7, Python 3.6, Python 3.7, Python 3.8 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34273> _______________________________________
Michael Fischer <michael-fischer89@web.de> added the comment: Terry: I absolutely agree with you. Changing 'Fixed point' to 'Fixed point notation' is the optimal solution here. ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34273> _______________________________________
Change by Terry J. Reedy <tjreedy@udel.edu>: ---------- keywords: +patch pull_requests: +8165 stage: needs patch -> patch review _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34273> _______________________________________
Terry J. Reedy <tjreedy@udel.edu> added the comment: New changeset 28c7f8c8ce34a0cb848822a252a9d0a761fb42d5 by Terry Jan Reedy in branch 'master': bpo-34273: Change 'Fixed point' to 'Fixed-point notation'. (#8673) https://github.com/python/cpython/commit/28c7f8c8ce34a0cb848822a252a9d0a761f... ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34273> _______________________________________
Change by miss-islington <mariatta.wijaya+miss-islington@gmail.com>: ---------- pull_requests: +8181 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34273> _______________________________________
Change by miss-islington <mariatta.wijaya+miss-islington@gmail.com>: ---------- pull_requests: +8182 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34273> _______________________________________
miss-islington <mariatta.wijaya+miss-islington@gmail.com> added the comment: New changeset e39fb207f26f8007e95fcf120f5ff1cb7372791a by Miss Islington (bot) in branch '3.7': bpo-34273: Change 'Fixed point' to 'Fixed-point notation'. (GH-8673) https://github.com/python/cpython/commit/e39fb207f26f8007e95fcf120f5ff1cb737... ---------- nosy: +miss-islington _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34273> _______________________________________
miss-islington <mariatta.wijaya+miss-islington@gmail.com> added the comment: New changeset ed8dd598ae7e0d944974af0fd73c2fbb6105fd5c by Miss Islington (bot) in branch '3.6': bpo-34273: Change 'Fixed point' to 'Fixed-point notation'. (GH-8673) https://github.com/python/cpython/commit/ed8dd598ae7e0d944974af0fd73c2fbb610... ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34273> _______________________________________
Change by Terry J. Reedy <tjreedy@udel.edu>: ---------- pull_requests: +8183 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34273> _______________________________________
Terry J. Reedy <tjreedy@udel.edu> added the comment: New changeset 9027502e99cba700cadb675b3b2db03c311d1c4d by Terry Jan Reedy in branch '2.7': [2.7] bpo-34273: Change 'Fixed point' to 'Fixed-point notation'. (GH-8673) https://github.com/python/cpython/commit/9027502e99cba700cadb675b3b2db03c311... ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34273> _______________________________________
Change by Terry J. Reedy <tjreedy@udel.edu>: ---------- resolution: -> fixed stage: patch review -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34273> _______________________________________
participants (4)
-
Mark Dickinson
-
Michael Fischer
-
miss-islington
-
Terry J. Reedy