2
2
3
3
use :: primitives :: * ;
4
4
use :: registers :: flags;
5
- use :: flags :: panic_on_overflow_enabled;
5
+ use :: flags :: {disable_panic_on_overflow, panic_on_overflow_enabled, set_flags} ;
6
6
7
7
const MAX_U32_U64 : u64 = __transmute :: <u32 , u64 >(u32 :: max ());
8
8
const MAX_U16_U64 : u64 = __transmute :: <u16 , u64 >(u16 :: max ());
@@ -1570,6 +1570,28 @@ impl PartialEq for str {
1570
1570
impl Eq for str {}
1571
1571
1572
1572
impl u8 {
1573
+ /// Wrapping (modular) addition. Computes `self + other`, wrapping around at the boundary of the type.
1574
+ pub fn wrapping_add (self , other : Self ) -> Self {
1575
+ let f = disable_panic_on_overflow ();
1576
+ let res = self + other ;
1577
+ set_flags (f );
1578
+ res
1579
+ }
1580
+ /// Wrapping (modular) subtraction. Computes `self - other`, wrapping around at the boundary of the type.
1581
+ pub fn wrapping_sub (self , other : Self ) -> Self {
1582
+ let f = disable_panic_on_overflow ();
1583
+ let res = self - other ;
1584
+ set_flags (f );
1585
+ res
1586
+ }
1587
+ /// Wrapping (modular) multiplication. Computes `self * other`, wrapping around at the boundary of the type.
1588
+ pub fn wrapping_mul (self , other : Self ) -> Self {
1589
+ let f = disable_panic_on_overflow ();
1590
+ let res = self * other ;
1591
+ set_flags (f );
1592
+ res
1593
+ }
1594
+
1573
1595
/// Returns whether a `u8` is set to zero.
1574
1596
///
1575
1597
/// # Returns
@@ -1590,6 +1612,28 @@ impl u8 {
1590
1612
}
1591
1613
1592
1614
impl u16 {
1615
+ /// Wrapping (modular) addition. Computes `self + other`, wrapping around at the boundary of the type.
1616
+ pub fn wrapping_add (self , other : Self ) -> Self {
1617
+ let f = disable_panic_on_overflow ();
1618
+ let res = self + other ;
1619
+ set_flags (f );
1620
+ res
1621
+ }
1622
+ /// Wrapping (modular) subtraction. Computes `self - other`, wrapping around at the boundary of the type.
1623
+ pub fn wrapping_sub (self , other : Self ) -> Self {
1624
+ let f = disable_panic_on_overflow ();
1625
+ let res = self - other ;
1626
+ set_flags (f );
1627
+ res
1628
+ }
1629
+ /// Wrapping (modular) multiplication. Computes `self * other`, wrapping around at the boundary of the type.
1630
+ pub fn wrapping_mul (self , other : Self ) -> Self {
1631
+ let f = disable_panic_on_overflow ();
1632
+ let res = self * other ;
1633
+ set_flags (f );
1634
+ res
1635
+ }
1636
+
1593
1637
/// Returns whether a `u16` is set to zero.
1594
1638
///
1595
1639
/// # Returns
@@ -1610,6 +1654,28 @@ impl u16 {
1610
1654
}
1611
1655
1612
1656
impl u32 {
1657
+ /// Wrapping (modular) addition. Computes `self + other`, wrapping around at the boundary of the type.
1658
+ pub fn wrapping_add (self , other : Self ) -> Self {
1659
+ let f = disable_panic_on_overflow ();
1660
+ let res = self + other ;
1661
+ set_flags (f );
1662
+ res
1663
+ }
1664
+ /// Wrapping (modular) subtraction. Computes `self - other`, wrapping around at the boundary of the type.
1665
+ pub fn wrapping_sub (self , other : Self ) -> Self {
1666
+ let f = disable_panic_on_overflow ();
1667
+ let res = self - other ;
1668
+ set_flags (f );
1669
+ res
1670
+ }
1671
+ /// Wrapping (modular) multiplication. Computes `self * other`, wrapping around at the boundary of the type.
1672
+ pub fn wrapping_mul (self , other : Self ) -> Self {
1673
+ let f = disable_panic_on_overflow ();
1674
+ let res = self * other ;
1675
+ set_flags (f );
1676
+ res
1677
+ }
1678
+
1613
1679
/// Returns whether a `u32` is set to zero.
1614
1680
///
1615
1681
/// # Returns
@@ -1630,6 +1696,28 @@ impl u32 {
1630
1696
}
1631
1697
1632
1698
impl u64 {
1699
+ /// Wrapping (modular) addition. Computes `self + other`, wrapping around at the boundary of the type.
1700
+ pub fn wrapping_add (self , other : Self ) -> Self {
1701
+ let f = disable_panic_on_overflow ();
1702
+ let res = self + other ;
1703
+ set_flags (f );
1704
+ res
1705
+ }
1706
+ /// Wrapping (modular) subtraction. Computes `self - other`, wrapping around at the boundary of the type.
1707
+ pub fn wrapping_sub (self , other : Self ) -> Self {
1708
+ let f = disable_panic_on_overflow ();
1709
+ let res = self - other ;
1710
+ set_flags (f );
1711
+ res
1712
+ }
1713
+ /// Wrapping (modular) multiplication. Computes `self * other`, wrapping around at the boundary of the type.
1714
+ pub fn wrapping_mul (self , other : Self ) -> Self {
1715
+ let f = disable_panic_on_overflow ();
1716
+ let res = self * other ;
1717
+ set_flags (f );
1718
+ res
1719
+ }
1720
+
1633
1721
/// Returns whether a `u64` is set to zero.
1634
1722
///
1635
1723
/// # Returns
@@ -1650,6 +1738,28 @@ impl u64 {
1650
1738
}
1651
1739
1652
1740
impl u256 {
1741
+ /// Wrapping (modular) addition. Computes `self + other`, wrapping around at the boundary of the type.
1742
+ pub fn wrapping_add (self , other : Self ) -> Self {
1743
+ let f = disable_panic_on_overflow ();
1744
+ let res = self + other ;
1745
+ set_flags (f );
1746
+ res
1747
+ }
1748
+ /// Wrapping (modular) subtraction. Computes `self - other`, wrapping around at the boundary of the type.
1749
+ pub fn wrapping_sub (self , other : Self ) -> Self {
1750
+ let f = disable_panic_on_overflow ();
1751
+ let res = self - other ;
1752
+ set_flags (f );
1753
+ res
1754
+ }
1755
+ /// Wrapping (modular) multiplication. Computes `self * other`, wrapping around at the boundary of the type.
1756
+ pub fn wrapping_mul (self , other : Self ) -> Self {
1757
+ let f = disable_panic_on_overflow ();
1758
+ let res = self * other ;
1759
+ set_flags (f );
1760
+ res
1761
+ }
1762
+
1653
1763
/// Returns whether a `u256` is set to zero.
1654
1764
///
1655
1765
/// # Returns
0 commit comments