abstract struct Int
- Int
- Number
- Value
- Object
Overview
Int is the base type of all integer types.
There are four signed integer types: Int8
, Int16
, Int32
and Int64
,
being able to represent numbers of 8, 16, 32 and 64 bits respectively.
There are four unsigned integer types: UInt8
, UInt16
, UInt32
and UInt64
.
An integer literal is an optional +
or -
sign, followed by
a sequence of digits and underscores, optionally followed by a suffix.
If no suffix is present, the literal's type is Int32
, or Int64
if the
number doesn't fit into an Int32
:
1 # Int32
1_i8 # Int8
1_i16 # Int16
1_i32 # Int32
1_i64 # Int64
1_u8 # UInt8
1_u16 # UInt16
1_u32 # UInt32
1_u64 # UInt64
+10 # Int32
-20 # Int32
2147483648 # Int64
Literals without a suffix that are larger than Int64::MAX
represent a
UInt64
if the number fits, e.g. 9223372036854775808
and
0x80000000_00000000
. This behavior is deprecated and will become an error in
the future.
The underscore _
before the suffix is optional.
Underscores can be used to make some numbers more readable:
1_000_000 # better than 1000000
Binary numbers start with 0b
:
0b1101 # == 13
Octal numbers start with 0o
:
0o123 # == 83
Hexadecimal numbers start with 0x
:
0xFE012D # == 16646445
0xfe012d # == 16646445
See Integer
literals in the language reference.
Included Modules
- Comparable(BigDecimal)
- Comparable(BigRational)
- Comparable(BigInt)
Direct Known Subclasses
Defined in:
remilib/extensions.crConstant Summary
-
ENGLISH_NUMBERS =
{0 => "zero", 1 => "one", 2 => "two", 3 => "three", 4 => "four", 5 => "five", 6 => "six", 7 => "seven", 8 => "eight", 9 => "nine", 10 => "ten", 11 => "eleven", 12 => "twelve", 13 => "thirteen", 14 => "fourteen", 15 => "fifteen", 16 => "sixteen", 17 => "seventeen", 18 => "eighteen", 19 => "nineteen", 20 => "twenty", 30 => "thirty", 40 => "forty", 50 => "fifty", 60 => "sixty", 70 => "seventy", 80 => "eighty", 90 => "ninety"}.to_h
-
ROMAN_NUMERALS =
[{1000, "M"}, {900, "CM"}, {500, "D"}, {400, "CD"}, {100, "C"}, {90, "XC"}, {50, "L"}, {40, "XL"}, {10, "X"}, {9, "IX"}, {5, "V"}, {4, "IV"}, {1, "I"}]
Class Method Summary
-
.positiveSpokenNumber(num) : String
Converts a number into a string such that it appears as English words.
Instance Method Summary
-
#positiveSpokenNumber : String
Converts a number into a string such that it appears as English words.
- #prettySize(io : IO, *, alwaysShowAsBytes : Bool = false, decimalPlaces : Int = 2, separator : Char = '.', delimiter : Char = ',', padding : Int = 0, padChar : Char = ' ', shortSuffix : Bool = false) : Nil
-
#prettySize(*, alwaysShowAsBytes : Bool = false, decimalPlaces : Int = 2, separator : Char = '.', delimiter : Char = ',', padding : Int = 0, padChar : Char = ' ', shortSuffix : Bool = false) : String
Similar to
Int#humanize_bytes
, except that this always usesInt::BinaryPrefixFormat::JEDEC
for the format, and formats numbers slightly differently. -
#toRoman : String
Converts this number to a Roman numeral.
-
#toRoman? : String | Nil
Converts this number to a Roman numeral.
- #toSpoken : String
Class Method Detail
Converts a number into a string such that it appears as English words. For
example, 100 would return "one hundred"
.
Instance Method Detail
Converts a number into a string such that it appears as English words. For
example, 100 would return "one hundred"
.
Similar to Int#humanize_bytes
, except that this always uses
Int::BinaryPrefixFormat::JEDEC
for the format, and formats numbers
slightly differently.
If alwaysShowAsBytes
is true, then this will always show the size as
bytes.
separator
is used for the decimal separator. delimiter
is used only
when alwaysShowAsBytes
is true, and is used as the thousands delimiter.
padding
instances of padChar
will be inserted to the left of the
formatted size if padding
is positive. If it's negative, then that many
instances of padChar
will be inserted to the right of the formatted size.
Converts this number to a Roman numeral. Only values between 1
and 3999, inclusive, are supported, otherwise an ArgumentError
is raised.
Converts this number to a Roman numeral. Only values between 1
and 3999, inclusive, are supported, otherwise this returns nil
.