Issue 12580: Documentation error in Decimal module (original) (raw)

Created on 2011-07-17 18:30 by holdenweb, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg140531 - (view) Author: Steve Holden (holdenweb) * (Python committer) Date: 2011-07-17 18:30
We see in the "Quick-Start Tutorial" (py3k section 8.4.1) the following example: >>> Decimal(3.14) Decimal('3.140000000000000124344978758017532527446746826171875') In actua; fact one would expect an exception from that code, which should perhaps instead read >>> Decimal.from_float(3.14) Decimal('3.140000000000000124344978758017532527446746826171875') This class method is the recommended way to convert floats to decimal when necessary.
msg140532 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2011-07-17 18:50
Behavior for mixed operations varies greatly between Python versions. The first table over here lists the differences and should be valid for decimal.py: http://www.bytereef.org/mpdecimal/doc/cdecimal/index.html#floatoperation-signal As an extension, cdecimal has the FloatOperation signal, which enforces stricter semantics. The second table on that page lists the behavior if the signal is enabled.
msg140535 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2011-07-17 19:07
The example is correct and runs as expected: >>> Decimal(3.14) Decimal('3.140000000000000124344978758017532527446746826171875') Per the Whatsnew3.2 document: ''' The decimal.Decimal constructor now accepts float objects directly so there in no longer a need to use the from_float() method (issue 8257). '''
msg140536 - (view) Author: Steve Holden (holdenweb) * (Python committer) Date: 2011-07-17 19:23
Sorry about that. I was using 3.1, as you will have gathered.
History
Date User Action Args
2022-04-11 14:57:19 admin set github: 56789
2011-07-17 19:23:09 holdenweb set status: open -> closedmessages: +
2011-07-17 19:07:50 rhettinger set messages: +
2011-07-17 19:04:53 rhettinger set assignee: georg.brandl -> rhettingernosy: + rhettingerversions: + Python 3.3, - Python 3.1
2011-07-17 18:50:57 skrah set nosy: + skrahmessages: +
2011-07-17 18:30:46 holdenweb set components: + Documentation
2011-07-17 18:30:01 holdenweb create