Exemple #1
10
def unpack_ibm_floats(data, num_items):
    """Unpack a series of binary-encoded big-endian single-precision IBM floats.

    Args:
        data: A sequence of bytes.

        num_items: The number of floats to be read.

    Returns:
        A sequence of floats.
    """
    return [IBMFloat.from_bytes(data[i: i+4]) for i in range(0, num_items * 4, 4)]
Exemple #2
1
def unpack_ibm_floats(data, count):
    """Unpack a series of binary-encoded big-endian single-precision IBM floats.

    Args:
        data: A sequence of bytes. (Python 2 - a str object,
            Python 3 - a bytes object)

        count: The number of floats to be read.

    Returns:
        A sequence of floats.
    """
    return [IBMFloat.from_bytes(data[i: i+4]) for i in range(0, count * 4, 4)]
Exemple #3
0
def unpack_ibm_floats(data, count):
    """Unpack a series of binary-encoded big-endian single-precision IBM floats.

    Args:
        data: A sequence of bytes. (Python 2 - a str object,
            Python 3 - a bytes object)

        count: The number of floats to be read.

    Returns:
        A sequence of floats.
    """
    return [IBMFloat.from_bytes(data[i: i+4]) for i in range(0, count * 4, 4)]
Exemple #4
0
    def test_zero_subnormal(self, b, c, d, shift):
        mantissa = (b << 16) | (c << 8) | d
        assume(mantissa != 0)
        mantissa >>= shift
        assert mantissa != 0

        sa = EXPONENT_BIAS
        sb = (mantissa >> 16) & 0xff
        sc = (mantissa >> 8) & 0xff
        sd = mantissa & 0xff

        ibm = IBMFloat.from_bytes((sa, sb, sc, sd))
        assert ibm.is_subnormal()
        z = ibm.zero_subnormal()
        self.assertTrue(z.is_zero())
Exemple #5
0
    def test_normalise_subnormal(self, b, c, d, shift):
        mantissa = (b << 16) | (c << 8) | d
        assume(mantissa != 0)
        mantissa >>= shift
        assert mantissa != 0

        sa = EXPONENT_BIAS
        sb = (mantissa >> 16) & 0xff
        sc = (mantissa >> 8) & 0xff
        sd = mantissa & 0xff

        ibm = IBMFloat.from_bytes((sa, sb, sc, sd))
        assert ibm.is_subnormal()
        normalized = ibm.normalize()
        self.assertFalse(normalized.is_subnormal())
Exemple #6
0
    def test_zero_subnormal(self, b, c, d, shift):
        mantissa = (b << 16) | (c << 8) | d
        assume(mantissa != 0)
        mantissa >>= shift
        assert mantissa != 0

        sa = EXPONENT_BIAS
        sb = (mantissa >> 16) & 0xff
        sc = (mantissa >> 8) & 0xff
        sd = mantissa & 0xff

        ibm = IBMFloat.from_bytes((sa, sb, sc, sd))
        assert ibm.is_subnormal()
        z = ibm.zero_subnormal()
        assert z.is_zero()
Exemple #7
0
    def test_normalise_subnormal(self, b, c, d, shift):
        mantissa = (b << 16) | (c << 8) | d
        assume(mantissa != 0)
        mantissa >>= shift
        assert mantissa != 0

        sa = EXPONENT_BIAS
        sb = (mantissa >> 16) & 0xff
        sc = (mantissa >> 8) & 0xff
        sd = mantissa & 0xff

        ibm = IBMFloat.from_bytes((sa, sb, sc, sd))
        assert ibm.is_subnormal()
        normalized = ibm.normalize()
        self.assertFalse(normalized.is_subnormal())
Exemple #8
0
 def test_normalise_subnormal2(self):
     ibm = IBMFloat.from_bytes((64, 1, 0, 0))
     assert ibm.is_subnormal()
     normalized = ibm.normalize()
     self.assertFalse(normalized.is_subnormal())
Exemple #9
0
 def test_zero_from_bytes(self):
     zero = IBMFloat.from_bytes(b'\x00\x00\x00\x00')
     assert zero.is_zero()
Exemple #10
0
 def test_negate_non_zero(self, a, b, c, d):
     ibm = IBMFloat.from_bytes((a, b, c, d))
     assume(not ibm.is_zero())
     negated = -ibm
     assert ibm.signbit != negated.signbit
Exemple #11
0
 def test_normalise_subnormal1(self):
     ibm = IBMFloat.from_bytes(
         (0b01000000, 0b00000000, 0b11111111, 0b00000000))
     assert ibm.is_subnormal()
     normalized = ibm.normalize()
     assert not normalized.is_subnormal()
Exemple #12
0
 def test_incorrect_number_of_bytes_raises_value_error(self):
     with raises(ValueError):
         IBMFloat.from_bytes(b'\x00\x00\x00')
Exemple #13
0
 def test_incorrect_number_of_bytes_raises_value_error(self):
     with raises(ValueError):
         IBMFloat.from_bytes(b'\x00\x00\x00')
Exemple #14
0
 def test_bytes_roundtrip(self, a, b, c, d):
     b = bytes((a, b, c, d))
     ibm = IBMFloat.from_bytes(b)
     self.assertEqual(bytes(ibm), b)
Exemple #15
0
 def test_abs(self, a, b, c, d):
     ibm = IBMFloat.from_bytes((a, b, c, d))
     abs_ibm = abs(ibm)
     self.assertGreaterEqual(abs_ibm.signbit, 0)
Exemple #16
0
 def test_zero_from_bytes(self):
     zero = IBMFloat.from_bytes(b'\x00\x00\x00\x00')
     self.assertTrue(zero.is_zero())
Exemple #17
0
 def unpack(self, data, num_items):
     return [IBMFloat.from_bytes(data[i: i+4])
             for i in range(0, num_items * 4, 4)]
Exemple #18
0
 def test_bytes_roundtrip(self, a, b, c, d):
     b = bytes((a, b, c, d))
     ibm = IBMFloat.from_bytes(b)
     assert bytes(ibm) == b
Exemple #19
0
 def test_negate_non_zero(self, a, b, c, d):
     ibm = IBMFloat.from_bytes((a, b, c, d))
     assume(not ibm.is_zero())
     negated = -ibm
     assert ibm.signbit != negated.signbit
Exemple #20
0
 def test_abs(self, a, b, c, d):
     ibm = IBMFloat.from_bytes((a, b, c, d))
     abs_ibm = abs(ibm)
     assert abs_ibm.signbit >= 0
Exemple #21
0
 def test_negate_non_zero(self, a, b, c, d):
     ibm = IBMFloat.from_bytes((a, b, c, d))
     assume(not ibm.is_zero())
     negated = -ibm
     self.assertNotEqual(ibm.signbit, negated.signbit)
Exemple #22
0
 def test_abs(self, a, b, c, d):
     ibm = IBMFloat.from_bytes((a, b, c, d))
     abs_ibm = abs(ibm)
     self.assertGreaterEqual(abs_ibm.signbit, 0)
Exemple #23
0
 def test_zero_from_bytes(self):
     zero = IBMFloat.from_bytes(b'\x00\x00\x00\x00')
     assert zero.is_zero()
Exemple #24
0
 def test_negate_non_zero(self, a, b, c, d):
     ibm = IBMFloat.from_bytes((a, b, c, d))
     assume(not ibm.is_zero())
     negated = -ibm
     self.assertNotEqual(ibm.signbit, negated.signbit)
Exemple #25
0
 def test_bytes_roundtrip(self, a, b, c, d):
     b = bytes((a, b, c, d))
     ibm = IBMFloat.from_bytes(b)
     assert bytes(ibm) == b
Exemple #26
0
def unpack_ibm_floats_py(data, num_items):
    return [
        IBMFloat.from_bytes(data[i:i + 4]) for i in range(0, num_items * 4, 4)
    ]
Exemple #27
0
 def test_normalise_subnormal2(self):
     ibm = IBMFloat.from_bytes((64, 1, 0, 0))
     assert ibm.is_subnormal()
     normalized = ibm.normalize()
     assert not normalized.is_subnormal()
Exemple #28
0
 def test_zero_from_bytes(self):
     zero = IBMFloat.from_bytes(b'\x00\x00\x00\x00')
     self.assertTrue(zero.is_zero())
Exemple #29
0
 def test_abs(self, a, b, c, d):
     ibm = IBMFloat.from_bytes((a, b, c, d))
     abs_ibm = abs(ibm)
     assert abs_ibm.signbit >= 0
Exemple #30
0
 def test_bytes_roundtrip(self, a, b, c, d):
     b = bytes((a, b, c, d))
     ibm = IBMFloat.from_bytes(b)
     self.assertEqual(bytes(ibm), b)
Exemple #31
0
 def unpack(self, data, num_items):
     return [
         IBMFloat.from_bytes(data[i:i + 4])
         for i in range(0, num_items * 4, 4)
     ]
Exemple #32
0
 def test_normalise_subnormal1(self):
     ibm = IBMFloat.from_bytes((0b01000000, 0b00000000, 0b11111111, 0b00000000))
     assert ibm.is_subnormal()
     normalized = ibm.normalize()
     self.assertFalse(normalized.is_subnormal())