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