MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_roundtrip

Method test_roundtrip

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected