Using bigger integers

The i128_type feature gives us the i128 and u128 integers, which work the same way as i64 and u64 types, but with 128 bits instead of 64, which gives them more capacity. They have the same API as the rest of the integers, so you can perform the same kind of operations. Sometimes it's great to have a bigger, full-precision integer and, in this case, since it uses LLVM intrinsics, the type is almost as lightweight as a u64 or i64 (more or less double the processing time in a 64-bit machine; it should be around the same in a 128-bit machine). A simple example is given in the main documentation:

#![feature(i128_type)]

fn main() {
assert_eq!(1u128 + 1u128, 2u128);
assert_eq!(u128::min_value(), 0);
assert_eq!(u128::max_value(),
340282366920938463463374607431768211455);

assert_eq!(1i128 - 2i128, -1i128);
assert_eq!(i128::min_value(),
-170141183460469231731687303715884105728);
assert_eq!(i128::max_value(),
170141183460469231731687303715884105727);
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.134.198