Skip to content

Commit 4cfc8c1

Browse files
authored
Make Uint::widening_mul into a const fn (#515)
Similar to #514
1 parent 47933c7 commit 4cfc8c1

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/uint/mul.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ macro_rules! impl_schoolbook_multiplication {
5656

5757
impl<const LIMBS: usize> Uint<LIMBS> {
5858
/// Multiply `self` by `rhs`, returning a concatenated "wide" result.
59-
pub fn widening_mul<const RHS_LIMBS: usize>(
59+
pub const fn widening_mul<const RHS_LIMBS: usize, const WIDE_LIMBS: usize>(
6060
&self,
6161
rhs: &Uint<RHS_LIMBS>,
62-
) -> <Uint<RHS_LIMBS> as ConcatMixed<Self>>::MixedOutput
62+
) -> Uint<WIDE_LIMBS>
6363
where
64-
Uint<RHS_LIMBS>: ConcatMixed<Self>,
64+
Uint<RHS_LIMBS>: ConcatMixed<Self, MixedOutput = Uint<WIDE_LIMBS>>,
6565
{
6666
let (lo, hi) = self.split_mul(rhs);
67-
hi.concat_mixed(&lo)
67+
concat_mixed(&lo, &hi)
6868
}
6969

7070
/// Compute "wide" multiplication as a 2-tuple containing the `(lo, hi)` components of the product, whose sizes
@@ -239,9 +239,10 @@ impl<const LIMBS: usize> MulAssign<&Checked<Uint<LIMBS>>> for Checked<Uint<LIMBS
239239
}
240240
}
241241

242-
impl<const LIMBS: usize, const RHS_LIMBS: usize> WideningMul<Uint<RHS_LIMBS>> for Uint<LIMBS>
242+
impl<const LIMBS: usize, const RHS_LIMBS: usize, const WIDE_LIMBS: usize>
243+
WideningMul<Uint<RHS_LIMBS>> for Uint<LIMBS>
243244
where
244-
Uint<RHS_LIMBS>: ConcatMixed<Self>,
245+
Uint<RHS_LIMBS>: ConcatMixed<Self, MixedOutput = Uint<WIDE_LIMBS>>,
245246
{
246247
type Output = <Uint<RHS_LIMBS> as ConcatMixed<Self>>::MixedOutput;
247248

@@ -251,9 +252,10 @@ where
251252
}
252253
}
253254

254-
impl<const LIMBS: usize, const RHS_LIMBS: usize> WideningMul<&Uint<RHS_LIMBS>> for Uint<LIMBS>
255+
impl<const LIMBS: usize, const RHS_LIMBS: usize, const WIDE_LIMBS: usize>
256+
WideningMul<&Uint<RHS_LIMBS>> for Uint<LIMBS>
255257
where
256-
Uint<RHS_LIMBS>: ConcatMixed<Self>,
258+
Uint<RHS_LIMBS>: ConcatMixed<Self, MixedOutput = Uint<WIDE_LIMBS>>,
257259
{
258260
type Output = <Uint<RHS_LIMBS> as ConcatMixed<Self>>::MixedOutput;
259261

0 commit comments

Comments
 (0)