File tree 1 file changed +20
-0
lines changed
1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -345,6 +345,16 @@ pub trait Int
345
345
346
346
/// Saturating integer addition. Computes `self + other`, saturating at
347
347
/// the numeric bounds instead of overflowing.
348
+ ///
349
+ /// # Examples
350
+ ///
351
+ /// ```
352
+ /// use std::num::Int;
353
+ ///
354
+ /// assert_eq!(5u16.saturating_add(65534), 65535);
355
+ /// assert_eq!((-5i16).saturating_add(-32767), -32768);
356
+ /// assert_eq!(100u32.saturating_add(4294967294), 4294967295);
357
+ /// ```
348
358
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
349
359
#[ inline]
350
360
fn saturating_add ( self , other : Self ) -> Self {
@@ -357,6 +367,16 @@ pub trait Int
357
367
358
368
/// Saturating integer subtraction. Computes `self - other`, saturating at
359
369
/// the numeric bounds instead of overflowing.
370
+ ///
371
+ /// # Examples
372
+ ///
373
+ /// ```
374
+ /// use std::num::Int;
375
+ ///
376
+ /// assert_eq!(5u16.saturating_sub(65534), 0);
377
+ /// assert_eq!(5i16.saturating_sub(-32767), 32767);
378
+ /// assert_eq!(100u32.saturating_sub(4294967294), 0);
379
+ /// ```
360
380
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
361
381
#[ inline]
362
382
fn saturating_sub ( self , other : Self ) -> Self {
You can’t perform that action at this time.
0 commit comments