Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 14 pull requests #89548

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
cb4519e
os current_exe using same approach as linux to get always the full ab…
devnexen Jul 30, 2021
ce450f8
Use the 64b inner:monotonize() implementation not the 128b one for aa…
AGSaidi Sep 4, 2021
4f5563d
Added abs_diff for integer types.
orlp Sep 9, 2021
77e7f8a
Added psadbw support for u8::abs_diff.
orlp Sep 9, 2021
f83853e
refactor: VecDeques PairSlices fields to private
DeveloperC286 Sep 25, 2021
e18a8ef
Don't ignore impls for primitive types
hkmatsumoto Aug 28, 2021
e46fc9d
Encode json files with UTF-8
hkmatsumoto Sep 29, 2021
03cf07f
Update to the final LLVM 13.0.0 release
cuviper Oct 2, 2021
98dde56
haiku thread affinity build fix
devnexen Oct 2, 2021
fb0b1a5
Follow the diagnostic output style guide
hkmatsumoto Oct 3, 2021
a0cc9bb
Add a test to detect overlapping entries in overview tables
dns2utf8 Sep 10, 2021
677fb6b
Show how many tests are running in parallel
dns2utf8 Sep 11, 2021
e599e2d
Move from grid layout to table based layout because of browser limits…
dns2utf8 Sep 11, 2021
9626f2b
Fix extra `non_snake_case` warning for shorthand field bindings
FabianWolff Oct 2, 2021
6dd6e7c
Added tracking issue numbers for int_abs_diff.
orlp Oct 3, 2021
e34fd54
Deny `where` clauses on `auto` traits
FabianWolff Oct 3, 2021
fdd8a0d
Don't suggest replacing region with 'static in NLL
Aaron1011 Oct 3, 2021
ccd2be5
fix busted JavaScript in error index generator
notriddle Oct 4, 2021
eb1bb97
Rollup merge of #87631 - :solarish_upd_fs, r=joshtriplett
Manishearth Oct 5, 2021
8c4bec2
Rollup merge of #88234 - hkmatsumoto:rustdoc-impls-for-primitive, r=j…
Manishearth Oct 5, 2021
244e2c7
Rollup merge of #88651 - AGSaidi:monotonize-inner-64b-aarch64, r=dtolnay
Manishearth Oct 5, 2021
b837cbf
Rollup merge of #88780 - orlp:int-abs-diff, r=m-ou-se
Manishearth Oct 5, 2021
117270d
Rollup merge of #88816 - dns2utf8:rustdoc_test_gui_2k_constants, r=Gu…
Manishearth Oct 5, 2021
27eddab
Rollup merge of #89244 - DeveloperC286:pair_slices_fields_to_private,…
Manishearth Oct 5, 2021
4547b80
Rollup merge of #89364 - hkmatsumoto:encode-json-with-utf-8, r=Mark-S…
Manishearth Oct 5, 2021
21407e1
Rollup merge of #89456 - cuviper:llvm-13, r=nikic
Manishearth Oct 5, 2021
c81173c
Rollup merge of #89462 - devnexen:haiku_thread_aff_build_fix, r=nagisa
Manishearth Oct 5, 2021
ace4d36
Rollup merge of #89473 - FabianWolff:issue-89469, r=joshtriplett
Manishearth Oct 5, 2021
21cdcac
Rollup merge of #89482 - hkmatsumoto:patch-diagnostics, r=joshtriplett
Manishearth Oct 5, 2021
6b44c97
Rollup merge of #89494 - FabianWolff:issue-84075, r=davidtwco
Manishearth Oct 5, 2021
2c1c140
Rollup merge of #89504 - Aaron1011:rpit-nll-static, r=nikomatsakis
Manishearth Oct 5, 2021
efeb9af
Rollup merge of #89535 - notriddle:notriddle/error-index-generator-js…
Manishearth Oct 5, 2021
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
Prev Previous commit
Next Next commit
Added abs_diff for integer types.
  • Loading branch information
orlp committed Sep 9, 2021
commit 4f5563d0275118cbebbc2a3d3d60be1a7600adaa
40 changes: 40 additions & 0 deletions library/core/src/num/int_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2227,6 +2227,46 @@ macro_rules! int_impl {
}
}

/// Computes the absolute difference between `self` and `other`.
///
/// This function always returns the correct answer without overflow or
/// panics by returning an unsigned integer.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// #![feature(int_abs_diff)]
#[doc = concat!("assert_eq!(100", stringify!($SelfT), ".abs_diff(80), 20", stringify!($UnsignedT), ");")]
#[doc = concat!("assert_eq!(100", stringify!($SelfT), ".abs_diff(110), 10", stringify!($UnsignedT), ");")]
#[doc = concat!("assert_eq!((-100", stringify!($SelfT), ").abs_diff(80), 180", stringify!($UnsignedT), ");")]
#[doc = concat!("assert_eq!((-100", stringify!($SelfT), ").abs_diff(-120), 20", stringify!($UnsignedT), ");")]
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.abs_diff(", stringify!($SelfT), "::MAX), ", stringify!($UnsignedT), "::MAX);")]
/// ```
#[unstable(feature = "int_abs_diff", issue = "none")]
#[inline]
pub const fn abs_diff(self, other: Self) -> $UnsignedT {
if self < other {
// Converting a non-negative x from signed to unsigned by using
// `x as U` is left unchanged, but a negative x is converted
// to value x + 2^N. Thus if `s` and `o` are binary variables
// respectively indicating whether `self` and `other` are
// negative, we are computing the mathematical value:
//
// (other + o*2^N) - (self + s*2^N) mod 2^N
// other - self + (o-s)*2^N mod 2^N
// other - self mod 2^N
//
// Finally, taking the mod 2^N of the mathematical value of
// `other - self` does not change it as it already is
// in the range [0, 2^N).
(other as $UnsignedT).wrapping_sub(self as $UnsignedT)
} else {
(self as $UnsignedT).wrapping_sub(other as $UnsignedT)
}
}

/// Returns a number representing sign of `self`.
///
/// - `0` if the number is zero
Expand Down
21 changes: 21 additions & 0 deletions library/core/src/num/uint_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,27 @@ macro_rules! uint_impl {
(c, b | d)
}

/// Computes the absolute difference between `self` and `other`.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// #![feature(int_abs_diff)]
#[doc = concat!("assert_eq!(100", stringify!($SelfT), ".abs_diff(80), 20", stringify!($SelfT), ");")]
#[doc = concat!("assert_eq!(100", stringify!($SelfT), ".abs_diff(110), 10", stringify!($SelfT), ");")]
/// ```
#[unstable(feature = "int_abs_diff", issue = "none")]
#[inline]
pub const fn abs_diff(self, other: Self) -> Self {
if self < other {
other - self
} else {
self - other
}
}

/// Calculates the multiplication of `self` and `rhs`.
///
/// Returns a tuple of the multiplication along with a boolean
Expand Down