diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7eeb4f7..19acc36 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: rust: [ - 1.86.0, # MSRV + 1.87.0, # MSRV stable, beta, nightly, @@ -52,7 +52,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@1.86.0 + - uses: dtolnay/rust-toolchain@1.87.0 with: components: rustfmt - run: cargo fmt --all --check diff --git a/Cargo.toml b/Cargo.toml index ef22b25..f14dbfc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,13 +1,13 @@ [package] name = "num-primitive" -version = "0.2.2" +version = "0.2.3" description = "Traits for primitive numeric types" repository = "https://github.com/rust-num/num-primitive" license = "MIT OR Apache-2.0" keywords = ["generic", "mathematics", "numerics", "primitive"] categories = ["algorithms", "science", "no-std"] edition = "2024" -rust-version = "1.86" +rust-version = "1.87" [features] default = ["std"] diff --git a/RELEASES.md b/RELEASES.md index 268c4af..90b3256 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,3 +1,10 @@ +# Release 0.2.3 (2025-12-16) + +- Updated to MSRV 1.87. +- Added `PrimitiveInteger::{unbounded_shl,unbounded_shr}` +- Added `PrimitiveSigned::{cast_unsigned,midpoint}` +- Added `PrimitiveUnsigned::{cast_signed,is_multiple_of}` + # Release 0.2.2 (2025-12-16) - Updated to MSRV 1.86. diff --git a/src/integer.rs b/src/integer.rs index cdc1519..1abeaec 100644 --- a/src/integer.rs +++ b/src/integer.rs @@ -382,6 +382,12 @@ pub trait PrimitiveInteger: /// Returns the number of trailing zeros in the binary representation of `self`. fn trailing_zeros(self) -> u32; + /// Unbounded shift left. Computes `self << rhs`, without bounding the value of `rhs`. + fn unbounded_shl(self, rhs: u32) -> Self; + + /// Unbounded shift right. Computes `self >> rhs`, without bounding the value of `rhs`. + fn unbounded_shr(self, rhs: u32) -> Self; + /// Wrapping (modular) addition. Computes `self + rhs`, wrapping around at the boundary of the /// type. fn wrapping_add(self, rhs: Self) -> Self; @@ -588,6 +594,8 @@ macro_rules! impl_integer { fn to_le(self) -> Self; fn trailing_ones(self) -> u32; fn trailing_zeros(self) -> u32; + fn unbounded_shl(self, rhs: u32) -> Self; + fn unbounded_shr(self, rhs: u32) -> Self; fn wrapping_add(self, rhs: Self) -> Self; fn wrapping_div(self, rhs: Self) -> Self; fn wrapping_div_euclid(self, rhs: Self) -> Self; diff --git a/src/signed.rs b/src/signed.rs index c10505a..20b237c 100644 --- a/src/signed.rs +++ b/src/signed.rs @@ -60,6 +60,9 @@ pub trait PrimitiveSigned: PrimitiveInteger + From + core::ops::Neg Self::Unsigned; + /// Returns the bit pattern of `self` reinterpreted as an unsigned integer of the same size. + fn cast_unsigned(self) -> Self::Unsigned; + /// Checked absolute value. Computes `self.abs()`, returning `None` if `self == MIN`. fn checked_abs(self) -> Option; @@ -80,6 +83,9 @@ pub trait PrimitiveSigned: PrimitiveInteger + From + core::ops::Neg bool; + /// Calculates the middle point of `self` and `other`. + fn midpoint(self, other: Self) -> Self; + /// Computes the absolute value of `self`. Returns a tuple of the absolute version of `self` /// along with a boolean indicating whether an overflow happened. fn overflowing_abs(self) -> (Self, bool); @@ -141,12 +147,14 @@ macro_rules! impl_signed { forward! { fn abs(self) -> Self; fn abs_diff(self, other: Self) -> Self::Unsigned; + fn cast_unsigned(self) -> Self::Unsigned; fn checked_abs(self) -> Option; fn checked_add_unsigned(self, rhs: Self::Unsigned) -> Option; fn checked_isqrt(self) -> Option; fn checked_sub_unsigned(self, rhs: Self::Unsigned) -> Option; fn is_negative(self) -> bool; fn is_positive(self) -> bool; + fn midpoint(self, other: Self) -> Self; fn overflowing_abs(self) -> (Self, bool); fn overflowing_add_unsigned(self, rhs: Self::Unsigned) -> (Self, bool); fn overflowing_sub_unsigned(self, rhs: Self::Unsigned) -> (Self, bool); diff --git a/src/unsigned.rs b/src/unsigned.rs index c8c78ee..04a6e07 100644 --- a/src/unsigned.rs +++ b/src/unsigned.rs @@ -40,6 +40,9 @@ pub trait PrimitiveUnsigned: PrimitiveInteger + From { /// Computes the absolute difference between `self` and `other`. fn abs_diff(self, other: Self) -> Self; + /// Returns the bit pattern of `self` reinterpreted as a signed integer of the same size. + fn cast_signed(self) -> Self::Signed; + /// Checked addition with a signed integer. Computes `self + rhs`, returning `None` if overflow /// occurred. fn checked_add_signed(self, rhs: Self::Signed) -> Option; @@ -56,7 +59,10 @@ pub trait PrimitiveUnsigned: PrimitiveInteger + From { /// Calculates the quotient of `self` and rhs, rounding the result towards positive infinity. fn div_ceil(self, rhs: Self) -> Self; - /// Returns true if and only if `self == 2^k` for some `k`. + /// Returns `true` if `self` is an integer multiple of `rhs`, and false otherwise. + fn is_multiple_of(self, rhs: Self) -> bool; + + /// Returns `true` if and only if `self == 2^k` for some `k`. fn is_power_of_two(self) -> bool; /// Calculates the middle point of `self` and `other`. @@ -94,10 +100,12 @@ macro_rules! impl_unsigned { forward! { fn abs_diff(self, other: Self) -> Self; + fn cast_signed(self) -> Self::Signed; fn checked_add_signed(self, rhs: Self::Signed) -> Option; fn checked_next_multiple_of(self, rhs: Self) -> Option; fn checked_next_power_of_two(self) -> Option; fn div_ceil(self, rhs: Self) -> Self; + fn is_multiple_of(self, rhs: Self) -> bool; fn is_power_of_two(self) -> bool; fn midpoint(self, other: Self) -> Self; fn next_multiple_of(self, rhs: Self) -> Self;