Skip to content

Commit 7900f09

Browse files
committed
Add new methods for MSRV 1.87
1 parent 734f9b1 commit 7900f09

5 files changed

Lines changed: 28 additions & 4 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
strategy:
1313
matrix:
1414
rust: [
15-
1.86.0, # MSRV
15+
1.87.0, # MSRV
1616
stable,
1717
beta,
1818
nightly,
@@ -52,7 +52,7 @@ jobs:
5252
runs-on: ubuntu-latest
5353
steps:
5454
- uses: actions/checkout@v4
55-
- uses: dtolnay/rust-toolchain@1.86.0
55+
- uses: dtolnay/rust-toolchain@1.87.0
5656
with:
5757
components: rustfmt
5858
- run: cargo fmt --all --check

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
77
keywords = ["generic", "mathematics", "numerics", "primitive"]
88
categories = ["algorithms", "science", "no-std"]
99
edition = "2024"
10-
rust-version = "1.86"
10+
rust-version = "1.87"
1111

1212
[features]
1313
default = ["std"]

src/integer.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,12 @@ pub trait PrimitiveInteger:
382382
/// Returns the number of trailing zeros in the binary representation of `self`.
383383
fn trailing_zeros(self) -> u32;
384384

385+
/// Unbounded shift left. Computes `self << rhs`, without bounding the value of `rhs`.
386+
fn unbounded_shl(self, rhs: u32) -> Self;
387+
388+
/// Unbounded shift right. Computes `self >> rhs`, without bounding the value of `rhs`.
389+
fn unbounded_shr(self, rhs: u32) -> Self;
390+
385391
/// Wrapping (modular) addition. Computes `self + rhs`, wrapping around at the boundary of the
386392
/// type.
387393
fn wrapping_add(self, rhs: Self) -> Self;
@@ -588,6 +594,8 @@ macro_rules! impl_integer {
588594
fn to_le(self) -> Self;
589595
fn trailing_ones(self) -> u32;
590596
fn trailing_zeros(self) -> u32;
597+
fn unbounded_shl(self, rhs: u32) -> Self;
598+
fn unbounded_shr(self, rhs: u32) -> Self;
591599
fn wrapping_add(self, rhs: Self) -> Self;
592600
fn wrapping_div(self, rhs: Self) -> Self;
593601
fn wrapping_div_euclid(self, rhs: Self) -> Self;

src/signed.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ pub trait PrimitiveSigned: PrimitiveInteger + From<i8> + core::ops::Neg<Output =
6060
/// Computes the absolute difference between `self` and `other`.
6161
fn abs_diff(self, other: Self) -> Self::Unsigned;
6262

63+
/// Returns the bit pattern of `self` reinterpreted as an unsigned integer of the same size.
64+
fn cast_unsigned(self) -> Self::Unsigned;
65+
6366
/// Checked absolute value. Computes `self.abs()`, returning `None` if `self == MIN`.
6467
fn checked_abs(self) -> Option<Self>;
6568

@@ -80,6 +83,9 @@ pub trait PrimitiveSigned: PrimitiveInteger + From<i8> + core::ops::Neg<Output =
8083
/// Returns true if `self` is positive and false if the number is zero or negative.
8184
fn is_positive(self) -> bool;
8285

86+
/// Calculates the middle point of `self` and `other`.
87+
fn midpoint(self, other: Self) -> Self;
88+
8389
/// Computes the absolute value of `self`. Returns a tuple of the absolute version of `self`
8490
/// along with a boolean indicating whether an overflow happened.
8591
fn overflowing_abs(self) -> (Self, bool);
@@ -141,12 +147,14 @@ macro_rules! impl_signed {
141147
forward! {
142148
fn abs(self) -> Self;
143149
fn abs_diff(self, other: Self) -> Self::Unsigned;
150+
fn cast_unsigned(self) -> Self::Unsigned;
144151
fn checked_abs(self) -> Option<Self>;
145152
fn checked_add_unsigned(self, rhs: Self::Unsigned) -> Option<Self>;
146153
fn checked_isqrt(self) -> Option<Self>;
147154
fn checked_sub_unsigned(self, rhs: Self::Unsigned) -> Option<Self>;
148155
fn is_negative(self) -> bool;
149156
fn is_positive(self) -> bool;
157+
fn midpoint(self, other: Self) -> Self;
150158
fn overflowing_abs(self) -> (Self, bool);
151159
fn overflowing_add_unsigned(self, rhs: Self::Unsigned) -> (Self, bool);
152160
fn overflowing_sub_unsigned(self, rhs: Self::Unsigned) -> (Self, bool);

src/unsigned.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ pub trait PrimitiveUnsigned: PrimitiveInteger + From<u8> {
4040
/// Computes the absolute difference between `self` and `other`.
4141
fn abs_diff(self, other: Self) -> Self;
4242

43+
/// Returns the bit pattern of `self` reinterpreted as a signed integer of the same size.
44+
fn cast_signed(self) -> Self::Signed;
45+
4346
/// Checked addition with a signed integer. Computes `self + rhs`, returning `None` if overflow
4447
/// occurred.
4548
fn checked_add_signed(self, rhs: Self::Signed) -> Option<Self>;
@@ -56,7 +59,10 @@ pub trait PrimitiveUnsigned: PrimitiveInteger + From<u8> {
5659
/// Calculates the quotient of `self` and rhs, rounding the result towards positive infinity.
5760
fn div_ceil(self, rhs: Self) -> Self;
5861

59-
/// Returns true if and only if `self == 2^k` for some `k`.
62+
/// Returns `true` if `self` is an integer multiple of `rhs`, and false otherwise.
63+
fn is_multiple_of(self, rhs: Self) -> bool;
64+
65+
/// Returns `true` if and only if `self == 2^k` for some `k`.
6066
fn is_power_of_two(self) -> bool;
6167

6268
/// Calculates the middle point of `self` and `other`.
@@ -94,10 +100,12 @@ macro_rules! impl_unsigned {
94100

95101
forward! {
96102
fn abs_diff(self, other: Self) -> Self;
103+
fn cast_signed(self) -> Self::Signed;
97104
fn checked_add_signed(self, rhs: Self::Signed) -> Option<Self>;
98105
fn checked_next_multiple_of(self, rhs: Self) -> Option<Self>;
99106
fn checked_next_power_of_two(self) -> Option<Self>;
100107
fn div_ceil(self, rhs: Self) -> Self;
108+
fn is_multiple_of(self, rhs: Self) -> bool;
101109
fn is_power_of_two(self) -> bool;
102110
fn midpoint(self, other: Self) -> Self;
103111
fn next_multiple_of(self, rhs: Self) -> Self;

0 commit comments

Comments
 (0)