(self)
| 104 | "expected {}, got {}".format(s, expected, got)) |
| 105 | |
| 106 | def test_short_halfway_cases(self): |
| 107 | # exact halfway cases with a small number of significant digits |
| 108 | for k in 0, 5, 10, 15, 20: |
| 109 | # upper = smallest integer >= 2**54/5**k |
| 110 | upper = -(-2**54//5**k) |
| 111 | # lower = smallest odd number >= 2**53/5**k |
| 112 | lower = -(-2**53//5**k) |
| 113 | if lower % 2 == 0: |
| 114 | lower += 1 |
| 115 | for i in range(TEST_SIZE): |
| 116 | # Select a random odd n in [2**53/5**k, |
| 117 | # 2**54/5**k). Then n * 10**k gives a halfway case |
| 118 | # with small number of significant digits. |
| 119 | n, e = random.randrange(lower, upper, 2), k |
| 120 | |
| 121 | # Remove any additional powers of 5. |
| 122 | while n % 5 == 0: |
| 123 | n, e = n // 5, e + 1 |
| 124 | assert n % 10 in (1, 3, 7, 9) |
| 125 | |
| 126 | # Try numbers of the form n * 2**p2 * 10**e, p2 >= 0, |
| 127 | # until n * 2**p2 has more than 20 significant digits. |
| 128 | digits, exponent = n, e |
| 129 | while digits < 10**20: |
| 130 | s = '{}e{}'.format(digits, exponent) |
| 131 | self.check_strtod(s) |
| 132 | # Same again, but with extra trailing zeros. |
| 133 | s = '{}e{}'.format(digits * 10**40, exponent - 40) |
| 134 | self.check_strtod(s) |
| 135 | digits *= 2 |
| 136 | |
| 137 | # Try numbers of the form n * 5**p2 * 10**(e - p5), p5 |
| 138 | # >= 0, with n * 5**p5 < 10**20. |
| 139 | digits, exponent = n, e |
| 140 | while digits < 10**20: |
| 141 | s = '{}e{}'.format(digits, exponent) |
| 142 | self.check_strtod(s) |
| 143 | # Same again, but with extra trailing zeros. |
| 144 | s = '{}e{}'.format(digits * 10**40, exponent - 40) |
| 145 | self.check_strtod(s) |
| 146 | digits *= 5 |
| 147 | exponent -= 1 |
| 148 | |
| 149 | def test_halfway_cases(self): |
| 150 | # test halfway cases for the round-half-to-even rule |
nothing calls this directly
no test coverage detected