crypto_bigint/limb/
neg.rs1use crate::{Limb, NegMod, NonZero, WrappingNeg};
4
5impl Limb {
6 #[inline(always)]
8 #[must_use]
9 pub const fn wrapping_neg(self) -> Self {
10 Limb(self.0.wrapping_neg())
11 }
12}
13
14impl WrappingNeg for Limb {
15 #[inline]
16 fn wrapping_neg(&self) -> Self {
17 Self(self.0.wrapping_neg())
18 }
19}
20
21impl NegMod for Limb {
22 type Output = Self;
23
24 fn neg_mod(&self, p: &NonZero<Self>) -> Self::Output {
25 let nz = self.is_nonzero();
26 let res = p.borrowing_sub(*self, Limb::ZERO).0;
27 Self::select(Limb::ZERO, res, nz)
28 }
29}