Type std::i64

Overview

The signed integer type.

Methods

fn to<f64>(self) -> f64

Converts an i64 to a f64.

Examples

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

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: i64) -> Option

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

Examples

Basic usage:

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

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

Examples

Basic usage:

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

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

Examples

Basic usage:

assert_eq!((i64::MIN + 1).checked_div(-1), Some(i64::MAX));
assert_eq!(i64::MIN.checked_div(-1), None);
assert_eq!(1i64.checked_div(0), None);
fn checked_mul(self, rhs: i64) -> Option

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

Examples

Basic usage:

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

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

Examples

Basic usage:

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

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

Examples

Basic usage:

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

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

Examples

Basic usage:

assert_eq!(0.wrapping_sub(127), -127);
assert_eq!((-2i64).wrapping_sub(i64::MAX), i64::MAX);
fn wrapping_div(self, rhs: i64) -> i64

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!(100i64.wrapping_div(10), 10i64);
fn wrapping_mul(self, rhs: i64) -> i64

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

Examples

Basic usage:

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

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!(100i64.wrapping_rem(10), 0);
fn saturating_add(self, rhs: i64) -> i64

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

Examples

Basic usage:

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

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

Examples

Basic usage:

assert_eq!(100.saturating_sub(127), -27);
assert_eq!(i64::MIN.saturating_sub(100), i64::MIN);
assert_eq!(i64::MAX.saturating_sub(-1), i64::MAX);
fn saturating_mul(self, rhs: i64) -> i64

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

Examples

Basic usage:

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

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

Examples

Basic usage:

assert_eq!((-4).saturating_pow(3), -64);
assert_eq!(i64::MIN.saturating_pow(2), i64::MAX);
assert_eq!(i64::MIN.saturating_pow(3), i64::MIN);

Returns the number as a string.

Examples

Basic usage:

assert_eq!((-10i64).to_string(), "-10");
assert_eq!(10i64.to_string(), "10");
fn abs(self) -> i64

Computes the absolute value of self.

Overflow behavior

The absolute value of i64::MIN cannot be represented as an int, and attempting to calculate it will cause an overflow. This means that such code will wrap to i64::MIN without a panic.

Examples

Basic usage:

assert_eq!(10.abs(), 10);
assert_eq!((-10).abs(), 10);

Saturating absolute value. Computes self.abs(), returning MAX if self == MIN instead of overflowing.

Examples

Basic usage:

assert_eq!(100.saturating_abs(), 100);
assert_eq!((-100).saturating_abs(), 100);
assert_eq!(i64::MIN.saturating_abs(), i64::MAX);
assert_eq!((i64::MIN + 1).saturating_abs(), i64::MAX);
fn signum(self) -> i64

Returns a number representing sign of self.

  • 0 if the number is zero
  • 1 if the number is positive
  • -1 if the number is negative

Examples

Basic usage:

assert_eq!(10.signum(), 1);
assert_eq!(0.signum(), 0);
assert_eq!((-10).signum(), -1);

Returns true if self is positive and false if the number is zero or negative.

Examples

Basic usage:

assert!(10.is_positive());
assert!(!(-10).is_positive());

Returns true if self is negative and false if the number is zero or positive.

Examples

Basic usage:

assert!((-10).is_negative());
assert!(!10.is_negative());

Trait Implementations

impl Clone for i64
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 i64
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 i64
impl PartialOrd for i64
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 i64
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!(1i64.max(2i64), 2i64);
assert_eq!(2i64.max(2i64), 2i64);
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!(1i64.min(2i64), 1i64);
assert_eq!(2i64.min(2i64), 2i64);
protocol CLONE
let $out = clone(value)

Clone a i64.

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

Examples

let a = 5i64;
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!(5i64 == 5, true);
assert_eq!(5i64 == 10, false);
assert_eq!(10i64 == 5, false);
protocol EQ
if value == b { }

Test two integers for total equality.

Examples

use std::ops::eq;

assert_eq!(eq(5i64, 5i64), true);
assert_eq!(eq(5i64, 10i64), false);
assert_eq!(eq(10i64, 5i64), 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(5i64, 10i64), Some(Ordering::Less));
assert_eq!(partial_cmp(10i64, 5i64), Some(Ordering::Greater));
assert_eq!(partial_cmp(5i64, 5i64), 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(5i64, 10i64), Ordering::Less);
assert_eq!(cmp(10i64, 5i64), Ordering::Greater);
assert_eq!(cmp(5i64, 5i64), 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.