Class: I32
Constant Summary collapse
- DIGITS =
"0123456789ABCDEF"
Class Method Summary collapse
-
.itoa(x, base) ⇒ Object
convert an integer to its string representation in a given base.
- .size ⇒ Object
Instance Method Summary collapse
Class Method Details
.itoa(x, base) ⇒ Object
convert an integer to its string representation in a given base
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rlang/lib/type/i32.rb', line 16 def self.itoa(x,base) result :String raise "itoa base out of range" if base < 2 || base > DIGITS.length if x <= 0 if x == 0 return DIGITS[0] else return "-" + self.itoa(0-x, base) end end result = "" while x > 0 remainder = x % base x /= base result += DIGITS[remainder] end result.reverse! end |
.size ⇒ Object
13 |
# File 'lib/rlang/lib/type/i32.rb', line 13 def self.size; 4; end |