Class: Integer
- Inherits:
-
Object
- Object
- Integer
- Defined in:
- lib/adlint/prelude.rb
Constant Summary collapse
- SHIFT_MAX_BITS =
NOTE: To restrict the bit-shift width.
64
Instance Method Summary collapse
Instance Method Details
#arithmetic_right_shift(rhs) ⇒ Object
114 115 116 |
# File 'lib/adlint/prelude.rb', line 114 def arithmetic_right_shift(rhs) rhs < 0 ? self : self >> [rhs, SHIFT_MAX_BITS].min end |
#left_shift(rhs) ⇒ Object
118 119 120 |
# File 'lib/adlint/prelude.rb', line 118 def left_shift(rhs) rhs < 0 ? self : self << [rhs, SHIFT_MAX_BITS].min end |
#logical_right_shift(rhs) ⇒ Object
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/adlint/prelude.rb', line 103 def logical_right_shift(rhs) return self if rhs < 0 bits = to_s(2) shift_width = [rhs, SHIFT_MAX_BITS].min if bits.length < shift_width 0 else ("0" * shift_width + bits[0..-(shift_width + 1)]).to_i(2) end end |