An Int number is a 64-bit signed integer.

Static Methods

LOWEST

Minimum value of Int.

IO.println(Int.LOWEST) #> -9223372036854775808

See also: MIN

MAX

Maximum value of Int.

IO.println(Int.MAX) #> 9223372036854775807

See also: MIN

MIN

Minimum value of Int.

IO.println(Int.MIN) #> -9223372036854775808

See also: MAX, LOWEST

Methods

clone()

Get a copy of the integer.

IO.println(42.clone()) #> 42

hash

Compute a hash for the integer.

IO.println(42.hash) #> -4767286540954276203

to_c

Transform the integer to a Char.

IO.println(42.to_c) #> *
IO.println(26408.to_c) #> 木

to_f

Transform the integer to a Float.

IO.println(42.to_f == 42.0) #> true

to_s

Transform the integer to a String.

IO.println(42.to_s == "42") #> true

Operators

+, - operators

Unary + return the integer itself. Unary - return the opposite of the integer.

IO.println(+42) #> 42
IO.println(-42) #> -42

~ operator

Return the bitwise complement of the integer.

IO.println(~0) #> -1
IO.println(~1) #> -2
IO.println(~Int.MIN == Int.MAX) #> true

+(other), -(other), *(other), /(other) operators

Compute binary operation using usual arithmetic operators on integers. other must be an Int or a Float. There is an implicit conversion from Float and, in this case, the result is a Float.

IO.println(42 + 69) #> 111
IO.println(42 - 69) #> -27
IO.println(42 * 69) #> 2898
IO.println(42 / 69) #> 0

%(other) operator

Compute the modulo operation and returns the remainder of the division of this by other. There is an implicit conversion from Float and, in this case, the result is a Float.

IO.println(69 % 42)   #> 27
IO.println(-69 % 42)  #> -27
IO.println(69 % -42)  #> 27
IO.println(-69 % -42) #> -27

&(other) operator

Return the bitwise AND between this and other. other must be an Int.

IO.println(0b0101 & 0b0011 == 0b0001) #> true

|(other) operator

Return the bitwise OR between this and other. other must be an Int.

IO.println(0b0101 | 0b0011 == 0b0111) #> true

^(other) operator

Return the bitwise XOR between this and other. other must be an Int.

IO.println(0b0101 ^ 0b0011 == 0b0110) #> true

<<(other) operator

Return the arithmetic left shift of this. other must be a non-negative integer. The number of bits of the shift is other % 0x3F.

IO.println(1 << 2)  #> 4
IO.println(-1 << 2) #> -4
IO.println(0b10101 << 3 == 0b10101000) #> true

>>(other) operator

Return the arithmetic right shift of this. other must be a non-negative integer. The number of bits of the shift is other % 0x3F.

IO.println(8 >> 2)  #> 2
IO.println(-8 >> 2) #> -2
IO.println(0b10101000 >> 3 == 0b10101) #> true

>>>(other) operator

Return the logical right shift of this. other must be a non-negative integer. The number of bits of the shift is other % 0x3F.

IO.println(8 >>> 2)  #> 2
IO.println(-8 >>> 2) #> 4611686018427387902
IO.println(0b10101000 >>> 3 == 0b10101) #> true

<(other), <=(other), >(other), >=(other) operators

Compare the integer with other. other must be an Int, there is no implicit conversion from Float.

IO.println(42 < 69)  #> true
IO.println(42 <= 69) #> true
IO.println(42 > 69)  #> false
IO.println(42 >= 69) #> false

..(other) operator

Create an inclusive Range between this and other.

def r = 42..69
IO.println(r.min) #> 42
IO.println(r.max) #> 69
IO.println(r.inclusive) #> true

…​(other) operator

Create an exclusive Range between this (included) and other (excluded).

def r = 42...69
IO.println(r.min) #> 42
IO.println(r.max) #> 69
IO.println(r.inclusive) #> false

See also: ..(other) operator