Skip to content
Permalink
Browse files

Added Fixnum#>>

  • Loading branch information
Alex Gaynor
Alex Gaynor committed Apr 4, 2013
1 parent b350001 commit 9c7d5e9305973afa733833678cab2d77a09e0ebb
Showing with 7 additions and 14 deletions.
  1. +0 −14 spec/tags/core/fixnum/right_shift_tags.txt
  2. +7 −0 topaz/objects/intobject.py
@@ -1,17 +1,3 @@
fails:Fixnum#>> with n >> m returns n shifted right m bits when n > 0, m > 0
fails:Fixnum#>> with n >> m returns n shifted right m bits when n < 0, m > 0
fails:Fixnum#>> with n >> m returns n shifted left m bits when n > 0, m < 0
fails:Fixnum#>> with n >> m returns n shifted left m bits when n < 0, m < 0
fails:Fixnum#>> with n >> m returns 0 when n == 0
fails:Fixnum#>> with n >> m returns n when n > 0, m == 0
fails:Fixnum#>> with n >> m returns n when n < 0, m == 0
fails:Fixnum#>> with n >> m returns 0 when m > 0 and m == p where 2**p > n >= 2**(p-1)
fails:Fixnum#>> with n >> m returns 0 when m is outside the available bits and n >= 0
fails:Fixnum#>> with n >> m returns -1 when m is outside the available bits and n < 0
fails:Fixnum#>> with n >> m returns 0 when m is a Bignum
fails:Fixnum#>> with n >> m returns a Bignum == fixnum_max() * 2 when fixnum_max() >> -1 and n > 0
fails:Fixnum#>> with n >> m returns a Bignum == fixnum_min() * 2 when fixnum_min() >> -1 and n < 0
fails:Fixnum#>> with n >> m calls #to_int to convert the argument to an Integer
fails:Fixnum#>> with n >> m raises a TypeError when #to_int does not return an Integer
fails:Fixnum#>> with n >> m raises a TypeError when passed nil
fails:Fixnum#>> with n >> m raises a TypeError when passed a String
@@ -203,6 +203,13 @@ def method_left_shift(self, space, other):
else:
return space.newint(value)

@classdef.method(">>", other="int")
def method_right_shift(self, space, other):
if other < 0:
return space.newint(self.intvalue << -other)
else:
return space.newint(self.intvalue >> other)

@classdef.method("&", other="int")
def method_and(self, space, other):
return space.newint(self.intvalue & other)

0 comments on commit 9c7d5e9

Please sign in to comment.
You can’t perform that action at this time.