/rust/registry/src/index.crates.io-1949cf8c6b5b557f/num-traits-0.2.19/src/ops/inv.rs
Line  | Count  | Source  | 
1  |  | /// Unary operator for retrieving the multiplicative inverse, or reciprocal, of a value.  | 
2  |  | pub trait Inv { | 
3  |  |     /// The result after applying the operator.  | 
4  |  |     type Output;  | 
5  |  |  | 
6  |  |     /// Returns the multiplicative inverse of `self`.  | 
7  |  |     ///  | 
8  |  |     /// # Examples  | 
9  |  |     ///  | 
10  |  |     /// ```  | 
11  |  |     /// use std::f64::INFINITY;  | 
12  |  |     /// use num_traits::Inv;  | 
13  |  |     ///  | 
14  |  |     /// assert_eq!(7.0.inv() * 7.0, 1.0);  | 
15  |  |     /// assert_eq!((-0.0).inv(), -INFINITY);  | 
16  |  |     /// ```  | 
17  |  |     fn inv(self) -> Self::Output;  | 
18  |  | }  | 
19  |  |  | 
20  |  | impl Inv for f32 { | 
21  |  |     type Output = f32;  | 
22  |  |     #[inline]  | 
23  | 0  |     fn inv(self) -> f32 { | 
24  | 0  |         1.0 / self  | 
25  | 0  |     }  | 
26  |  | }  | 
27  |  | impl Inv for f64 { | 
28  |  |     type Output = f64;  | 
29  |  |     #[inline]  | 
30  | 0  |     fn inv(self) -> f64 { | 
31  | 0  |         1.0 / self  | 
32  | 0  |     }  | 
33  |  | }  | 
34  |  | impl<'a> Inv for &'a f32 { | 
35  |  |     type Output = f32;  | 
36  |  |     #[inline]  | 
37  | 0  |     fn inv(self) -> f32 { | 
38  | 0  |         1.0 / *self  | 
39  | 0  |     }  | 
40  |  | }  | 
41  |  | impl<'a> Inv for &'a f64 { | 
42  |  |     type Output = f64;  | 
43  |  |     #[inline]  | 
44  | 0  |     fn inv(self) -> f64 { | 
45  | 0  |         1.0 / *self  | 
46  | 0  |     }  | 
47  |  | }  |