Type std::u64

Overview

The unsigned integer type.

Methods

fn to<f64>(self) -> f64

Converts an u64 to a f64.

Examples

assert!(10u64.to::<f64>() is f64);
fn pow(self, pow: u64) -> u64

Raises self to the power of exp, using exponentiation by squaring.

Overflow behavior

This function will wrap on overflow.

Examples

Basic usage:

let x = 2;

assert_eq!(x.pow(5), 32);
fn checked_add(self, rhs: u64) -> Option

Checked integer addition. Computes self + rhs, returning None if overflow occurred.

Examples

Basic usage:

assert_eq!((u64::MAX - 2).checked_add(1), Some(u64::MAX - 1));
assert_eq!((u64::MAX - 2).checked_add(3), None);
fn checked_sub(self, rhs: u64) -> Option

Checked integer subtraction. Computes self - rhs, returning None if overflow occurred.

Examples

Basic usage:

assert_eq!((u64::MIN + 2).checked_sub(1), Some(u64::MIN + 1));
assert_eq!((u64::MIN + 2).checked_sub(3), None);
fn checked_div(self, rhs: u64) -> Option

Checked integer division. Computes self / rhs, returning None if rhs == 0 or the division results in overflow.

Examples

Basic usage:

assert_eq!(128u64.checked_div(2), Some(64));
assert_eq!(1u64.checked_div(0), None);
fn checked_mul(self, rhs: u64) -> Option

Checked integer multiplication. Computes self * rhs, returning None if overflow occurred.

Examples

Basic usage:

assert_eq!(u64::MAX.checked_mul(1), Some(u64::MAX));
assert_eq!(u64::MAX.checked_mul(2), None);
fn checked_rem(self, rhs: u64) -> Option

Checked integer remainder. Computes self % rhs, returning None if rhs == 0 or the division results in overflow.

Examples

Basic usage:

assert_eq!(5u64.checked_rem(2), Some(1));
assert_eq!(5u64.checked_rem(0), None);
fn wrapping_add(self, rhs: u64) -> u64

Wrapping (modular) addition. Computes self + rhs, wrapping around at the boundary of the type.

Examples

Basic usage:

assert_eq!(100u64.wrapping_add(27), 127u64);
assert_eq!(u64::MAX.wrapping_add(2), u64::MIN + 1);
fn wrapping_sub(self, rhs: u64) -> u64

Wrapping (modular) subtraction. Computes self - rhs, wrapping around at the boundary of the type.

Examples

Basic usage:

assert_eq!(200u64.wrapping_add(55), 255);
assert_eq!(200u64.wrapping_add(u64::MAX), 199);
fn wrapping_div(self, rhs: u64) -> u64

Wrapping (modular) division. Computes self / rhs, wrapping around at the boundary of the type.

The only case where such wrapping can occur is when one divides MIN / -1 on a signed type (where MIN is the negative minimal value for the type); this is equivalent to -MIN, a positive value that is too large to represent in the type. In such a case, this function returns MIN itself.

Panics

This function will panic if rhs is 0.

Examples

Basic usage:

assert_eq!(100u64.wrapping_div(10), 10u64);
fn wrapping_mul(self, rhs: u64) -> u64

Wrapping (modular) multiplication. Computes self * rhs, wrapping around at the boundary of the type.

Examples

Basic usage:

assert_eq!(10u64.wrapping_mul(12), 120u64);
fn wrapping_rem(self, rhs: u64) -> u64

Wrapping (modular) remainder. Computes self % rhs, wrapping around at the boundary of the type.

Such wrap-around never actually occurs mathematically; implementation artifacts make x % y invalid for MIN / -1 on a signed type (where MIN is the negative minimal value). In such a case, this function returns 0.

Panics

This function will panic if rhs is 0.

Examples

Basic usage:

assert_eq!(100u64.wrapping_rem(10), 0);
fn saturating_add(self, rhs: u64) -> u64

Saturating integer addition. Computes self + rhs, saturating at the numeric bounds instead of overflowing.

Examples

Basic usage:

assert_eq!(100u64.saturating_add(1), 101);
assert_eq!(u64::MAX.saturating_add(127), u64::MAX);
fn saturating_sub(self, rhs: u64) -> u64

Saturating integer subtraction. Computes self - rhs, saturating at the numeric bounds instead of overflowing.

Examples

Basic usage:

assert_eq!(100u64.saturating_sub(27), 73);
assert_eq!(13u64.saturating_sub(127), 0);
fn saturating_mul(self, rhs: u64) -> u64

Saturating integer multiplication. Computes self * rhs, saturating at the numeric bounds instead of overflowing.

Examples

Basic usage:

assert_eq!(10u64.saturating_mul(12), 120);
assert_eq!(u64::MAX.saturating_mul(10), u64::MAX);
assert_eq!(u64::MIN.saturating_mul(10), u64::MIN);
fn saturating_pow(self, rhs: u64) -> u64

Saturating integer exponentiation. Computes self.pow(exp), saturating at the numeric bounds instead of overflowing.

Examples

Basic usage:

assert_eq!(4u64.saturating_pow(3), 64);
assert_eq!(u64::MAX.saturating_pow(2), u64::MAX);

Returns the number as a string.

Examples

Basic usage:

assert_eq!(10u64.to_string(), "10");

Trait Implementations

impl Clone for u64
fn clone(value: any) -> any

Clone the specified value.

Examples

let a = 42;
let b = a;
let c = a.clone();

a += 1;

assert_eq!(a, 43);
assert_eq!(b, 42);
assert_eq!(c, 42);
impl PartialEq for u64
fn eq(value: any, value1: any) -> bool

Compare two values for equality.

Examples

assert_eq!(1.eq(2), false);
assert_eq!(2.eq(2), true);
assert_eq!(2.eq(1), false);
fn ne(value: any, value1: any) -> bool

Compare two values for inequality.

Examples

assert_eq!(1.ne(2), true);
assert_eq!(2.ne(2), false);
assert_eq!(2.ne(1), true);
impl Eq for u64
impl PartialOrd for u64
fn partial_cmp(value: any, value1: any) -> Option

Compare two values.

Examples

use std::cmp::Ordering;

assert_eq!(1.partial_cmp(2), Some(Ordering::Less));
assert_eq!(2.partial_cmp(2), Some(Ordering::Equal));
assert_eq!(2.partial_cmp(1), Some(Ordering::Greater));
fn lt(value: any, value1: any) -> bool

Tests less than (for self and other) and is used by the < operator.

Examples

assert_eq!(1.0 < 1.0, false);
assert_eq!(1.0 < 2.0, true);
assert_eq!(2.0 < 1.0, false);
fn le(value: any, value1: any) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator.

Examples

assert_eq!(1.0 <= 1.0, true);
assert_eq!(1.0 <= 2.0, true);
assert_eq!(2.0 <= 1.0, false);
fn gt(value: any, value1: any) -> bool

Tests greater than (for self and other) and is used by the > operator.

Examples

assert_eq!(1.0 > 1.0, false);
assert_eq!(1.0 > 2.0, false);
assert_eq!(2.0 > 1.0, true);
fn ge(value: any, value1: any) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator.

Examples

assert_eq!(1.0 >= 1.0, true);
assert_eq!(1.0 >= 2.0, false);
assert_eq!(2.0 >= 1.0, true);
impl Ord for u64
fn cmp(value: any, value1: any) -> Ordering

Compare two values.

Examples

use std::cmp::Ordering;

assert_eq!(1.cmp(2), Ordering::Less);
assert_eq!(2.cmp(2), Ordering::Equal);
assert_eq!(2.cmp(1), Ordering::Greater);
fn min(value: any, value1: any) -> Ordering

Return the minimum of two values.

Examples

assert_eq!(1.min(2), 1);
assert_eq!(2.min(2), 2);
assert_eq!(2.min(1), 1);
fn max(value: any, value1: any) -> Ordering

Return the maximum of two values.

Examples

assert_eq!(1.max(2), 2);
assert_eq!(2.max(2), 2);
assert_eq!(2.max(1), 2);

Protocols

protocol MAX
$a.max($b)

Compares and returns the maximum of two values.

Returns the second argument if the comparison determines them to be equal.

Examples

assert_eq!(1u64.max(2u64), 2u64);
assert_eq!(2u64.max(2u64), 2u64);
protocol MIN
$a.min($b)

Compares and returns the minimum of two values.

Returns the first argument if the comparison determines them to be equal.

Examples

assert_eq!(1u64.min(2u64), 1u64);
assert_eq!(2u64.min(2u64), 2u64);
protocol CLONE
let $out = clone(value)

Clone a u64.

Note that since the type is copy, cloning has the same effect as assigning it.

Examples

let a = 5u64;
let b = a;
let c = a.clone();

a += 1;

assert_eq!(a, 6);
assert_eq!(b, 5);
assert_eq!(c, 5);
protocol PARTIAL_EQ
if value == b { }

Test two integers for partial equality.

Examples

assert_eq!(5u64 == 5, true);
assert_eq!(5u64 == 10, false);
assert_eq!(10u64 == 5, false);
protocol EQ
if value == b { }

Test two integers for total equality.

Examples

use std::ops::eq;

assert_eq!(eq(5u64, 5u64), true);
assert_eq!(eq(5u64, 10u64), false);
assert_eq!(eq(10u64, 5u64), false);
protocol PARTIAL_CMP
if value < b { }

Perform a partial ordered comparison between two integers.

Examples

use std::cmp::Ordering;
use std::ops::partial_cmp;

assert_eq!(partial_cmp(5u64, 10u64), Some(Ordering::Less));
assert_eq!(partial_cmp(10u64, 5u64), Some(Ordering::Greater));
assert_eq!(partial_cmp(5u64, 5u64), Some(Ordering::Equal));
protocol CMP
if value < b { }

Perform a totally ordered comparison between two integers.

Examples

use std::cmp::Ordering;
use std::ops::cmp;

assert_eq!(cmp(5u64, 10u64), Ordering::Less);
assert_eq!(cmp(10u64, 5u64), Ordering::Greater);
assert_eq!(cmp(5u64, 5u64), Ordering::Equal);
protocol LT
if $a < $b { }

The protocol behind the < operator.

protocol LE
if $a <= $b { }

The protocol behind the <= operator.

protocol GT
if $a > $b { }

The protocol behind the > operator.

protocol GE
if $a >= $b { }

The protocol behind the >= operator.