about summary refs log tree commit diff
path: root/src/libcore/num
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-03-20 01:35:54 +0000
committerbors <bors@rust-lang.org>2015-03-20 01:35:54 +0000
commite98e391337fdbf32607de4889345c13fed9de21b (patch)
tree57dcc155bcf6a4165f734f94590fb8429773e2f9 /src/libcore/num
parentf4e0ce66a3cde6bd0df54a367896c5c6a3392c53 (diff)
parent62be565811e9805ec1045395eef2f977d7385efb (diff)
downloadrust-e98e391337fdbf32607de4889345c13fed9de21b.tar.gz
rust-e98e391337fdbf32607de4889345c13fed9de21b.zip
Auto merge of #23254 - jbcrail:saturating-math-docs, r=steveklabnik
This was added for #23241.
Diffstat (limited to 'src/libcore/num')
-rw-r--r--src/libcore/num/mod.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs
index 156bc2708fb..17ef0ecb1c0 100644
--- a/src/libcore/num/mod.rs
+++ b/src/libcore/num/mod.rs
@@ -345,6 +345,16 @@ pub trait Int
 
     /// Saturating integer addition. Computes `self + other`, saturating at
     /// the numeric bounds instead of overflowing.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::num::Int;
+    ///
+    /// assert_eq!(5u16.saturating_add(65534), 65535);
+    /// assert_eq!((-5i16).saturating_add(-32767), -32768);
+    /// assert_eq!(100u32.saturating_add(4294967294), 4294967295);
+    /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
     #[inline]
     fn saturating_add(self, other: Self) -> Self {
@@ -357,6 +367,16 @@ pub trait Int
 
     /// Saturating integer subtraction. Computes `self - other`, saturating at
     /// the numeric bounds instead of overflowing.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::num::Int;
+    ///
+    /// assert_eq!(5u16.saturating_sub(65534), 0);
+    /// assert_eq!(5i16.saturating_sub(-32767), 32767);
+    /// assert_eq!(100u32.saturating_sub(4294967294), 0);
+    /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
     #[inline]
     fn saturating_sub(self, other: Self) -> Self {