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
10e667.__format__('+') should return 'inf' #48732
Comments
10e667.__format__('+') returns '+1.0#INF' vs: 10e667.__format__('') which returns 'inf' The docs say 'inf' is right. |
Here's a patch to add tests for this and a few other problems with |
This is a duplicate of 4799, which I've closed. I've resisted fixing this because differences in various platform Not sure what this means for 2.7, yet. We're not planning on backporting |
Actually this isn't quite a duplicate of 4799, but it's close. Any fix
|
The patch I submitted adds a special-case for inf/-inf/NaN so that I'm not sure how it interacts with your 3.x plans. Seems like it would (and the patch that adds tests should go into both 2.7 and 3.x) |
Agreed. That might be the strategy for 2.7. But it depends on how much of the other float and int formatting code I I'll decide in the next few weeks. |
A somewhat related comment about formatting of infs and nans: I think "%+e" % float('nan') should give "nan" rather than "+nan" or "-nan". (In contrast, infinities |
Here are my proposed tests for this---they're for percent formatting format(float('inf'), '+') should produce '+inf' rather than plain 'inf'. |
I used 'inf' instead of "+inf' because the original bug report states Now that I actually look at the docs, I don't agree with the original |
I'm not so sure about this any more. Sometimes the role of an explicit For example: >>> "{}{:+}".format(1, float('nan'))
'1+nan' Also, the implementation is definitely easier this way. :-) |
I agree on the alignment issue. Maybe if you explicitly ask for the And when requesting leading zeros, you also get leading spaces instead? |
Actually, I think '+nan' for format(float('nan'), '+'), and ' nan'
Should do the same thing for nans and infs here. But certainly leading |
With the new PyOS_double_to_string, this issue largely goes away. There |
This patch has tests that currently pass on trunk. I think this is the |
Looks good to me, except that the second comment in the patch doesn't make |
This version adds format() testing and fixes the comments (I hope). |
LGTM. |
Added tests to trunk in r76632 and py3k in r76634. Note that the only thing that was changed are the tests. The actual |
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: