@@ -1153,7 +1153,7 @@ impl isize {
1153
1153
intrinsics:: mul_with_overflow }
1154
1154
}
1155
1155
1156
- // `Int` + `UnsignedInt` implemented for signed integers
1156
+ // `Int` + `UnsignedInt` implemented for unsigned integers
1157
1157
macro_rules! uint_impl {
1158
1158
( $ActualT: ty, $BITS: expr,
1159
1159
$ctpop: path,
@@ -1457,8 +1457,8 @@ macro_rules! uint_impl {
1457
1457
/// Basic usage:
1458
1458
///
1459
1459
/// ```
1460
- /// assert_eq!((-127i8) .checked_sub(1), Some(-128 ));
1461
- /// assert_eq!((-128i8) .checked_sub(1), None);
1460
+ /// assert_eq!(1u8 .checked_sub(1), Some(0 ));
1461
+ /// assert_eq!(0u8 .checked_sub(1), None);
1462
1462
/// ```
1463
1463
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1464
1464
#[ inline]
@@ -1493,9 +1493,8 @@ macro_rules! uint_impl {
1493
1493
/// Basic usage:
1494
1494
///
1495
1495
/// ```
1496
- /// assert_eq!((-127i8).checked_div(-1), Some(127));
1497
- /// assert_eq!((-128i8).checked_div(-1), None);
1498
- /// assert_eq!((1i8).checked_div(0), None);
1496
+ /// assert_eq!(128u8.checked_div(2), Some(64));
1497
+ /// assert_eq!(1u8.checked_div(0), None);
1499
1498
/// ```
1500
1499
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1501
1500
#[ inline]
@@ -1591,16 +1590,15 @@ macro_rules! uint_impl {
1591
1590
/// Basic usage:
1592
1591
///
1593
1592
/// ```
1594
- /// assert_eq!(100i8 .saturating_add(1), 101);
1595
- /// assert_eq!(100i8 .saturating_add(127), 127 );
1593
+ /// assert_eq!(100u8 .saturating_add(1), 101);
1594
+ /// assert_eq!(200u8 .saturating_add(127), 255 );
1596
1595
/// ```
1597
1596
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1598
1597
#[ inline]
1599
1598
pub fn saturating_add( self , other: Self ) -> Self {
1600
1599
match self . checked_add( other) {
1601
- Some ( x) => x,
1602
- None if other >= Self :: zero( ) => Self :: max_value( ) ,
1603
- None => Self :: min_value( ) ,
1600
+ Some ( x) => x,
1601
+ None => Self :: max_value( ) ,
1604
1602
}
1605
1603
}
1606
1604
@@ -1612,16 +1610,15 @@ macro_rules! uint_impl {
1612
1610
/// Basic usage:
1613
1611
///
1614
1612
/// ```
1615
- /// assert_eq!(100i8 .saturating_sub(127 ), -27 );
1616
- /// assert_eq!((-100i8) .saturating_sub(127), -128 );
1613
+ /// assert_eq!(100u8 .saturating_sub(27 ), 73 );
1614
+ /// assert_eq!(13u8 .saturating_sub(127), 0 );
1617
1615
/// ```
1618
1616
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1619
1617
#[ inline]
1620
1618
pub fn saturating_sub( self , other: Self ) -> Self {
1621
1619
match self . checked_sub( other) {
1622
- Some ( x) => x,
1623
- None if other >= Self :: zero( ) => Self :: min_value( ) ,
1624
- None => Self :: max_value( ) ,
1620
+ Some ( x) => x,
1621
+ None => Self :: min_value( ) ,
1625
1622
}
1626
1623
}
1627
1624
@@ -1652,8 +1649,8 @@ macro_rules! uint_impl {
1652
1649
/// Basic usage:
1653
1650
///
1654
1651
/// ```
1655
- /// assert_eq!(100i8 .wrapping_add(27 ), 127 );
1656
- /// assert_eq!(100i8 .wrapping_add(127 ), -29 );
1652
+ /// assert_eq!(200u8 .wrapping_add(55 ), 255 );
1653
+ /// assert_eq!(200u8 .wrapping_add(155 ), 99 );
1657
1654
/// ```
1658
1655
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1659
1656
#[ inline]
@@ -1671,8 +1668,8 @@ macro_rules! uint_impl {
1671
1668
/// Basic usage:
1672
1669
///
1673
1670
/// ```
1674
- /// assert_eq!(0i8 .wrapping_sub(127 ), -127 );
1675
- /// assert_eq!((-2i8) .wrapping_sub(127 ), 127 );
1671
+ /// assert_eq!(100u8 .wrapping_sub(100 ), 0 );
1672
+ /// assert_eq!(100u8 .wrapping_sub(155 ), 201 );
1676
1673
/// ```
1677
1674
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1678
1675
#[ inline]
@@ -1690,8 +1687,8 @@ macro_rules! uint_impl {
1690
1687
/// Basic usage:
1691
1688
///
1692
1689
/// ```
1693
- /// assert_eq!(10i8 .wrapping_mul(12), 120);
1694
- /// assert_eq!(11i8 .wrapping_mul(12), -124 );
1690
+ /// assert_eq!(10u8 .wrapping_mul(12), 120);
1691
+ /// assert_eq!(25u8 .wrapping_mul(12), 44 );
1695
1692
/// ```
1696
1693
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1697
1694
#[ inline]
@@ -1701,68 +1698,64 @@ macro_rules! uint_impl {
1701
1698
}
1702
1699
}
1703
1700
1704
- /// Wrapping (modular) division. Computes `self / other`,
1705
- /// wrapping around at the boundary of the type.
1706
- ///
1707
- /// The only case where such wrapping can occur is when one
1708
- /// divides `MIN / -1` on a signed type (where `MIN` is the
1709
- /// negative minimal value for the type); this is equivalent
1710
- /// to `-MIN`, a positive value that is too large to represent
1711
- /// in the type. In such a case, this function returns `MIN`
1712
- /// itself.
1701
+ /// Wrapping (modular) division. Computes `self / other`.
1702
+ /// Wrapped division on unsigned types is just normal division.
1703
+ /// There's no way wrapping could ever happen.
1704
+ /// This function exists, so that all operations
1705
+ /// are accounted for in the wrapping operations.
1713
1706
///
1714
1707
/// # Examples
1715
1708
///
1716
1709
/// Basic usage:
1717
1710
///
1718
1711
/// ```
1719
1712
/// assert_eq!(100u8.wrapping_div(10), 10);
1720
- /// assert_eq!((-128i8).wrapping_div(-1), -128);
1721
1713
/// ```
1722
1714
#[ stable( feature = "num_wrapping" , since = "1.2.0" ) ]
1723
1715
#[ inline( always) ]
1724
1716
pub fn wrapping_div( self , rhs: Self ) -> Self {
1725
- self . overflowing_div ( rhs) . 0
1717
+ self / rhs
1726
1718
}
1727
1719
1728
- /// Wrapping (modular) remainder. Computes `self % other`,
1729
- /// wrapping around at the boundary of the type.
1730
- ///
1731
- /// Such wrap-around never actually occurs mathematically;
1732
- /// implementation artifacts make `x % y` invalid for `MIN /
1733
- /// -1` on a signed type (where `MIN` is the negative
1734
- /// minimal value). In such a case, this function returns `0`.
1720
+ /// Wrapping (modular) remainder. Computes `self % other`.
1721
+ /// Wrapped remainder calculation on unsigned types is
1722
+ /// just the regular remainder calculation.
1723
+ /// There's no way wrapping could ever happen.
1724
+ /// This function exists, so that all operations
1725
+ /// are accounted for in the wrapping operations.
1735
1726
///
1736
1727
/// # Examples
1737
1728
///
1738
1729
/// Basic usage:
1739
1730
///
1740
1731
/// ```
1741
1732
/// assert_eq!(100i8.wrapping_rem(10), 0);
1742
- /// assert_eq!((-128i8).wrapping_rem(-1), 0);
1743
1733
/// ```
1744
1734
#[ stable( feature = "num_wrapping" , since = "1.2.0" ) ]
1745
1735
#[ inline( always) ]
1746
1736
pub fn wrapping_rem( self , rhs: Self ) -> Self {
1747
- self . overflowing_rem ( rhs) . 0
1737
+ self % rhs
1748
1738
}
1749
1739
1750
1740
/// Wrapping (modular) negation. Computes `-self`,
1751
1741
/// wrapping around at the boundary of the type.
1752
1742
///
1753
- /// The only case where such wrapping can occur is when one
1754
- /// negates `MIN` on a signed type (where `MIN` is the
1755
- /// negative minimal value for the type); this is a positive
1756
- /// value that is too large to represent in the type. In such
1757
- /// a case, this function returns `MIN` itself.
1743
+ /// Since unsigned types do not have negative equivalents
1744
+ /// all applications of this function will wrap (except for `-0`).
1745
+ /// For values smaller than the corresponding signed type's maximum
1746
+ /// the result is the same as casting the corresponding signed value.
1747
+ /// Any larger values are equivalent to `MAX + 1 - (val - MAX - 1)` where
1748
+ /// `MAX` is the corresponding signed type's maximum.
1758
1749
///
1759
1750
/// # Examples
1760
1751
///
1761
1752
/// Basic usage:
1762
1753
///
1763
1754
/// ```
1764
- /// assert_eq!(100i8.wrapping_neg(), -100);
1765
- /// assert_eq!((-128i8).wrapping_neg(), -128);
1755
+ /// assert_eq!(100u8.wrapping_neg(), 156);
1756
+ /// assert_eq!(0u8.wrapping_neg(), 0);
1757
+ /// assert_eq!(180u8.wrapping_neg(), 76);
1758
+ /// assert_eq!(180u8.wrapping_neg(), (127 + 1) - (180u8 - (127 + 1)));
1766
1759
/// ```
1767
1760
#[ stable( feature = "num_wrapping" , since = "1.2.0" ) ]
1768
1761
#[ inline( always) ]
@@ -2002,7 +1995,7 @@ macro_rules! uint_impl {
2002
1995
/// Basic usage:
2003
1996
///
2004
1997
/// ```
2005
- /// assert_eq!(2i32 .pow(4), 16);
1998
+ /// assert_eq!(2u32 .pow(4), 16);
2006
1999
/// ```
2007
2000
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2008
2001
#[ inline]
0 commit comments