Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DoubleEndedIterator to U32Digits and U64Digits #208

Merged
merged 5 commits into from
Aug 27, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added iter_u*_digits_be() methods to BigInt
PatrickNorton committed Jul 22, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit aef8dcb6a3783ac694a754d5a87eca7cdc2fc132
40 changes: 40 additions & 0 deletions src/bigint.rs
Original file line number Diff line number Diff line change
@@ -303,6 +303,7 @@ enum CheckedUnsignedAbs<T> {
Negative(T),
}
use self::CheckedUnsignedAbs::{Negative, Positive};
use crate::{U32DigitsBe, U64DigitsBe};

macro_rules! impl_unsigned_abs {
($Signed:ty, $Unsigned:ty) => {
@@ -825,6 +826,45 @@ impl BigInt {
self.data.iter_u64_digits()
}

/// Returns an iterator of `u32` digits representation of the `BigInt` ordered most
/// significant digit first.
///
/// # Examples
///
/// ```
/// use num_bigint::BigInt;
///
/// assert_eq!(BigInt::from(-1125).iter_u32_digits().collect::<Vec<u32>>(), vec![1125]);
/// assert_eq!(BigInt::from(4294967295u32).iter_u32_digits().collect::<Vec<u32>>(), vec![4294967295]);
/// assert_eq!(BigInt::from(4294967296u64).iter_u32_digits().collect::<Vec<u32>>(), vec![1, 0]);
/// assert_eq!(BigInt::from(-112500000000i64).iter_u32_digits().collect::<Vec<u32>>(), vec![26, 830850304]);
/// assert_eq!(BigInt::from(112500000000i64).iter_u32_digits().collect::<Vec<u32>>(), vec![26, 830850304]);
/// ```
#[inline]
pub fn iter_u32_digits_be(&self) -> U32DigitsBe<'_> {
self.data.iter_u32_digits_be()
}

/// Returns an iterator of `u64` digits representation of the `BigInt` ordered most
/// significant digit first.
///
/// # Examples
///
/// ```
/// use num_bigint::BigInt;
///
/// assert_eq!(BigInt::from(-1125).iter_u64_digits().collect::<Vec<u64>>(), vec![1125u64]);
/// assert_eq!(BigInt::from(4294967295u32).iter_u64_digits().collect::<Vec<u64>>(), vec![4294967295u64]);
/// assert_eq!(BigInt::from(4294967296u64).iter_u64_digits().collect::<Vec<u64>>(), vec![4294967296u64]);
/// assert_eq!(BigInt::from(-112500000000i64).iter_u64_digits().collect::<Vec<u64>>(), vec![112500000000u64]);
/// assert_eq!(BigInt::from(112500000000i64).iter_u64_digits().collect::<Vec<u64>>(), vec![112500000000u64]);
/// assert_eq!(BigInt::from(1u128 << 64).iter_u64_digits().collect::<Vec<u64>>(), vec![1, 0]);
/// ```
#[inline]
pub fn iter_u64_digits_be(&self) -> U64DigitsBe<'_> {
self.data.iter_u64_digits_be()
}

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