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.91.0, # MSRV
1.93.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.91.0
- uses: dtolnay/rust-toolchain@1.93.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.4"
version = "0.3.5"
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.91"
rust-version = "1.93"

[package.metadata.release]
allow-branch = ["main"]
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.91](https://img.shields.io/badge/rustc-1.91+-red.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html)
[![minimum rustc 1.93](https://img.shields.io/badge/rustc-1.93+-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.91 and greater. This
The `num-primitive` crate is currently tested for Rust 1.93 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
6 changes: 6 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Release 0.3.5 (2026-01-22)

- Updated to MSRV 1.93.
- Added `PrimitiveInteger::unchecked_{shl,shr}`.
- Added `PrimitiveSigned::unchecked_neg`.

# Release 0.3.4 (2025-12-20)

- Added `PrimitiveInteger::from_str_radix`.
Expand Down
20 changes: 20 additions & 0 deletions src/integer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,24 @@ pub trait PrimitiveInteger:
/// Self::MIN`, i.e. when [`checked_mul`][Self::checked_mul] would return `None`.
unsafe fn unchecked_mul(self, rhs: Self) -> Self;

/// Unchecked shift left. Computes `self << rhs`, assuming that
/// `rhs` is less than the number of bits in `self`.
///
/// # Safety
///
/// This results in undefined behavior if `rhs` is larger than or equal to the number of bits
/// in `self`, i.e. when [`checked_shl`][Self::checked_shl] would return `None`.
unsafe fn unchecked_shl(self, rhs: u32) -> Self;

/// Unchecked shift right. Computes `self >> rhs`, assuming that
/// `rhs` is less than the number of bits in `self`.
///
/// # Safety
///
/// This results in undefined behavior if `rhs` is larger than or equal to the number of bits
/// in `self`, i.e. when [`checked_shr`][Self::checked_shr] would return `None`.
unsafe fn unchecked_shr(self, rhs: u32) -> Self;

/// Unchecked integer subtraction. Computes `self - rhs`, assuming overflow cannot occur.
///
/// # Safety
Expand Down Expand Up @@ -668,6 +686,8 @@ macro_rules! impl_integer {
forward! {
unsafe fn unchecked_add(self, rhs: Self) -> Self;
unsafe fn unchecked_mul(self, rhs: Self) -> Self;
unsafe fn unchecked_shl(self, rhs: u32) -> Self;
unsafe fn unchecked_shr(self, rhs: u32) -> Self;
unsafe fn unchecked_sub(self, rhs: Self) -> Self;
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ pub trait PrimitiveSigned:
/// Wrapping (modular) subtraction with an unsigned integer. Computes `self - rhs`, wrapping
/// around at the boundary of the type.
fn wrapping_sub_unsigned(self, rhs: Self::Unsigned) -> Self;

/// Unchecked negation. Computes `-self`, assuming overflow cannot occur.
///
/// # Safety
///
/// This results in undefined behavior when `self == Self::MIN`, i.e. when
/// [`checked_neg`][PrimitiveInteger::checked_neg] would return `None`.
unsafe fn unchecked_neg(self) -> Self;
}

/// Trait for references to primitive signed integer types ([`PrimitiveSigned`]).
Expand Down Expand Up @@ -185,6 +193,9 @@ macro_rules! impl_signed {
fn wrapping_add_unsigned(self, rhs: Self::Unsigned) -> Self;
fn wrapping_sub_unsigned(self, rhs: Self::Unsigned) -> Self;
}
forward! {
unsafe fn unchecked_neg(self) -> Self;
}
}

impl PrimitiveSignedRef<$Signed> for &$Signed {}
Expand Down