Issue 27720: decimal.Context.to_eng_string wrong docstring (original) (raw)

Created on 2016-08-09 17:25 by ztane, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
patch27720 Evelyn Mitchell,2016-08-11 02:09
decimal_eng_doc.diff rhettinger,2016-08-11 06:14
Messages (10)
msg272259 - (view) Author: Antti Haapala (ztane) * Date: 2016-08-09 17:25
https://docs.python.org/3/library/decimal.html#decimal.Context.to_eng_string The docstring for `Context.to_eng_string` says "Converts a number to a string, using scientific notation.", which is, less extra comma, exactly the docstring for `Context.to_sci_string`. It should probably say "using engineering notation". Additionally, docstring for Decimal.to_eng_string uses the term "an engineering-type string", which no one uses outside the said docstring. It should probably also say "Convert to a string using engineering notation."
msg272393 - (view) Author: Evelyn Mitchell (Evelyn Mitchell) * (Python triager) Date: 2016-08-11 02:09
I had to look up what engineering notation meant, so I added detail to the docstring.
msg272402 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2016-08-11 06:14
Thanks Evelyn. I've refined this a bit to incorporate the more precise wording in the decimal arithmetic specification (see http://speleotrove.com/decimal/daconvs.html ). Also added the missing doctests and synced-up the wording between the docstrings and the main docs.
msg272412 - (view) Author: Antti Haapala (ztane) * Date: 2016-08-11 07:51
Raymond: your doc patch is not quite right. Decimal('123e1') is converted to Decimal('1.23e3') internally already; so that str(d) will print 1.23e3, scientific notation of that number is '1.23e3' and engineering notation is '1.23e3', thus not a good example. A better example would be Also, the engineering notation is a string, not a Decimal instance. Also, now that I test it, the whole `to_eng_string` seems to be utterly broken, same applies to "to_sci_string". They do not print in scientific notation if the exponent in the original number was 0: decimal.Decimal('123456789101214161820222426.0e0').to_eng_string() And all operations with decimal will now generate numbers with exponent of 0 if it is within their precision, so no engineering notation is ever printed, duh.
msg272416 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2016-08-11 07:57
@Antti The behavior follows this standard: http://speleotrove.com/decimal/decarith.html Nothing we can do about it even if we wanted to.
msg272430 - (view) Author: Antti Haapala (ztane) * Date: 2016-08-11 09:35
@Stefan after reading the bad standard I agree that it follows the standard, as unfortunate as it is. However, that part is then also wrong in Raymond's documentation patch. It should be something like: the exponent is adjusted to a multiple of 3 if *any* exponent is to be shown, and exponent is shown only if the exponent is larger than there are significant figures in the number, or if it is less than or equal to -6, or something alike. Or perhaps it should say "This is not the notation you are looking for."
msg272433 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2016-08-11 10:14
> after reading the bad standard ... Make sure not to buy a Power 6 processor and not to use IEEE 754-2008, because that's essentially what you'll get. IEEE doesn't specify engineering notation though.
msg272456 - (view) Author: Evelyn Mitchell (Evelyn Mitchell) * (Python triager) Date: 2016-08-11 15:30
Thank you Raymond for a detailed patch update. I will mention that matlab does not support this conversion [1]. R doesn't support engineering notation, either. It may be that this conversion isn't expected to be part of the standard library, and people are more likely to write their own. [2] The rationale for engineering notation is that it corresponds to SI units of measure. [1] https://www.mathworks.com/matlabcentral/newsreader/view_thread/22843 [2] http://stackoverflow.com/questions/8262302/python-fixed-exponent-in-scientific-notation
msg272603 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-08-13 18:10
New changeset 825713d3786a by Raymond Hettinger in branch '2.7': Issue #27720: Fix error in eng_to_decimal docs and add examples from the specification. https://hg.python.org/cpython/rev/825713d3786a
msg272604 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-08-13 18:16
New changeset de2a9c98948e by Raymond Hettinger in branch '3.5': Issue #27720: Fix error in eng_to_decimal docs and add examples from the specification. https://hg.python.org/cpython/rev/de2a9c98948e
History
Date User Action Args
2022-04-11 14:58:34 admin set github: 71907
2016-08-13 18🔞23 rhettinger set status: open -> closedresolution: fixed
2016-08-13 18:16:08 python-dev set messages: +
2016-08-13 18:10:30 python-dev set nosy: + python-devmessages: +
2016-08-11 15:30:43 Evelyn Mitchell set messages: +
2016-08-11 10:14:19 skrah set messages: +
2016-08-11 09:35:45 ztane set messages: +
2016-08-11 07:57:28 skrah set messages: +
2016-08-11 07:51:07 ztane set messages: +
2016-08-11 06:14:26 rhettinger set files: + decimal_eng_doc.diffkeywords: + patchmessages: +
2016-08-11 04:48:08 rhettinger set assignee: docs@python -> rhettingernosy: + rhettinger
2016-08-11 02:09:08 Evelyn Mitchell set files: + patch27720nosy: + Evelyn Mitchellmessages: + stage: patch review
2016-08-10 00:12:39 berker.peksag set nosy: + skrah
2016-08-09 17:25:19 ztane create