-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
Comments
Per discussion on python-dev, let Decimal(x) accept floats as a possible input, making Decimal.from_float unnecessary. See attached patch. |
Will Decimal.from_float be deprecated and eventually removed? Could you provide a link to said discussion thread for us outsiders? :) Regards |
É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: Guido's "If you really want this I won't stop you": |
(Assuming “no place” means “no reason”) Apart from TOOTDI, there is Regards |
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. |
Added the requires decorator as requested. 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. |
That's fine with me in principle. But isn't 2.7 in feature freeze from tomorrow? |
What about Fraction(1.1)? |
The decimal changes were implemented by Raymond in r79609 (trunk) and r79602 (py3k). For the fractions module changes, see bpo-8294. |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: