Skip to content
Permalink
Browse files

Merge pull request #545 from jstepien/some-numeric-methods

Numeric#{zero?,nonzero?,-@,+@,truncate}
  • Loading branch information
alex committed Mar 23, 2013
2 parents b20db28 + 5c75520 commit 511078589a0feb6215fb28b82188b843f7b2dc4c
@@ -16,14 +16,6 @@ def upto(n)
self
end

def zero?
self == 0
end

def nonzero?
self != 0
end

def even?
self % 2 == 0
end
@@ -24,4 +24,30 @@ def %(other)
def divmod(other)
[div(other), self % other]
end

def zero?
self == 0
end

def nonzero?
self unless zero?
end

def +@
self
end

def -@
zero, value = self.coerce(0)
zero - value
end

def truncate
val = self.to_f
if val > 0
val.floor
else
val.ceil
end
end
end

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

@@ -205,7 +205,7 @@ def test_to_i(self, space):

def test_nonzero(self, space):
w_res = space.execute("return [2.nonzero?, 0.nonzero?]")
assert self.unwrap(space, w_res) == [True, False]
assert self.unwrap(space, w_res) == [2, None]

def test_object_id(self, space):
w_res = space.execute("return 2.object_id, 2.object_id")
@@ -87,10 +87,6 @@ def method_and(self, space, other):
def method_xor(self, space, other):
return space.newbigint_fromrbigint(self.bigint.xor(other))

@classdef.method("-@")
def method_uminus(self, space):
return space.newbigint_fromrbigint(self.bigint.neg())

@classdef.method("==", other="bigint")
def method_eq(self, space, other):
return space.newbool(self.bigint.eq(other))
@@ -80,10 +80,6 @@ def method_to_i(self, space):
)
return self.float_to_w_int(space, self.floatvalue)

@classdef.method("-@")
def method_neg(self, space):
return space.newfloat(-self.floatvalue)

@classdef.method("+", other="float")
def method_add(self, space, other):
return space.newfloat(self.floatvalue + other)
@@ -246,10 +246,6 @@ def method(self, space, w_other):
method_gt = new_bool_op(classdef, ">", operator.gt)
method_gte = new_bool_op(classdef, ">=", operator.ge)

@classdef.method("-@")
def method_neg(self, space):
return space.newint(-self.intvalue)

@classdef.method("<=>")
def method_comparator(self, space, w_other):
if isinstance(w_other, W_FixnumObject):

0 comments on commit 5110785

Please sign in to comment.