@@ -173,6 +173,32 @@ fn div() {
173
173
assert_eq ! ( Duration :: new( 99 , 999_999_000 ) / 100 , Duration :: new( 0 , 999_999_990 ) ) ;
174
174
}
175
175
176
+ #[ test]
177
+ fn div_duration_f32 ( ) {
178
+ assert_eq ! ( Duration :: ZERO . div_duration_f32( Duration :: MAX ) , 0.0 ) ;
179
+ assert_eq ! ( Duration :: MAX . div_duration_f32( Duration :: ZERO ) , f32 :: INFINITY ) ;
180
+ assert_eq ! ( ( Duration :: SECOND * 2 ) . div_duration_f32( Duration :: SECOND ) , 2.0 ) ;
181
+ assert ! ( Duration :: ZERO . div_duration_f32( Duration :: ZERO ) . is_nan( ) ) ;
182
+ // These tests demonstrate it doesn't panic with extreme values.
183
+ // Accuracy of the computed value is not a huge concern, we know floats don't work well
184
+ // at these extremes.
185
+ assert ! ( ( Duration :: MAX ) . div_duration_f32( Duration :: NANOSECOND ) > 10.0f32 . powf( 28.0 ) ) ;
186
+ assert ! ( ( Duration :: NANOSECOND ) . div_duration_f32( Duration :: MAX ) < 0.1 ) ;
187
+ }
188
+
189
+ #[ test]
190
+ fn div_duration_f64 ( ) {
191
+ assert_eq ! ( Duration :: ZERO . div_duration_f64( Duration :: MAX ) , 0.0 ) ;
192
+ assert_eq ! ( Duration :: MAX . div_duration_f64( Duration :: ZERO ) , f64 :: INFINITY ) ;
193
+ assert_eq ! ( ( Duration :: SECOND * 2 ) . div_duration_f64( Duration :: SECOND ) , 2.0 ) ;
194
+ assert ! ( Duration :: ZERO . div_duration_f64( Duration :: ZERO ) . is_nan( ) ) ;
195
+ // These tests demonstrate it doesn't panic with extreme values.
196
+ // Accuracy of the computed value is not a huge concern, we know floats don't work well
197
+ // at these extremes.
198
+ assert ! ( ( Duration :: MAX ) . div_duration_f64( Duration :: NANOSECOND ) > 10.0f64 . powf( 28.0 ) ) ;
199
+ assert ! ( ( Duration :: NANOSECOND ) . div_duration_f64( Duration :: MAX ) < 0.1 ) ;
200
+ }
201
+
176
202
#[ test]
177
203
fn checked_div ( ) {
178
204
assert_eq ! ( Duration :: new( 2 , 0 ) . checked_div( 2 ) , Some ( Duration :: new( 1 , 0 ) ) ) ;
0 commit comments