/// Provides a multiplicative inverse operation for numeric types.
pub trait Reciprocal: Sized {
/// Returns the multiplicative inverse of `self`.
///
/// Implementations should document how they behave for zero (panic, `None`,
/// infinity, etc.).
fn reciprocal(self) -> Self;
}
macro_rules! impl_reciprocal_for_float {
($($ty:ty),+ $(,)?) => {
$(impl Reciprocal for $ty {
fn reciprocal(self) -> Self {
1.0 as $ty / self
}
})+
};
}
impl_reciprocal_for_float!(f32, f64);