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

Function test_halfway_cases

Modules/_decimal/tests/randfloat.py:54–79  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

52 exponent -= 1
53
54def test_halfway_cases():
55 # test halfway cases for the round-half-to-even rule
56 for i in range(1000):
57 for j in range(TEST_SIZE):
58 # bit pattern for a random finite positive (or +0.0) float
59 bits = random.randrange(2047*2**52)
60
61 # convert bit pattern to a number of the form m * 2**e
62 e, m = divmod(bits, 2**52)
63 if e:
64 m, e = m + 2**52, e - 1
65 e -= 1074
66
67 # add 0.5 ulps
68 m, e = 2*m + 1, e - 1
69
70 # convert to a decimal string
71 if e >= 0:
72 digits = m << e
73 exponent = 0
74 else:
75 # m * 2**e = (m * 5**-e) * 10**e
76 digits = m * 5**-e
77 exponent = e
78 s = '{}e{}'.format(digits, exponent)
79 yield s
80
81def test_boundaries():
82 # boundaries expressed as triples (n, e, u), where

Callers 1

randfloat.pyFile · 0.85

Calls 2

randrangeMethod · 0.80
formatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…