This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Decimal constructor to accept float
Type: enhancement Stage: resolved
Components: Versions: Python 3.2, Python 2.7
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: eric.araujo, eric.smith, mark.dickinson, rhettinger
Priority: high Keywords: easy, patch

Created on 2010-03-28 23:12 by rhettinger, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
deci_float_constructor.diff rhettinger, 2010-03-28 23:12 decimal_from_float.diff
Messages (9)
msg101882 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2010-03-28 23:12
Per discussion on python-dev, let Decimal(x) accept floats as a possible input, making Decimal.from_float unnecessary.

See attached patch.
msg101898 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-03-29 17:02
Will Decimal.from_float be deprecated and eventually removed?

Could you provide a link to said discussion thread for us outsiders? :)

Regards
msg101899 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2010-03-29 17:45
Éric, there is no place to deprecate Decimal.from_float().  It will be redundant but there is no need to break working code.  Also, it has the nice property of being explicit about what it is doing.


Link to my proposal:
  http://mail.python.org/pipermail/python-dev/2010-March/098699.html

Guido's "If you really want this I won't stop you":
  http://mail.python.org/pipermail/python-dev/2010-March/098701.html
msg101905 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-03-29 21:12
(Assuming “no place” means “no reason”) Apart from TOOTDI, there is 
indeed none.

Regards
msg102149 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-04-02 09:17
Raymond, do you want this to go into 2.7 as well?  I'm assuming that we're not going to allow mixed-type float+decimal operations in 2.7.

Also, if we're doing this, it seems to me that all the reasons you give for the Decimal constructor accepting floats also apply to the Fraction constructor.

The patch looks fine to me.  The new testcase is specific to IEEE 754 binary64 floating-point format, so I'll slap a 'requires_IEEE_754' decorator on it (copying the definition from test_math.py), if that's okay.
msg102181 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2010-04-02 17:06
Added the requires decorator as requested.
Committed in r79602.  Will backport to 2.7 this weekend.

And yes, I agree that Fraction(somedecimal) should work too.  It would be weird to have Fraction("1.1") work but not Fraction(Decimal("1.1")).

Mark, I do think we should have decimal+float-->float in 2.7 also.  I don't see any reason to have the two versions diverge on this issue.
msg102182 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-04-02 17:08
> Mark, I do think we should have decimal+float-->float in 2.7 also.

That's fine with me in principle.  But isn't 2.7 in feature freeze from tomorrow?
msg102183 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-04-02 17:11
> And yes, I agree that Fraction(somedecimal) should work too.

What about Fraction(1.1)?
msg102468 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-04-06 14:34
The decimal changes were implemented by Raymond in r79609 (trunk) and r79602 (py3k).  For the fractions module changes, see issue 8294.
History
Date User Action Args
2022-04-11 14:56:59adminsetgithub: 52504
2010-04-06 14:34:03mark.dickinsonsetstatus: open -> closed
messages: + msg102468

assignee: mark.dickinson ->
resolution: accepted
stage: patch review -> resolved
2010-04-02 17:11:09mark.dickinsonsetmessages: + msg102183
2010-04-02 17:08:43mark.dickinsonsetmessages: + msg102182
2010-04-02 17:06:40rhettingersetmessages: + msg102181
2010-04-02 09:17:15mark.dickinsonsetmessages: + msg102149
2010-04-02 08:41:36mark.dickinsonsetpriority: high
2010-03-29 21:12:18eric.araujosetmessages: + msg101905
2010-03-29 17:45:03rhettingersetmessages: + msg101899
2010-03-29 17:02:42eric.araujosetnosy: + eric.araujo
messages: + msg101898
2010-03-29 05:54:03eric.smithsetnosy: + eric.smith
2010-03-28 23:12:19rhettingercreate