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.86.0, # MSRV
1.87.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.86.0
- uses: dtolnay/rust-toolchain@1.87.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.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"]
Expand Down
7 changes: 7 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
8 changes: 8 additions & 0 deletions src/integer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ pub trait PrimitiveSigned: PrimitiveInteger + From<i8> + core::ops::Neg<Output =
/// Computes the absolute difference between `self` and `other`.
fn abs_diff(self, other: Self) -> 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<Self>;

Expand All @@ -80,6 +83,9 @@ pub trait PrimitiveSigned: PrimitiveInteger + From<i8> + core::ops::Neg<Output =
/// Returns true if `self` is positive and false if the number is zero or negative.
fn is_positive(self) -> 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);
Expand Down Expand Up @@ -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<Self>;
fn checked_add_unsigned(self, rhs: Self::Unsigned) -> Option<Self>;
fn checked_isqrt(self) -> Option<Self>;
fn checked_sub_unsigned(self, rhs: Self::Unsigned) -> Option<Self>;
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);
Expand Down
10 changes: 9 additions & 1 deletion src/unsigned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ pub trait PrimitiveUnsigned: PrimitiveInteger + From<u8> {
/// 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<Self>;
Expand All @@ -56,7 +59,10 @@ pub trait PrimitiveUnsigned: PrimitiveInteger + From<u8> {
/// 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`.
Expand Down Expand Up @@ -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<Self>;
fn checked_next_multiple_of(self, rhs: Self) -> Option<Self>;
fn checked_next_power_of_two(self) -> 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 midpoint(self, other: Self) -> Self;
fn next_multiple_of(self, rhs: Self) -> Self;
Expand Down