本文整理汇总了Python中segpy.ibm_float.IBMFloat类的典型用法代码示例。如果您正苦于以下问题:Python IBMFloat类的具体用法?Python IBMFloat怎么用?Python IBMFloat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IBMFloat类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: unpack_ibm_floats
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)]
开发者ID:Abushalaa,项目名称:segpy,代码行数:12,代码来源:toolkit.py
示例2: unpack_ibm_floats
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)]
开发者ID:stevejpurves,项目名称:segpy,代码行数:13,代码来源:toolkit.py
示例3: test_rfloordiv_ibm
def test_rfloordiv_ibm(self, a, b):
ibm_a = IBMFloat.from_float(a)
ibm_b = IBMFloat.from_float(b)
assume(not ibm_b.is_zero())
ieee_a = float(ibm_a)
ieee_b = float(ibm_b)
assert ieee_a // ibm_b == ieee_a // ieee_b
开发者ID:abingham,项目名称:segpy,代码行数:7,代码来源:test_float.py
示例4: test_sub
def test_sub(self, a, b):
ibm_a = IBMFloat.from_float(a)
ibm_b = IBMFloat.from_float(b)
ibm_c = ibm_a - ibm_b
ieee_a = float(ibm_a)
ieee_b = float(ibm_b)
ieee_c = ieee_a - ieee_b
self.assertTrue(almost_equal(ieee_c, ibm_c, epsilon=EPSILON_IBM_FLOAT))
开发者ID:hohogpb,项目名称:segpy,代码行数:10,代码来源:test_float.py
示例5: test_mul_ibm
def test_mul_ibm(self, a, b):
ibm_a = IBMFloat.from_float(a)
ibm_b = IBMFloat.from_float(b)
ieee_a = float(ibm_a)
ieee_b = float(ibm_b)
try:
ibm_c = ibm_a * ibm_b
except OverflowError:
raise UnsatisfiedAssumption
ieee_c = ieee_a * ieee_b
assert almost_equal(ibm_c, ieee_c, epsilon=EPSILON_IBM_FLOAT)
开发者ID:abingham,项目名称:segpy,代码行数:11,代码来源:test_float.py
示例6: test_rmod_ibm
def test_rmod_ibm(self, a, b):
ibm_a = IBMFloat.from_float(a)
ibm_b = IBMFloat.from_float(b)
assume(not ibm_b.is_zero())
ieee_a = float(ibm_a)
ieee_b = float(ibm_b)
try:
ieee_c1 = ieee_a % ibm_b
except OverflowError:
raise UnsatisfiedAssumption
ieee_c2 = ieee_a % ieee_b
assert almost_equal(ieee_c1, ieee_c2, epsilon=EPSILON_IBM_FLOAT)
开发者ID:abingham,项目名称:segpy,代码行数:12,代码来源:test_float.py
示例7: test_rpow_ibm_ieee_results
def test_rpow_ibm_ieee_results(self, a, b):
assume(a != 0.0)
ibm_a = IBMFloat.from_float(a)
ibm_b = IBMFloat.from_float(b)
ieee_a = float(ibm_a)
ieee_b = float(ibm_b)
try:
ieee_c1 = ieee_a ** ibm_b
except OverflowError:
raise UnsatisfiedAssumption
ieee_c2 = ieee_a ** ieee_b
assert almost_equal(ieee_c1, ieee_c2, epsilon=EPSILON_IBM_FLOAT)
开发者ID:abingham,项目名称:segpy,代码行数:12,代码来源:test_float.py
示例8: test_add
def test_add(self, f, p):
a = f * p
b = f - a
ibm_a = IBMFloat.from_float(a)
ibm_b = IBMFloat.from_float(b)
ibm_c = ibm_a + ibm_b
ieee_a = float(ibm_a)
ieee_b = float(ibm_b)
ieee_c = ieee_a + ieee_b
self.assertTrue(almost_equal(ieee_c, ibm_c, epsilon=EPSILON_IBM_FLOAT * 4))
开发者ID:hohogpb,项目名称:segpy,代码行数:13,代码来源:test_float.py
示例9: test_sub
def test_sub(self, a, b):
try:
ibm_a = IBMFloat.from_float(a)
ibm_b = IBMFloat.from_float(b)
ibm_c = ibm_a - ibm_b
except FloatingPointError:
raise UnsatisfiedAssumption
ieee_a = float(ibm_a)
ieee_b = float(ibm_b)
ieee_c = ieee_a - ieee_b
self.assertTrue(almost_equal(ieee_c, ibm_c, epsilon=EPSILON_IBM_FLOAT))
开发者ID:weiliu620,项目名称:segpy,代码行数:13,代码来源:test_float.py
示例10: test_pow_ibm_complex_result
def test_pow_ibm_complex_result(self, a, b):
assume(a != 0.0)
assume(b != 0.0 and b != 1.0)
ibm_a = IBMFloat.from_float(a)
ibm_b = IBMFloat.from_float(b)
ieee_a = float(ibm_a)
ieee_b = float(ibm_b)
try:
ibm_c = ibm_a ** ibm_b
except OverflowError:
raise UnsatisfiedAssumption
ieee_c = ieee_a ** ieee_b
assert almost_equal(ibm_c, ieee_c, epsilon=EPSILON_IBM_FLOAT)
开发者ID:abingham,项目名称:segpy,代码行数:13,代码来源:test_float.py
示例11: test_add
def test_add(self, f, p):
a = f * p
b = f - a
try:
ibm_a = IBMFloat.from_float(a)
ibm_b = IBMFloat.from_float(b)
ibm_c = ibm_a + ibm_b
except FloatingPointError:
raise UnsatisfiedAssumption
ieee_a = float(ibm_a)
ieee_b = float(ibm_b)
ieee_c = ieee_a + ieee_b
self.assertTrue(almost_equal(ieee_c, ibm_c, epsilon=EPSILON_IBM_FLOAT * 4))
开发者ID:weiliu620,项目名称:segpy,代码行数:16,代码来源:test_float.py
示例12: test_ldexp_frexp
def test_ldexp_frexp(self, fraction, exponent):
try:
ibm = IBMFloat.ldexp(fraction, exponent)
except OverflowError:
assume(False)
else:
f, e = ibm.frexp()
self.assertTrue(almost_equal(fraction * 2**exponent, f * 2**e, epsilon=EPSILON_IBM_FLOAT))
开发者ID:hohogpb,项目名称:segpy,代码行数:8,代码来源:test_float.py
示例13: test_ldexp_frexp
def test_ldexp_frexp(self, fraction, exponent):
try:
ibm = IBMFloat.ldexp(fraction, exponent)
except (OverflowError, FloatingPointError):
raise UnsatisfiedAssumption
else:
f, e = ibm.frexp()
self.assertTrue(almost_equal(fraction * 2**exponent, f * 2**e, epsilon=EPSILON_IBM_FLOAT))
开发者ID:weiliu620,项目名称:segpy,代码行数:8,代码来源:test_float.py
示例14: pack_ibm_floats
def pack_ibm_floats(values):
"""Pack floats into binary-encoded big-endian single-precision IBM floats.
Args:
values: An iterable series of numeric values.
Returns:
A sequence of bytes.
"""
return EMPTY_BYTE_STRING.join(bytes(IBMFloat.from_real(value)) for value in values)
开发者ID:Abushalaa,项目名称:segpy,代码行数:10,代码来源:toolkit.py
示例15: test_normalise_subnormal
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())
开发者ID:hohogpb,项目名称:segpy,代码行数:15,代码来源:test_float.py
示例16: test_zero_subnormal
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())
开发者ID:hohogpb,项目名称:segpy,代码行数:15,代码来源:test_float.py
示例17: test_floor
def test_floor(self, i, f):
assume(f != 1.0)
ieee = i + f
ibm = IBMFloat.from_float(ieee)
self.assertEqual(math.floor(ibm), i)
开发者ID:hohogpb,项目名称:segpy,代码行数:5,代码来源:test_float.py
示例18: test_too_large
def test_too_large(self):
with self.assertRaises(OverflowError):
IBMFloat.from_float(MAX_IBM_FLOAT * 10)
开发者ID:hohogpb,项目名称:segpy,代码行数:3,代码来源:test_float.py
示例19: test_too_small
def test_too_small(self):
with self.assertRaises(OverflowError):
IBMFloat.from_float(MIN_IBM_FLOAT * 10)
开发者ID:hohogpb,项目名称:segpy,代码行数:3,代码来源:test_float.py
示例20: test_bool
def test_bool(self, f):
self.assertEqual(bool(IBMFloat.from_float(f)), bool(f))
开发者ID:hohogpb,项目名称:segpy,代码行数:2,代码来源:test_float.py
注:本文中的segpy.ibm_float.IBMFloat类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论