Skip to content

Commit 47933c7

Browse files
authored
Make Uint::square into a const fn (#514)
Wound up being pretty trivial to do.
1 parent c714e43 commit 47933c7

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/uint/mul.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
// TODO(tarcieri): use Karatsuba for better performance
44

5+
use super::concat::concat_mixed;
56
use crate::{
67
Checked, CheckedMul, Concat, ConcatMixed, Limb, Uint, WideningMul, Wrapping, WrappingMul, Zero,
78
};
@@ -90,12 +91,12 @@ impl<const LIMBS: usize> Uint<LIMBS> {
9091
}
9192

9293
/// Square self, returning a concatenated "wide" result.
93-
pub fn square(&self) -> <Self as Concat>::Output
94+
pub const fn square<const WIDE_LIMBS: usize>(&self) -> Uint<WIDE_LIMBS>
9495
where
95-
Self: Concat,
96+
Self: Concat<Output = Uint<WIDE_LIMBS>>,
9697
{
9798
let (lo, hi) = self.square_wide();
98-
hi.concat(&lo)
99+
concat_mixed(&lo, &hi)
99100
}
100101

101102
/// Square self, returning a "wide" result in two parts as (lo, hi).

0 commit comments

Comments
 (0)