Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,21 @@ $EndFeature, "
}
}

doc_comment! {
concat!("Unchecked integer addition. Computes `self + rhs`, assuming overflow
cannot occur.

This results in undefined behavior when `self + rhs > ", stringify!($SelfT), "::max_value()`
or `self + rhs < ", stringify!($SelfT), "::min_value()`."),
#[unstable(feature = "unchecked_math", issue = "0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub unsafe fn unchecked_add(self, rhs: Self) -> Self {
intrinsics::unchecked_add(self, rhs)
}
}

doc_comment! {
concat!("Checked integer subtraction. Computes `self - rhs`, returning `None` if
overflow occurred.
Expand All @@ -656,6 +671,21 @@ $EndFeature, "
}
}

doc_comment! {
concat!("Unchecked integer subtraction. Computes `self - rhs`, assuming overflow
cannot occur.

This results in undefined behavior when `self - rhs > ", stringify!($SelfT), "::max_value()`
or `self - rhs < ", stringify!($SelfT), "::min_value()`."),
#[unstable(feature = "unchecked_math", issue = "0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub unsafe fn unchecked_sub(self, rhs: Self) -> Self {
intrinsics::unchecked_sub(self, rhs)
}
}

doc_comment! {
concat!("Checked integer multiplication. Computes `self * rhs`, returning `None` if
overflow occurred.
Expand Down Expand Up @@ -2686,6 +2716,21 @@ assert_eq!((", stringify!($SelfT), "::max_value() - 2).checked_add(3), None);",
}
}

doc_comment! {
concat!("Unchecked integer addition. Computes `self + rhs`, assuming overflow
cannot occur.

This results in undefined behavior when `self + rhs > ", stringify!($SelfT), "::max_value()`
or `self + rhs < ", stringify!($SelfT), "::min_value()`."),
#[unstable(feature = "unchecked_math", issue = "0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub unsafe fn unchecked_add(self, rhs: Self) -> Self {
intrinsics::unchecked_add(self, rhs)
}
}

doc_comment! {
concat!("Checked integer subtraction. Computes `self - rhs`, returning
`None` if overflow occurred.
Expand All @@ -2708,6 +2753,21 @@ assert_eq!(0", stringify!($SelfT), ".checked_sub(1), None);", $EndFeature, "
}
}

doc_comment! {
concat!("Unchecked integer subtraction. Computes `self - rhs`, assuming overflow
cannot occur.

This results in undefined behavior when `self - rhs > ", stringify!($SelfT), "::max_value()`
or `self - rhs < ", stringify!($SelfT), "::min_value()`."),
#[unstable(feature = "unchecked_math", issue = "0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub unsafe fn unchecked_sub(self, rhs: Self) -> Self {
intrinsics::unchecked_sub(self, rhs)
}
}

doc_comment! {
concat!("Checked integer multiplication. Computes `self * rhs`, returning
`None` if overflow occurred.
Expand Down