num-traits/src/ops/inv.rs

30 lines
703 B
Rust
Raw Normal View History

2018-02-18 19:29:21 +00:00
/// Unary operator for retrieving the multiplicative inverse, or reciprocal, of a value.
pub trait Inv {
/// The result after applying the operator.
type Output;
/// Returns the multiplicative inverse of `Self`.
fn inv(self) -> Self::Output;
}
macro_rules! inv_impl {
($t:ty, $out:ty, $fn:expr) => {
impl<'a> Inv for $t {
type Output = $out;
#[inline]
fn inv(self) -> $out {
($fn)(self)
}
}
}
}
#[cfg(feature = "std")]
mod float_impls {
inv_impl!(f32, f32, f32::recip);
inv_impl!(f64, f64, f64::recip);
inv_impl!(&'a f32, f32, f32::recip);
inv_impl!(&'a f64, f64, f64::recip);
}