@@ -399,3 +399,57 @@ test_impl_try_from_signed_to_unsigned_err! { test_try_i32u16, i32, u16 }
399
399
test_impl_try_from_signed_to_unsigned_err ! { test_try_i64u8, i64 , u8 }
400
400
test_impl_try_from_signed_to_unsigned_err ! { test_try_i64u16, i64 , u16 }
401
401
test_impl_try_from_signed_to_unsigned_err ! { test_try_i64u32, i64 , u32 }
402
+
403
+ macro_rules! test_float {
404
+ ( $modname: ident, $fty: ty, $inf: expr, $neginf: expr, $nan: expr) => { mod $modname {
405
+ use core:: num:: Float ;
406
+ // FIXME(nagisa): these tests should test for sign of -0.0
407
+ #[ test]
408
+ fn min( ) {
409
+ assert_eq!( 0.0 . min( 0.0 ) , 0.0 ) ;
410
+ assert_eq!( ( -0.0 ) . min( -0.0 ) , -0.0 ) ;
411
+ assert_eq!( 9.0 . min( 9.0 ) , 9.0 ) ;
412
+ assert_eq!( ( -9.0 ) . min( 0.0 ) , -9.0 ) ;
413
+ assert_eq!( 0.0 . min( 9.0 ) , 0.0 ) ;
414
+ assert_eq!( ( -0.0 ) . min( -9.0 ) , -9.0 ) ;
415
+ assert_eq!( $inf. min( 9.0 ) , 9.0 ) ;
416
+ assert_eq!( 9.0 . min( $inf) , 9.0 ) ;
417
+ assert_eq!( $inf. min( -9.0 ) , -9.0 ) ;
418
+ assert_eq!( ( -9.0 ) . min( $inf) , -9.0 ) ;
419
+ assert_eq!( $neginf. min( 9.0 ) , $neginf) ;
420
+ assert_eq!( 9.0 . min( $neginf) , $neginf) ;
421
+ assert_eq!( $neginf. min( -9.0 ) , $neginf) ;
422
+ assert_eq!( ( -9.0 ) . min( $neginf) , $neginf) ;
423
+ assert_eq!( $nan. min( 9.0 ) , 9.0 ) ;
424
+ assert_eq!( $nan. min( -9.0 ) , -9.0 ) ;
425
+ assert_eq!( 9.0 . min( $nan) , 9.0 ) ;
426
+ assert_eq!( ( -9.0 ) . min( $nan) , -9.0 ) ;
427
+ assert!( $nan. min( $nan) . is_nan( ) ) ;
428
+ }
429
+ #[ test]
430
+ fn max( ) {
431
+ assert_eq!( 0.0 . max( 0.0 ) , 0.0 ) ;
432
+ assert_eq!( ( -0.0 ) . max( -0.0 ) , -0.0 ) ;
433
+ assert_eq!( 9.0 . max( 9.0 ) , 9.0 ) ;
434
+ assert_eq!( ( -9.0 ) . max( 0.0 ) , 0.0 ) ;
435
+ assert_eq!( 0.0 . max( 9.0 ) , 9.0 ) ;
436
+ assert_eq!( ( -0.0 ) . max( -9.0 ) , -0.0 ) ;
437
+ assert_eq!( $inf. max( 9.0 ) , $inf) ;
438
+ assert_eq!( 9.0 . max( $inf) , $inf) ;
439
+ assert_eq!( $inf. max( -9.0 ) , $inf) ;
440
+ assert_eq!( ( -9.0 ) . max( $inf) , $inf) ;
441
+ assert_eq!( $neginf. max( 9.0 ) , 9.0 ) ;
442
+ assert_eq!( 9.0 . max( $neginf) , 9.0 ) ;
443
+ assert_eq!( $neginf. max( -9.0 ) , -9.0 ) ;
444
+ assert_eq!( ( -9.0 ) . max( $neginf) , -9.0 ) ;
445
+ assert_eq!( $nan. max( 9.0 ) , 9.0 ) ;
446
+ assert_eq!( $nan. max( -9.0 ) , -9.0 ) ;
447
+ assert_eq!( 9.0 . max( $nan) , 9.0 ) ;
448
+ assert_eq!( ( -9.0 ) . max( $nan) , -9.0 ) ;
449
+ assert!( $nan. max( $nan) . is_nan( ) ) ;
450
+ }
451
+ } }
452
+ }
453
+
454
+ test_float ! ( f32 , f32 , :: core:: f32 :: INFINITY , :: core:: f32 :: NEG_INFINITY , :: core:: f32 :: NAN ) ;
455
+ test_float ! ( f64 , f64 , :: core:: f64 :: INFINITY , :: core:: f64 :: NEG_INFINITY , :: core:: f64 :: NAN ) ;
0 commit comments