Skip to content

Commit a841288

Browse files
nhamalexcrichton
authored andcommitted
---
yaml --- r: 153736 b: refs/heads/try2 c: 62bddfa h: refs/heads/master v: v3
1 parent 7c70170 commit a841288

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: bb165eb5c21b057cb63a4421d6233e82deac4cba
8+
refs/heads/try2: 62bddfa0a5bf7753f835aa9c299232eb75c7bdaa
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libcore/num/mod.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,14 @@ impl<T: CheckedAdd + CheckedSub + Zero + PartialOrd + Bounded> Saturating for T
12171217
/// Performs addition that returns `None` instead of wrapping around on overflow.
12181218
pub trait CheckedAdd: Add<Self, Self> {
12191219
/// Adds two numbers, checking for overflow. If overflow happens, `None` is returned.
1220+
///
1221+
/// # Example
1222+
///
1223+
/// ```rust
1224+
/// use std::num::CheckedAdd;
1225+
/// assert_eq!(5u16.checked_add(&65530), Some(65535));
1226+
/// assert_eq!(6u16.checked_add(&65530), None);
1227+
/// ```
12201228
fn checked_add(&self, v: &Self) -> Option<Self>;
12211229
}
12221230

@@ -1270,6 +1278,14 @@ checked_impl!(CheckedAdd, checked_add, i64, intrinsics::i64_add_with_overflow)
12701278
/// Performs subtraction that returns `None` instead of wrapping around on underflow.
12711279
pub trait CheckedSub: Sub<Self, Self> {
12721280
/// Subtracts two numbers, checking for underflow. If underflow happens, `None` is returned.
1281+
///
1282+
/// # Example
1283+
///
1284+
/// ```rust
1285+
/// use std::num::CheckedSub;
1286+
/// assert_eq!((-127i8).checked_sub(&1), Some(-128));
1287+
/// assert_eq!((-128i8).checked_sub(&1), None);
1288+
/// ```
12731289
fn checked_sub(&self, v: &Self) -> Option<Self>;
12741290
}
12751291

@@ -1298,6 +1314,14 @@ checked_impl!(CheckedSub, checked_sub, i64, intrinsics::i64_sub_with_overflow)
12981314
pub trait CheckedMul: Mul<Self, Self> {
12991315
/// Multiplies two numbers, checking for underflow or overflow. If underflow or overflow
13001316
/// happens, `None` is returned.
1317+
///
1318+
/// # Example
1319+
///
1320+
/// ```rust
1321+
/// use std::num::CheckedMul;
1322+
/// assert_eq!(5u8.checked_mul(&51), Some(255));
1323+
/// assert_eq!(5u8.checked_mul(&52), None);
1324+
/// ```
13011325
fn checked_mul(&self, v: &Self) -> Option<Self>;
13021326
}
13031327

@@ -1325,6 +1349,14 @@ checked_impl!(CheckedMul, checked_mul, i64, intrinsics::i64_mul_with_overflow)
13251349
pub trait CheckedDiv: Div<Self, Self> {
13261350
/// Divides two numbers, checking for underflow or overflow. If underflow or overflow happens,
13271351
/// `None` is returned.
1352+
///
1353+
/// # Example
1354+
///
1355+
/// ```rust
1356+
/// use std::num::CheckedDiv;
1357+
/// assert_eq!((-127i8).checked_div(&-1), Some(127));
1358+
/// assert_eq!((-128i8).checked_div(&-1), None);
1359+
/// ```
13281360
fn checked_div(&self, v: &Self) -> Option<Self>;
13291361
}
13301362

0 commit comments

Comments
 (0)