Skip to content

Stabilize unsigned and float variants of num_midpoint feature#131784

Merged
bors merged 1 commit intorust-lang:masterfrom
Urgau:stabilize-midpoint
Dec 2, 2024
Merged

Stabilize unsigned and float variants of num_midpoint feature#131784
bors merged 1 commit intorust-lang:masterfrom
Urgau:stabilize-midpoint

Conversation

@Urgau
Copy link
Member

@Urgau Urgau commented Oct 16, 2024

This PR proposes that we stabilize the unsigned variants of the num_midpoint feature as well as the floats variants, since they are not subject to any unresolved questions, which is equivalent to doing (a + b) / 2 (and (a + b) >> 1) in a sufficiently large number.

The stabilized API surface would be:

/// Calculates the middle point of `self` and `rhs`.
///
/// `midpoint(a, b)` is `(a + b) / 2` as if it were performed in a sufficiently-large unsigned integral type.
/// This implies that the result is always rounded towards negative infinity and that no overflow will ever occur.

impl u{8,16,32,64,128,size} {
    pub const fn midpoint(self, rhs: Self) -> Self;
}

impl NonZeroU{8,16,32,64,size} {
    pub const fn midpoint(self, rhs: Self) -> Self;
}

impl f{32,64} {
    pub const fn midpoint(self, rhs: Self) -> Self;
}

The signed variants u{8,16,32,64,128,size} would remain gated, until a decision is made about the rounding mode, in other words that the unresolved questions are resolved.

cc @rust-lang/libs-api
cc @scottmcm
r? libs-api

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. S-waiting-on-fcp Status: PR is in FCP and is awaiting for FCP to complete. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.