Skip to content

Commit

Permalink
Rollup merge of rust-lang#65312 - tspiteri:signed-sat-mul, r=dtolnay
Browse files Browse the repository at this point in the history
improve performance of signed saturating_mul

Reciprocal throughput is improved from 2.3 to 1.7. https://godbolt.org/z/ROMiX6

Fixes rust-lang#65309.
  • Loading branch information
Centril authored Oct 13, 2019
2 parents 2a9c791 + 57aae75 commit f0f5e77
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ $EndFeature, "
#[inline]
pub fn saturating_mul(self, rhs: Self) -> Self {
self.checked_mul(rhs).unwrap_or_else(|| {
if (self < 0 && rhs < 0) || (self > 0 && rhs > 0) {
if (self < 0) == (rhs < 0) {
Self::max_value()
} else {
Self::min_value()
Expand Down

0 comments on commit f0f5e77

Please sign in to comment.