An Int
number is a 64-bit signed integer.
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
See also: &(other) operator, |(other) operator, ^(other) operator
+(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
See also: +, - operators, %(other) operator
%(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
See also: ~ operator, |(other) operator, ^(other) operator
|(other) operator
Return the bitwise OR between this
and other
. other
must be an Int
.
IO.println(0b0101 | 0b0011 == 0b0111) #> true
See also: ~ operator, &(other) operator, ^(other) operator
^(other) operator
Return the bitwise XOR between this
and other
. other
must be an Int
.
IO.println(0b0101 ^ 0b0011 == 0b0110) #> true
See also: ~ operator, &(other) operator, |(other) operator
<<(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
See also: >>(other) operator, >>>(other) operator
>>(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
See also: <<(other) operator, >>>(other) operator
>>>(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
See also: >>(other) operator, <<(other) operator
<(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
See also: …(other) operator
…(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