Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decimal constructor to accept float #52504

Closed
rhettinger opened this issue Mar 28, 2010 · 9 comments
Closed

Decimal constructor to accept float #52504

rhettinger opened this issue Mar 28, 2010 · 9 comments
Labels
easy type-feature A feature request or enhancement

Comments

@rhettinger
Copy link
Contributor

BPO 8257
Nosy @rhettinger, @mdickinson, @ericvsmith, @merwok
Files
  • deci_float_constructor.diff: decimal_from_float.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2010-04-06.14:34:03.814>
    created_at = <Date 2010-03-28.23:12:19.560>
    labels = ['easy', 'type-feature']
    title = 'Decimal constructor to accept float'
    updated_at = <Date 2010-04-06.14:34:03.812>
    user = 'https://github.com/rhettinger'

    bugs.python.org fields:

    activity = <Date 2010-04-06.14:34:03.812>
    actor = 'mark.dickinson'
    assignee = 'none'
    closed = True
    closed_date = <Date 2010-04-06.14:34:03.814>
    closer = 'mark.dickinson'
    components = []
    creation = <Date 2010-03-28.23:12:19.560>
    creator = 'rhettinger'
    dependencies = []
    files = ['16683']
    hgrepos = []
    issue_num = 8257
    keywords = ['patch', 'easy']
    message_count = 9.0
    messages = ['101882', '101898', '101899', '101905', '102149', '102181', '102182', '102183', '102468']
    nosy_count = 4.0
    nosy_names = ['rhettinger', 'mark.dickinson', 'eric.smith', 'eric.araujo']
    pr_nums = []
    priority = 'high'
    resolution = 'accepted'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue8257'
    versions = ['Python 2.7', 'Python 3.2']

    @rhettinger
    Copy link
    Contributor Author

    Per discussion on python-dev, let Decimal(x) accept floats as a possible input, making Decimal.from_float unnecessary.

    See attached patch.

    @rhettinger rhettinger added easy type-feature A feature request or enhancement labels Mar 28, 2010
    @merwok
    Copy link
    Member

    merwok commented Mar 29, 2010

    Will Decimal.from_float be deprecated and eventually removed?

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

    Regards

    @rhettinger
    Copy link
    Contributor Author

    É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

    @merwok
    Copy link
    Member

    merwok commented Mar 29, 2010

    (Assuming “no place” means “no reason”) Apart from TOOTDI, there is
    indeed none.

    Regards

    @mdickinson
    Copy link
    Member

    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.

    @rhettinger
    Copy link
    Contributor Author

    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.

    @mdickinson
    Copy link
    Member

    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?

    @mdickinson
    Copy link
    Member

    And yes, I agree that Fraction(somedecimal) should work too.

    What about Fraction(1.1)?

    @mdickinson
    Copy link
    Member

    The decimal changes were implemented by Raymond in r79609 (trunk) and r79602 (py3k). For the fractions module changes, see bpo-8294.

    @mdickinson mdickinson removed their assignment Apr 6, 2010
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    easy type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants