diff --git a/src/bint/cast.rs b/src/bint/cast.rs index 93cec7f..38291f1 100644 --- a/src/bint/cast.rs +++ b/src/bint/cast.rs @@ -1,5 +1,5 @@ use super::BIntD8; -use crate::{BUintD8, digit, Digit}; +use crate::{digit, BUintD8, Digit}; macro_rules! bint_as { ($($int: ty), *) => { diff --git a/src/bint/convert.rs b/src/bint/convert.rs index c50cd67..cb99d9a 100644 --- a/src/bint/convert.rs +++ b/src/bint/convert.rs @@ -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); diff --git a/src/bint/mod.rs b/src/bint/mod.rs index 9f58467..9fc75e8 100644 --- a/src/bint/mod.rs +++ b/src/bint/mod.rs @@ -425,10 +425,7 @@ impl quickcheck::Arbitrary for BIntD8 { #[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); @@ -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()); } diff --git a/src/bint/radix.rs b/src/bint/radix.rs index 172a465..0aad0a9 100644 --- a/src/bint/radix.rs +++ b/src/bint/radix.rs @@ -168,8 +168,8 @@ impl BIntD8 { #[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! { @@ -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); @@ -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); @@ -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); diff --git a/src/bint/strict.rs b/src/bint/strict.rs index 9207551..9e9a31f 100644 --- a/src/bint/strict.rs +++ b/src/bint/strict.rs @@ -1,7 +1,6 @@ use super::BIntD8; use crate::{BUintD8, Digit}; - #[doc = doc::strict::impl_desc!()] impl BIntD8 { crate::int::strict::impls!(I); diff --git a/src/bint/unchecked.rs b/src/bint/unchecked.rs index c438038..63e230c 100644 --- a/src/bint/unchecked.rs +++ b/src/bint/unchecked.rs @@ -1,7 +1,6 @@ use super::BIntD8; use crate::{BUintD8, Digit}; - crate::int::unchecked::impls!(BIntD8, I); #[cfg(test)] diff --git a/src/buint/bigint_helpers.rs b/src/buint/bigint_helpers.rs index 2df3484..1525ada 100644 --- a/src/buint/bigint_helpers.rs +++ b/src/buint/bigint_helpers.rs @@ -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 BUintD8 { diff --git a/src/buint/checked.rs b/src/buint/checked.rs index 6bf6ff6..29d3147 100644 --- a/src/buint/checked.rs +++ b/src/buint/checked.rs @@ -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 BUintD8 { diff --git a/src/buint/const_trait_fillers.rs b/src/buint/const_trait_fillers.rs index d895633..4655276 100644 --- a/src/buint/const_trait_fillers.rs +++ b/src/buint/const_trait_fillers.rs @@ -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!()] diff --git a/src/buint/convert.rs b/src/buint/convert.rs index 3e73be3..2d1747f 100644 --- a/src/buint/convert.rs +++ b/src/buint/convert.rs @@ -195,7 +195,7 @@ impl From for BUintD8 { } } -use crate::{BTryFrom, BIntD8}; +use crate::{BIntD8, BTryFrom}; uint_try_from_uint!(BTryFrom; BUintD8; BUintD8); uint_try_from_int!(BTryFrom; BUintD8; BIntD8); @@ -224,8 +224,8 @@ impl From> 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*/); diff --git a/src/buint/div.rs b/src/buint/div.rs index 1fa8f09..5221b02 100644 --- a/src/buint/div.rs +++ b/src/buint/div.rs @@ -1,6 +1,6 @@ use super::BUintD8; -use crate::{digit, Digit}; use crate::ExpType; +use crate::{digit, Digit}; impl BUintD8 { pub(crate) const fn basecase_div_rem(self, mut v: Self, n: usize) -> (Self, Self) { @@ -167,8 +167,7 @@ impl BUintD8 { // 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), diff --git a/src/buint/endian.rs b/src/buint/endian.rs index 7205fe5..3259642 100644 --- a/src/buint/endian.rs +++ b/src/buint/endian.rs @@ -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)] diff --git a/src/buint/mod.rs b/src/buint/mod.rs index a5e64fb..3d1ca50 100644 --- a/src/buint/mod.rs +++ b/src/buint/mod.rs @@ -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; @@ -503,8 +503,7 @@ impl BUintD8 { #[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 } @@ -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()); } diff --git a/src/buint/ops.rs b/src/buint/ops.rs index f5f4751..f615d94 100644 --- a/src/buint/ops.rs +++ b/src/buint/ops.rs @@ -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, diff --git a/src/buint/overflowing.rs b/src/buint/overflowing.rs index 16e908b..30bd286 100644 --- a/src/buint/overflowing.rs +++ b/src/buint/overflowing.rs @@ -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 BUintD8 { diff --git a/src/buint/radix.rs b/src/buint/radix.rs index 33f32f8..797aefa 100644 --- a/src/buint/radix.rs +++ b/src/buint/radix.rs @@ -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; @@ -587,11 +587,10 @@ impl FromStr for BUintD8 { #[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: ::from_str, diff --git a/src/buint/saturating.rs b/src/buint/saturating.rs index c9e7cc1..f9e566c 100644 --- a/src/buint/saturating.rs +++ b/src/buint/saturating.rs @@ -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 BUintD8 { diff --git a/src/buint/strict.rs b/src/buint/strict.rs index e575676..c8aca99 100644 --- a/src/buint/strict.rs +++ b/src/buint/strict.rs @@ -1,5 +1,5 @@ use super::BUintD8; -use crate::{digit, Digit, BIntD8}; +use crate::{digit, BIntD8, Digit}; #[doc = doc::strict::impl_desc!()] impl BUintD8 { diff --git a/src/buint/wrapping.rs b/src/buint/wrapping.rs index d8f107b..cd08b6e 100644 --- a/src/buint/wrapping.rs +++ b/src/buint/wrapping.rs @@ -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!()] diff --git a/src/digit.rs b/src/digit.rs index 736f682..47e718e 100644 --- a/src/digit.rs +++ b/src/digit.rs @@ -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) } diff --git a/src/lib.rs b/src/lib.rs index 10659db..e91d114 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 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> for BUint`). 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. diff --git a/src/random.rs b/src/random.rs index 85519be..9cf18b4 100644 --- a/src/random.rs +++ b/src/random.rs @@ -296,10 +296,10 @@ pub struct UniformInt { 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 Distribution> for Standard { #[inline] diff --git a/src/test/types.rs b/src/test/types.rs index 0563c7a..66f5955 100644 --- a/src/test/types.rs +++ b/src/test/types.rs @@ -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"))]