Esempio n. 1
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)
Esempio n. 2
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)
Esempio n. 3
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, "/")
Esempio n. 4
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
Esempio n. 5
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, "/")
Esempio n. 6
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, "/")
Esempio n. 7
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)
Esempio n. 8
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
Esempio n. 9
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)
Esempio n. 10
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")
Esempio n. 11
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")
Esempio n. 12
0
 def __init__(self, space, floatvalue):
     W_NumericObject.__init__(self, space)
     self.floatvalue = floatvalue
Esempio n. 13
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)
Esempio n. 14
0
 def __init__(self, space, floatvalue):
     W_NumericObject.__init__(self, space)
     self.floatvalue = floatvalue