@@ -3,6 +3,7 @@ use super::Quantity;
33use approx:: { AbsDiffEq , RelativeEq } ;
44#[ cfg( feature = "ndarray" ) ]
55use ndarray:: { Array , ArrayBase , Data , DataMut , DataOwned , Dimension } ;
6+ use num_traits:: { Inv , Signed } ;
67use std:: marker:: PhantomData ;
78use std:: ops:: { Add , AddAssign , Div , DivAssign , Mul , MulAssign , Neg , Sub , SubAssign } ;
89use typenum:: { Diff , Integer , Negate , Prod , Quot , Sum , P2 , P3 } ;
@@ -401,7 +402,9 @@ impl<U> Quantity<f64, U> {
401402 {
402403 Quantity ( self . 0 . powf ( 1.0 / R :: I32 as f64 ) , PhantomData )
403404 }
405+ }
404406
407+ impl < T , U > Quantity < T , U > {
405408 /// Return the absolute value of `self`.
406409 ///
407410 /// # Example
@@ -410,10 +413,31 @@ impl<U> Quantity<f64, U> {
410413 /// # use approx::assert_relative_eq;
411414 /// let t = -50.0 * KELVIN;
412415 /// assert_relative_eq!(t.abs(), &(50.0 * KELVIN));
413- pub fn abs ( self ) -> Self {
416+ pub fn abs ( self ) -> Self
417+ where
418+ T : Signed ,
419+ {
414420 Self ( self . 0 . abs ( ) , PhantomData )
415421 }
416422
423+ /// Return the multiplicative inverse of `self`.
424+ ///
425+ /// # Example
426+ /// ```
427+ /// # use quantity::PASCAL;
428+ /// # use approx::assert_relative_eq;
429+ /// let t = 5.0 * PASCAL;
430+ /// assert_relative_eq!(t.inv(), &(0.2/PASCAL));
431+ pub fn inv ( self ) -> Quantity < T , Negate < U > >
432+ where
433+ T : Inv < Output = T > ,
434+ U : Neg ,
435+ {
436+ Quantity ( self . 0 . inv ( ) , PhantomData )
437+ }
438+ }
439+
440+ impl < U > Quantity < f64 , U > {
417441 /// Returns a number that represents the sign of `self`.
418442 ///
419443 /// - `1.0` if the number is positive, `+0.0` or `INFINITY`
0 commit comments