-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement Pow for BigInt #106
Comments
Hmm, I see. This was sort of intentional, because having We probably should have made |
I think we should just implement For consistency's sake, I think we should implement all of: impl Pow<_> for BigInt { ... }
impl Pow<_> for &'_ BigInt { ... }
impl Pow<&'_ _> for BigInt { ... }
impl<'l, 'r> Pow<&'r _> for &'l BigInt { ... }
impl Pow<_> for BigUint { ... }
impl Pow<_> for &'_ BigUint { ... }
impl Pow<&'_ _> for BigUint { ... }
impl<'l, 'r> Pow<&'r _> for &'l BigUint { ... } if that isn't acceptable, an alternate solution is: trait PowWorkaround<Rhs> {
type Output;
fn pow_workaround(self, rhs: Rhs) -> Self::Output;
}
impl<Rhs> PowWorkaround<Rhs> for BigInt // also BigUint
where
for<'a> &'a Self: Pow<Rhs, Output=Self>
{
type Output = Self;
fn pow_workaround(self, rhs: Rhs) -> Self {
(&self).pow(rhs)
}
}
impl<T, Rhs> PowWorkaround<Rhs> for T
where
Self: Pow<Rhs>
{
type Output = <Self as Pow<Rhs>>::Output;
fn pow_workaround(self, rhs: Rhs) -> Self::Output {
Pow::pow(self, rhs)
}
}
impl<T: Integer + Clone + PowWorkaround<_, Output=T>> impl Pow<_> for &'_ Ratio<T> {
...
} |
137: Implement `Pow` by value r=cuviper a=cuviper We already had `Pow` for references, so the default call doesn't consume your allocation, but this wasn't sufficient for uses like `BigRational`. Now we do implement it by value, and have also added a new inherent method `pow(&self, exp: u32)` that takes precedence. That exponent type matches the same method on primitive integers, and is likely sufficient for most use cases. Fixes #106 Co-authored-by: Josh Stone <cuviper@gmail.com>
Pow<T>
is not implemented forBigInt
, only for&BigInt
. This causes problems for usingPow
onRatio<BigInt>
sinceRatio<T>
'sPow
implementation requiresT: Pow
.The text was updated successfully, but these errors were encountered: