class Int32
simulate 32 bit integer with overflow
Attributes
val[RW]
Public Class Methods
force_overflow_signed(i)
click to toggle source
# File lib/sign/int32.rb, line 22 def self.force_overflow_signed(i) force_overflow_unsigned(i + 2**31) - 2**31 end
force_overflow_unsigned(i)
click to toggle source
# File lib/sign/int32.rb, line 26 def self.force_overflow_unsigned(i) i % 2**32 # or equivalently: i & 0xffffffff end
new(val)
click to toggle source
# File lib/sign/int32.rb, line 6 def initialize(val) self.val = if val.is_a?(Int32) val.val else val end end
Public Instance Methods
==(other)
click to toggle source
# File lib/sign/int32.rb, line 14 def ==(other) to_i == if other.is_a?(Int32) other.to_i else other end end
dup()
click to toggle source
# File lib/sign/int32.rb, line 39 def dup Int32.new(val) end
r_shift_pos(other)
click to toggle source
# File lib/sign/int32.rb, line 30 def r_shift_pos(other) other_val = other.is_a?(Int32) ? other.val : other Int32.new(self.class.force_overflow_unsigned(val) >> other_val) end
to_i()
click to toggle source
# File lib/sign/int32.rb, line 35 def to_i self.class.force_overflow_signed(val) end
Private Instance Methods
method_missing(meth, *args, &block)
click to toggle source
Calls superclass method
# File lib/sign/int32.rb, line 59 def method_missing(meth, *args, &block) return super unless respond_to_missing?(meth) Int32.new(self.class.force_overflow_signed(val.send(meth, *args, &block))) end
respond_to_missing?(meth, _include_private = false)
click to toggle source
# File lib/sign/int32.rb, line 55 def respond_to_missing?(meth, _include_private = false) val.respond_to?(meth) end