File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed
Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ use std::fmt;
1515use std:: io;
1616use std:: mem;
1717use unreachable:: unreachable;
18- use num_traits:: Float ;
18+ use num_traits:: { Bounded , Float } ;
1919
2020/// A wrapper around Floats providing an implementation of Ord and Hash.
2121///
@@ -569,6 +569,16 @@ fn raw_double_bits<F: Float>(f: &F) -> u64 {
569569 ( man & MAN_MASK ) | ( ( exp_u64 << 52 ) & EXP_MASK ) | ( ( sign_u64 << 63 ) & SIGN_MASK )
570570}
571571
572+ impl < T : Float + Bounded > Bounded for NotNaN < T > {
573+ fn min_value ( ) -> Self {
574+ NotNaN ( Bounded :: min_value ( ) )
575+ }
576+
577+ fn max_value ( ) -> Self {
578+ NotNaN ( Bounded :: max_value ( ) )
579+ }
580+ }
581+
572582#[ cfg( feature = "serde" ) ]
573583mod impl_serde {
574584 extern crate serde;
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ extern crate ordered_float;
55extern crate num_traits;
66
77pub use ordered_float:: * ;
8- pub use num_traits:: Float ;
8+ pub use num_traits:: { Bounded , Float } ;
99pub use std:: cmp:: Ordering :: * ;
1010pub use std:: { f32, f64, panic} ;
1111
@@ -104,6 +104,11 @@ describe! not_nan32 {
104104 assert!( panic:: catch_unwind( || { let mut tmp = NotNan :: from( 0.0f32 ) ; tmp /= f32 :: NAN ; } ) . is_err( ) ) ;
105105 assert!( panic:: catch_unwind( || { let mut tmp = NotNan :: from( 0.0f32 ) ; tmp %= f32 :: NAN ; } ) . is_err( ) ) ;
106106 }
107+
108+ it "should implement Bounded" {
109+ assert_eq!( NotNaN :: <f32 >:: min_value( ) , NotNaN :: from( <f32 as Bounded >:: min_value( ) ) ) ;
110+ assert_eq!( NotNaN :: <f32 >:: max_value( ) , NotNaN :: from( <f32 as Bounded >:: max_value( ) ) ) ;
111+ }
107112}
108113
109114describe ! not_nan64 {
@@ -167,6 +172,11 @@ describe! not_nan64 {
167172 assert!( panic:: catch_unwind( || { let mut tmp = NotNan :: from( 0.0f64 ) ; tmp /= f64 :: NAN ; } ) . is_err( ) ) ;
168173 assert!( panic:: catch_unwind( || { let mut tmp = NotNan :: from( 0.0f64 ) ; tmp %= f64 :: NAN ; } ) . is_err( ) ) ;
169174 }
175+
176+ it "should implement Bounded" {
177+ assert_eq!( NotNaN :: <f64 >:: min_value( ) , NotNaN :: from( <f64 as Bounded >:: min_value( ) ) ) ;
178+ assert_eq!( NotNaN :: <f64 >:: max_value( ) , NotNaN :: from( <f64 as Bounded >:: max_value( ) ) ) ;
179+ }
170180}
171181
172182describe ! hashing {
You can’t perform that action at this time.
0 commit comments