Skip to content

Commit 8b45612

Browse files
authored
Merge pull request #11 from cuviper/midpoint
Move `midpoint` to `PrimitiveNumber`
2 parents 6534cfb + c608952 commit 8b45612

8 files changed

Lines changed: 16 additions & 19 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "num-primitive"
3-
version = "0.2.3"
3+
version = "0.3.0"
44
description = "Traits for primitive numeric types"
55
repository = "https://github.com/rust-num/num-primitive"
66
license = "MIT OR Apache-2.0"

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![crate](https://img.shields.io/crates/v/num-primitive.svg)](https://crates.io/crates/num-primitive)
44
[![documentation](https://docs.rs/num-primitive/badge.svg)](https://docs.rs/num-primitive)
5-
[![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)
5+
[![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)
66
[![build status](https://github.com/rust-num/num-primitive/workflows/CI/badge.svg)](https://github.com/rust-num/num-primitive/actions)
77

88
Traits for primitive numeric types in Rust.
@@ -38,7 +38,7 @@ Add this to your `Cargo.toml`:
3838

3939
```toml
4040
[dependencies]
41-
num-primitive = "0.2"
41+
num-primitive = "0.3"
4242
```
4343

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

4949
```toml
5050
[dependencies.num-primitive]
51-
version = "0.2"
51+
version = "0.3"
5252
default-features = false
5353
```
5454

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

6262
## Compatibility
6363

64-
The `num-primitive` crate is currently tested for Rust 1.85 and greater. This
64+
The `num-primitive` crate is currently tested for Rust 1.87 and greater. This
6565
minimum-supported Rust version (MSRV) may be increased at any time to add
6666
support for newly-stabilized functionality from the standard library. Changes
6767
will be documented prominently in the release notes.

RELEASES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# Release 0.3.0 (2025-12-16)
2+
3+
- Added `PrimitiveNumber::midpoint`
4+
- Removed `Primitive{Float,Signed,Unsigned}::midpoint`
5+
16
# Release 0.2.3 (2025-12-16)
27

38
- Updated to MSRV 1.87.

src/float.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,6 @@ pub trait PrimitiveFloat:
218218
/// Returns the maximum of the two numbers, ignoring NaN.
219219
fn max(self, other: Self) -> Self;
220220

221-
/// Calculates the middle point of `self` and `other`.
222-
fn midpoint(self, other: Self) -> Self;
223-
224221
/// Returns the minimum of the two numbers, ignoring NaN.
225222
fn min(self, other: Self) -> Self;
226223

@@ -527,7 +524,6 @@ macro_rules! impl_float {
527524
fn is_sign_positive(self) -> bool;
528525
fn is_subnormal(self) -> bool;
529526
fn max(self, other: Self) -> Self;
530-
fn midpoint(self, other: Self) -> Self;
531527
fn min(self, other: Self) -> Self;
532528
fn next_down(self) -> Self;
533529
fn next_up(self) -> Self;

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
//!
3434
//! ```toml
3535
//! [dependencies]
36-
//! num-primitive = "0.2"
36+
//! num-primitive = "0.3"
3737
//! ```
3838
//!
3939
//! ## Features
@@ -43,7 +43,7 @@
4343
//!
4444
//! ```toml
4545
//! [dependencies.num-primitive]
46-
//! version = "0.2"
46+
//! version = "0.3"
4747
//! default-features = false
4848
//! ```
4949
//!

src/number.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ pub trait PrimitiveNumber:
129129
/// Creates a number from its representation as a byte array in native endian.
130130
fn from_ne_bytes(bytes: Self::Bytes) -> Self;
131131

132+
/// Calculates the midpoint (average) between `self` and `other`.
133+
fn midpoint(self, other: Self) -> Self;
134+
132135
/// Returns the memory representation of this number as a byte array in little-endian order.
133136
fn to_be_bytes(self) -> Self::Bytes;
134137

@@ -272,6 +275,7 @@ macro_rules! impl_primitive {
272275
fn from_ne_bytes(bytes: Self::Bytes) -> Self;
273276
}
274277
forward! {
278+
fn midpoint(self, other: Self) -> Self;
275279
fn to_be_bytes(self) -> Self::Bytes;
276280
fn to_le_bytes(self) -> Self::Bytes;
277281
fn to_ne_bytes(self) -> Self::Bytes;

src/signed.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,6 @@ pub trait PrimitiveSigned: PrimitiveInteger + From<i8> + core::ops::Neg<Output =
8383
/// Returns true if `self` is positive and false if the number is zero or negative.
8484
fn is_positive(self) -> bool;
8585

86-
/// Calculates the middle point of `self` and `other`.
87-
fn midpoint(self, other: Self) -> Self;
88-
8986
/// Computes the absolute value of `self`. Returns a tuple of the absolute version of `self`
9087
/// along with a boolean indicating whether an overflow happened.
9188
fn overflowing_abs(self) -> (Self, bool);
@@ -154,7 +151,6 @@ macro_rules! impl_signed {
154151
fn checked_sub_unsigned(self, rhs: Self::Unsigned) -> Option<Self>;
155152
fn is_negative(self) -> bool;
156153
fn is_positive(self) -> bool;
157-
fn midpoint(self, other: Self) -> Self;
158154
fn overflowing_abs(self) -> (Self, bool);
159155
fn overflowing_add_unsigned(self, rhs: Self::Unsigned) -> (Self, bool);
160156
fn overflowing_sub_unsigned(self, rhs: Self::Unsigned) -> (Self, bool);

src/unsigned.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ pub trait PrimitiveUnsigned: PrimitiveInteger + From<u8> {
6565
/// Returns `true` if and only if `self == 2^k` for some `k`.
6666
fn is_power_of_two(self) -> bool;
6767

68-
/// Calculates the middle point of `self` and `other`.
69-
fn midpoint(self, other: Self) -> Self;
70-
7168
/// Calculates the smallest value greater than or equal to `self` that is a multiple of `rhs`.
7269
fn next_multiple_of(self, rhs: Self) -> Self;
7370

@@ -107,7 +104,6 @@ macro_rules! impl_unsigned {
107104
fn div_ceil(self, rhs: Self) -> Self;
108105
fn is_multiple_of(self, rhs: Self) -> bool;
109106
fn is_power_of_two(self) -> bool;
110-
fn midpoint(self, other: Self) -> Self;
111107
fn next_multiple_of(self, rhs: Self) -> Self;
112108
fn next_power_of_two(self) -> Self;
113109
fn overflowing_add_signed(self, rhs: Self::Signed) -> (Self, bool);

0 commit comments

Comments
 (0)