Trait BigInt

Source
pub trait BigInt<const BASE: usize>
where Self: GetBack<Item = Digit> + Clone + Default + Debug + Display + PartialEq + Eq + PartialOrd + Ord + Neg<Output = Self> + Add<Output = Self> + AddAssign + Sub<Output = Self> + SubAssign + Div<Output = Self> + DivAssign + Mul<Output = Self> + MulAssign + Shl<Output = Self> + ShlAssign + Shr<Output = Self> + ShrAssign + FromStr<Err = BigIntError> + FromIterator<Digit> + IntoIterator<Item = Digit, IntoIter = BigIntIntoIter<BASE, Self>> + From<Vec<Digit>> + From<u8> + From<u16> + From<u32> + From<u64> + From<u128> + From<usize> + From<i8> + From<i16> + From<i32> + From<i64> + From<i128> + From<isize> + Into<u8> + Into<u16> + Into<u32> + Into<u64> + Into<u128> + Into<usize> + Into<i8> + Into<i16> + Into<i32> + Into<i64> + Into<i128> + Into<isize>,
{ type Builder: BigIntBuilder<BASE> + Into<Self::Denormal> + Into<Self>; type Denormal: BigInt<BASE> + From<Self> + UnsafeInto<Self> + Unwrap<Self>; const BITS_PER_DIGIT: usize = _;
Show 55 methods // Required methods fn len(&self) -> usize; fn get_digit(&self, digit: usize) -> Option<Digit>; fn set_digit(&mut self, digit: usize, value: Digit); fn zero() -> Self; fn sign(&self) -> Sign; fn with_sign(self, sign: Sign) -> Self; fn set_sign(&mut self, sign: Sign); fn push_back(&mut self, digit: Digit); unsafe fn push_front(&mut self, digit: Digit); unsafe fn pop_back(&mut self) -> Option<Digit>; unsafe fn pop_front(&mut self) -> Option<Digit>; // Provided methods fn get_back_inner(&self, index: usize) -> Option<Digit> { ... } fn default_inner() -> Self { ... } fn fmt_inner(&self, f: &mut Formatter<'_>) -> Result { ... } fn partial_cmp_inner<RHS: BigInt<BASE>>( &self, other: &RHS, ) -> Option<Ordering> { ... } fn cmp_inner<RHS: BigInt<BASE>>(&self, other: &RHS) -> Ordering { ... } fn eq_inner<RHS: BigInt<BASE>>(&self, other: &RHS) -> bool { ... } fn neg_inner(self) -> Self::Denormal { ... } fn add_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> OUT::Denormal { ... } unsafe fn add_assign_inner<RHS: BigInt<BASE>>(&mut self, rhs: RHS) { ... } fn sub_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> OUT::Denormal { ... } unsafe fn sub_assign_inner<RHS: BigInt<BASE>>(&mut self, rhs: RHS) { ... } fn mul_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> OUT::Denormal { ... } unsafe fn mul_assign_inner<RHS: BigInt<BASE>>(&mut self, rhs: RHS) { ... } fn div_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> OUT::Denormal { ... } unsafe fn div_assign_inner<RHS: BigInt<BASE>>(&mut self, rhs: RHS) { ... } fn from_str_inner(s: &str) -> Result<Self::Denormal, BigIntError> { ... } fn from_iter_inner<T: IntoIterator<Item = Digit>>(iter: T) -> Self::Denormal { ... } fn from_u128_inner(value: u128) -> Self::Denormal { ... } fn from_i128_inner(value: i128) -> Self::Denormal { ... } fn into_u128_inner(self) -> u128 { ... } fn into_i128_inner(self) -> i128 { ... } fn is_zero(&self) -> bool { ... } fn shr_inner(self, amount: usize) -> Self::Denormal { ... } unsafe fn shr_assign_inner(&mut self, amount: usize) { ... } fn shl_inner(self, amount: usize) -> Self::Denormal { ... } unsafe fn shl_assign_inner(&mut self, amount: usize) { ... } fn div_rem_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<(OUT::Denormal, OUT::Denormal), BigIntError> { ... } fn div_rem<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<(OUT, OUT), BigIntError> { ... } fn exp_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<OUT::Denormal, BigIntError> { ... } fn exp<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<OUT, BigIntError> { ... } fn log_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<OUT::Denormal, BigIntError> { ... } fn log<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<OUT, BigIntError> { ... } fn root_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<OUT::Denormal, BigIntError> { ... } fn root<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<OUT, BigIntError> { ... } fn is_even(&self) -> bool { ... } fn iter<'a>(&'a self) -> BigIntIter<'a, BASE, Self> { ... } fn normalized(self) -> Self { ... } fn normalize(&mut self) { ... } fn display(&self, alphabet: &str) -> Result<String, BigIntError> { ... } fn parse(value: &str, alphabet: &str) -> Result<Self::Denormal, ParseError> { ... } fn convert_inner<const TO: usize, OUT: BigInt<TO>>(self) -> OUT::Denormal { ... } fn convert<const TO: usize, OUT: BigInt<TO>>(self) -> OUT { ... } fn cmp_magnitude<RHS: BigInt<BASE>>(&self, rhs: &RHS) -> Ordering { ... } fn abs(self) -> Self { ... }
}
Expand description

A big int.

Represents an arbitrary precision, arbitrary base natural number.

Supports basic arithmetic operations, as well as all utilities necessary for coercing to and from various builtin types, such as primitive int types, Vecs, and Strings.

§For implementors:

If implementing this trait for your own type, don’t be alarmed by the massive list of Self constraints. Use the included derive macro big_int::BigIntTraits to automatically derive all traits using default *_inner implementations pre-provided by BigInt.

At least one of normalize or normalized must be defined to prevent recursion.
At least one of shl_inner or shl_assign_inner must be defined to prevent recursion.
At least one of shr_inner or shr_assign_inner must be defined to prevent recursion.\

use big_int::prelude::*;

let mut a = TightBuilder::<10>::new();
a.push_back(1);
a.push_back(0);
a.push_back(4);
let a: DenormalTight<10> = a.into();
let a: Tight<10> = a.unwrap();
assert_eq!(a, 104.into());

Provided Associated Constants§

Required Associated Types§

Source

type Builder: BigIntBuilder<BASE> + Into<Self::Denormal> + Into<Self>

Source

type Denormal: BigInt<BASE> + From<Self> + UnsafeInto<Self> + Unwrap<Self>

Required Methods§

Source

fn len(&self) -> usize

The length of the big int in digits.

use big_int::prelude::*;

let a: Tight<10> = 211864.into();
assert_eq!(a.len(), 6);
Source

fn get_digit(&self, digit: usize) -> Option<Digit>

Get the digit of the big int at position digit, or None if the number does not have that many digits.

use big_int::prelude::*;

let a: Tight<10> = 12345.into();
assert_eq!(a.get_digit(2), Some(3));
assert_eq!(a.get_digit(6), None);
Source

fn set_digit(&mut self, digit: usize, value: Digit)

Set the digit of the big int to value at position digit.

If the set digit causes the leftmost digit of the number to be zero, the number will become denormal, and should be normalized before being used.

use big_int::prelude::*;

let mut a: Tight<10> = 10000.into();
a.set_digit(1, 7);
a.set_digit(4, 9);
assert_eq!(a, 17009.into());
Source

fn zero() -> Self

The value zero represented as a big int.

use big_int::prelude::*;

let a: Tight<10> = 13.into();
let b = 13.into();
assert_eq!(a - b, BigInt::zero());
Source

fn sign(&self) -> Sign

The sign of the big int.

use big_int::prelude::*;

let mut a: Tight<10> = 5.into();
assert_eq!(a.sign(), Positive);
a -= 14.into();
assert_eq!(a.sign(), Negative);
Source

fn with_sign(self, sign: Sign) -> Self

The big int with the given sign.

use big_int::prelude::*;

let a: Tight<10> = 95.into();
assert_eq!(a.with_sign(Negative), (-95).into());
Source

fn set_sign(&mut self, sign: Sign)

Set the sign of the big int to sign.

use big_int::prelude::*;

let mut a: Tight<10> = (-109).into();
a.set_sign(Positive);
assert_eq!(a, 109.into());
Source

fn push_back(&mut self, digit: Digit)

Append a digit to the right side of the int. Equivalent to (int << 1) + digit

use big_int::prelude::*;

let mut a: Tight<10> = 6.into();
a.push_back(1);
assert_eq!(a, 61.into());
Source

unsafe fn push_front(&mut self, digit: Digit)

Append a digit to the left side of the int.

If a zero is pushed onto the end of the int, it will become denormalized.

use big_int::prelude::*;

let mut a: Tight<10> = 6.into();
unsafe {
    a.push_front(1);
}
assert_eq!(a.normalized(), 16.into());
Source

unsafe fn pop_back(&mut self) -> Option<Digit>

Pop the rightmost digit from the end of the int, and return it.

If the last digit is popped, the number will become denormalized.

use big_int::prelude::*;

let mut a: Tight<10> = 651.into();
let digit = unsafe { a.pop_back() };
assert_eq!(a, 65.into());
assert_eq!(digit, Some(1));
Source

unsafe fn pop_front(&mut self) -> Option<Digit>

Pop the leftmost digit from the end of the int, and return it.

If the last digit is popped, the number will become denormalized.

use big_int::prelude::*;

let mut a: Tight<10> = 651.into();
let digit = unsafe { a.pop_front() };
assert_eq!(a, 51.into());
assert_eq!(digit, Some(6));

Provided Methods§

Source

fn get_back_inner(&self, index: usize) -> Option<Digit>

Default implementation of big_int::GetBack.

Trait implementation may be provided automatically by big_int_proc::BigIntTraits.

Source

fn default_inner() -> Self

Default implementation of Default.

Trait implementation may be provided automatically by big_int_proc::BigIntTraits.

Source

fn fmt_inner(&self, f: &mut Formatter<'_>) -> Result

Default implementation of Display.

Trait implementation may be provided automatically by big_int_proc::BigIntTraits.

Source

fn partial_cmp_inner<RHS: BigInt<BASE>>(&self, other: &RHS) -> Option<Ordering>

Default implementation of PartialOrd.

Trait implementation may be provided automatically by big_int_proc::BigIntTraits.

Source

fn cmp_inner<RHS: BigInt<BASE>>(&self, other: &RHS) -> Ordering

Default implementation of Ord.

Trait implementation may be provided automatically by big_int_proc::BigIntTraits.

Source

fn eq_inner<RHS: BigInt<BASE>>(&self, other: &RHS) -> bool

Default implementation of PartialEq.

Trait implementation may be provided automatically by big_int_proc::BigIntTraits.

Source

fn neg_inner(self) -> Self::Denormal

Default implementation of Neg.

Trait implementation may be provided automatically by big_int_proc::BigIntTraits.

Source

fn add_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> OUT::Denormal

Default implementation of Add.

Trait implementation may be provided automatically by big_int_proc::BigIntTraits.

Source

unsafe fn add_assign_inner<RHS: BigInt<BASE>>(&mut self, rhs: RHS)

Default implementation of AddAssign.

Trait implementation may be provided automatically by big_int_proc::BigIntTraits.

If this method is used directly, it may cause the number to become denormalized.

Source

fn sub_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> OUT::Denormal

Default implementation of Sub.

Trait implementation may be provided automatically by big_int_proc::BigIntTraits.

Source

unsafe fn sub_assign_inner<RHS: BigInt<BASE>>(&mut self, rhs: RHS)

Default implementation of SubAssign.

Trait implementation may be provided automatically by big_int_proc::BigIntTraits.

If this method is used directly, it may cause the number to become denormalized.

Source

fn mul_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> OUT::Denormal

Default implementation of Mul.

Trait implementation may be provided automatically by big_int_proc::BigIntTraits.

Source

unsafe fn mul_assign_inner<RHS: BigInt<BASE>>(&mut self, rhs: RHS)

Default implementation of MulAssign.

Trait implementation may be provided automatically by big_int_proc::BigIntTraits.

If this method is used directly, it may cause the number to become denormalized.

Source

fn div_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> OUT::Denormal

Default implementation of Div.

Trait implementation may be provided automatically by big_int_proc::BigIntTraits.

Source

unsafe fn div_assign_inner<RHS: BigInt<BASE>>(&mut self, rhs: RHS)

Default implementation of DivAssign.

Trait implementation may be provided automatically by big_int_proc::BigIntTraits.

If this method is used directly, it may cause the number to become denormalized.

Source

fn from_str_inner(s: &str) -> Result<Self::Denormal, BigIntError>

Default implementation of FromStr.

Trait implementation may be provided automatically by big_int_proc::BigIntTraits.

§Errors:
  • ParseFailed if parsing of the string fails.
Source

fn from_iter_inner<T: IntoIterator<Item = Digit>>(iter: T) -> Self::Denormal

Default implementation of FromIterator.

Trait implementation may be provided automatically by big_int_proc::BigIntTraits.

Source

fn from_u128_inner(value: u128) -> Self::Denormal

Default implementation of From<_> for all unsigned primitive int types.

Trait implementation may be provided automatically by big_int_proc::BigIntTraits.

Source

fn from_i128_inner(value: i128) -> Self::Denormal

Default implementation of From<_> for all signed primitive int types.

Trait implementation may be provided automatically by big_int_proc::BigIntTraits.

Source

fn into_u128_inner(self) -> u128

Default implementation of Into<_> for all unsigned primitive int types.

Trait implementation may be provided automatically by big_int_proc::BigIntTraits.

Source

fn into_i128_inner(self) -> i128

Default implementation of Into<_> for all signed primitive int types.

Trait implementation may be provided automatically by big_int_proc::BigIntTraits.

Source

fn is_zero(&self) -> bool

Check if the big int is zero.

use big_int::prelude::*;

let a: Tight<10> = 13.into();
let b = 13.into();
assert!((a - b).is_zero());
Source

fn shr_inner(self, amount: usize) -> Self::Denormal

Divide the int by BASE^amount.

Note: works in powers of BASE, not in powers of 2.

Defined in terms of shr_assign; at least one of shr or shr_assign must be defined by implementers.

Also acts as the default implementation of the Shr trait, as provided automatically by big_int_proc::BigIntTraits.

use big_int::prelude::*;

let a: Tight<10> = 600.into();
assert_eq!(a.shr_inner(2), 6.into());
Source

unsafe fn shr_assign_inner(&mut self, amount: usize)

Divide the int by BASE^amount in place.

Note: works in powers of BASE, not in powers of 2.

Defined in terms of shr; at least one of shr or shr_assign must be defined by implementers.

Also acts as the default implementation of the ShrAssign trait, as provided automatically by big_int_proc::BigIntTraits.

If the last number is shifted off, may cause the number to become denormalized.

use big_int::prelude::*;

let mut a: Tight<10> = 600.into();
unsafe {
    a.shr_assign_inner(2);
}
assert_eq!(a, 6.into());
Source

fn shl_inner(self, amount: usize) -> Self::Denormal

Multiply the int by BASE^amount.

Note: works in powers of BASE, not in powers of 2.

Defined in terms of shl_assign; at least one of shl or shl_assign must be defined by implementers.

Also acts as the default implementation of the Shl trait, as provided automatically by big_int_proc::BigIntTraits.

use big_int::prelude::*;

let a: Tight<10> = 3.into();
assert_eq!(a.shl_inner(2), 300.into());
Source

unsafe fn shl_assign_inner(&mut self, amount: usize)

Multiply the int by BASE^amount in place.

Note: works in powers of BASE, not in powers of 2.

Defined in terms of shl; at least one of shl or shl_assign must be defined by implementers.

Also acts as the default implementation of the ShlAssign trait, as provided automatically by big_int_proc::BigIntTraits.

use big_int::prelude::*;

let mut a: Tight<10> = 3.into();
unsafe {
    a.shl_assign_inner(2);
}
assert_eq!(a, 300.into());
Source

fn div_rem_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<(OUT::Denormal, OUT::Denormal), BigIntError>

Divide one int by another, returning the quotient & remainder as a pair. Returns the result as a denormalized pair.

§Errors:
  • DivisionByZero if rhs is zero.
use big_int::prelude::*;

let a: Loose<10> = 999_999_999.into();
let b: Loose<10> = 56_789.into();
assert_eq!(a.div_rem_inner::<_, Loose<10>>(b), Ok((17_609.into(), 2_498.into())));
Source

fn div_rem<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<(OUT, OUT), BigIntError>

Divide one int by another, returning the quotient & remainder as a pair.

§Errors:
  • DivisionByZero if rhs is zero.
use big_int::prelude::*;

let a: Loose<10> = 999_999_999.into();
let b: Loose<10> = 56_789.into();
assert_eq!(a.div_rem::<_, Loose<10>>(b), Ok((17_609.into(), 2_498.into())));
Source

fn exp_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<OUT::Denormal, BigIntError>

Exponentiate the big int by rhs. Returns the result as a denormalized number.

§Errors:
  • NegativeExponentiation if rhs is negative.
use big_int::prelude::*;

let a: Loose<10> = 10.into();
let b: Loose<10> = a.exp::<Loose<10>, Loose<10>>(3.into()).unwrap();
assert_eq!(b, 1000.into());
Source

fn exp<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<OUT, BigIntError>

Exponentiate the big int by rhs.

§Errors:
  • NegativeExponentiation if rhs is negative.
use big_int::prelude::*;

let a: Loose<10> = 10.into();
let b: Loose<10> = a.exp::<Loose<10>, Loose<10>>(3.into()).unwrap();
assert_eq!(b, 1000.into());
Source

fn log_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<OUT::Denormal, BigIntError>

Compute the logarithm of the big int with the base rhs. Returns the result as a denormalized number.

§Errors:
  • NonPositiveLogarithm if the number is less than 1.
  • LogOfSmallBase if rhs is less than 2.
use big_int::prelude::*;

let a: Loose<10> = 1000.into();
let b: Loose<10> = a.log::<Loose<10>, Loose<10>>(10.into()).unwrap();
assert_eq!(b, 3.into());
Source

fn log<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<OUT, BigIntError>

Compute the logarithm of the big int with the base rhs.

§Errors:
  • NonPositiveLogarithm if the number is less than 1.
  • LogOfSmallBase if rhs is less than 2.
use big_int::prelude::*;

let a: Loose<10> = 1000.into();
let b: Loose<10> = a.log::<Loose<10>, Loose<10>>(10.into()).unwrap();
assert_eq!(b, 3.into());
Source

fn root_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<OUT::Denormal, BigIntError>

Compute the nth root of the big int, with root rhs. Returns the result as a denormalized number.

§Errors:
  • NegativeRoot if the number is negative.
  • SmallRoot if rhs is less than 2.
use big_int::prelude::*;

let a: Loose<10> = 27.into();
assert_eq!(a.root::<Loose<10>, Loose<10>>(3.into()).unwrap(), 3.into());
Source

fn root<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<OUT, BigIntError>

Compute the nth root of the big int, with root rhs.

§Errors:
  • NegativeRoot if the number is negative.
  • SmallRoot if rhs is less than 2.
use big_int::prelude::*;

let a: Loose<10> = 27.into();
assert_eq!(a.root::<Loose<10>, Loose<10>>(3.into()).unwrap(), 3.into());
Source

fn is_even(&self) -> bool

Check if the number is even.

O(1) for numbers with even bases, and O(log(n)) for numbers with odd bases.

use big_int::prelude::*;

let mut n: Tight<10> = 16.into();
assert!(n.is_even());
n += 1.into();
assert!(!n.is_even());
Source

fn iter<'a>(&'a self) -> BigIntIter<'a, BASE, Self>

Iterate over the digits of the int.

implements DoubleEndedIterator, so digits can be iterated over forward or in reverse.

use big_int::prelude::*;

let a: Tight<10> = 12345.into();
assert_eq!(a.iter().collect::<Vec<_>>(), vec![1, 2, 3, 4, 5]);
assert_eq!(a.iter().rev().collect::<Vec<_>>(), vec![5, 4, 3, 2, 1]);
Source

fn normalized(self) -> Self

Return a normalized version of the int. A normalized int:

  • has no trailing zeros
  • has at least one digit
  • is not negative zero

Additionally, Tight ints will be aligned to the beginning of their data segment when normalized.

Defined in terms of normalize; at least one of normalize or normalized must be defined by the implementer.

use big_int::prelude::*;

let n = unsafe { Loose::<10>::from_raw_parts(vec![0, 0, 8, 3]) };
assert_eq!(n.normalized(), 83.into());
Source

fn normalize(&mut self)

Normalize a big int in place. A normalized int:

  • has no trailing zeros
  • has at least one digit
  • is not negative zero

Additionally, Tight ints will be aligned to the beginning of their data segment when normalized.

Defined in terms of normalized; at least one of normalize or normalized must be defined by the implementer.

use big_int::prelude::*;

let mut n = unsafe { Loose::<10>::from_raw_parts(vec![0, 0, 8, 3]) };
n.normalize();
assert_eq!(n, 83.into());
Source

fn display(&self, alphabet: &str) -> Result<String, BigIntError>

Convert a big int to a printable string using the provided alphabet alphabet. Display uses this method with the default alphabet STANDARD_ALPHABET.

§Errors:
  • BaseTooHigh if a digit in the number is too large to be displayed with the chosen character alphabet.
use big_int::prelude::*;

assert_eq!(
    Loose::<10>::from(6012).display(STANDARD_ALPHABET).unwrap(),
    "6012".to_string()
);
Source

fn parse(value: &str, alphabet: &str) -> Result<Self::Denormal, ParseError>

Parse a big int from a value: &str, referencing the provided alphabet to determine what characters represent which digits. FromStr uses this method with the default alphabet STANDARD_ALPHABET.

§Errors:
  • NotEnoughCharacters if there are no digit characters in the string.
  • UnrecognizedCharacter if there is a character present which is neither a - sign nor a character present in the passed alphabet.
  • DigitTooLarge if a character decodes to a digit value which is larger than the base of the number being parsed can represent.
use big_int::prelude::*;

assert_eq!(Loose::parse("125", STANDARD_ALPHABET), Ok(DenormalLoose::<10>::from(125)));
Source

fn convert_inner<const TO: usize, OUT: BigInt<TO>>(self) -> OUT::Denormal

Convert an int from its own base to another target base, to another BigInt type, or both at once. Returns the result as a denormalized number.

use big_int::prelude::*;

let a: DenormalTight<16> = Loose::<10>::from(99825).convert_inner::<16, Tight<16>>();
assert_eq!(a, DenormalTight::<16>::from(99825));
Source

fn convert<const TO: usize, OUT: BigInt<TO>>(self) -> OUT

Convert an int from its own base to another target base, to another BigInt type, or both at once.

use big_int::prelude::*;

let a: Tight<16> = Loose::<10>::from(99825).convert();
assert_eq!(a, Tight::<16>::from(99825));
Source

fn cmp_magnitude<RHS: BigInt<BASE>>(&self, rhs: &RHS) -> Ordering

Compare the absolute magnitude of two big ints, ignoring their sign.

use big_int::prelude::*;

let a: Tight<10> = (-105).into();
let b: Tight<10> = 15.into();
assert!(a.cmp_magnitude(&b).is_gt());
Source

fn abs(self) -> Self

Return the absolute value of the int.

use big_int::prelude::*;
 
let a: Loose<10> = (-13).into();
assert_eq!(a.abs(), 13.into());

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<const BASE: usize> BigInt<BASE> for Loose<BASE>

Source§

impl<const BASE: usize> BigInt<BASE> for LooseBytes<BASE>

Source§

impl<const BASE: usize> BigInt<BASE> for LooseShorts<BASE>

Source§

impl<const BASE: usize> BigInt<BASE> for LooseWords<BASE>

Source§

impl<const BASE: usize> BigInt<BASE> for Tight<BASE>

Source§

impl<const BASE: usize, B: BigInt<BASE>> BigInt<BASE> for Denormal<BASE, B>

Source§

type Builder = DenormalBuilder<BASE, <B as BigInt<BASE>>::Builder>

Source§

type Denormal = Denormal<BASE, B>