File tree 2 files changed +38
-0
lines changed
2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -970,6 +970,7 @@ impl f32 {
970
970
/// assert!((-3.0f32).clamp(-2.0f32, 1.0f32) == -2.0f32);
971
971
/// assert!((0.0f32).clamp(-2.0f32, 1.0f32) == 0.0f32);
972
972
/// assert!((2.0f32).clamp(-2.0f32, 1.0f32) == 1.0f32);
973
+ /// assert!((std::f32::NAN).clamp(-2.0f32, 1.0f32).is_nan());
973
974
/// ```
974
975
#[ unstable( feature = "clamp" , issue = "44095" ) ]
975
976
#[ inline]
@@ -1581,4 +1582,22 @@ mod tests {
1581
1582
assert_eq ! ( f32 :: from_bits( masked_nan1) . to_bits( ) , masked_nan1) ;
1582
1583
assert_eq ! ( f32 :: from_bits( masked_nan2) . to_bits( ) , masked_nan2) ;
1583
1584
}
1585
+
1586
+ #[ test]
1587
+ #[ should_panic]
1588
+ fn test_clamp_min_greater_than_max ( ) {
1589
+ 1.0f32 . clamp ( 3.0 , 1.0 ) ;
1590
+ }
1591
+
1592
+ #[ test]
1593
+ #[ should_panic]
1594
+ fn test_clamp_min_is_nan ( ) {
1595
+ 1.0f32 . clamp ( NAN , 1.0 ) ;
1596
+ }
1597
+
1598
+ #[ test]
1599
+ #[ should_panic]
1600
+ fn test_clamp_max_is_nan ( ) {
1601
+ 1.0f32 . clamp ( 3.0 , NAN ) ;
1602
+ }
1584
1603
}
Original file line number Diff line number Diff line change @@ -892,6 +892,7 @@ impl f64 {
892
892
/// assert!((-3.0f64).clamp(-2.0f64, 1.0f64) == -2.0f64);
893
893
/// assert!((0.0f64).clamp(-2.0f64, 1.0f64) == 0.0f64);
894
894
/// assert!((2.0f64).clamp(-2.0f64, 1.0f64) == 1.0f64);
895
+ /// assert!((std::f64::NAN).clamp(-2.0f64, 1.0f64).is_nan());
895
896
/// ```
896
897
#[ unstable( feature = "clamp" , issue = "44095" ) ]
897
898
#[ inline]
@@ -1522,4 +1523,22 @@ mod tests {
1522
1523
assert_eq ! ( f64 :: from_bits( masked_nan1) . to_bits( ) , masked_nan1) ;
1523
1524
assert_eq ! ( f64 :: from_bits( masked_nan2) . to_bits( ) , masked_nan2) ;
1524
1525
}
1526
+
1527
+ #[ test]
1528
+ #[ should_panic]
1529
+ fn test_clamp_min_greater_than_max ( ) {
1530
+ 1.0f64 . clamp ( 3.0 , 1.0 ) ;
1531
+ }
1532
+
1533
+ #[ test]
1534
+ #[ should_panic]
1535
+ fn test_clamp_min_is_nan ( ) {
1536
+ 1.0f64 . clamp ( NAN , 1.0 ) ;
1537
+ }
1538
+
1539
+ #[ test]
1540
+ #[ should_panic]
1541
+ fn test_clamp_max_is_nan ( ) {
1542
+ 1.0f64 . clamp ( 3.0 , NAN ) ;
1543
+ }
1525
1544
}
You can’t perform that action at this time.
0 commit comments