@@ -325,6 +325,13 @@ impl Signed for f64 {
325
325
#[ inline( always) ]
326
326
fn abs ( & self ) -> f64 { abs ( * self ) }
327
327
328
+ ///
329
+ /// The positive difference of two numbers. Returns `0.0` if the number is less than or
330
+ /// equal to `other`, otherwise the difference between`self` and `other` is returned.
331
+ ///
332
+ #[ inline( always) ]
333
+ fn abs_sub ( & self , other : & f64 ) -> f64 { abs_sub ( * self , * other) }
334
+
328
335
///
329
336
/// # Returns
330
337
///
@@ -594,6 +601,7 @@ impl Float for f64 {
594
601
#[ inline( always) ]
595
602
fn neg_zero ( ) -> f64 { -0.0 }
596
603
604
+ /// Returns `true` if the number is NaN
597
605
#[ inline( always) ]
598
606
fn is_NaN ( & self ) -> bool { * self != * self }
599
607
@@ -603,7 +611,7 @@ impl Float for f64 {
603
611
* self == Float :: infinity ( ) || * self == Float :: neg_infinity ( )
604
612
}
605
613
606
- /// Returns `true` if the number is finite
614
+ /// Returns `true` if the number is not infinite or NaN
607
615
#[ inline( always) ]
608
616
fn is_finite ( & self ) -> bool {
609
617
!( self . is_NaN ( ) || self . is_infinite ( ) )
@@ -1005,7 +1013,7 @@ mod tests {
1005
1013
}
1006
1014
1007
1015
#[ test]
1008
- pub fn test_signed ( ) {
1016
+ pub fn test_abs ( ) {
1009
1017
assert_eq ! ( infinity. abs( ) , infinity) ;
1010
1018
assert_eq ! ( 1f64 . abs( ) , 1f64 ) ;
1011
1019
assert_eq ! ( 0f64 . abs( ) , 0f64 ) ;
@@ -1014,7 +1022,24 @@ mod tests {
1014
1022
assert_eq ! ( neg_infinity. abs( ) , infinity) ;
1015
1023
assert_eq ! ( ( 1f64 /neg_infinity) . abs( ) , 0f64 ) ;
1016
1024
assert ! ( NaN . abs( ) . is_NaN( ) ) ;
1025
+ }
1017
1026
1027
+ #[ test]
1028
+ fn test_abs_sub ( ) {
1029
+ assert_eq ! ( ( -1f64 ) . abs_sub( & 1f64 ) , 0f64 ) ;
1030
+ assert_eq ! ( 1f64 . abs_sub( & 1f64 ) , 0f64 ) ;
1031
+ assert_eq ! ( 1f64 . abs_sub( & 0f64 ) , 1f64 ) ;
1032
+ assert_eq ! ( 1f64 . abs_sub( & -1f64 ) , 2f64 ) ;
1033
+ assert_eq ! ( neg_infinity. abs_sub( & 0f64 ) , 0f64 ) ;
1034
+ assert_eq ! ( infinity. abs_sub( & 1f64 ) , infinity) ;
1035
+ assert_eq ! ( 0f64 . abs_sub( & neg_infinity) , infinity) ;
1036
+ assert_eq ! ( 0f64 . abs_sub( & infinity) , 0f64 ) ;
1037
+ assert ! ( NaN . abs_sub( & -1f64 ) . is_NaN( ) ) ;
1038
+ assert ! ( 1f64 . abs_sub( & NaN ) . is_NaN( ) ) ;
1039
+ }
1040
+
1041
+ #[ test]
1042
+ fn test_signum ( ) {
1018
1043
assert_eq ! ( infinity. signum( ) , 1f64 ) ;
1019
1044
assert_eq ! ( 1f64 . signum( ) , 1f64 ) ;
1020
1045
assert_eq ! ( 0f64 . signum( ) , 1f64 ) ;
@@ -1023,7 +1048,10 @@ mod tests {
1023
1048
assert_eq ! ( neg_infinity. signum( ) , -1f64 ) ;
1024
1049
assert_eq ! ( ( 1f64 /neg_infinity) . signum( ) , -1f64 ) ;
1025
1050
assert ! ( NaN . signum( ) . is_NaN( ) ) ;
1051
+ }
1026
1052
1053
+ #[ test]
1054
+ fn test_is_positive ( ) {
1027
1055
assert ! ( infinity. is_positive( ) ) ;
1028
1056
assert ! ( 1f64 . is_positive( ) ) ;
1029
1057
assert ! ( 0f64 . is_positive( ) ) ;
@@ -1032,7 +1060,10 @@ mod tests {
1032
1060
assert ! ( !neg_infinity. is_positive( ) ) ;
1033
1061
assert ! ( !( 1f64 /neg_infinity) . is_positive( ) ) ;
1034
1062
assert ! ( !NaN . is_positive( ) ) ;
1063
+ }
1035
1064
1065
+ #[ test]
1066
+ fn test_is_negative ( ) {
1036
1067
assert ! ( !infinity. is_negative( ) ) ;
1037
1068
assert ! ( !1f64 . is_negative( ) ) ;
1038
1069
assert ! ( !0f64 . is_negative( ) ) ;
0 commit comments