pub trait Power<Rhs = Self>{
type Output;
fn to_the_power_of(self, other: Rhs) -> Self::Output;
}
macro_rules! impl_power {
(signed; $($t : ty),*) => {
$(
impl Power<$t> for $t {
type Output = $t;
fn to_the_power_of(self, other: $t) -> Self::Output {
self.pow(other as u32)
}
}
)*
};
(float; $($t : ty),*) => {
$(
impl Power<$t> for $t {
type Output = $t;
fn to_the_power_of(self, other: $t) -> Self::Output {
self.powf(other)
}
}
)*
};
}
impl_power!(signed; i8,i16,i32,i64);
impl_power!(float; f32,f64);