use crate::integer::Integer;
use malachite_base::num::arithmetic::traits::Parity;
use malachite_base::num::factorization::traits::{RemovePower, RemovePowerAssign};
fn remove_power_helper(x: &Integer, y: &Integer) -> (Integer, u64) {
let (abs, k) = x.unsigned_abs_ref().remove_power(y.unsigned_abs_ref());
let negative = (*x < 0) != (*y < 0 && k.odd());
(Integer::from_sign_and_abs(!negative, abs), k)
}
impl RemovePower<Self> for Integer {
type Output = Self;
#[inline]
fn remove_power(self, other: Self) -> (Self, u64) {
remove_power_helper(&self, &other)
}
}
impl RemovePower<&Self> for Integer {
type Output = Self;
#[inline]
fn remove_power(self, other: &Self) -> (Self, u64) {
remove_power_helper(&self, other)
}
}
impl RemovePower<Integer> for &Integer {
type Output = Integer;
#[inline]
fn remove_power(self, other: Integer) -> (Integer, u64) {
remove_power_helper(self, &other)
}
}
impl RemovePower<&Integer> for &Integer {
type Output = Integer;
#[inline]
fn remove_power(self, other: &Integer) -> (Integer, u64) {
remove_power_helper(self, other)
}
}
impl RemovePowerAssign<Self> for Integer {
#[inline]
fn remove_power_assign(&mut self, other: Self) -> u64 {
let (q, k) = remove_power_helper(self, &other);
*self = q;
k
}
}
impl RemovePowerAssign<&Self> for Integer {
#[inline]
fn remove_power_assign(&mut self, other: &Self) -> u64 {
let (q, k) = remove_power_helper(self, other);
*self = q;
k
}
}