diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 19acc36..b483954 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: rust: [ - 1.87.0, # MSRV + 1.90.0, # MSRV stable, beta, nightly, @@ -52,7 +52,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@1.87.0 + - uses: dtolnay/rust-toolchain@1.90.0 with: components: rustfmt - run: cargo fmt --all --check diff --git a/Cargo.toml b/Cargo.toml index 9816b48..d2f9cd9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,13 +1,13 @@ [package] name = "num-primitive" -version = "0.3.0" +version = "0.3.1" 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.87" +rust-version = "1.90" [features] default = ["std"] diff --git a/README.md b/README.md index 680cbf2..e6b3392 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![crate](https://img.shields.io/crates/v/num-primitive.svg)](https://crates.io/crates/num-primitive) [![documentation](https://docs.rs/num-primitive/badge.svg)](https://docs.rs/num-primitive) -[![minimum rustc 1.87](https://img.shields.io/badge/rustc-1.87+-red.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html) +[![minimum rustc 1.90](https://img.shields.io/badge/rustc-1.90+-red.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html) [![build status](https://github.com/rust-num/num-primitive/workflows/CI/badge.svg)](https://github.com/rust-num/num-primitive/actions) Traits for primitive numeric types in Rust. @@ -61,7 +61,7 @@ Release notes are available in [RELEASES.md](RELEASES.md). ## Compatibility -The `num-primitive` crate is currently tested for Rust 1.87 and greater. This +The `num-primitive` crate is currently tested for Rust 1.90 and greater. This minimum-supported Rust version (MSRV) may be increased at any time to add support for newly-stabilized functionality from the standard library. Changes will be documented prominently in the release notes. diff --git a/RELEASES.md b/RELEASES.md index 7571666..58a0094 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,3 +1,8 @@ +# Release 0.3.1 (2025-12-16) + +- Updated to MSRV 1.90. +- Added `PrimitiveUnsigned::{checked,overflowing,saturating,wrapping}_sub_signed` + # Release 0.3.0 (2025-12-16) - Added `PrimitiveNumber::midpoint` diff --git a/src/unsigned.rs b/src/unsigned.rs index 7614128..8f797ad 100644 --- a/src/unsigned.rs +++ b/src/unsigned.rs @@ -56,6 +56,10 @@ pub trait PrimitiveUnsigned: PrimitiveInteger + From { /// wrapped in Some. fn checked_next_power_of_two(self) -> Option; + /// Checked subtraction with a signed integer. Computes `self - rhs`, + /// returning `None` if overflow occurred. + fn checked_sub_signed(self, rhs: Self::Signed) -> Option; + /// Calculates the quotient of `self` and rhs, rounding the result towards positive infinity. fn div_ceil(self, rhs: Self) -> Self; @@ -75,13 +79,25 @@ pub trait PrimitiveUnsigned: PrimitiveInteger + From { /// boolean indicating whether an arithmetic overflow would occur. fn overflowing_add_signed(self, rhs: Self::Signed) -> (Self, bool); + /// Calculates `self` - `rhs` with a signed `rhs`. Returns a tuple of the subtraction along + /// with a boolean indicating whether an arithmetic overflow would occur. + fn overflowing_sub_signed(self, rhs: Self::Signed) -> (Self, bool); + /// Saturating addition with a signed integer. Computes `self + rhs`, saturating at the numeric /// bounds instead of overflowing. fn saturating_add_signed(self, rhs: Self::Signed) -> Self; + /// Saturating integer subtraction. Computes `self` - `rhs`, saturating at + /// the numeric bounds instead of overflowing. + fn saturating_sub_signed(self, rhs: Self::Signed) -> Self; + /// Wrapping (modular) addition with a signed integer. Computes `self + rhs`, wrapping around /// at the boundary of the type. fn wrapping_add_signed(self, rhs: Self::Signed) -> Self; + + /// Wrapping (modular) subtraction with a signed integer. Computes + /// `self - rhs`, wrapping around at the boundary of the type. + fn wrapping_sub_signed(self, rhs: Self::Signed) -> Self; } /// Trait for references to primitive unsigned integer types ([`PrimitiveUnsigned`]). @@ -101,14 +117,18 @@ macro_rules! impl_unsigned { 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 checked_sub_signed(self, rhs: Self::Signed) -> Option; fn div_ceil(self, rhs: Self) -> Self; fn is_multiple_of(self, rhs: Self) -> bool; fn is_power_of_two(self) -> bool; fn next_multiple_of(self, rhs: Self) -> Self; fn next_power_of_two(self) -> Self; fn overflowing_add_signed(self, rhs: Self::Signed) -> (Self, bool); + fn overflowing_sub_signed(self, rhs: Self::Signed) -> (Self, bool); fn saturating_add_signed(self, rhs: Self::Signed) -> Self; + fn saturating_sub_signed(self, rhs: Self::Signed) -> Self; fn wrapping_add_signed(self, rhs: Self::Signed) -> Self; + fn wrapping_sub_signed(self, rhs: Self::Signed) -> Self; } }