bpo-44954: Fix wrong result in float.fromhex corner case (GH-27834)

(cherry picked from commit 60b93d9e49)

Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
This commit is contained in:
Miss Islington (bot) 2021-08-20 10:48:47 -07:00 committed by GitHub
parent f0e2a46349
commit 838b0e975f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 2 deletions

View file

@ -1468,6 +1468,20 @@ class HexFloatTestCase(unittest.TestCase):
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)
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))