Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
rust: [
1.87.0, # MSRV
1.90.0, # MSRV
stable,
beta,
nightly,
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
20 changes: 20 additions & 0 deletions src/unsigned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ pub trait PrimitiveUnsigned: PrimitiveInteger + From<u8> {
/// wrapped in Some.
fn checked_next_power_of_two(self) -> Option<Self>;

/// Checked subtraction with a signed integer. Computes `self - rhs`,
/// returning `None` if overflow occurred.
fn checked_sub_signed(self, rhs: Self::Signed) -> Option<Self>;

/// Calculates the quotient of `self` and rhs, rounding the result towards positive infinity.
fn div_ceil(self, rhs: Self) -> Self;

Expand All @@ -75,13 +79,25 @@ pub trait PrimitiveUnsigned: PrimitiveInteger + From<u8> {
/// 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`]).
Expand All @@ -101,14 +117,18 @@ macro_rules! impl_unsigned {
fn checked_add_signed(self, rhs: Self::Signed) -> Option<Self>;
fn checked_next_multiple_of(self, rhs: Self) -> Option<Self>;
fn checked_next_power_of_two(self) -> Option<Self>;
fn checked_sub_signed(self, rhs: Self::Signed) -> Option<Self>;
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;
}
}

Expand Down