示例#1
0
 def method(self, space, w_other):
     if space.is_kind_of(w_other, space.w_float):
         return space.newbool(
             func(self.floatvalue, space.float_w(w_other)))
     else:
         return W_NumericObject.retry_binop_coercing(
             space, self, w_other, name)
示例#2
0
 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)
示例#3
0
 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")
示例#4
0
 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, "/")
示例#5
0
 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)
示例#6
0
 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)
 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, "/")
示例#8
0
    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, space.newsymbol("=="), [self])
            else:
                raise
示例#9
0
    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
示例#10
0
 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, "/")
示例#11
0
 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), "/", [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, "/")
示例#12
0
 def method(self, space, w_other):
     if space.is_kind_of(w_other, space.w_fixnum):
         other = space.int_w(w_other)
         try:
             value = ovfcheck(func(self.intvalue, other))
         except OverflowError:
             return space.send(space.newbigint_fromint(self.intvalue), name, [w_other])
         else:
             return space.newint(value)
     elif space.is_kind_of(w_other, space.w_bignum):
         return space.send(space.newbigint_fromint(self.intvalue), name, [w_other])
     elif space.is_kind_of(w_other, space.w_float):
         return space.newfloat(func(self.intvalue, space.float_w(w_other)))
     else:
         return W_NumericObject.retry_binop_coercing(space, self, w_other, name)
示例#13
0
    def method_equalp(self, space, w_other):
        if space.is_kind_of(w_other, space.w_float):
            other = space.float_w(w_other)
            return space.newbool(
                self.floatvalue == other
                or (math.isnan(self.floatvalue) and math.isnan(other)))

        try:
            return W_NumericObject.retry_binop_coercing(
                space, self, w_other, "equal?")
        except RubyError as e:
            if isinstance(e.w_value, W_ArgumentError):
                return space.send(w_other, "equal?", [self])
            else:
                raise
示例#14
0
 def method(self, space, w_other):
     if space.is_kind_of(w_other, space.w_fixnum):
         other = space.int_w(w_other)
         try:
             value = ovfcheck(func(self.intvalue, other))
         except OverflowError:
             return space.send(
                 space.newbigint_fromint(self.intvalue), name,
                 [w_other]
             )
         else:
             return space.newint(value)
     elif space.is_kind_of(w_other, space.w_bignum):
         return space.send(space.newbigint_fromint(self.intvalue), name, [w_other])
     elif space.is_kind_of(w_other, space.w_float):
         return space.newfloat(func(self.intvalue, space.float_w(w_other)))
     else:
         return W_NumericObject.retry_binop_coercing(space, self, w_other, name)
示例#15
0
 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")