pub struct I64 {
    /// The underlying unsigned number representing the `I64` type.
    underlying: u64,
}
Expand description

The 64-bit signed integer type.

Additional Information

Represented as an underlying u64 value.
Actual value is underlying value minus 2 ^ 63
Max value is 2 ^ 63 - 1, min value is - 2 ^ 63

Fields

underlying: u64

The underlying unsigned number representing the I64 type.

Implementations

fn indent() -> u64

The underlying value that corresponds to zero value.

Returns

  • [u64] - The unsigned integer value representing a zero value.

Examples

use sway_libs::signed_integers::i64::I64;

fn foo() {
    let zero = I64::indent();
    assert(zero == 9223372036854775808u64);
}

fn bits() -> u64

The size of this type in bits.

Returns

[u64] - The defined size of the I64 type.

Examples

``sway
use sway_libs::signed_integers::i64::I64;

fn foo() {
let bits = I64::bits();
assert(bits == 64);
}

fn from_uint(underlying: u64) -> Self

Helper function to get a signed number from with an underlying.

Arguments

  • underlying: [u64] - The unsigned number to become the underlying value for the I64.

Returns

  • [I64] - The newly created I64 struct.

Examples

use sway_libs::signed_integers::i64::I64;

fn foo() {
    let underlying = 1u64;
    let i64 = I64::from_uint(underlying);
    assert(i64.underlying() == underlying);
}

fn max() -> Self

The largest value that can be represented by this integer type.

Returns

  • [I64] - The newly created I64 struct.

Examples

use sway_libs::signed_integers::i64::I64;

fn foo() {
    let i64 = I64::max();
    assert(i64.underlying() == u64::max());
}

fn min() -> Self

The smallest value that can be represented by this integer type.

Returns

  • [I64] - The newly created I64 type.

Examples

use sway_libs::signed_integers::i64::I64;

fn foo() {
    let i64 = I64::min();
    assert(i64.underlying() == u64::min());
}

fn neg_try_from(value: u64) -> Option<Self>

Helper function to get a negative value of an unsigned number.

Arguments

  • value: [u64] - The unsigned number to negate.

Returns

  • [Option] - The newly created I64 struct.

Examples

use sway_libs::signed_integers::i64::I64;

fn foo() {
    let underlying = 1u64;
    let i64 = I64::neg_try_from(underlying).unwrap();
    assert(i64.underlying() == 9223372036854775807u64);
}

fn new() -> Self

Initializes a new, zeroed I64.

Additional Information

The zero value of I64 is 9223372036854775808.

Returns

  • [I64] - The newly created I64 struct.

Examples

use sway_libs::signed_integers::i64::I64;

fn foo() {
    let i64 = I64::new();
    assert(i64.underlying() == 9223372036854775808);
}

fn zero() -> Self

The zero value I64.

Returns

  • [I64] - The newly created I64 type.

Examples

use sway_libs::signed_integers::i64::I64;

fn foo() {
    let i64 = I64::zero();
    assert(i64.underlying() == 9223372036854775808);
}

fn is_zero(self) -> bool

Returns whether a I64 is set to zero.

Returns

  • [bool] -> True if the I64 is zero, otherwise false.

Examples

use sway_libs::signed_integers::i64::I64;

fn foo() {
    let i64 = I64::zero();
    assert(i64.is_zero());
}

fn underlying(self) -> u64

Returns the underlying u64 representing the I64.

Returns

  • [u64] - The u64 representing the I64.

Examples

use sway_libs::signed_integers::i64::I64;

fn foo() {
    let i64 = I64::zero();
    assert(i64.underlying() == 9223372036854775808);
}

Trait Implementations

fn eq(self, other: Self) -> bool

fn neq(self, other: Self) -> bool

Evaluates if two values of the same type are not equal.

Additional Information

This function is inherited when eq() is implemented.

Arguments

  • other: [Self] - The value of the same type.

Returns

  • [bool] - true if the two values are not equal, otherwise false.

Examples

struct MyStruct {
    val: u64,
}

impl Eq for MyStruct {
    fn eq(self, other: Self) -> bool {
         self.val == other.val
    }
}

fn foo() {
    let struct1 = MyStruct { val: 10 };
    let struct2 = MyStruct { val: 2 };
    let result = struct1 != struct2;
    assert(result);
}

fn gt(self, other: Self) -> bool

fn lt(self, other: Self) -> bool

fn ge(self, other: Self) -> bool

Evaluates if one value of the same type is greater or equal to than another.

Additional Information

This trait requires that the Ord and Eq traits are implemented.

Arguments

  • other: [Self] - The value of the same type.

Returns

  • [bool] - true if self is greater than or equal to other, otherwise false.

Examples

struct MyStruct {
    val: u64,
}

impl Eq for MyStruct {
    fn eq(self, other: Self) -> bool {
        self.val == other.val
    }
}

impl Ord for MyStruct {
    fn gt(self, other: Self) -> bool {
        self.val > other.val
    }
}

impl OrdEq for MyStruct {}

fn foo() {
    let struct1 = MyStruct { val: 10 };
    let struct2 = MyStruct { val: 10 };
    let result = struct1 >= struct2;
    assert(result);
}

fn le(self, other: Self) -> bool

Evaluates if one value of the same type is less or equal to than another.

Additional Information

This trait requires that the Ord and Eq traits are implemented.

Arguments

  • other: [Self] - The value of the same type.

Returns

  • [bool] - true if self is less than or equal to other, otherwise false.

Examples

struct MyStruct {
    val: u64,
}

impl Eq for MyStruct {
    fn eq(self, other: Self) -> bool {
        self.val == other.val
    }
}

impl Ord for MyStruct {
    fn lt(self, other: Self) -> bool {
        self.val < other.val
    }
}

impl OrdEq for MyStruct {}

fn foo() {
    let struct1 = MyStruct { val: 10 };
    let struct2 = MyStruct { val: 10 };
    let result = struct1 <= struct2;
    assert(result);
}

fn add(self, other: Self) -> Self

Add a I64 to a I64. Panics on overflow.

fn subtract(self, other: Self) -> Self

Subtract a I64 from a I64. Panics of overflow.

fn multiply(self, other: Self) -> Self

Multiply a I64 with a I64. Panics of overflow.

fn divide(self, divisor: Self) -> Self

Divide a I64 by a I64. Panics if divisor is zero.

fn wrapping_neg(self) -> Self

fn try_from(value: u64) -> Option<Self>