@@ -5,7 +5,7 @@ extern crate ordered_float;
55extern crate num_traits;
66
77pub use ordered_float:: * ;
8- pub use num_traits:: { Bounded , Float , FromPrimitive , Num , One , ToPrimitive , Zero } ;
8+ pub use num_traits:: { Bounded , Float , FromPrimitive , Num , One , Signed , ToPrimitive , Zero } ;
99pub use std:: cmp:: Ordering :: * ;
1010pub use std:: { f32, f64, panic} ;
1111
@@ -160,6 +160,14 @@ describe! not_nan32 {
160160 assert_eq!( NotNaN :: <f32 >:: from_str_radix( "42.0" , 10 ) . unwrap( ) , NotNaN :: from( 42.0f32 ) ) ;
161161 assert!( NotNaN :: <f32 >:: from_str_radix( "NaN" , 10 ) . is_err( ) ) ;
162162 }
163+
164+ it "should implement Signed" {
165+ assert_eq!( NotNaN :: from( 42f32 ) . abs( ) , NotNaN :: from( 42f32 ) ) ;
166+ assert_eq!( NotNaN :: from( -42f32 ) . abs( ) , NotNaN :: from( 42f32 ) ) ;
167+
168+ assert_eq!( NotNaN :: from( 50f32 ) . abs_sub( & NotNaN :: from( 8f32 ) ) , NotNaN :: from( 42f32 ) ) ;
169+ assert_eq!( NotNaN :: from( 8f32 ) . abs_sub( & NotNaN :: from( 50f32 ) ) , NotNaN :: from( 0f32 ) ) ;
170+ }
163171}
164172
165173describe ! not_nan64 {
@@ -279,6 +287,14 @@ describe! not_nan64 {
279287 assert_eq!( NotNaN :: <f64 >:: from_str_radix( "42.0" , 10 ) . unwrap( ) , NotNaN :: from( 42.0f64 ) ) ;
280288 assert!( NotNaN :: <f64 >:: from_str_radix( "NaN" , 10 ) . is_err( ) ) ;
281289 }
290+
291+ it "should implement Signed" {
292+ assert_eq!( NotNaN :: from( 42f64 ) . abs( ) , NotNaN :: from( 42f64 ) ) ;
293+ assert_eq!( NotNaN :: from( -42f64 ) . abs( ) , NotNaN :: from( 42f64 ) ) ;
294+
295+ assert_eq!( NotNaN :: from( 50f64 ) . abs_sub( & NotNaN :: from( 8f64 ) ) , NotNaN :: from( 42f64 ) ) ;
296+ assert_eq!( NotNaN :: from( 8f64 ) . abs_sub( & NotNaN :: from( 50f64 ) ) , NotNaN :: from( 0f64 ) ) ;
297+ }
282298}
283299
284300describe ! hashing {
0 commit comments