Skip to content

Mention average in midpoint documentations #140075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 24, 2025
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
3 changes: 2 additions & 1 deletion library/core/src/num/f128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ impl f128 {
}
}

/// Calculates the middle point of `self` and `rhs`.
/// Calculates the midpoint (average) between `self` and `rhs`.
///
/// This returns NaN when *either* argument is NaN or if a combination of
/// +inf and -inf is provided as arguments.
Expand All @@ -818,6 +818,7 @@ impl f128 {
/// # }
/// ```
#[inline]
#[doc(alias = "average")]
#[unstable(feature = "f128", issue = "116909")]
#[rustc_const_unstable(feature = "f128", issue = "116909")]
pub const fn midpoint(self, other: f128) -> f128 {
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/num/f16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ impl f16 {
}
}

/// Calculates the middle point of `self` and `rhs`.
/// Calculates the midpoint (average) between `self` and `rhs`.
///
/// This returns NaN when *either* argument is NaN or if a combination of
/// +inf and -inf is provided as arguments.
Expand All @@ -805,6 +805,7 @@ impl f16 {
/// # }
/// ```
#[inline]
#[doc(alias = "average")]
#[unstable(feature = "f16", issue = "116909")]
#[rustc_const_unstable(feature = "f16", issue = "116909")]
pub const fn midpoint(self, other: f16) -> f16 {
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ impl f32 {
}
}

/// Calculates the middle point of `self` and `rhs`.
/// Calculates the midpoint (average) between `self` and `rhs`.
///
/// This returns NaN when *either* argument is NaN or if a combination of
/// +inf and -inf is provided as arguments.
Expand All @@ -995,6 +995,7 @@ impl f32 {
/// assert_eq!((-5.5f32).midpoint(8.0), 1.25);
/// ```
#[inline]
#[doc(alias = "average")]
#[stable(feature = "num_midpoint", since = "1.85.0")]
#[rustc_const_stable(feature = "num_midpoint", since = "1.85.0")]
pub const fn midpoint(self, other: f32) -> f32 {
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ impl f64 {
}
}

/// Calculates the middle point of `self` and `rhs`.
/// Calculates the midpoint (average) between `self` and `rhs`.
///
/// This returns NaN when *either* argument is NaN or if a combination of
/// +inf and -inf is provided as arguments.
Expand All @@ -1013,6 +1013,7 @@ impl f64 {
/// assert_eq!((-5.5f64).midpoint(8.0), 1.25);
/// ```
#[inline]
#[doc(alias = "average")]
#[stable(feature = "num_midpoint", since = "1.85.0")]
#[rustc_const_stable(feature = "num_midpoint", since = "1.85.0")]
pub const fn midpoint(self, other: f64) -> f64 {
Expand Down
18 changes: 14 additions & 4 deletions library/core/src/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ depending on the target pointer size.

macro_rules! midpoint_impl {
($SelfT:ty, unsigned) => {
/// Calculates the middle point of `self` and `rhs`.
/// Calculates the midpoint (average) between `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
Expand All @@ -146,6 +146,8 @@ macro_rules! midpoint_impl {
#[rustc_const_stable(feature = "num_midpoint", since = "1.85.0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[doc(alias = "average_floor")]
#[doc(alias = "average")]
#[inline]
pub const fn midpoint(self, rhs: $SelfT) -> $SelfT {
// Use the well known branchless algorithm from Hacker's Delight to compute
Expand All @@ -154,7 +156,7 @@ macro_rules! midpoint_impl {
}
};
($SelfT:ty, signed) => {
/// Calculates the middle point of `self` and `rhs`.
/// Calculates the midpoint (average) between `self` and `rhs`.
///
/// `midpoint(a, b)` is `(a + b) / 2` as if it were performed in a
/// sufficiently-large signed integral type. This implies that the result is
Expand All @@ -173,6 +175,9 @@ macro_rules! midpoint_impl {
#[rustc_const_stable(feature = "num_midpoint_signed", since = "1.87.0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[doc(alias = "average_floor")]
#[doc(alias = "average_ceil")]
#[doc(alias = "average")]
#[inline]
pub const fn midpoint(self, rhs: Self) -> Self {
// Use the well known branchless algorithm from Hacker's Delight to compute
Expand All @@ -184,7 +189,7 @@ macro_rules! midpoint_impl {
}
};
($SelfT:ty, $WideT:ty, unsigned) => {
/// Calculates the middle point of `self` and `rhs`.
/// Calculates the midpoint (average) between `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
Expand All @@ -200,13 +205,15 @@ macro_rules! midpoint_impl {
#[rustc_const_stable(feature = "num_midpoint", since = "1.85.0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[doc(alias = "average_floor")]
#[doc(alias = "average")]
#[inline]
pub const fn midpoint(self, rhs: $SelfT) -> $SelfT {
((self as $WideT + rhs as $WideT) / 2) as $SelfT
}
};
($SelfT:ty, $WideT:ty, signed) => {
/// Calculates the middle point of `self` and `rhs`.
/// Calculates the midpoint (average) between `self` and `rhs`.
///
/// `midpoint(a, b)` is `(a + b) / 2` as if it were performed in a
/// sufficiently-large signed integral type. This implies that the result is
Expand All @@ -225,6 +232,9 @@ macro_rules! midpoint_impl {
#[rustc_const_stable(feature = "num_midpoint_signed", since = "1.87.0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[doc(alias = "average_floor")]
#[doc(alias = "average_ceil")]
#[doc(alias = "average")]
#[inline]
pub const fn midpoint(self, rhs: $SelfT) -> $SelfT {
((self as $WideT + rhs as $WideT) / 2) as $SelfT
Expand Down
4 changes: 3 additions & 1 deletion library/core/src/num/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1589,7 +1589,7 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
super::int_log10::$Int(self.get())
}

/// Calculates the middle point of `self` and `rhs`.
/// Calculates the midpoint (average) between `self` and `rhs`.
///
/// `midpoint(a, b)` is `(a + b) >> 1` as if it were performed in a
/// sufficiently-large signed integral type. This implies that the result is
Expand All @@ -1615,6 +1615,8 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
#[rustc_const_stable(feature = "num_midpoint", since = "1.85.0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[doc(alias = "average_floor")]
#[doc(alias = "average")]
#[inline]
pub const fn midpoint(self, rhs: Self) -> Self {
// SAFETY: The only way to get `0` with midpoint is to have two opposite or
Expand Down
Loading