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 0-'9'.

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

src Int abs()

Return the absolute value of this integer. If this value is positive then return this, otherwise return the negation.

and

src Int and(Int b)

Bitwise-and of this and b.

clamp

src Int clamp(Int min, Int max)

Clamp this integer between the min and max. If it's less than min then return min, if it's greater than max return max, otherwise return this integer itself.

compare

src virtual override Int compare(Obj obj)

Compare based on integer value.

decrement

src @Operator
Int decrement()

Decrement by one. Shortcut is --a or a--.

defVal

src const static Int defVal

Default value is zero.

div

src @Operator
Int div(Int b)

Divide this by b. Shortcut is a/b.

divDecimal

src @Operator
Decimal divDecimal(Decimal b)

Divide this by b. Shortcut is a/b.

divFloat

src @Operator
Float divFloat(Float b)

Divide this by b. Shortcut is a/b.

equals

src virtual override Bool equals(Obj? obj)

Return true if same integer value.

equalsIgnoreCase

src Bool equalsIgnoreCase(Int ch)

Return if the two Unicode chars are equal without regard to ASCII case.

fromDigit

src Int? fromDigit(Int radix := 10)

Convert a Unicode digit character into a number for the specified radix. Return null if this char is not a valid digit.

Example:

'3'.fromDigit     => 3
'f'.fromDigit(16) => 15
'%'.fromDigit     => null

fromStr

src static new fromStr(Str s, Int radix := 10, Bool checked := true)

Parse a Str into a Int using the specified radix. Unless the radix is 10, then a leading minus sign is illegal. If invalid format and checked is false return null, otherwise throw ParseErr.

hash

src virtual override Int hash()

Return this.

increment

src @Operator
Int increment()

Increment by one. Shortcut is ++a or a++.

isAlpha

src Bool isAlpha()

Return if this Unicode char is an ASCII alpha char: isUpper||isLower

isAlphaNum

src Bool isAlphaNum()

Return if this Unicode char is an ASCII alpha-numeric char: isAlpha||isDigit

isDigit

src Bool isDigit(Int radix := 10)

Return if this Unicode char is a digit in the specified radix. A decimal radix of ten returns true for 0-9. A radix of 16 also returns true for a-f and A-F.

Example:

'3'.toDigit     => true
3.toDigit       => false
'B'.toDigit(16) => true

isEven

src Bool isEven()

Return if this integer is evenly divisible by two.

isLower

src Bool isLower()

Return if this Unicode char is an ASCII lowercase alphabetic char: a-z

isOdd

src Bool isOdd()

Return if this integer is not evenly divisible by two.

isSpace

src Bool isSpace()

Return if this Unicode char is whitespace: space \t \n \r \f

isUpper

src Bool isUpper()

Return if this Unicode char is an ASCII uppercase alphabetic char: A-Z

localeIsLower

src Bool localeIsLower()

Return if this Unicode char is a lowercase letter in the current locale. See also localeIsUpper and isLower.

localeIsUpper

src Bool localeIsUpper()

Return if this Unicode char is an uppercase letter in the current locale. See also localeIsLower and isUpper.

localeLower

src Int 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

src Int 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

src Int lower()

If this Unicode char is an ASCII uppercase char, then return it as lowercase, otherwise return this.

Example:

'A'.lower => 'a'
'h'.lower => 'h'

max

src Int max(Int that)

Return the larger of this and the specified Int values.

maxVal

src const static Int maxVal

Maximum value which can be stored in a signed 64-bit Int: 9,223,372,036,854,775,807

min

src Int min(Int that)

Return the smaller of this and the specified Int values.

minVal

src const static Int minVal

Minimum value which can be stored in a signed 64-bit Int: -9,223,372,036,854,775,808

minus

src @Operator
Int minus(Int b)

Subtract b from this. Shortcut is a-b.

minusDecimal

src @Operator
Decimal minusDecimal(Decimal b)

Subtract b from this. Shortcut is a-b.

minusFloat

src @Operator
Float minusFloat(Float b)

Subtract b from this. Shortcut is a-b.

mod

src @Operator
Int mod(Int b)

Return remainder of this divided by b. Shortcut is a%b.

modDecimal

src @Operator
Decimal modDecimal(Decimal b)

Return remainder of this divided by b. Shortcut is a%b.

modFloat

src @Operator
Float modFloat(Float b)

Return remainder of this divided by b. Shortcut is a%b.

mult

src @Operator
Int mult(Int b)

Multiply this with b. Shortcut is a*b.

multDecimal

src @Operator
Decimal multDecimal(Decimal b)

Multiply this with b. Shortcut is a*b.

multFloat

src @Operator
Float multFloat(Float b)

Multiply this with b. Shortcut is a*b.

negate

src @Operator
Int negate()

Negative of this. Shortcut is -a.

not

src Int not()

Bitwise not/inverse of this.

or

src Int or(Int b)

Bitwise-or of this and b.

plus

src @Operator
Int plus(Int b)

Add this with b. Shortcut is a+b.

plusDecimal

src @Operator
Decimal plusDecimal(Decimal b)

Add this with b. Shortcut is a+b.

plusFloat

src @Operator
Float plusFloat(Float b)

Add this with b. Shortcut is a+b.

pow

src Int pow(Int pow)

Return this value raised to the specified power. Throw ArgErr if pow is less than zero.

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

src Int shifta(Int b)

Bitwise arithmetic right-shift of this by b. The left-most bit is shifted into the highest bits performing like a signed shift. This is equivalent to the Java >> operator.

shiftl

src Int shiftl(Int b)

Bitwise left shift of this by b.

shiftr

src Int shiftr(Int b)

Bitwise right shift of this by b. Zero is shifted into the highest bits performing like an unsigned shift. This is equivalent to the Java >>> operator.

times

src Void times(|Int| c)

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

src Str toChar()

Map as a Unicode code point to a single character Str.

toCode

src Str toCode(Int base := 10)

Get this Int as a Fantom code literal. Base must be 10 or 16.

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

src Duration toDuration()

Convert nano-seconds ticks to a Duration. Convenience for Duration.make.

toHex

src Str toHex(Int? width := null)

Return hexdecimal string representation. If width is non-null, then leading zeros are prepended to ensure the specified number of nibble characters.

Examples:

255.toHex     =>  "ff"
255.toHex(4)  =>  "00ff"

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

toRadix

src Str toRadix(Int radix, Int? width := null)

Return string representation in given radix. If width is non-null, then leading zeros are prepended to ensure the specified width.

Examples:

255.toRadix(8)    =>  "377"
255.toRadix(8, 5) =>  "00377"

toStr

src virtual override Str toStr()

Return decimal string representation.

upper

src Int upper()

If this Unicode char is an ASCII lowercase char, then return it as uppercase, otherwise return this.

Example:

'a'.upper => 'A'
'4'.upper => '4'

xor

src Int xor(Int b)

Bitwise-exclusive-or of this and b.