pub struct Int256(pub BigInt);
Tuple Fields§
§0: BigInt
Implementations§
Methods from Deref<Target = BigInt>§
sourcepub fn to_bytes_be(&self) -> (Sign, Vec<u8, Global>)
pub fn to_bytes_be(&self) -> (Sign, Vec<u8, Global>)
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]));
sourcepub fn to_bytes_le(&self) -> (Sign, Vec<u8, Global>)
pub fn to_bytes_le(&self) -> (Sign, Vec<u8, Global>)
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]));
sourcepub fn to_u32_digits(&self) -> (Sign, Vec<u32, Global>)
pub fn to_u32_digits(&self) -> (Sign, Vec<u32, Global>)
Returns the sign and the u32
digits representation of the BigInt
ordered least
significant digit first.
Examples
use num_bigint::{BigInt, Sign};
assert_eq!(BigInt::from(-1125).to_u32_digits(), (Sign::Minus, vec![1125]));
assert_eq!(BigInt::from(4294967295u32).to_u32_digits(), (Sign::Plus, vec![4294967295]));
assert_eq!(BigInt::from(4294967296u64).to_u32_digits(), (Sign::Plus, vec![0, 1]));
assert_eq!(BigInt::from(-112500000000i64).to_u32_digits(), (Sign::Minus, vec![830850304, 26]));
assert_eq!(BigInt::from(112500000000i64).to_u32_digits(), (Sign::Plus, vec![830850304, 26]));
sourcepub fn to_signed_bytes_be(&self) -> Vec<u8, Global>
pub fn to_signed_bytes_be(&self) -> Vec<u8, Global>
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]);
sourcepub fn to_signed_bytes_le(&self) -> Vec<u8, Global>
pub fn to_signed_bytes_le(&self) -> Vec<u8, Global>
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]);
sourcepub fn to_str_radix(&self, radix: u32) -> String
pub fn to_str_radix(&self, radix: u32) -> String
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();
assert_eq!(i.to_str_radix(16), "ff");
sourcepub fn to_radix_be(&self, radix: u32) -> (Sign, Vec<u8, Global>)
pub fn to_radix_be(&self, radix: u32) -> (Sign, Vec<u8, Global>)
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};
assert_eq!(BigInt::from(-0xFFFFi64).to_radix_be(159),
(Sign::Minus, vec![2, 94, 27]));
// 0xFFFF = 65535 = 2*(159^2) + 94*159 + 27
sourcepub fn to_radix_le(&self, radix: u32) -> (Sign, Vec<u8, Global>)
pub fn to_radix_le(&self, radix: u32) -> (Sign, Vec<u8, Global>)
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};
assert_eq!(BigInt::from(-0xFFFFi64).to_radix_le(159),
(Sign::Minus, vec![27, 94, 2]));
// 0xFFFF = 65535 = 27 + 94*159 + 2*(159^2)
sourcepub fn sign(&self) -> Sign
pub fn sign(&self) -> Sign
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);
sourcepub fn bits(&self) -> usize
pub fn bits(&self) -> usize
Determines the fewest bits necessary to express the BigInt
,
not including the sign.
sourcepub fn to_biguint(&self) -> Option<BigUint>
pub fn to_biguint(&self) -> Option<BigUint>
Converts this BigInt
into a BigUint
, if it’s not negative.
pub fn checked_add(&self, v: &BigInt) -> Option<BigInt>
pub fn checked_sub(&self, v: &BigInt) -> Option<BigInt>
pub fn checked_mul(&self, v: &BigInt) -> Option<BigInt>
pub fn checked_div(&self, v: &BigInt) -> Option<BigInt>
sourcepub fn modpow(&self, exponent: &BigInt, modulus: &BigInt) -> BigInt
pub fn modpow(&self, exponent: &BigInt, modulus: &BigInt) -> BigInt
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.
sourcepub fn sqrt(&self) -> BigInt
pub fn sqrt(&self) -> BigInt
Returns the truncated principal square root of self
–
see Roots::sqrt.
sourcepub fn cbrt(&self) -> BigInt
pub fn cbrt(&self) -> BigInt
Returns the truncated principal cube root of self
–
see Roots::cbrt.
sourcepub fn nth_root(&self, n: u32) -> BigInt
pub fn nth_root(&self, n: u32) -> BigInt
Returns the truncated principal n
th root of self
–
See Roots::nth_root.
Trait Implementations§
source§impl<T> AddAssign<T> for Int256where
T: Into<Int256>,
impl<T> AddAssign<T> for Int256where
T: Into<Int256>,
source§fn add_assign(&mut self, v: T)
fn add_assign(&mut self, v: T)
+=
operation. Read moresource§impl CheckedAdd for Int256
impl CheckedAdd for Int256
source§impl CheckedDiv for Int256
impl CheckedDiv for Int256
source§impl CheckedMul for Int256
impl CheckedMul for Int256
source§impl CheckedSub for Int256
impl CheckedSub for Int256
source§impl<'de> Deserialize<'de> for Int256
impl<'de> Deserialize<'de> for Int256
source§fn deserialize<D>(deserializer: D) -> Result<Int256, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Int256, D::Error>where
D: Deserializer<'de>,
source§impl<T> DivAssign<T> for Int256where
T: Into<Int256>,
impl<T> DivAssign<T> for Int256where
T: Into<Int256>,
source§fn div_assign(&mut self, v: T)
fn div_assign(&mut self, v: T)
/=
operation. Read moresource§impl<T> MulAssign<T> for Int256where
T: Into<Int256>,
impl<T> MulAssign<T> for Int256where
T: Into<Int256>,
source§fn mul_assign(&mut self, v: T)
fn mul_assign(&mut self, v: T)
*=
operation. Read moresource§impl Ord for Int256
impl Ord for Int256
source§impl PartialOrd<Int256> for Int256
impl PartialOrd<Int256> for Int256
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<T> SubAssign<T> for Int256where
T: Into<Int256>,
impl<T> SubAssign<T> for Int256where
T: Into<Int256>,
source§fn sub_assign(&mut self, v: T)
fn sub_assign(&mut self, v: T)
-=
operation. Read more