Пример #1
0
def byte_arrays_of_floats(draw):
    num_items = draw(st.integers(min_value=0, max_value=10))
    floats = draw(st.lists(ibm_compatible_floats(),
                           min_size=num_items,
                           max_size=num_items))
    byte_data = b''.join([ieee2ibm(f) for f in floats])
    return (byte_data, num_items)
Пример #2
0
def byte_arrays_of_floats(draw):
    num_items = draw(st.integers(min_value=0, max_value=10))
    floats = draw(
        st.lists(ibm_compatible_floats(),
                 min_size=num_items,
                 max_size=num_items))
    byte_data = b''.join([ieee2ibm(f) for f in floats])
    return (byte_data, num_items)
Пример #3
0
 def test_zero(self):
     self.assertEqual(ieee2ibm(0.0), b'\0\0\0\0')
Пример #4
0
 def test_zero(self):
     ibm_start = b'\0\0\0\0'
     f = ibm2ieee(ibm_start)
     ibm_result = ieee2ibm(f)
     assert ibm_start == ibm_result
Пример #5
0
 def test_one(self):
     assert ieee2ibm(1.0) == b'\x41\x10\x00\x00'
Пример #6
0
 def test_one(self):
     assert ieee2ibm(1.0) == b'\x41\x10\x00\x00'
Пример #7
0
 def test_smallest_subnormal(self):
     assert ieee2ibm(5.147557589468029e-85) == bytes((0x00, 0x00, 0x00, 0x01))
Пример #8
0
 def test_subnormal(self):
     self.assertEqual(ieee2ibm(1.6472184286297693e-83), bytes((0x00, 0x00, 0x00, 0x20)))
Пример #9
0
 def test_inf(self):
     with self.assertRaises(ValueError):
         ieee2ibm(float('inf'))
Пример #10
0
 def test_zero(self):
     ibm_start = b'\0\0\0\0'
     f = ibm2ieee(ibm_start)
     ibm_result = ieee2ibm(f)
     assert ibm_start == ibm_result
Пример #11
0
 def test_positive_half(self):
     ibm_start = bytes((0b11000000, 0x80, 0x00, 0x00))
     f = ibm2ieee(ibm_start)
     ibm_result = ieee2ibm(f)
     assert ibm_start == ibm_result
Пример #12
0
 def test_too_large(self):
     with pytest.raises(OverflowError):
         ieee2ibm(MAX_IBM_FLOAT * 10)
Пример #13
0
 def test_too_small(self):
     with pytest.raises(OverflowError):
         ieee2ibm(MIN_IBM_FLOAT * 10)
Пример #14
0
 def test_inf(self):
     with pytest.raises(ValueError):
         ieee2ibm(float('inf'))
Пример #15
0
 def test_nan(self):
     with pytest.raises(ValueError):
         ieee2ibm(float('nan'))
Пример #16
0
 def test_too_small_subnormal(self):
     with pytest.raises(FloatingPointError):
         ieee2ibm(1e-86)
Пример #17
0
 def test_negative_half(self):
     self.assertEqual(ieee2ibm(0.5), bytes((0b01000000, 0x80, 0x00, 0x00)))
Пример #18
0
 def test_one(self):
     ibm_start = b'\x41\x10\x00\x00'
     f = ibm2ieee(ibm_start)
     ibm_result = ieee2ibm(f)
     assert ibm_start == ibm_result
Пример #19
0
 def test_negative_118_625(self):
     # Example taken from Wikipedia http://en.wikipedia.org/wiki/IBM_Floating_Point_Architecture
     self.assertEqual(ieee2ibm(-118.625), bytes((0b11000010, 0b01110110, 0b10100000, 0b00000000)))
Пример #20
0
 def test_subnormal(self):
     ibm_start = bytes((0x00, 0x00, 0x00, 0x20))
     f = ibm2ieee(ibm_start)
     ibm_result = ieee2ibm(f)
     assert ibm_start == ibm_result
Пример #21
0
 def test_too_small_subnormal(self):
     with self.assertRaises(FloatingPointError):
         ieee2ibm(1e-86)
Пример #22
0
 def test_nan(self):
     with self.assertRaises(ValueError):
         ieee2ibm(float('nan'))
Пример #23
0
 def test_positive_half(self):
     assert ieee2ibm(-0.5) == bytes((0b11000000, 0x80, 0x00, 0x00))
Пример #24
0
 def test_inf(self):
     with self.assertRaises(ValueError):
         ieee2ibm(float('inf'))
Пример #25
0
 def test_0_1(self):
     # Note, this is different from the Wikipedia example, because the Wikipedia example does
     # round to nearest, and our routine does round to zero
     assert ieee2ibm(0.1) == bytes(
         (0b01000000, 0b00011001, 0b10011001, 0b10011001))
Пример #26
0
 def test_too_large(self):
     with self.assertRaises(OverflowError):
         ieee2ibm(MAX_IBM_FLOAT * 10)
Пример #27
0
 def test_too_large(self):
     with pytest.raises(OverflowError):
         ieee2ibm(MAX_IBM_FLOAT * 10)
Пример #28
0
 def test_too_small(self):
     with self.assertRaises(OverflowError):
         ieee2ibm(MIN_IBM_FLOAT * 10)
Пример #29
0
 def test_one(self):
     ibm_start = b'\x41\x10\x00\x00'
     f = ibm2ieee(ibm_start)
     ibm_result = ieee2ibm(f)
     assert ibm_start == ibm_result
Пример #30
0
 def test_zero(self):
     ibm_start = b'\0\0\0\0'
     f = ibm2ieee(ibm_start)
     ibm_result = ieee2ibm(f)
     self.assertEqual(ibm_start, ibm_result)
Пример #31
0
 def test_subnormal(self):
     ibm_start = bytes((0x00, 0x00, 0x00, 0x20))
     f = ibm2ieee(ibm_start)
     ibm_result = ieee2ibm(f)
     self.assertEqual(ibm_start, ibm_result)
Пример #32
0
 def test_positive_half(self):
     ibm_start = bytes((0b11000000, 0x80, 0x00, 0x00))
     f = ibm2ieee(ibm_start)
     ibm_result = ieee2ibm(f)
     self.assertEqual(ibm_start, ibm_result)
Пример #33
0
 def test_positive_half(self):
     self.assertEqual(ieee2ibm(-0.5), bytes((0b11000000, 0x80, 0x00, 0x00)))
Пример #34
0
 def test_one(self):
     ibm_start = b'\x41\x10\x00\x00'
     f = ibm2ieee(ibm_start)
     ibm_result = ieee2ibm(f)
     self.assertEqual(ibm_start, ibm_result)
Пример #35
0
 def test_one(self):
     self.assertEqual(ieee2ibm(1.0), b'\x41\x10\x00\x00')
Пример #36
0
 def test_subnormal(self):
     ibm_start = bytes((0x00, 0x00, 0x00, 0x20))
     f = ibm2ieee(ibm_start)
     ibm_result = ieee2ibm(f)
     self.assertEqual(ibm_start, ibm_result)
Пример #37
0
 def test_0_1(self):
     # Note, this is different from the Wikipedia example, because the Wikipedia example does
     # round to nearest, and our routine does round to zero
     self.assertEqual(ieee2ibm(0.1), bytes((0b01000000, 0b00011001, 0b10011001, 0b10011001)))
Пример #38
0
 def test_zero(self):
     self.assertEqual(ieee2ibm(0.0), b'\0\0\0\0')
Пример #39
0
 def test_smallest_subnormal(self):
     self.assertEqual(ieee2ibm(5.147557589468029e-85), bytes((0x00, 0x00, 0x00, 0x01)))
Пример #40
0
 def test_positive_half(self):
     self.assertEqual(ieee2ibm(-0.5), bytes((0b11000000, 0x80, 0x00, 0x00)))
Пример #41
0
 def test_nan(self):
     with self.assertRaises(ValueError):
         ieee2ibm(float('nan'))
Пример #42
0
 def test_negative_half(self):
     self.assertEqual(ieee2ibm(0.5), bytes((0b01000000, 0x80, 0x00, 0x00)))
Пример #43
0
 def test_zero(self):
     assert ieee2ibm(0.0) == b'\0\0\0\0'
Пример #44
0
 def test_one(self):
     self.assertEqual(ieee2ibm(1.0), b'\x41\x10\x00\x00')
Пример #45
0
 def test_negative_half(self):
     assert ieee2ibm(0.5) == bytes((0b01000000, 0x80, 0x00, 0x00))
Пример #46
0
 def test_smallest_subnormal(self):
     assert ieee2ibm(5.147557589468029e-85) == bytes(
         (0x00, 0x00, 0x00, 0x01))
Пример #47
0
 def test_negative_118_625(self):
     # Example taken from Wikipedia http://en.wikipedia.org/wiki/IBM_Floating_Point_Architecture
     assert ieee2ibm(-118.625) == bytes(
         (0b11000010, 0b01110110, 0b10100000, 0b00000000))
Пример #48
0
 def test_nan(self):
     with pytest.raises(ValueError):
         ieee2ibm(float('nan'))
Пример #49
0
 def test_subnormal(self):
     assert ieee2ibm(1.6472184286297693e-83) == bytes(
         (0x00, 0x00, 0x00, 0x20))
Пример #50
0
 def test_subnormal(self):
     assert ieee2ibm(1.6472184286297693e-83) == bytes((0x00, 0x00, 0x00, 0x20))
Пример #51
0
 def test_too_small_subnormal(self):
     with pytest.raises(FloatingPointError):
         ieee2ibm(1e-86)
Пример #52
0
 def test_too_large(self):
     with self.assertRaises(OverflowError):
         ieee2ibm(MAX_IBM_FLOAT * 10)
Пример #53
0
 def test_inf(self):
     with pytest.raises(ValueError):
         ieee2ibm(float('inf'))
Пример #54
0
 def test_too_small(self):
     with self.assertRaises(OverflowError):
         ieee2ibm(MIN_IBM_FLOAT * 10)
Пример #55
0
 def test_too_small(self):
     with pytest.raises(OverflowError):
         ieee2ibm(MIN_IBM_FLOAT * 10)
Пример #56
0
 def test_zero(self):
     ibm_start = b'\0\0\0\0'
     f = ibm2ieee(ibm_start)
     ibm_result = ieee2ibm(f)
     self.assertEqual(ibm_start, ibm_result)
Пример #57
0
 def test_negative_half(self):
     ibm_start = bytes((0b01000000, 0x80, 0x00, 0x00))
     f = ibm2ieee(ibm_start)
     ibm_result = ieee2ibm(f)
     assert ibm_start == ibm_result
Пример #58
0
 def test_negative_half(self):
     ibm_start = bytes((0b01000000, 0x80, 0x00, 0x00))
     f = ibm2ieee(ibm_start)
     ibm_result = ieee2ibm(f)
     self.assertEqual(ibm_start, ibm_result)
Пример #59
0
 def test_subnormal(self):
     ibm_start = bytes((0x00, 0x00, 0x00, 0x20))
     f = ibm2ieee(ibm_start)
     ibm_result = ieee2ibm(f)
     assert ibm_start == ibm_result
Пример #60
0
 def test_one(self):
     ibm_start = b'\x41\x10\x00\x00'
     f = ibm2ieee(ibm_start)
     ibm_result = ieee2ibm(f)
     self.assertEqual(ibm_start, ibm_result)