const_num_traits/ops/inv.rs
1c0nst::c0nst! {
2/// Unary operator for retrieving the multiplicative inverse, or reciprocal, of a value.
3pub c0nst trait Inv {
4 /// The result after applying the operator.
5 type Output;
6
7 /// Returns the multiplicative inverse of `self`.
8 ///
9 /// # Examples
10 ///
11 /// ```
12 /// use std::f64::INFINITY;
13 /// use const_num_traits::Inv;
14 ///
15 /// assert_eq!(7.0.inv() * 7.0, 1.0);
16 /// assert_eq!((-0.0).inv(), -INFINITY);
17 /// ```
18 fn inv(self) -> Self::Output;
19}
20}
21
22c0nst::c0nst! {
23c0nst impl Inv for f32 {
24 type Output = f32;
25 #[inline]
26 fn inv(self) -> f32 {
27 1.0 / self
28 }
29}
30}
31c0nst::c0nst! {
32c0nst impl Inv for f64 {
33 type Output = f64;
34 #[inline]
35 fn inv(self) -> f64 {
36 1.0 / self
37 }
38}
39}
40c0nst::c0nst! {
41c0nst impl<'a> Inv for &'a f32 {
42 type Output = f32;
43 #[inline]
44 fn inv(self) -> f32 {
45 1.0 / *self
46 }
47}
48}
49c0nst::c0nst! {
50c0nst impl<'a> Inv for &'a f64 {
51 type Output = f64;
52 #[inline]
53 fn inv(self) -> f64 {
54 1.0 / *self
55 }
56}
57}