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

Method test_705836

Lib/test/test_struct.py:369–400  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

367
368 @unittest.expectedFailure # TODO: RUSTPYTHON
369 def test_705836(self):
370 # SF bug 705836. "<f" and ">f" had a severe rounding bug, where a carry
371 # from the low-order discarded bits could propagate into the exponent
372 # field, causing the result to be wrong by a factor of 2.
373 for base in range(1, 33):
374 # smaller <- largest representable float less than base.
375 delta = 0.5
376 while base - delta / 2.0 != base:
377 delta /= 2.0
378 smaller = base - delta
379 # Packing this rounds away a solid string of trailing 1 bits.
380 packed = struct.pack("<f", smaller)
381 unpacked = struct.unpack("<f", packed)[0]
382 # This failed at base = 2, 4, and 32, with unpacked = 1, 2, and
383 # 16, respectively.
384 self.assertEqual(base, unpacked)
385 bigpacked = struct.pack(">f", smaller)
386 self.assertEqual(bigpacked, string_reverse(packed))
387 unpacked = struct.unpack(">f", bigpacked)[0]
388 self.assertEqual(base, unpacked)
389
390 # Largest finite IEEE single.
391 big = (1 << 24) - 1
392 big = math.ldexp(big, 127 - 23)
393 packed = struct.pack(">f", big)
394 unpacked = struct.unpack(">f", packed)[0]
395 self.assertEqual(big, unpacked)
396
397 # The same, but tack on a 1 bit so it rounds up to infinity.
398 big = (1 << 25) - 1
399 big = math.ldexp(big, 127 - 24)
400 self.assertRaises(OverflowError, struct.pack, ">f", big)
401
402 def test_1530559(self):
403 for code, byteorder in iter_integer_formats():

Callers

nothing calls this directly

Calls 5

string_reverseFunction · 0.85
packMethod · 0.45
unpackMethod · 0.45
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected