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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "num-primitive"
version = "0.2.3"
version = "0.3.0"
description = "Traits for primitive numeric types"
repository = "https://github.com/rust-num/num-primitive"
license = "MIT OR Apache-2.0"
Expand Down
8 changes: 4 additions & 4 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.85](https://img.shields.io/badge/rustc-1.85+-red.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html)
[![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)
[![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 @@ -38,7 +38,7 @@ Add this to your `Cargo.toml`:

```toml
[dependencies]
num-primitive = "0.2"
num-primitive = "0.3"
```

## Features
Expand All @@ -48,7 +48,7 @@ the default `std` feature. Use this in `Cargo.toml`:

```toml
[dependencies.num-primitive]
version = "0.2"
version = "0.3"
default-features = false
```

Expand All @@ -61,7 +61,7 @@ Release notes are available in [RELEASES.md](RELEASES.md).

## Compatibility

The `num-primitive` crate is currently tested for Rust 1.85 and greater. This
The `num-primitive` crate is currently tested for Rust 1.87 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.0 (2025-12-16)

- Added `PrimitiveNumber::midpoint`
- Removed `Primitive{Float,Signed,Unsigned}::midpoint`

# Release 0.2.3 (2025-12-16)

- Updated to MSRV 1.87.
Expand Down
4 changes: 0 additions & 4 deletions src/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,6 @@ pub trait PrimitiveFloat:
/// Returns the maximum of the two numbers, ignoring NaN.
fn max(self, other: Self) -> Self;

/// Calculates the middle point of `self` and `other`.
fn midpoint(self, other: Self) -> Self;

/// Returns the minimum of the two numbers, ignoring NaN.
fn min(self, other: Self) -> Self;

Expand Down Expand Up @@ -527,7 +524,6 @@ macro_rules! impl_float {
fn is_sign_positive(self) -> bool;
fn is_subnormal(self) -> bool;
fn max(self, other: Self) -> Self;
fn midpoint(self, other: Self) -> Self;
fn min(self, other: Self) -> Self;
fn next_down(self) -> Self;
fn next_up(self) -> Self;
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
//!
//! ```toml
//! [dependencies]
//! num-primitive = "0.2"
//! num-primitive = "0.3"
//! ```
//!
//! ## Features
Expand All @@ -43,7 +43,7 @@
//!
//! ```toml
//! [dependencies.num-primitive]
//! version = "0.2"
//! version = "0.3"
//! default-features = false
//! ```
//!
Expand Down
4 changes: 4 additions & 0 deletions src/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ pub trait PrimitiveNumber:
/// Creates a number from its representation as a byte array in native endian.
fn from_ne_bytes(bytes: Self::Bytes) -> Self;

/// Calculates the midpoint (average) between `self` and `other`.
fn midpoint(self, other: Self) -> Self;

/// Returns the memory representation of this number as a byte array in little-endian order.
fn to_be_bytes(self) -> Self::Bytes;

Expand Down Expand Up @@ -272,6 +275,7 @@ macro_rules! impl_primitive {
fn from_ne_bytes(bytes: Self::Bytes) -> Self;
}
forward! {
fn midpoint(self, other: Self) -> Self;
fn to_be_bytes(self) -> Self::Bytes;
fn to_le_bytes(self) -> Self::Bytes;
fn to_ne_bytes(self) -> Self::Bytes;
Expand Down
4 changes: 0 additions & 4 deletions src/signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ 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 @@ -154,7 +151,6 @@ macro_rules! impl_signed {
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
4 changes: 0 additions & 4 deletions src/unsigned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ pub trait PrimitiveUnsigned: PrimitiveInteger + From<u8> {
/// 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`.
fn midpoint(self, other: Self) -> Self;

/// Calculates the smallest value greater than or equal to `self` that is a multiple of `rhs`.
fn next_multiple_of(self, rhs: Self) -> Self;

Expand Down Expand Up @@ -107,7 +104,6 @@ macro_rules! impl_unsigned {
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;
fn next_power_of_two(self) -> Self;
fn overflowing_add_signed(self, rhs: Self::Signed) -> (Self, bool);
Expand Down