type
Int
src
@Serializable { simple=true }
const class Int : Num
Int is used to represent a signed 64-bit integer.
constructors
fromStr |
Parse a Str into a Int using the specified radix. |
---|
fields
defVal |
Default value is zero. |
---|---|
maxVal |
Maximum value which can be stored in a signed 64-bit Int: 9,223,372,036,854,775,807 |
minVal |
Minimum value which can be stored in a signed 64-bit Int: -9,223,372,036,854,775,808 |
methods
abs |
Return the absolute value of this integer. |
---|---|
and |
Bitwise-and of this and b. |
clamp |
Clamp this integer between the min and max. |
compare |
Compare based on integer value. |
decrement |
Decrement by one. |
div |
Divide this by b. |
divDecimal |
Divide this by b. |
divFloat |
Divide this by b. |
equals |
Return true if same integer value. |
equalsIgnoreCase |
Return if the two Unicode chars are equal without regard to ASCII case. |
fromDigit |
Convert a Unicode digit character into a number for the specified radix. |
hash |
Return this. |
increment |
Increment by one. |
isAlpha |
Return if this Unicode char is an ASCII alpha char: isUpper||isLower |
isAlphaNum |
Return if this Unicode char is an ASCII alpha-numeric char: isAlpha||isDigit |
isDigit |
Return if this Unicode char is a digit in the specified radix. |
isEven |
Return if this integer is evenly divisible by two. |
isLower |
Return if this Unicode char is an ASCII lowercase alphabetic char: a-z |
isOdd |
Return if this integer is not evenly divisible by two. |
isSpace |
Return if this Unicode char is whitespace: space \t \n \r \f |
isUpper |
Return if this Unicode char is an ASCII uppercase alphabetic char: A-Z |
localeIsLower |
Return if this Unicode char is a lowercase letter in the current locale. |
localeIsUpper |
Return if this Unicode char is an uppercase letter in the current locale. |
localeLower |
If this Unicode char is an uppercase char, then return it as lowercase according to the current locale. |
localeUpper |
If this Unicode char is a lowercase char, then return it as uppercase according to the current locale. |
lower |
If this Unicode char is an ASCII uppercase char, then return it as lowercase, otherwise return this. |
max |
Return the larger of this and the specified Int values. |
min |
Return the smaller of this and the specified Int values. |
minus |
Subtract b from this. |
minusDecimal |
Subtract b from this. |
minusFloat |
Subtract b from this. |
mod |
Return remainder of this divided by b. |
modDecimal |
Return remainder of this divided by b. |
modFloat |
Return remainder of this divided by b. |
mult |
Multiply this with b. |
multDecimal |
Multiply this with b. |
multFloat |
Multiply this with b. |
negate |
Negative of this. |
not |
Bitwise not/inverse of this. |
or |
Bitwise-or of this and b. |
plus |
Add this with b. |
plusDecimal |
Add this with b. |
plusFloat |
Add this with b. |
pow |
Return this value raised to the specified power. |
random |
Generate a random number. |
shifta |
Bitwise arithmetic right-shift of this by b. |
shiftl |
Bitwise left shift of this by b. |
shiftr |
Bitwise right shift of this by b. |
times |
Call the specified function to this times passing the current counter. |
toChar |
Map as a Unicode code point to a single character Str. |
toCode |
Get this Int as a Fantom code literal. |
toDateTime |
Convert nano-seconds ticks since 1-Jan-2000 to a DateTime. |
toDigit |
Convert this number into a Unicode char |
toDuration |
Convert nano-seconds ticks to a Duration. |
toHex |
Return hexdecimal string representation. |
toLocale |
Format this integer number for the current locale. |
toRadix |
Return string representation in given radix. |
toStr |
Return decimal string representation. |
upper |
If this Unicode char is an ASCII lowercase char, then return it as uppercase, otherwise return this. |
xor |
Bitwise-exclusive-or of this and b. |
Slot Details
abs
and
clamp
compare
decrement
defVal
div
divDecimal
divFloat
equals
equalsIgnoreCase
fromDigit
fromStr
hash
increment
isAlpha
isAlphaNum
isDigit
isEven
isLower
isOdd
isSpace
isUpper
localeIsLower
Return if this Unicode char is a lowercase letter in the current locale. See also localeIsUpper
and isLower
.
localeIsUpper
Return if this Unicode char is an uppercase letter in the current locale. See also localeIsLower
and isUpper
.
localeLower
If this Unicode char is an uppercase char, then return it as lowercase according to the current locale. Note that Unicode contains some case conversion rules that don't work correctly on a single character, so Str.localeLower
should be preferred. See also localeUpper
and lower
.
localeUpper
If this Unicode char is a lowercase char, then return it as uppercase according to the current locale. Note that Unicode contains some case conversion rules that don't work correctly on a single character, so Str.localeUpper
should be preferred. See also localeLower
and upper
.
lower
max
maxVal
min
minVal
minus
minusDecimal
minusFloat
mod
modDecimal
modFloat
mult
multDecimal
multFloat
negate
not
or
plus
plusDecimal
plusFloat
pow
random
src
static Int random(Range? r := null)
Generate a random number. If range is null then all 2^64 integer values (both negative and positive) are produced with equal probability. If range is non-null, then the result is guaranteed to be inclusive of the range. Also see Float.random
, Range.random
, List.random
, and Random
.
Examples:
r := Int.random r := Int.random(0..100)
shifta
shiftl
shiftr
times
Call the specified function to this times passing the current counter. The counter begins at zero. Also see Range.each
.
Example:
3.times |i| { echo(i) } => 0, 1, 2
toChar
toCode
toDateTime
src
DateTime toDateTime(TimeZone tz := TimeZone.cur())
Convert nano-seconds ticks since 1-Jan-2000 to a DateTime. Convenience for DateTime.makeTicks
.
toDigit
src
Int? toDigit(Int radix := 10)
Convert this number into a Unicode char 0
-'9'. If radix is greater than 10, then use a lower case letter. Return null if this number cannot be represented as a single digit character for the specified radix.
Example:
3.toDigit => '3' 15.toDigit(16) => 'f' 99.toDigit => null
toDuration
Convert nano-seconds ticks to a Duration. Convenience for Duration.make
.
toHex
toLocale
src
Str toLocale(Str? pattern := null, Locale locale := Locale.cur())
Format this integer number for the current locale. If pattern is null, then the locale's default pattern is used. See Float.toLocale
for pattern language. Fractional formatting is not supported for integers.
In addition Int.toLocale
supports the "B" pattern which will format a number of bytes with the appropriate B, KB, MB, GB suffix based on the magnitude (1024B == 1KB).
Examples:
3.toLocale("00") => 03 3.toLocale("000") => 003 123456789.toLocale("#,###") => 123,456,789 123.toLocale("B") => 123B 1234.toLocale("B") => 1.2KB 100_000.toLocale("B") => 98KB (3*1024*1024).toLocale("B") => 3MB