[−][src]Struct num256::int256::Int256

pub struct Int256(pub BigInt);

Methods

impl Int256[src]

pub fn to_uint256(&self) -> Option<Uint256>[src]

Checked conversion to Uint256

Methods from Deref<Target = BigInt>

pub fn to_bytes_be(&self) -> (Sign, Vec<u8>)[src]

Returns the sign and the byte representation of the BigInt in big-endian byte order.

Examples

use num_bigint::{ToBigInt, Sign};

let i = -1125.to_bigint().unwrap();
assert_eq!(i.to_bytes_be(), (Sign::Minus, vec![4, 101]));

pub fn to_bytes_le(&self) -> (Sign, Vec<u8>)[src]

Returns the sign and the byte representation of the BigInt in little-endian byte order.

Examples

use num_bigint::{ToBigInt, Sign};

let i = -1125.to_bigint().unwrap();
assert_eq!(i.to_bytes_le(), (Sign::Minus, vec![101, 4]));

pub fn to_signed_bytes_be(&self) -> Vec<u8>[src]

Returns the two's complement byte representation of the BigInt in big-endian byte order.

Examples

use num_bigint::ToBigInt;

let i = -1125.to_bigint().unwrap();
assert_eq!(i.to_signed_bytes_be(), vec![251, 155]);

pub fn to_signed_bytes_le(&self) -> Vec<u8>[src]

Returns the two's complement byte representation of the BigInt in little-endian byte order.

Examples

use num_bigint::ToBigInt;

let i = -1125.to_bigint().unwrap();
assert_eq!(i.to_signed_bytes_le(), vec![155, 251]);

pub fn to_str_radix(&self, radix: u32) -> String[src]

Returns the integer formatted as a string in the given radix. radix must be in the range 2...36.

Examples

use num_bigint::BigInt;

let i = BigInt::parse_bytes(b"ff", 16).unwrap();

pub fn to_radix_be(&self, radix: u32) -> (Sign, Vec<u8>)[src]

Returns the integer in the requested base in big-endian digit order. The output is not given in a human readable alphabet but as a zero based u8 number. radix must be in the range 2...256.

Examples

use num_bigint::{BigInt, Sign};

(Sign::Minus, vec![2, 94, 27]));
// 0xFFFF = 65535 = 2*(159^2) + 94*159 + 27

pub fn to_radix_le(&self, radix: u32) -> (Sign, Vec<u8>)[src]

Returns the integer in the requested base in little-endian digit order. The output is not given in a human readable alphabet but as a zero based u8 number. radix must be in the range 2...256.

Examples

use num_bigint::{BigInt, Sign};

(Sign::Minus, vec![27, 94, 2]));
// 0xFFFF = 65535 = 27 + 94*159 + 2*(159^2)

pub fn sign(&self) -> Sign[src]

Returns the sign of the BigInt as a Sign.

Examples

use num_bigint::{ToBigInt, Sign};

assert_eq!(ToBigInt::to_bigint(&1234).unwrap().sign(), Sign::Plus);
assert_eq!(ToBigInt::to_bigint(&-4321).unwrap().sign(), Sign::Minus);
assert_eq!(ToBigInt::to_bigint(&0).unwrap().sign(), Sign::NoSign);

pub fn bits(&self) -> usize[src]

Determines the fewest bits necessary to express the BigInt, not including the sign.

pub fn to_biguint(&self) -> Option<BigUint>[src]

Converts this BigInt into a BigUint, if it's not negative.

pub fn modpow(&self, exponent: &BigInt, modulus: &BigInt) -> BigInt[src]

Returns (self ^ exponent) mod modulus

Note that this rounds like mod_floor, not like the % operator, which makes a difference when given a negative self or modulus. The result will be in the interval [0, modulus) for modulus > 0, or in the interval (modulus, 0] for modulus < 0

Panics if the exponent is negative or the modulus is zero.

pub fn sqrt(&self) -> BigInt[src]

Returns the truncated principal square root of self -- see Roots::sqrt.

pub fn cbrt(&self) -> BigInt[src]

Returns the truncated principal cube root of self -- see Roots::cbrt.

pub fn nth_root(&self, n: u32) -> BigInt[src]

Returns the truncated principal nth root of self -- See Roots::nth_root.

Trait Implementations

impl Clone for Int256[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Ord for Int256[src]

fn max(self, other: Self) -> Self1.21.0[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self1.21.0[src]

Compares and returns the minimum of two values. Read more

impl Add<Int256> for Int256[src]

type Output = Int256

The resulting type after applying the + operator.

impl Sub<Int256> for Int256[src]

type Output = Int256

The resulting type after applying the - operator.

impl Mul<Int256> for Int256[src]

type Output = Int256

The resulting type after applying the * operator.

impl Div<Int256> for Int256[src]

type Output = Int256

The resulting type after applying the / operator.

impl Neg for Int256[src]

type Output = Int256

The resulting type after applying the - operator.

impl Deref for Int256[src]

type Target = BigInt

The resulting type after dereferencing.

impl Hash for Int256[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where    H: Hasher, 1.3.0[src]

Feeds a slice of this type into the given [Hasher]. Read more

Blanket Implementations

impl<T, U> TryFrom for T where    T: From<U>, [src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T, U> TryInto for T where    U: TryFrom<T>, [src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.