Skip to content

Commit be47342

Browse files
committed
pirmitives - BigNum - impl num::pow::Pow
1 parent 3f8ec05 commit be47342

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

primitives/src/big_num.rs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66
str::FromStr,
77
};
88

9-
use num::{rational::Ratio, BigUint, CheckedSub, Integer};
9+
use num::{pow::Pow, rational::Ratio, BigUint, CheckedSub, Integer};
1010
use num_derive::{Num, NumOps, One, Zero};
1111
use serde::{Deserialize, Deserializer, Serialize, Serializer};
1212

@@ -99,6 +99,46 @@ impl Integer for BigNum {
9999
}
100100
}
101101

102+
impl Pow<BigNum> for BigNum {
103+
type Output = BigNum;
104+
105+
fn pow(self, rhs: BigNum) -> Self::Output {
106+
Self(self.0.pow(rhs.0))
107+
}
108+
}
109+
110+
impl Pow<&BigNum> for BigNum {
111+
type Output = BigNum;
112+
113+
fn pow(self, rhs: &BigNum) -> Self::Output {
114+
BigNum(self.0.pow(&rhs.0))
115+
}
116+
}
117+
118+
impl Pow<BigNum> for &BigNum {
119+
type Output = BigNum;
120+
121+
fn pow(self, rhs: BigNum) -> Self::Output {
122+
BigNum(Pow::pow(&self.0, rhs.0))
123+
}
124+
}
125+
126+
impl Pow<&BigNum> for &BigNum {
127+
type Output = BigNum;
128+
129+
fn pow(self, rhs: &BigNum) -> Self::Output {
130+
BigNum(Pow::pow(&self.0, &rhs.0))
131+
}
132+
}
133+
134+
impl Pow<u8> for BigNum {
135+
type Output = BigNum;
136+
137+
fn pow(self, rhs: u8) -> Self::Output {
138+
BigNum(self.0.pow(rhs))
139+
}
140+
}
141+
102142
impl Add<&BigNum> for &BigNum {
103143
type Output = BigNum;
104144

0 commit comments

Comments
 (0)