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

Method test_halfway_cases

Lib/test/test_strtod.py:149–173  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

147 exponent -= 1
148
149 def test_halfway_cases(self):
150 # test halfway cases for the round-half-to-even rule
151 for i in range(100 * TEST_SIZE):
152 # bit pattern for a random finite positive (or +0.0) float
153 bits = random.randrange(2047*2**52)
154
155 # convert bit pattern to a number of the form m * 2**e
156 e, m = divmod(bits, 2**52)
157 if e:
158 m, e = m + 2**52, e - 1
159 e -= 1074
160
161 # add 0.5 ulps
162 m, e = 2*m + 1, e - 1
163
164 # convert to a decimal string
165 if e >= 0:
166 digits = m << e
167 exponent = 0
168 else:
169 # m * 2**e = (m * 5**-e) * 10**e
170 digits = m * 5**-e
171 exponent = e
172 s = '{}e{}'.format(digits, exponent)
173 self.check_strtod(s)
174
175 def test_boundaries(self):
176 # boundaries expressed as triples (n, e, u), where

Callers

nothing calls this directly

Calls 3

check_strtodMethod · 0.95
randrangeMethod · 0.80
formatMethod · 0.45

Tested by

no test coverage detected