Skip to content

Commit

Permalink
cargo fmt and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacholt100 committed Jan 6, 2025
1 parent 3c2bb41 commit 200f7e1
Show file tree
Hide file tree
Showing 23 changed files with 57 additions and 60 deletions.
2 changes: 1 addition & 1 deletion src/bint/cast.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::BIntD8;
use crate::{BUintD8, digit, Digit};
use crate::{digit, BUintD8, Digit};

macro_rules! bint_as {
($($int: ty), *) => {
Expand Down
2 changes: 1 addition & 1 deletion src/bint/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ uint_try_from_bint!(u8, u16, u32, u64, u128, usize);
#[cfg(test)]
mod tests {
use crate::test;
use crate::test::types::*;
use crate::test::cast_types::*;
use crate::test::types::*;
use crate::BTryFrom;

test::test_btryfrom!(itest; TestUint1, TestUint2, TestUint3, TestUint4, TestUint5, TestUint6, TestUint7, TestUint8, TestUint9, TestUint10, TestInt1, TestInt2, TestInt3, TestInt4, TestInt5, TestInt6, TestInt7, TestInt8, TestInt9, TestInt10);
Expand Down
13 changes: 8 additions & 5 deletions src/bint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,7 @@ impl<const N: usize> quickcheck::Arbitrary for BIntD8<N> {

#[cfg(test)]
mod tests {
use crate::test::{
debug_skip, test_bignum,
types::*,
};
use crate::test::{debug_skip, test_bignum, types::*};
// use crate::test::types::big_types::Digit::*;

crate::int::tests!(itest);
Expand Down Expand Up @@ -501,7 +498,13 @@ mod tests {

#[test]
fn sum() {
let v = vec![&ITEST::ZERO, &ITEST::ONE, &ITEST::TWO, &ITEST::THREE, &ITEST::FOUR];
let v = vec![
&ITEST::ZERO,
&ITEST::ONE,
&ITEST::TWO,
&ITEST::THREE,
&ITEST::FOUR,
];
assert_eq!(ITEST::TEN, v.iter().copied().sum());
assert_eq!(ITEST::TEN, v.into_iter().sum());
}
Expand Down
32 changes: 16 additions & 16 deletions src/bint/radix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ impl<const N: usize> BIntD8<N> {

#[cfg(test)]
mod tests {
use crate::test::{quickcheck_from_to_radix, test_bignum, self};
use crate::test::types::*;
use crate::test::{self, quickcheck_from_to_radix, test_bignum};
use crate::BIntD8;

test_bignum! {
Expand Down Expand Up @@ -204,8 +204,8 @@ mod tests {
#[test]
fn from_to_radix_le() {
let buf = &[
61, 45, 48, 20, 37, 59, 53, 28, 28, 52, 54, 13, 44, 3, 46, 42, 20, 46, 37, 32,
13, 27, 47, 30, 33, 25, 3, 32, 4, 54, 53, 6, 44, 25, 10, 22, 33, 48, 7, 17,
61, 45, 48, 20, 37, 59, 53, 28, 28, 52, 54, 13, 44, 3, 46, 42, 20, 46, 37, 32, 13, 27,
47, 30, 33, 25, 3, 32, 4, 54, 53, 6, 44, 25, 10, 22, 33, 48, 7, 17,
];
let u = BIntD8::<100>::from_radix_le(buf, 64).unwrap();
let v = u.to_radix_le(64);
Expand All @@ -218,9 +218,9 @@ mod tests {
assert!(option.is_none());

let buf = &[
1, 3, 3, 0, 2, 1, 2, 3, 0, 4, 1, 2, 0, 0, 0, 0, 3, 2, 0, 1, 0, 4, 1, 3, 1, 4,
3, 3, 3, 4, 1, 2, 2, 1, 3, 0, 2, 1, 2, 3, 1, 1, 0, 2, 2, 1, 1, 2, 1, 0, 0, 0,
3, 3, 3, 0, 0, 4, 4, 2,
1, 3, 3, 0, 2, 1, 2, 3, 0, 4, 1, 2, 0, 0, 0, 0, 3, 2, 0, 1, 0, 4, 1, 3, 1, 4, 3, 3, 3,
4, 1, 2, 2, 1, 3, 0, 2, 1, 2, 3, 1, 1, 0, 2, 2, 1, 1, 2, 1, 0, 0, 0, 3, 3, 3, 0, 0, 4,
4, 2,
];
let u = BIntD8::<100>::from_radix_le(buf, 5).unwrap();
let v = u.to_radix_le(5);
Expand All @@ -229,33 +229,33 @@ mod tests {
#[test]
fn from_to_radix_be() {
let buf = &[
29, 89, 92, 118, 69, 140, 141, 70, 71, 76, 66, 13, 30, 28, 38, 145, 40, 7, 57,
18, 25, 65, 150, 119, 155, 18, 64, 76, 106, 87,
29, 89, 92, 118, 69, 140, 141, 70, 71, 76, 66, 13, 30, 28, 38, 145, 40, 7, 57, 18, 25,
65, 150, 119, 155, 18, 64, 76, 106, 87,
];
let u = BIntD8::<100>::from_radix_be(buf, 157).unwrap();
let v = u.to_radix_be(157);
assert_eq!(v, buf);

let buf = &[
1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1,
1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0,
1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0,
0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1,
1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1,
1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1,
0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0,
0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1,
];
let u = BIntD8::<100>::from_radix_be(buf, 2).unwrap();
let v = u.to_radix_be(2);
assert_eq!(v, buf);

let buf = &[
91, 167, 5, 99, 61, 38, 158, 149, 115, 79, 13, 118, 53, 16, 144, 123, 70, 81,
78, 61, 39, 6, 34, 95, 98, 23, 175, 182,
91, 167, 5, 99, 61, 38, 158, 149, 115, 79, 13, 118, 53, 16, 144, 123, 70, 81, 78, 61,
39, 6, 34, 95, 98, 23, 175, 182,
];
let option = BIntD8::<100>::from_radix_le(buf, 180);
assert!(option.is_none());

let buf = &[
39, 90, 119, 93, 95, 7, 70, 81, 3, 100, 39, 107, 98, 31, 61, 5, 36, 19, 18,
124, 4, 77, 119, 17, 121, 116, 24, 35,
39, 90, 119, 93, 95, 7, 70, 81, 3, 100, 39, 107, 98, 31, 61, 5, 36, 19, 18, 124, 4, 77,
119, 17, 121, 116, 24, 35,
];
let u = BIntD8::<100>::from_radix_be(buf, 128).unwrap();
let v = u.to_radix_be(128);
Expand Down
1 change: 0 additions & 1 deletion src/bint/strict.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use super::BIntD8;
use crate::{BUintD8, Digit};


#[doc = doc::strict::impl_desc!()]
impl<const N: usize> BIntD8<N> {
crate::int::strict::impls!(I);
Expand Down
1 change: 0 additions & 1 deletion src/bint/unchecked.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use super::BIntD8;
use crate::{BUintD8, Digit};


crate::int::unchecked::impls!(BIntD8, I);

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion src/buint/bigint_helpers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::BUintD8;
use crate::{digit, Digit};
use crate::doc;
use crate::{digit, Digit};

#[doc = doc::bigint_helpers::impl_desc!()]
impl<const N: usize> BUintD8<N> {
Expand Down
2 changes: 1 addition & 1 deletion src/buint/checked.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use super::BUintD8;
use crate::{digit, Digit, BIntD8};
use crate::doc;
use crate::errors::div_zero;
use crate::helpers::tuple_to_option;
use crate::ExpType;
use crate::{digit, BIntD8, Digit};

#[doc = doc::checked::impl_desc!()]
impl<const N: usize> BUintD8<N> {
Expand Down
2 changes: 1 addition & 1 deletion src/buint/const_trait_fillers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::BUintD8;
use crate::{digit, Digit};
use crate::doc;
use crate::ExpType;
use crate::{digit, Digit};
use core::cmp::Ordering;

#[doc = doc::const_trait_fillers::impl_desc!()]
Expand Down
4 changes: 2 additions & 2 deletions src/buint/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl<const N: usize> From<char> for BUintD8<N> {
}
}

use crate::{BTryFrom, BIntD8};
use crate::{BIntD8, BTryFrom};

uint_try_from_uint!(BTryFrom; BUintD8; BUintD8<N>);
uint_try_from_int!(BTryFrom; BUintD8; BIntD8<N>);
Expand Down Expand Up @@ -224,8 +224,8 @@ impl<const N: usize> From<BUintD8<N>> for [Digit; N] {

#[cfg(test)]
mod tests {
use crate::test::{self, types::*};
use crate::test::cast_types::*;
use crate::test::{self, types::*};
use crate::BTryFrom;

test::test_btryfrom!(utest; TestUint1, TestUint2, TestUint3, TestUint4, TestUint5, TestUint6, TestUint7, TestUint8, TestUint9, TestUint10, TestInt1, TestInt2, TestInt3, TestInt4, TestInt5, TestInt6, TestInt7, TestInt8, TestInt9, TestInt10/*, u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize*/);
Expand Down
5 changes: 2 additions & 3 deletions src/buint/div.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::BUintD8;
use crate::{digit, Digit};
use crate::ExpType;
use crate::{digit, Digit};

impl<const N: usize> BUintD8<N> {
pub(crate) const fn basecase_div_rem(self, mut v: Self, n: usize) -> (Self, Self) {
Expand Down Expand Up @@ -167,8 +167,7 @@ impl<const N: usize> BUintD8<N> {

// q_hat will be either `q` or `q + 1`
let mut q_hat = if u_jn < v_n_m1 {
let (mut q_hat, r_hat) =
digit::div_rem_wide(u.digit(j + n - 1), u_jn, v_n_m1); // D3
let (mut q_hat, r_hat) = digit::div_rem_wide(u.digit(j + n - 1), u_jn, v_n_m1); // D3

if tuple_gt(
digit::widening_mul(q_hat, v_n_m2),
Expand Down
2 changes: 1 addition & 1 deletion src/buint/endian.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::BUintD8;
use crate::{digit, Digit};
use crate::doc;
use crate::{digit, Digit};
// use core::mem::MaybeUninit;

#[doc = doc::endian::impl_desc!(BUintD8)]
Expand Down
13 changes: 9 additions & 4 deletions src/buint/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{digit, Digit, BIntD8};
use crate::errors::{self, option_expect};
use crate::{digit, BIntD8, Digit};

use crate::doc;
use crate::ExpType;
Expand Down Expand Up @@ -503,8 +503,7 @@ impl<const N: usize> BUintD8<N> {
#[inline]
pub const fn power_of_two(power: ExpType) -> Self {
let mut out = Self::ZERO;
out.digits[power as usize >> digit::BIT_SHIFT] =
1 << (power & (digit::BITS - 1));
out.digits[power as usize >> digit::BIT_SHIFT] = 1 << (power & (digit::BITS - 1));
out
}

Expand Down Expand Up @@ -710,7 +709,13 @@ mod tests {

#[test]
fn sum() {
let v = vec![&UTEST::ZERO, &UTEST::ONE, &UTEST::TWO, &UTEST::THREE, &UTEST::FOUR];
let v = vec![
&UTEST::ZERO,
&UTEST::ONE,
&UTEST::TWO,
&UTEST::THREE,
&UTEST::FOUR,
];
assert_eq!(UTEST::TEN, v.iter().copied().sum());
assert_eq!(UTEST::TEN, v.into_iter().sum());
}
Expand Down
2 changes: 1 addition & 1 deletion src/buint/ops.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::BUintD8;
use crate::{digit, Digit, BIntD8};
use crate::ExpType;
use crate::{digit, BIntD8, Digit};
use core::ops::{
Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign,
Mul, MulAssign, Not, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign, Sub, SubAssign,
Expand Down
2 changes: 1 addition & 1 deletion src/buint/overflowing.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::BUintD8;
use crate::{digit, Digit, BIntD8};
use crate::doc;
use crate::ExpType;
use crate::{digit, BIntD8, Digit};

#[doc = doc::overflowing::impl_desc!()]
impl<const N: usize> BUintD8<N> {
Expand Down
7 changes: 3 additions & 4 deletions src/buint/radix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ The original license file and copyright notice for `num_bigint` can be found in
*/

use super::BUintD8;
use crate::{digit, Digit};
use crate::doc;
use crate::errors::ParseIntError;
use crate::int::radix::assert_range;
use crate::ExpType;
use crate::{digit, Digit};
use alloc::string::String;
use alloc::vec::Vec;
use core::iter::Iterator;
Expand Down Expand Up @@ -587,11 +587,10 @@ impl<const N: usize> FromStr for BUintD8<N> {

#[cfg(test)]
mod tests {
use crate::test::{quickcheck_from_to_radix, test_bignum, self};
use core::str::FromStr;
use crate::test::types::*;
use crate::test::{self, quickcheck_from_to_radix, test_bignum};
use crate::BUintD8;

use core::str::FromStr;

test_bignum! {
function: <utest>::from_str,
Expand Down
2 changes: 1 addition & 1 deletion src/buint/saturating.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::BUintD8;
use crate::{digit, Digit, BIntD8};
use crate::doc;
use crate::ExpType;
use crate::{digit, BIntD8, Digit};

#[doc = doc::saturating::impl_desc!()]
impl<const N: usize> BUintD8<N> {
Expand Down
2 changes: 1 addition & 1 deletion src/buint/strict.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::BUintD8;
use crate::{digit, Digit, BIntD8};
use crate::{digit, BIntD8, Digit};

#[doc = doc::strict::impl_desc!()]
impl<const N: usize> BUintD8<N> {
Expand Down
2 changes: 1 addition & 1 deletion src/buint/wrapping.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::BUintD8;
use crate::{digit, Digit, BIntD8};
use crate::errors::option_expect;
use crate::ExpType;
use crate::{digit, BIntD8, Digit};
use crate::{doc, errors};

#[doc = doc::wrapping::impl_desc!()]
Expand Down
12 changes: 3 additions & 9 deletions src/digit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,9 @@ pub const fn widening_mul(a: Digit, b: Digit) -> (Digit, Digit) {
}

#[inline]
pub const fn carrying_mul(
a: Digit,
b: Digit,
carry: Digit,
current: Digit,
) -> (Digit, Digit) {
let prod = carry as DoubleDigit
+ current as DoubleDigit
+ (a as DoubleDigit) * (b as DoubleDigit);
pub const fn carrying_mul(a: Digit, b: Digit, carry: Digit, current: Digit) -> (Digit, Digit) {
let prod =
carry as DoubleDigit + current as DoubleDigit + (a as DoubleDigit) * (b as DoubleDigit);
(prod as Digit, (prod >> BITS) as Digit)
}

Expand Down
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,11 @@ use test::types::*;

type ExpType = u32;

pub use buint::BUintD8;
pub use bint::BIntD8;
pub use buint::BUintD8;

type Digit = u8;


/// Trait for fallible conversions between `bnum` integer types.
///
/// Unfortunately, [`TryFrom`] cannot currently be used for conversions between `bnum` integers, since [`TryFrom<T> for T`](https://doc.rust-lang.org/std/convert/trait.TryFrom.html#impl-TryFrom%3CU%3E-for-T) is already implemented by the standard library (and so it is not possible to implement `TryFrom<BUint<M>> for BUint<N>`). When the [`generic_const_exprs`](https://github.com/rust-lang/rust/issues/76560) feature becomes stabilised, it may be possible to use [`TryFrom`] instead of `BTryFrom`. `BTryFrom` is designed to have the same behaviour as [`TryFrom`] for conversions between two primitive types, and conversions between a primitive type and a bnum type. `BTryFrom` is a workaround for the issue described above, and so you should not implement it yourself. It should only be used for conversions between `bnum` integers.
Expand Down
2 changes: 1 addition & 1 deletion src/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,10 @@ pub struct UniformInt<X> {
z: X,
}

use crate::{BIntD8, BUintD8};
use rand::distributions::uniform::{SampleBorrow, SampleUniform, UniformSampler};
use rand::distributions::{Distribution, Standard};
use rand::{Error, Fill, Rng};
use crate::{BUintD8, BIntD8};

impl<const N: usize> Distribution<BUintD8<N>> for Standard {
#[inline]
Expand Down
2 changes: 1 addition & 1 deletion src/test/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ test_types!(128);
#[cfg(not(any(test_int_bits = "16", test_int_bits = "32", test_int_bits = "128")))]
test_types!(64);

pub use types::*;
pub use core::primitive::*;
pub use types::*;

// #[cfg(feature = "float")]
// #[cfg(not(test_int_bits = "32"))]
Expand Down

0 comments on commit 200f7e1

Please sign in to comment.