本文整理汇总了Python中segpy.ibm_float.IBMFloat.from_float方法的典型用法代码示例。如果您正苦于以下问题:Python IBMFloat.from_float方法的具体用法?Python IBMFloat.from_float怎么用?Python IBMFloat.from_float使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类segpy.ibm_float.IBMFloat
的用法示例。
在下文中一共展示了IBMFloat.from_float方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_rfloordiv_ibm
# 需要导入模块: from segpy.ibm_float import IBMFloat [as 别名]
# 或者: from segpy.ibm_float.IBMFloat import from_float [as 别名]
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
示例2: test_sub
# 需要导入模块: from segpy.ibm_float import IBMFloat [as 别名]
# 或者: from segpy.ibm_float.IBMFloat import from_float [as 别名]
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))
示例3: test_mul_ibm
# 需要导入模块: from segpy.ibm_float import IBMFloat [as 别名]
# 或者: from segpy.ibm_float.IBMFloat import from_float [as 别名]
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)
示例4: test_rpow_ibm_ieee_results
# 需要导入模块: from segpy.ibm_float import IBMFloat [as 别名]
# 或者: from segpy.ibm_float.IBMFloat import from_float [as 别名]
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)
示例5: test_rmod_ibm
# 需要导入模块: from segpy.ibm_float import IBMFloat [as 别名]
# 或者: from segpy.ibm_float.IBMFloat import from_float [as 别名]
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)
示例6: test_pow_ibm_complex_result
# 需要导入模块: from segpy.ibm_float import IBMFloat [as 别名]
# 或者: from segpy.ibm_float.IBMFloat import from_float [as 别名]
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)
示例7: test_sub
# 需要导入模块: from segpy.ibm_float import IBMFloat [as 别名]
# 或者: from segpy.ibm_float.IBMFloat import from_float [as 别名]
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))
示例8: test_add
# 需要导入模块: from segpy.ibm_float import IBMFloat [as 别名]
# 或者: from segpy.ibm_float.IBMFloat import from_float [as 别名]
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))
示例9: test_add
# 需要导入模块: from segpy.ibm_float import IBMFloat [as 别名]
# 或者: from segpy.ibm_float.IBMFloat import from_float [as 别名]
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))
示例10: test_bool
# 需要导入模块: from segpy.ibm_float import IBMFloat [as 别名]
# 或者: from segpy.ibm_float.IBMFloat import from_float [as 别名]
def test_bool(self, f):
self.assertEqual(bool(IBMFloat.from_float(f)), bool(f))
示例11: test_too_small
# 需要导入模块: from segpy.ibm_float import IBMFloat [as 别名]
# 或者: from segpy.ibm_float.IBMFloat import from_float [as 别名]
def test_too_small(self):
with self.assertRaises(OverflowError):
IBMFloat.from_float(MIN_IBM_FLOAT * 10)
示例12: test_too_large
# 需要导入模块: from segpy.ibm_float import IBMFloat [as 别名]
# 或者: from segpy.ibm_float.IBMFloat import from_float [as 别名]
def test_too_large(self):
with self.assertRaises(OverflowError):
IBMFloat.from_float(MAX_IBM_FLOAT * 10)
示例13: test_inf
# 需要导入模块: from segpy.ibm_float import IBMFloat [as 别名]
# 或者: from segpy.ibm_float.IBMFloat import from_float [as 别名]
def test_inf(self):
with self.assertRaises(ValueError):
IBMFloat.from_float(float('inf'))
示例14: test_nan
# 需要导入模块: from segpy.ibm_float import IBMFloat [as 别名]
# 或者: from segpy.ibm_float.IBMFloat import from_float [as 别名]
def test_nan(self):
with self.assertRaises(ValueError):
IBMFloat.from_float(float('nan'))
示例15: test_too_small_subnormal
# 需要导入模块: from segpy.ibm_float import IBMFloat [as 别名]
# 或者: from segpy.ibm_float.IBMFloat import from_float [as 别名]
def test_too_small_subnormal(self):
with self.assertRaises(FloatingPointError):
IBMFloat.from_float(1e-86)