@@ -829,6 +829,13 @@ impl f32 {
829829 /// ```
830830 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
831831 #[ inline]
832+ #[ rustc_deprecated( since = "1.10.0" ,
833+ reason = "you probably meant `(self - other).abs()`: \
834+ this operation is `(self - other).max(0.0)` (also \
835+ known as `fdimf` in C). If you truly need the positive \
836+ difference, consider using that expression or the C function \
837+ `fdimf`, depending on how you wish to handle NaN (please consider \
838+ filing an issue describing your use-case too).") ]
832839 pub fn abs_sub ( self , other : f32 ) -> f32 {
833840 unsafe { cmath:: fdimf ( self , other) }
834841 }
@@ -939,7 +946,7 @@ impl f32 {
939946 /// let f = f32::consts::PI / 2.0;
940947 ///
941948 /// // asin(sin(pi/2))
942- /// let abs_difference = f.sin().asin().abs_sub( f32::consts::PI / 2.0);
949+ /// let abs_difference = ( f.sin().asin() - f32::consts::PI / 2.0).abs( );
943950 ///
944951 /// assert!(abs_difference <= f32::EPSILON);
945952 /// ```
@@ -959,7 +966,7 @@ impl f32 {
959966 /// let f = f32::consts::PI / 4.0;
960967 ///
961968 /// // acos(cos(pi/4))
962- /// let abs_difference = f.cos().acos().abs_sub( f32::consts::PI / 4.0);
969+ /// let abs_difference = ( f.cos().acos() - f32::consts::PI / 4.0).abs( );
963970 ///
964971 /// assert!(abs_difference <= f32::EPSILON);
965972 /// ```
@@ -978,7 +985,7 @@ impl f32 {
978985 /// let f = 1.0f32;
979986 ///
980987 /// // atan(tan(1))
981- /// let abs_difference = f.tan().atan().abs_sub( 1.0);
988+ /// let abs_difference = ( f.tan().atan() - 1.0).abs( );
982989 ///
983990 /// assert!(abs_difference <= f32::EPSILON);
984991 /// ```
@@ -1048,7 +1055,7 @@ impl f32 {
10481055 /// let x = 7.0f64;
10491056 ///
10501057 /// // e^(ln(7)) - 1
1051- /// let abs_difference = x.ln().exp_m1().abs_sub( 6.0);
1058+ /// let abs_difference = ( x.ln().exp_m1() - 6.0).abs( );
10521059 ///
10531060 /// assert!(abs_difference < 1e-10);
10541061 /// ```
@@ -1108,7 +1115,7 @@ impl f32 {
11081115 /// let f = x.cosh();
11091116 /// // Solving cosh() at 1 gives this result
11101117 /// let g = (e*e + 1.0)/(2.0*e);
1111- /// let abs_difference = f.abs_sub(g );
1118+ /// let abs_difference = (f - g).abs( );
11121119 ///
11131120 /// // Same result
11141121 /// assert!(abs_difference <= f32::EPSILON);
@@ -1191,9 +1198,9 @@ impl f32 {
11911198 /// let e = f32::consts::E;
11921199 /// let f = e.tanh().atanh();
11931200 ///
1194- /// let abs_difference = f.abs_sub(e );
1201+ /// let abs_difference = (f - e).abs( );
11951202 ///
1196- /// assert!(abs_difference <= f32::EPSILON );
1203+ /// assert!(abs_difference <= 1e-5 );
11971204 /// ```
11981205 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
11991206 #[ inline]
@@ -1747,24 +1754,6 @@ mod tests {
17471754 assert ! ( match nan. frexp( ) { ( x, _) => x. is_nan( ) } )
17481755 }
17491756
1750- #[ test]
1751- fn test_abs_sub ( ) {
1752- assert_eq ! ( ( -1f32 ) . abs_sub( 1f32 ) , 0f32 ) ;
1753- assert_eq ! ( 1f32 . abs_sub( 1f32 ) , 0f32 ) ;
1754- assert_eq ! ( 1f32 . abs_sub( 0f32 ) , 1f32 ) ;
1755- assert_eq ! ( 1f32 . abs_sub( -1f32 ) , 2f32 ) ;
1756- assert_eq ! ( NEG_INFINITY . abs_sub( 0f32 ) , 0f32 ) ;
1757- assert_eq ! ( INFINITY . abs_sub( 1f32 ) , INFINITY ) ;
1758- assert_eq ! ( 0f32 . abs_sub( NEG_INFINITY ) , INFINITY ) ;
1759- assert_eq ! ( 0f32 . abs_sub( INFINITY ) , 0f32 ) ;
1760- }
1761-
1762- #[ test]
1763- fn test_abs_sub_nowin ( ) {
1764- assert ! ( NAN . abs_sub( -1f32 ) . is_nan( ) ) ;
1765- assert ! ( 1f32 . abs_sub( NAN ) . is_nan( ) ) ;
1766- }
1767-
17681757 #[ test]
17691758 fn test_asinh ( ) {
17701759 assert_eq ! ( 0.0f32 . asinh( ) , 0.0f32 ) ;
0 commit comments