本文整理汇总了Python中segpy.ibm_float.IBMFloat.from_bytes方法的典型用法代码示例。如果您正苦于以下问题:Python IBMFloat.from_bytes方法的具体用法?Python IBMFloat.from_bytes怎么用?Python IBMFloat.from_bytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类segpy.ibm_float.IBMFloat
的用法示例。
在下文中一共展示了IBMFloat.from_bytes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: unpack_ibm_floats
# 需要导入模块: from segpy.ibm_float import IBMFloat [as 别名]
# 或者: from segpy.ibm_float.IBMFloat import from_bytes [as 别名]
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)]
示例2: unpack_ibm_floats
# 需要导入模块: from segpy.ibm_float import IBMFloat [as 别名]
# 或者: from segpy.ibm_float.IBMFloat import from_bytes [as 别名]
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)]
示例3: test_zero_subnormal
# 需要导入模块: from segpy.ibm_float import IBMFloat [as 别名]
# 或者: from segpy.ibm_float.IBMFloat import from_bytes [as 别名]
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())
示例4: test_normalise_subnormal
# 需要导入模块: from segpy.ibm_float import IBMFloat [as 别名]
# 或者: from segpy.ibm_float.IBMFloat import from_bytes [as 别名]
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())
示例5: test_negate_non_zero
# 需要导入模块: from segpy.ibm_float import IBMFloat [as 别名]
# 或者: from segpy.ibm_float.IBMFloat import from_bytes [as 别名]
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)
示例6: test_abs
# 需要导入模块: from segpy.ibm_float import IBMFloat [as 别名]
# 或者: from segpy.ibm_float.IBMFloat import from_bytes [as 别名]
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)
示例7: test_normalise_subnormal2
# 需要导入模块: from segpy.ibm_float import IBMFloat [as 别名]
# 或者: from segpy.ibm_float.IBMFloat import from_bytes [as 别名]
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())
示例8: test_normalise_subnormal1
# 需要导入模块: from segpy.ibm_float import IBMFloat [as 别名]
# 或者: from segpy.ibm_float.IBMFloat import from_bytes [as 别名]
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())
示例9: test_bytes_roundtrip
# 需要导入模块: from segpy.ibm_float import IBMFloat [as 别名]
# 或者: from segpy.ibm_float.IBMFloat import from_bytes [as 别名]
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)
示例10: test_zero_from_bytes
# 需要导入模块: from segpy.ibm_float import IBMFloat [as 别名]
# 或者: from segpy.ibm_float.IBMFloat import from_bytes [as 别名]
def test_zero_from_bytes(self):
zero = IBMFloat.from_bytes(b'\x00\x00\x00\x00')
self.assertTrue(zero.is_zero())
示例11: unpack
# 需要导入模块: from segpy.ibm_float import IBMFloat [as 别名]
# 或者: from segpy.ibm_float.IBMFloat import from_bytes [as 别名]
def unpack(self, data, num_items):
return [IBMFloat.from_bytes(data[i: i+4])
for i in range(0, num_items * 4, 4)]
示例12: test_negate_non_zero
# 需要导入模块: from segpy.ibm_float import IBMFloat [as 别名]
# 或者: from segpy.ibm_float.IBMFloat import from_bytes [as 别名]
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
示例13: test_abs
# 需要导入模块: from segpy.ibm_float import IBMFloat [as 别名]
# 或者: from segpy.ibm_float.IBMFloat import from_bytes [as 别名]
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
示例14: test_bytes_roundtrip
# 需要导入模块: from segpy.ibm_float import IBMFloat [as 别名]
# 或者: from segpy.ibm_float.IBMFloat import from_bytes [as 别名]
def test_bytes_roundtrip(self, a, b, c, d):
b = bytes((a, b, c, d))
ibm = IBMFloat.from_bytes(b)
assert bytes(ibm) == b
示例15: test_incorrect_number_of_bytes_raises_value_error
# 需要导入模块: from segpy.ibm_float import IBMFloat [as 别名]
# 或者: from segpy.ibm_float.IBMFloat import from_bytes [as 别名]
def test_incorrect_number_of_bytes_raises_value_error(self):
with raises(ValueError):
IBMFloat.from_bytes(b'\x00\x00\x00')