MCPcopy Index your code
hub / github.com/python/cpython / test_roundtrip

Method test_roundtrip

Lib/test/test_float.py:1561–1580  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1559 self.identical(fromHex('+8p-1078'), 0.0)
1560
1561 def test_roundtrip(self):
1562 def roundtrip(x):
1563 return fromHex(toHex(x))
1564
1565 for x in [NAN, INF, self.MAX, self.MIN, self.MIN-self.TINY, self.TINY, 0.0]:
1566 self.identical(x, roundtrip(x))
1567 self.identical(-x, roundtrip(-x))
1568
1569 # fromHex(toHex(x)) should exactly recover x, for any non-NaN float x.
1570 import random
1571 for i in range(10000):
1572 e = random.randrange(-1200, 1200)
1573 m = random.random()
1574 s = random.choice([1.0, -1.0])
1575 try:
1576 x = s*ldexp(m, e)
1577 except OverflowError:
1578 pass
1579 else:
1580 self.identical(x, fromHex(toHex(x)))
1581
1582 def test_subclass(self):
1583 class F(float):

Callers

nothing calls this directly

Calls 4

identicalMethod · 0.95
randrangeMethod · 0.80
choiceMethod · 0.80
randomMethod · 0.45

Tested by

no test coverage detected