Skip to content

Commit cf3aa1d

Browse files
committed
Stabilize unsigned num_midpoint feature
1 parent db034ce commit cf3aa1d

File tree

7 files changed

+32
-37
lines changed

7 files changed

+32
-37
lines changed

library/core/src/num/f128.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,6 @@ impl f128 {
819819
///
820820
/// ```
821821
/// #![feature(f128)]
822-
/// #![feature(num_midpoint)]
823822
/// # // Using aarch64 because `reliable_f128_math` is needed
824823
/// # #[cfg(all(target_arch = "aarch64", target_os = "linux"))] {
825824
///
@@ -829,8 +828,7 @@ impl f128 {
829828
/// ```
830829
#[inline]
831830
#[unstable(feature = "f128", issue = "116909")]
832-
// #[unstable(feature = "num_midpoint", issue = "110840")]
833-
pub fn midpoint(self, other: f128) -> f128 {
831+
pub const fn midpoint(self, other: f128) -> f128 {
834832
const LO: f128 = f128::MIN_POSITIVE * 2.;
835833
const HI: f128 = f128::MAX / 2.;
836834

library/core/src/num/f16.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,6 @@ impl f16 {
805805
///
806806
/// ```
807807
/// #![feature(f16)]
808-
/// #![feature(num_midpoint)]
809808
/// # #[cfg(target_arch = "aarch64")] { // FIXME(f16_F128): rust-lang/rust#123885
810809
///
811810
/// assert_eq!(1f16.midpoint(4.0), 2.5);
@@ -814,8 +813,7 @@ impl f16 {
814813
/// ```
815814
#[inline]
816815
#[unstable(feature = "f16", issue = "116909")]
817-
// #[unstable(feature = "num_midpoint", issue = "110840")]
818-
pub fn midpoint(self, other: f16) -> f16 {
816+
pub const fn midpoint(self, other: f16) -> f16 {
819817
const LO: f16 = f16::MIN_POSITIVE * 2.;
820818
const HI: f16 = f16::MAX / 2.;
821819

library/core/src/num/f32.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -992,27 +992,27 @@ impl f32 {
992992
/// # Examples
993993
///
994994
/// ```
995-
/// #![feature(num_midpoint)]
996995
/// assert_eq!(1f32.midpoint(4.0), 2.5);
997996
/// assert_eq!((-5.5f32).midpoint(8.0), 1.25);
998997
/// ```
999998
#[inline]
1000-
#[unstable(feature = "num_midpoint", issue = "110840")]
1001-
pub fn midpoint(self, other: f32) -> f32 {
999+
#[stable(feature = "num_midpoint", since = "CURRENT_RUSTC_VERSION")]
1000+
#[rustc_const_stable(feature = "num_midpoint", since = "CURRENT_RUSTC_VERSION")]
1001+
pub const fn midpoint(self, other: f32) -> f32 {
10021002
cfg_if! {
1003+
// Allow faster implementation that have known good 64-bit float
1004+
// implementations. Falling back to the branchy code on targets that don't
1005+
// have 64-bit hardware floats or buggy implementations.
1006+
// https://github.com/rust-lang/rust/pull/121062#issuecomment-2123408114
10031007
if #[cfg(any(
10041008
target_arch = "x86_64",
10051009
target_arch = "aarch64",
1006-
all(any(target_arch="riscv32", target_arch= "riscv64"), target_feature="d"),
1007-
all(target_arch = "arm", target_feature="vfp2"),
1010+
all(any(target_arch = "riscv32", target_arch = "riscv64"), target_feature = "d"),
1011+
all(target_arch = "arm", target_feature = "vfp2"),
10081012
target_arch = "wasm32",
10091013
target_arch = "wasm64",
10101014
))] {
1011-
// whitelist the faster implementation to targets that have known good 64-bit float
1012-
// implementations. Falling back to the branchy code on targets that don't have
1013-
// 64-bit hardware floats or buggy implementations.
1014-
// see: https://github.com/rust-lang/rust/pull/121062#issuecomment-2123408114
1015-
((f64::from(self) + f64::from(other)) / 2.0) as f32
1015+
((self as f64 + other as f64) / 2.0) as f32
10161016
} else {
10171017
const LO: f32 = f32::MIN_POSITIVE * 2.;
10181018
const HI: f32 = f32::MAX / 2.;

library/core/src/num/f64.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1010,13 +1010,13 @@ impl f64 {
10101010
/// # Examples
10111011
///
10121012
/// ```
1013-
/// #![feature(num_midpoint)]
10141013
/// assert_eq!(1f64.midpoint(4.0), 2.5);
10151014
/// assert_eq!((-5.5f64).midpoint(8.0), 1.25);
10161015
/// ```
10171016
#[inline]
1018-
#[unstable(feature = "num_midpoint", issue = "110840")]
1019-
pub fn midpoint(self, other: f64) -> f64 {
1017+
#[stable(feature = "num_midpoint", since = "CURRENT_RUSTC_VERSION")]
1018+
#[rustc_const_stable(feature = "num_midpoint", since = "CURRENT_RUSTC_VERSION")]
1019+
pub const fn midpoint(self, other: f64) -> f64 {
10201020
const LO: f64 = f64::MIN_POSITIVE * 2.;
10211021
const HI: f64 = f64::MAX / 2.;
10221022

library/core/src/num/mod.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,18 @@ macro_rules! midpoint_impl {
102102
($SelfT:ty, unsigned) => {
103103
/// Calculates the middle point of `self` and `rhs`.
104104
///
105-
/// `midpoint(a, b)` is `(a + b) >> 1` as if it were performed in a
106-
/// sufficiently-large signed integral type. This implies that the result is
107-
/// always rounded towards negative infinity and that no overflow will ever occur.
105+
/// `midpoint(a, b)` is `(a + b) / 2` as if it were performed in a
106+
/// sufficiently-large unsigned integral type. This implies that the result is
107+
/// always rounded towards zero and that no overflow will ever occur.
108108
///
109109
/// # Examples
110110
///
111111
/// ```
112-
/// #![feature(num_midpoint)]
113112
#[doc = concat!("assert_eq!(0", stringify!($SelfT), ".midpoint(4), 2);")]
114113
#[doc = concat!("assert_eq!(1", stringify!($SelfT), ".midpoint(4), 2);")]
115114
/// ```
116-
#[unstable(feature = "num_midpoint", issue = "110840")]
115+
#[stable(feature = "num_midpoint", since = "CURRENT_RUSTC_VERSION")]
116+
#[rustc_const_stable(feature = "num_midpoint", since = "CURRENT_RUSTC_VERSION")]
117117
#[must_use = "this returns the result of the operation, \
118118
without modifying the original"]
119119
#[inline]
@@ -133,14 +133,14 @@ macro_rules! midpoint_impl {
133133
/// # Examples
134134
///
135135
/// ```
136-
/// #![feature(num_midpoint)]
136+
/// #![feature(num_midpoint_signed)]
137137
#[doc = concat!("assert_eq!(0", stringify!($SelfT), ".midpoint(4), 2);")]
138138
#[doc = concat!("assert_eq!((-1", stringify!($SelfT), ").midpoint(2), 0);")]
139139
#[doc = concat!("assert_eq!((-7", stringify!($SelfT), ").midpoint(0), -3);")]
140140
#[doc = concat!("assert_eq!(0", stringify!($SelfT), ".midpoint(-7), -3);")]
141141
#[doc = concat!("assert_eq!(0", stringify!($SelfT), ".midpoint(7), 3);")]
142142
/// ```
143-
#[unstable(feature = "num_midpoint", issue = "110840")]
143+
#[unstable(feature = "num_midpoint_signed", issue = "110840")]
144144
#[must_use = "this returns the result of the operation, \
145145
without modifying the original"]
146146
#[inline]
@@ -156,18 +156,18 @@ macro_rules! midpoint_impl {
156156
($SelfT:ty, $WideT:ty, unsigned) => {
157157
/// Calculates the middle point of `self` and `rhs`.
158158
///
159-
/// `midpoint(a, b)` is `(a + b) >> 1` as if it were performed in a
160-
/// sufficiently-large signed integral type. This implies that the result is
161-
/// always rounded towards negative infinity and that no overflow will ever occur.
159+
/// `midpoint(a, b)` is `(a + b) / 2` as if it were performed in a
160+
/// sufficiently-large unsigned integral type. This implies that the result is
161+
/// always rounded towards zero and that no overflow will ever occur.
162162
///
163163
/// # Examples
164164
///
165165
/// ```
166-
/// #![feature(num_midpoint)]
167166
#[doc = concat!("assert_eq!(0", stringify!($SelfT), ".midpoint(4), 2);")]
168167
#[doc = concat!("assert_eq!(1", stringify!($SelfT), ".midpoint(4), 2);")]
169168
/// ```
170-
#[unstable(feature = "num_midpoint", issue = "110840")]
169+
#[stable(feature = "num_midpoint", since = "CURRENT_RUSTC_VERSION")]
170+
#[rustc_const_stable(feature = "num_midpoint", since = "CURRENT_RUSTC_VERSION")]
171171
#[must_use = "this returns the result of the operation, \
172172
without modifying the original"]
173173
#[inline]
@@ -185,14 +185,14 @@ macro_rules! midpoint_impl {
185185
/// # Examples
186186
///
187187
/// ```
188-
/// #![feature(num_midpoint)]
188+
/// #![feature(num_midpoint_signed)]
189189
#[doc = concat!("assert_eq!(0", stringify!($SelfT), ".midpoint(4), 2);")]
190190
#[doc = concat!("assert_eq!((-1", stringify!($SelfT), ").midpoint(2), 0);")]
191191
#[doc = concat!("assert_eq!((-7", stringify!($SelfT), ").midpoint(0), -3);")]
192192
#[doc = concat!("assert_eq!(0", stringify!($SelfT), ".midpoint(-7), -3);")]
193193
#[doc = concat!("assert_eq!(0", stringify!($SelfT), ".midpoint(7), 3);")]
194194
/// ```
195-
#[unstable(feature = "num_midpoint", issue = "110840")]
195+
#[unstable(feature = "num_midpoint_signed", issue = "110840")]
196196
#[must_use = "this returns the result of the operation, \
197197
without modifying the original"]
198198
#[inline]

library/core/src/num/nonzero.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1458,8 +1458,6 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
14581458
/// # Examples
14591459
///
14601460
/// ```
1461-
/// #![feature(num_midpoint)]
1462-
///
14631461
/// # use std::num::NonZero;
14641462
/// #
14651463
/// # fn main() { test().unwrap(); }
@@ -1473,7 +1471,8 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
14731471
/// # Some(())
14741472
/// # }
14751473
/// ```
1476-
#[unstable(feature = "num_midpoint", issue = "110840")]
1474+
#[stable(feature = "num_midpoint", since = "CURRENT_RUSTC_VERSION")]
1475+
#[rustc_const_stable(feature = "num_midpoint", since = "CURRENT_RUSTC_VERSION")]
14771476
#[must_use = "this returns the result of the operation, \
14781477
without modifying the original"]
14791478
#[inline]

library/core/tests/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
#![feature(min_specialization)]
7272
#![feature(never_type)]
7373
#![feature(noop_waker)]
74-
#![feature(num_midpoint)]
74+
#![feature(num_midpoint_signed)]
7575
#![feature(numfmt)]
7676
#![feature(pattern)]
7777
#![feature(pointer_is_aligned_to)]

0 commit comments

Comments
 (0)