-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
bpo-44954: Fix wrong result in float.fromhex corner case #27834
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
Changes from all commits
617180e
dfb3fef
45cd7dd
2fed72c
e6e6a24
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1468,6 +1468,20 @@ def test_from_hex(self): | |
| self.identical(fromHex('0X1.0000000000001fp0'), 1.0+2*EPS) | ||
| self.identical(fromHex('0x1.00000000000020p0'), 1.0+2*EPS) | ||
|
|
||
| # Regression test for a corner-case bug reported in b.p.o. 44954 | ||
| self.identical(fromHex('0x.8p-1074'), 0.0) | ||
| self.identical(fromHex('0x.80p-1074'), 0.0) | ||
| self.identical(fromHex('0x.81p-1074'), TINY) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to find what is the minimal example for non-zero result, but seems it works for arbitrary number of zeroes between 8 and 1:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, that's reassuring, and as it should be: |
||
| self.identical(fromHex('0x8p-1078'), 0.0) | ||
| self.identical(fromHex('0x8.0p-1078'), 0.0) | ||
| self.identical(fromHex('0x8.1p-1078'), TINY) | ||
| self.identical(fromHex('0x80p-1082'), 0.0) | ||
| self.identical(fromHex('0x81p-1082'), TINY) | ||
| self.identical(fromHex('.8p-1074'), 0.0) | ||
| self.identical(fromHex('8p-1078'), 0.0) | ||
| self.identical(fromHex('-.8p-1074'), -0.0) | ||
| self.identical(fromHex('+8p-1078'), 0.0) | ||
|
|
||
| def test_roundtrip(self): | ||
| def roundtrip(x): | ||
| return fromHex(toHex(x)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Fixed a corner case bug where the result of ``float.fromhex('0x.8p-1074')`` | ||
| was rounded the wrong way. |
Uh oh!
There was an error while loading. Please reload this page.