本文整理汇总了Python中topaz.objects.numericobject.W_NumericObject.retry_binop_coercing方法的典型用法代码示例。如果您正苦于以下问题:Python W_NumericObject.retry_binop_coercing方法的具体用法?Python W_NumericObject.retry_binop_coercing怎么用?Python W_NumericObject.retry_binop_coercing使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类topaz.objects.numericobject.W_NumericObject
的用法示例。
在下文中一共展示了W_NumericObject.retry_binop_coercing方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: method
# 需要导入模块: from topaz.objects.numericobject import W_NumericObject [as 别名]
# 或者: from topaz.objects.numericobject.W_NumericObject import retry_binop_coercing [as 别名]
def method(self, space, w_other):
if space.is_kind_of(w_other, space.w_float):
return space.newbool(func(self.intvalue, space.float_w(w_other)))
elif space.is_kind_of(w_other, space.w_fixnum):
return space.newbool(func(self.intvalue, space.int_w(w_other)))
else:
return W_NumericObject.retry_binop_coercing(space, self, w_other, name, raise_error=True)
示例2: method_divide
# 需要导入模块: from topaz.objects.numericobject import W_NumericObject [as 别名]
# 或者: from topaz.objects.numericobject.W_NumericObject import retry_binop_coercing [as 别名]
def method_divide(self, space, w_other):
if space.is_kind_of(w_other, space.w_fixnum):
return self.floordiv(space, rbigint.fromint(space.int_w(w_other)))
elif space.is_kind_of(w_other, space.w_bignum):
return self.floordiv(space, space.bigint_w(w_other))
elif space.is_kind_of(w_other, space.w_float):
return space.send(space.newfloat(space.float_w(self)), "/", [w_other])
else:
return W_NumericObject.retry_binop_coercing(space, self, w_other, "/")
示例3: method
# 需要导入模块: from topaz.objects.numericobject import W_NumericObject [as 别名]
# 或者: from topaz.objects.numericobject.W_NumericObject import retry_binop_coercing [as 别名]
def method(self, space, w_other):
w_other = space.convert_type(w_other, space.w_integer, "to_int")
if space.is_kind_of(w_other, space.w_fixnum):
other = space.int_w(w_other)
return space.newint(func(self.intvalue, other))
elif space.is_kind_of(w_other, space.w_bignum):
return space.send(space.newbigint_fromint(self.intvalue), name, [w_other])
else:
return W_NumericObject.retry_binop_coercing(space, self, w_other, name)
示例4: method_eq
# 需要导入模块: from topaz.objects.numericobject import W_NumericObject [as 别名]
# 或者: from topaz.objects.numericobject.W_NumericObject import retry_binop_coercing [as 别名]
def method_eq(self, space, w_other):
if space.is_kind_of(w_other, space.w_float):
return space.newbool(self.floatvalue == space.float_w(w_other))
try:
return W_NumericObject.retry_binop_coercing(space, self, w_other, "==")
except RubyError as e:
if isinstance(e.w_value, W_ArgumentError):
return space.send(w_other, "==", [self])
else:
raise
示例5: divide
# 需要导入模块: from topaz.objects.numericobject import W_NumericObject [as 别名]
# 或者: from topaz.objects.numericobject.W_NumericObject import retry_binop_coercing [as 别名]
def divide(self, space, w_other):
if space.is_kind_of(w_other, space.w_fixnum):
other = space.int_w(w_other)
try:
return space.newint(self.intvalue / other)
except ZeroDivisionError:
self.raise_zero_division_error(space)
elif space.is_kind_of(w_other, space.w_bignum):
return space.send(space.newbigint_fromint(self.intvalue), space.newsymbol("/"), [w_other])
elif space.is_kind_of(w_other, space.w_float):
return space.send(space.newfloat(space.float_w(self)), space.newsymbol("/"), [w_other])
else:
return W_NumericObject.retry_binop_coercing(space, self, w_other, "/")
示例6: method_fdiv
# 需要导入模块: from topaz.objects.numericobject import W_NumericObject [as 别名]
# 或者: from topaz.objects.numericobject.W_NumericObject import retry_binop_coercing [as 别名]
def method_fdiv(self, space, w_other):
if space.is_kind_of(w_other, space.w_fixnum):
other = space.int_w(w_other)
try:
res = float(self.intvalue) / float(other)
except ZeroDivisionError:
return space.newfloat(rfloat.copysign(rfloat.INFINITY, float(self.intvalue)))
else:
return space.newfloat(res)
elif space.is_kind_of(w_other, space.w_bignum):
return space.send(space.newbigint_fromint(self.intvalue), "fdiv", [w_other])
elif space.is_kind_of(w_other, space.w_float):
other = space.float_w(w_other)
try:
res = float(self.intvalue) / other
except ZeroDivisionError:
return space.newfloat(rfloat.copysign(rfloat.INFINITY, float(self.intvalue)))
else:
return space.newfloat(res)
else:
return W_NumericObject.retry_binop_coercing(space, self, w_other, "fdiv")