Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e217d60

Browse files
committedOct 27, 2024·
Stabilize unsigned num_midpoint feature
1 parent 9fa0146 commit e217d60

File tree

8 files changed

+36
-45
lines changed

8 files changed

+36
-45
lines changed
 

‎library/core/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@
125125
#![feature(const_hash)]
126126
#![feature(const_heap)]
127127
#![feature(const_nonnull_new)]
128-
#![feature(const_num_midpoint)]
129128
#![feature(const_option_ext)]
130129
#![feature(const_pin_2)]
131130
#![feature(const_pointer_is_aligned)]

‎library/core/src/num/f128.rs

+2-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,8 @@ 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+
#[rustc_const_unstable(feature = "f128", issue = "116909")]
832+
pub const fn midpoint(self, other: f128) -> f128 {
834833
const LO: f128 = f128::MIN_POSITIVE * 2.;
835834
const HI: f128 = f128::MAX / 2.;
836835

‎library/core/src/num/f16.rs

+2-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,8 @@ 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+
#[rustc_const_unstable(feature = "f16", issue = "116909")]
817+
pub const fn midpoint(self, other: f16) -> f16 {
819818
const LO: f16 = f16::MIN_POSITIVE * 2.;
820819
const HI: f16 = f16::MAX / 2.;
821820

‎library/core/src/num/f32.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -994,27 +994,27 @@ impl f32 {
994994
/// # Examples
995995
///
996996
/// ```
997-
/// #![feature(num_midpoint)]
998997
/// assert_eq!(1f32.midpoint(4.0), 2.5);
999998
/// assert_eq!((-5.5f32).midpoint(8.0), 1.25);
1000999
/// ```
10011000
#[inline]
1002-
#[unstable(feature = "num_midpoint", issue = "110840")]
1003-
pub fn midpoint(self, other: f32) -> f32 {
1001+
#[stable(feature = "num_midpoint", since = "CURRENT_RUSTC_VERSION")]
1002+
#[rustc_const_stable(feature = "num_midpoint", since = "CURRENT_RUSTC_VERSION")]
1003+
pub const fn midpoint(self, other: f32) -> f32 {
10041004
cfg_if! {
1005+
// Allow faster implementation that have known good 64-bit float
1006+
// implementations. Falling back to the branchy code on targets that don't
1007+
// have 64-bit hardware floats or buggy implementations.
1008+
// https://github.com/rust-lang/rust/pull/121062#issuecomment-2123408114
10051009
if #[cfg(any(
10061010
target_arch = "x86_64",
10071011
target_arch = "aarch64",
1008-
all(any(target_arch="riscv32", target_arch= "riscv64"), target_feature="d"),
1009-
all(target_arch = "arm", target_feature="vfp2"),
1012+
all(any(target_arch = "riscv32", target_arch = "riscv64"), target_feature = "d"),
1013+
all(target_arch = "arm", target_feature = "vfp2"),
10101014
target_arch = "wasm32",
10111015
target_arch = "wasm64",
10121016
))] {
1013-
// whitelist the faster implementation to targets that have known good 64-bit float
1014-
// implementations. Falling back to the branchy code on targets that don't have
1015-
// 64-bit hardware floats or buggy implementations.
1016-
// see: https://github.com/rust-lang/rust/pull/121062#issuecomment-2123408114
1017-
((f64::from(self) + f64::from(other)) / 2.0) as f32
1017+
((self as f64 + other as f64) / 2.0) as f32
10181018
} else {
10191019
const LO: f32 = f32::MIN_POSITIVE * 2.;
10201020
const HI: f32 = f32::MAX / 2.;

‎library/core/src/num/f64.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1012,13 +1012,13 @@ impl f64 {
10121012
/// # Examples
10131013
///
10141014
/// ```
1015-
/// #![feature(num_midpoint)]
10161015
/// assert_eq!(1f64.midpoint(4.0), 2.5);
10171016
/// assert_eq!((-5.5f64).midpoint(8.0), 1.25);
10181017
/// ```
10191018
#[inline]
1020-
#[unstable(feature = "num_midpoint", issue = "110840")]
1021-
pub fn midpoint(self, other: f64) -> f64 {
1019+
#[stable(feature = "num_midpoint", since = "CURRENT_RUSTC_VERSION")]
1020+
#[rustc_const_stable(feature = "num_midpoint", since = "CURRENT_RUSTC_VERSION")]
1021+
pub const fn midpoint(self, other: f64) -> f64 {
10221022
const LO: f64 = f64::MIN_POSITIVE * 2.;
10231023
const HI: f64 = f64::MAX / 2.;
10241024

‎library/core/src/num/mod.rs

+16-18
Original file line numberDiff line numberDiff line change
@@ -102,19 +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")]
117-
#[rustc_const_unstable(feature = "const_num_midpoint", issue = "110840")]
115+
#[stable(feature = "num_midpoint", since = "CURRENT_RUSTC_VERSION")]
116+
#[rustc_const_stable(feature = "const_num_midpoint", since = "CURRENT_RUSTC_VERSION")]
118117
#[must_use = "this returns the result of the operation, \
119118
without modifying the original"]
120119
#[inline]
@@ -134,15 +133,15 @@ macro_rules! midpoint_impl {
134133
/// # Examples
135134
///
136135
/// ```
137-
/// #![feature(num_midpoint)]
136+
/// #![feature(num_midpoint_signed)]
138137
#[doc = concat!("assert_eq!(0", stringify!($SelfT), ".midpoint(4), 2);")]
139138
#[doc = concat!("assert_eq!((-1", stringify!($SelfT), ").midpoint(2), 0);")]
140139
#[doc = concat!("assert_eq!((-7", stringify!($SelfT), ").midpoint(0), -3);")]
141140
#[doc = concat!("assert_eq!(0", stringify!($SelfT), ".midpoint(-7), -3);")]
142141
#[doc = concat!("assert_eq!(0", stringify!($SelfT), ".midpoint(7), 3);")]
143142
/// ```
144-
#[unstable(feature = "num_midpoint", issue = "110840")]
145-
#[rustc_const_unstable(feature = "const_num_midpoint", issue = "110840")]
143+
#[unstable(feature = "num_midpoint_signed", issue = "110840")]
144+
#[rustc_const_unstable(feature = "num_midpoint_signed", issue = "110840")]
146145
#[must_use = "this returns the result of the operation, \
147146
without modifying the original"]
148147
#[inline]
@@ -158,19 +157,18 @@ macro_rules! midpoint_impl {
158157
($SelfT:ty, $WideT:ty, unsigned) => {
159158
/// Calculates the middle point of `self` and `rhs`.
160159
///
161-
/// `midpoint(a, b)` is `(a + b) >> 1` as if it were performed in a
162-
/// sufficiently-large signed integral type. This implies that the result is
163-
/// always rounded towards negative infinity and that no overflow will ever occur.
160+
/// `midpoint(a, b)` is `(a + b) / 2` as if it were performed in a
161+
/// sufficiently-large unsigned integral type. This implies that the result is
162+
/// always rounded towards zero and that no overflow will ever occur.
164163
///
165164
/// # Examples
166165
///
167166
/// ```
168-
/// #![feature(num_midpoint)]
169167
#[doc = concat!("assert_eq!(0", stringify!($SelfT), ".midpoint(4), 2);")]
170168
#[doc = concat!("assert_eq!(1", stringify!($SelfT), ".midpoint(4), 2);")]
171169
/// ```
172-
#[unstable(feature = "num_midpoint", issue = "110840")]
173-
#[rustc_const_unstable(feature = "const_num_midpoint", issue = "110840")]
170+
#[stable(feature = "num_midpoint", since = "CURRENT_RUSTC_VERSION")]
171+
#[rustc_const_stable(feature = "const_num_midpoint", since = "CURRENT_RUSTC_VERSION")]
174172
#[must_use = "this returns the result of the operation, \
175173
without modifying the original"]
176174
#[inline]
@@ -188,15 +186,15 @@ macro_rules! midpoint_impl {
188186
/// # Examples
189187
///
190188
/// ```
191-
/// #![feature(num_midpoint)]
189+
/// #![feature(num_midpoint_signed)]
192190
#[doc = concat!("assert_eq!(0", stringify!($SelfT), ".midpoint(4), 2);")]
193191
#[doc = concat!("assert_eq!((-1", stringify!($SelfT), ").midpoint(2), 0);")]
194192
#[doc = concat!("assert_eq!((-7", stringify!($SelfT), ").midpoint(0), -3);")]
195193
#[doc = concat!("assert_eq!(0", stringify!($SelfT), ".midpoint(-7), -3);")]
196194
#[doc = concat!("assert_eq!(0", stringify!($SelfT), ".midpoint(7), 3);")]
197195
/// ```
198-
#[unstable(feature = "num_midpoint", issue = "110840")]
199-
#[rustc_const_unstable(feature = "const_num_midpoint", issue = "110840")]
196+
#[unstable(feature = "num_midpoint_signed", issue = "110840")]
197+
#[rustc_const_unstable(feature = "num_midpoint_signed", issue = "110840")]
200198
#[must_use = "this returns the result of the operation, \
201199
without modifying the original"]
202200
#[inline]

‎library/core/src/num/nonzero.rs

+2-5
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,9 +1471,8 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
14731471
/// # Some(())
14741472
/// # }
14751473
/// ```
1476-
#[unstable(feature = "num_midpoint", issue = "110840")]
1477-
#[rustc_const_unstable(feature = "const_num_midpoint", issue = "110840")]
1478-
#[rustc_allow_const_fn_unstable(const_num_midpoint)]
1474+
#[stable(feature = "num_midpoint", since = "CURRENT_RUSTC_VERSION")]
1475+
#[rustc_const_stable(feature = "const_num_midpoint", since = "CURRENT_RUSTC_VERSION")]
14791476
#[must_use = "this returns the result of the operation, \
14801477
without modifying the original"]
14811478
#[inline]

‎library/core/tests/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#![feature(const_hash)]
2424
#![feature(const_heap)]
2525
#![feature(const_nonnull_new)]
26-
#![feature(const_num_midpoint)]
2726
#![feature(const_option_ext)]
2827
#![feature(const_pin_2)]
2928
#![feature(const_pointer_is_aligned)]
@@ -74,7 +73,7 @@
7473
#![feature(min_specialization)]
7574
#![feature(never_type)]
7675
#![feature(noop_waker)]
77-
#![feature(num_midpoint)]
76+
#![feature(num_midpoint_signed)]
7877
#![feature(numfmt)]
7978
#![feature(pattern)]
8079
#![feature(pointer_is_aligned_to)]

0 commit comments

Comments
 (0)
Please sign in to comment.