Integers
It is highly recommended to use integer types where possible, as they come with extra protection against potential vulnerabilities in the code, such as overflow checks.
Integer types include i8
, i16
, i32
, i64
, and i128
for signed integers and u8
, u16
, u32
, u64
, u128
, and u256
for unsigned integers, and may be annotated via a suffix.
Integer division is truncated down to the nearest integer.
Example
fn main() {
let a: u64 = 56; // Regular annotation
let b = 32_u64; // Suffix annotation
assert!(a / b == 1);
assert!(b / a == 0);
}
You can experiment with this example in cairovm.codes and read more about integers in the Cairo Book. |