Int¶
An Int is a whole number: a signed 64-bit integer. Use it for counts,
positions, page numbers and years. A number written without a decimal point
is an Int, and arithmetic on two Int operands gives an Int.
2 + 3 * 4
14
* and / bind tighter than + and -. Division truncates towards zero,
and % is the remainder:
[7 / 2, -7 / 2, 7 % 3]
[3, -3, 1]
An Int that leaves the 64-bit range is an error, never a wrapped value:
9223372036854775807 + 1
execute failure[numeric-overflow]: numeric overflow
--> <expression>:1:1
|
1 | 9223372036854775807 + 1
| ^^^^^^^^^^^^^^^^^^^^^^^
The math module adds what operators do not cover:
[2.pow(10), (-5).abs(), (-5).sign()]
[1024, 5, -1]
An Int is Orderable, so <, >, min, max and sort work on it. It
compares with another Int or with a Decimal, and with no other
type. float converts it to a Float, and str to a
String.