Merge from rustc
This commit is contained in:
commit
65e76849ac
183 changed files with 2692 additions and 874 deletions
|
|
@ -549,8 +549,6 @@ impl<T: Copy> Cell<T> {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(cell_update)]
|
||||
///
|
||||
/// use std::cell::Cell;
|
||||
///
|
||||
/// let c = Cell::new(5);
|
||||
|
|
@ -558,7 +556,7 @@ impl<T: Copy> Cell<T> {
|
|||
/// assert_eq!(c.get(), 6);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "cell_update", issue = "50186")]
|
||||
#[stable(feature = "cell_update", since = "CURRENT_RUSTC_VERSION")]
|
||||
pub fn update(&self, f: impl FnOnce(T) -> T) {
|
||||
let old = self.get();
|
||||
self.set(f(old));
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ pub(super) const fn from_u32(i: u32) -> Option<char> {
|
|||
/// Converts a `u32` to a `char`, ignoring validity. See [`char::from_u32_unchecked`].
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[cfg_attr(not(bootstrap), allow(unnecessary_transmutes))]
|
||||
pub(super) const unsafe fn from_u32_unchecked(i: u32) -> char {
|
||||
// SAFETY: the caller must guarantee that `i` is a valid char value.
|
||||
unsafe {
|
||||
|
|
@ -221,6 +222,7 @@ impl FromStr for char {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg_attr(not(bootstrap), allow(unnecessary_transmutes))]
|
||||
const fn char_try_from_u32(i: u32) -> Result<char, CharTryFromError> {
|
||||
// This is an optimized version of the check
|
||||
// (i > MAX as u32) || (i >= 0xD800 && i <= 0xDFFF),
|
||||
|
|
|
|||
|
|
@ -1497,6 +1497,7 @@ pub const fn forget<T: ?Sized>(_: T);
|
|||
/// Turning raw bytes (`[u8; SZ]`) into `u32`, `f64`, etc.:
|
||||
///
|
||||
/// ```
|
||||
/// # #![cfg_attr(not(bootstrap), allow(unnecessary_transmutes))]
|
||||
/// let raw_bytes = [0x78, 0x56, 0x34, 0x12];
|
||||
///
|
||||
/// let num = unsafe {
|
||||
|
|
@ -2429,35 +2430,35 @@ pub unsafe fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> In
|
|||
/// Stabilized as [`f16::algebraic_add`], [`f32::algebraic_add`], [`f64::algebraic_add`] and [`f128::algebraic_add`].
|
||||
#[rustc_nounwind]
|
||||
#[rustc_intrinsic]
|
||||
pub fn fadd_algebraic<T: Copy>(a: T, b: T) -> T;
|
||||
pub const fn fadd_algebraic<T: Copy>(a: T, b: T) -> T;
|
||||
|
||||
/// Float subtraction that allows optimizations based on algebraic rules.
|
||||
///
|
||||
/// Stabilized as [`f16::algebraic_sub`], [`f32::algebraic_sub`], [`f64::algebraic_sub`] and [`f128::algebraic_sub`].
|
||||
#[rustc_nounwind]
|
||||
#[rustc_intrinsic]
|
||||
pub fn fsub_algebraic<T: Copy>(a: T, b: T) -> T;
|
||||
pub const fn fsub_algebraic<T: Copy>(a: T, b: T) -> T;
|
||||
|
||||
/// Float multiplication that allows optimizations based on algebraic rules.
|
||||
///
|
||||
/// Stabilized as [`f16::algebraic_mul`], [`f32::algebraic_mul`], [`f64::algebraic_mul`] and [`f128::algebraic_mul`].
|
||||
#[rustc_nounwind]
|
||||
#[rustc_intrinsic]
|
||||
pub fn fmul_algebraic<T: Copy>(a: T, b: T) -> T;
|
||||
pub const fn fmul_algebraic<T: Copy>(a: T, b: T) -> T;
|
||||
|
||||
/// Float division that allows optimizations based on algebraic rules.
|
||||
///
|
||||
/// Stabilized as [`f16::algebraic_div`], [`f32::algebraic_div`], [`f64::algebraic_div`] and [`f128::algebraic_div`].
|
||||
#[rustc_nounwind]
|
||||
#[rustc_intrinsic]
|
||||
pub fn fdiv_algebraic<T: Copy>(a: T, b: T) -> T;
|
||||
pub const fn fdiv_algebraic<T: Copy>(a: T, b: T) -> T;
|
||||
|
||||
/// Float remainder that allows optimizations based on algebraic rules.
|
||||
///
|
||||
/// Stabilized as [`f16::algebraic_rem`], [`f32::algebraic_rem`], [`f64::algebraic_rem`] and [`f128::algebraic_rem`].
|
||||
#[rustc_nounwind]
|
||||
#[rustc_intrinsic]
|
||||
pub fn frem_algebraic<T: Copy>(a: T, b: T) -> T;
|
||||
pub const fn frem_algebraic<T: Copy>(a: T, b: T) -> T;
|
||||
|
||||
/// Returns the number of bits set in an integer type `T`
|
||||
///
|
||||
|
|
|
|||
|
|
@ -197,16 +197,22 @@ impl f128 {
|
|||
#[unstable(feature = "f128", issue = "116909")]
|
||||
pub const MAX: f128 = 1.18973149535723176508575932662800702e+4932_f128;
|
||||
|
||||
/// One greater than the minimum possible normal power of 2 exponent.
|
||||
/// One greater than the minimum possible *normal* power of 2 exponent
|
||||
/// for a significand bounded by 1 ≤ x < 2 (i.e. the IEEE definition).
|
||||
///
|
||||
/// If <i>x</i> = `MIN_EXP`, then normal numbers
|
||||
/// ≥ 0.5 × 2<sup><i>x</i></sup>.
|
||||
/// This corresponds to the exact minimum possible *normal* power of 2 exponent
|
||||
/// for a significand bounded by 0.5 ≤ x < 1 (i.e. the C definition).
|
||||
/// In other words, all normal numbers representable by this type are
|
||||
/// greater than or equal to 0.5 × 2<sup><i>MIN_EXP</i></sup>.
|
||||
#[unstable(feature = "f128", issue = "116909")]
|
||||
pub const MIN_EXP: i32 = -16_381;
|
||||
/// Maximum possible power of 2 exponent.
|
||||
/// One greater than the maximum possible power of 2 exponent
|
||||
/// for a significand bounded by 1 ≤ x < 2 (i.e. the IEEE definition).
|
||||
///
|
||||
/// If <i>x</i> = `MAX_EXP`, then normal numbers
|
||||
/// < 1 × 2<sup><i>x</i></sup>.
|
||||
/// This corresponds to the exact maximum possible power of 2 exponent
|
||||
/// for a significand bounded by 0.5 ≤ x < 1 (i.e. the C definition).
|
||||
/// In other words, all numbers representable by this type are
|
||||
/// strictly less than 2<sup><i>MAX_EXP</i></sup>.
|
||||
#[unstable(feature = "f128", issue = "116909")]
|
||||
pub const MAX_EXP: i32 = 16_384;
|
||||
|
||||
|
|
@ -804,7 +810,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.
|
||||
|
|
@ -821,6 +827,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 {
|
||||
|
|
@ -903,6 +910,7 @@ impl f128 {
|
|||
#[inline]
|
||||
#[unstable(feature = "f128", issue = "116909")]
|
||||
#[must_use = "this returns the result of the operation, without modifying the original"]
|
||||
#[cfg_attr(not(bootstrap), allow(unnecessary_transmutes))]
|
||||
pub const fn to_bits(self) -> u128 {
|
||||
// SAFETY: `u128` is a plain old datatype so we can always transmute to it.
|
||||
unsafe { mem::transmute(self) }
|
||||
|
|
@ -950,6 +958,7 @@ impl f128 {
|
|||
#[inline]
|
||||
#[must_use]
|
||||
#[unstable(feature = "f128", issue = "116909")]
|
||||
#[cfg_attr(not(bootstrap), allow(unnecessary_transmutes))]
|
||||
pub const fn from_bits(v: u128) -> Self {
|
||||
// It turns out the safety issues with sNaN were overblown! Hooray!
|
||||
// SAFETY: `u128` is a plain old datatype so we can always transmute from it.
|
||||
|
|
@ -1373,8 +1382,9 @@ impl f128 {
|
|||
/// See [algebraic operators](primitive@f32#algebraic-operators) for more info.
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[rustc_const_unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[inline]
|
||||
pub fn algebraic_add(self, rhs: f128) -> f128 {
|
||||
pub const fn algebraic_add(self, rhs: f128) -> f128 {
|
||||
intrinsics::fadd_algebraic(self, rhs)
|
||||
}
|
||||
|
||||
|
|
@ -1383,8 +1393,9 @@ impl f128 {
|
|||
/// See [algebraic operators](primitive@f32#algebraic-operators) for more info.
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[rustc_const_unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[inline]
|
||||
pub fn algebraic_sub(self, rhs: f128) -> f128 {
|
||||
pub const fn algebraic_sub(self, rhs: f128) -> f128 {
|
||||
intrinsics::fsub_algebraic(self, rhs)
|
||||
}
|
||||
|
||||
|
|
@ -1393,8 +1404,9 @@ impl f128 {
|
|||
/// See [algebraic operators](primitive@f32#algebraic-operators) for more info.
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[rustc_const_unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[inline]
|
||||
pub fn algebraic_mul(self, rhs: f128) -> f128 {
|
||||
pub const fn algebraic_mul(self, rhs: f128) -> f128 {
|
||||
intrinsics::fmul_algebraic(self, rhs)
|
||||
}
|
||||
|
||||
|
|
@ -1403,8 +1415,9 @@ impl f128 {
|
|||
/// See [algebraic operators](primitive@f32#algebraic-operators) for more info.
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[rustc_const_unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[inline]
|
||||
pub fn algebraic_div(self, rhs: f128) -> f128 {
|
||||
pub const fn algebraic_div(self, rhs: f128) -> f128 {
|
||||
intrinsics::fdiv_algebraic(self, rhs)
|
||||
}
|
||||
|
||||
|
|
@ -1413,8 +1426,9 @@ impl f128 {
|
|||
/// See [algebraic operators](primitive@f32#algebraic-operators) for more info.
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[rustc_const_unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[inline]
|
||||
pub fn algebraic_rem(self, rhs: f128) -> f128 {
|
||||
pub const fn algebraic_rem(self, rhs: f128) -> f128 {
|
||||
intrinsics::frem_algebraic(self, rhs)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -192,16 +192,22 @@ impl f16 {
|
|||
#[unstable(feature = "f16", issue = "116909")]
|
||||
pub const MAX: f16 = 6.5504e+4_f16;
|
||||
|
||||
/// One greater than the minimum possible normal power of 2 exponent.
|
||||
/// One greater than the minimum possible *normal* power of 2 exponent
|
||||
/// for a significand bounded by 1 ≤ x < 2 (i.e. the IEEE definition).
|
||||
///
|
||||
/// If <i>x</i> = `MIN_EXP`, then normal numbers
|
||||
/// ≥ 0.5 × 2<sup><i>x</i></sup>.
|
||||
/// This corresponds to the exact minimum possible *normal* power of 2 exponent
|
||||
/// for a significand bounded by 0.5 ≤ x < 1 (i.e. the C definition).
|
||||
/// In other words, all normal numbers representable by this type are
|
||||
/// greater than or equal to 0.5 × 2<sup><i>MIN_EXP</i></sup>.
|
||||
#[unstable(feature = "f16", issue = "116909")]
|
||||
pub const MIN_EXP: i32 = -13;
|
||||
/// Maximum possible power of 2 exponent.
|
||||
/// One greater than the maximum possible power of 2 exponent
|
||||
/// for a significand bounded by 1 ≤ x < 2 (i.e. the IEEE definition).
|
||||
///
|
||||
/// If <i>x</i> = `MAX_EXP`, then normal numbers
|
||||
/// < 1 × 2<sup><i>x</i></sup>.
|
||||
/// This corresponds to the exact maximum possible power of 2 exponent
|
||||
/// for a significand bounded by 0.5 ≤ x < 1 (i.e. the C definition).
|
||||
/// In other words, all numbers representable by this type are
|
||||
/// strictly less than 2<sup><i>MAX_EXP</i></sup>.
|
||||
#[unstable(feature = "f16", issue = "116909")]
|
||||
pub const MAX_EXP: i32 = 16;
|
||||
|
||||
|
|
@ -792,7 +798,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.
|
||||
|
|
@ -808,6 +814,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 {
|
||||
|
|
@ -891,6 +898,7 @@ impl f16 {
|
|||
#[inline]
|
||||
#[unstable(feature = "f16", issue = "116909")]
|
||||
#[must_use = "this returns the result of the operation, without modifying the original"]
|
||||
#[cfg_attr(not(bootstrap), allow(unnecessary_transmutes))]
|
||||
pub const fn to_bits(self) -> u16 {
|
||||
// SAFETY: `u16` is a plain old datatype so we can always transmute to it.
|
||||
unsafe { mem::transmute(self) }
|
||||
|
|
@ -937,6 +945,7 @@ impl f16 {
|
|||
#[inline]
|
||||
#[must_use]
|
||||
#[unstable(feature = "f16", issue = "116909")]
|
||||
#[cfg_attr(not(bootstrap), allow(unnecessary_transmutes))]
|
||||
pub const fn from_bits(v: u16) -> Self {
|
||||
// It turns out the safety issues with sNaN were overblown! Hooray!
|
||||
// SAFETY: `u16` is a plain old datatype so we can always transmute from it.
|
||||
|
|
@ -1349,8 +1358,9 @@ impl f16 {
|
|||
/// See [algebraic operators](primitive@f32#algebraic-operators) for more info.
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[rustc_const_unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[inline]
|
||||
pub fn algebraic_add(self, rhs: f16) -> f16 {
|
||||
pub const fn algebraic_add(self, rhs: f16) -> f16 {
|
||||
intrinsics::fadd_algebraic(self, rhs)
|
||||
}
|
||||
|
||||
|
|
@ -1359,8 +1369,9 @@ impl f16 {
|
|||
/// See [algebraic operators](primitive@f32#algebraic-operators) for more info.
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[rustc_const_unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[inline]
|
||||
pub fn algebraic_sub(self, rhs: f16) -> f16 {
|
||||
pub const fn algebraic_sub(self, rhs: f16) -> f16 {
|
||||
intrinsics::fsub_algebraic(self, rhs)
|
||||
}
|
||||
|
||||
|
|
@ -1369,8 +1380,9 @@ impl f16 {
|
|||
/// See [algebraic operators](primitive@f32#algebraic-operators) for more info.
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[rustc_const_unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[inline]
|
||||
pub fn algebraic_mul(self, rhs: f16) -> f16 {
|
||||
pub const fn algebraic_mul(self, rhs: f16) -> f16 {
|
||||
intrinsics::fmul_algebraic(self, rhs)
|
||||
}
|
||||
|
||||
|
|
@ -1379,8 +1391,9 @@ impl f16 {
|
|||
/// See [algebraic operators](primitive@f32#algebraic-operators) for more info.
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[rustc_const_unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[inline]
|
||||
pub fn algebraic_div(self, rhs: f16) -> f16 {
|
||||
pub const fn algebraic_div(self, rhs: f16) -> f16 {
|
||||
intrinsics::fdiv_algebraic(self, rhs)
|
||||
}
|
||||
|
||||
|
|
@ -1389,8 +1402,9 @@ impl f16 {
|
|||
/// See [algebraic operators](primitive@f32#algebraic-operators) for more info.
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[rustc_const_unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[inline]
|
||||
pub fn algebraic_rem(self, rhs: f16) -> f16 {
|
||||
pub const fn algebraic_rem(self, rhs: f16) -> f16 {
|
||||
intrinsics::frem_algebraic(self, rhs)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -443,16 +443,22 @@ impl f32 {
|
|||
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
|
||||
pub const MAX: f32 = 3.40282347e+38_f32;
|
||||
|
||||
/// One greater than the minimum possible normal power of 2 exponent.
|
||||
/// One greater than the minimum possible *normal* power of 2 exponent
|
||||
/// for a significand bounded by 1 ≤ x < 2 (i.e. the IEEE definition).
|
||||
///
|
||||
/// If <i>x</i> = `MIN_EXP`, then normal numbers
|
||||
/// ≥ 0.5 × 2<sup><i>x</i></sup>.
|
||||
/// This corresponds to the exact minimum possible *normal* power of 2 exponent
|
||||
/// for a significand bounded by 0.5 ≤ x < 1 (i.e. the C definition).
|
||||
/// In other words, all normal numbers representable by this type are
|
||||
/// greater than or equal to 0.5 × 2<sup><i>MIN_EXP</i></sup>.
|
||||
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
|
||||
pub const MIN_EXP: i32 = -125;
|
||||
/// Maximum possible power of 2 exponent.
|
||||
/// One greater than the maximum possible power of 2 exponent
|
||||
/// for a significand bounded by 1 ≤ x < 2 (i.e. the IEEE definition).
|
||||
///
|
||||
/// If <i>x</i> = `MAX_EXP`, then normal numbers
|
||||
/// < 1 × 2<sup><i>x</i></sup>.
|
||||
/// This corresponds to the exact maximum possible power of 2 exponent
|
||||
/// for a significand bounded by 0.5 ≤ x < 1 (i.e. the C definition).
|
||||
/// In other words, all numbers representable by this type are
|
||||
/// strictly less than 2<sup><i>MAX_EXP</i></sup>.
|
||||
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
|
||||
pub const MAX_EXP: i32 = 128;
|
||||
|
||||
|
|
@ -710,8 +716,7 @@ impl f32 {
|
|||
pub const fn is_sign_negative(self) -> bool {
|
||||
// IEEE754 says: isSignMinus(x) is true if and only if x has negative sign. isSignMinus
|
||||
// applies to zeros and NaNs as well.
|
||||
// SAFETY: This is just transmuting to get the sign bit, it's fine.
|
||||
unsafe { mem::transmute::<f32, u32>(self) & 0x8000_0000 != 0 }
|
||||
self.to_bits() & 0x8000_0000 != 0
|
||||
}
|
||||
|
||||
/// Returns the least number greater than `self`.
|
||||
|
|
@ -986,7 +991,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.
|
||||
|
|
@ -998,6 +1003,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 {
|
||||
|
|
@ -1096,6 +1102,7 @@ impl f32 {
|
|||
#[stable(feature = "float_bits_conv", since = "1.20.0")]
|
||||
#[rustc_const_stable(feature = "const_float_bits_conv", since = "1.83.0")]
|
||||
#[inline]
|
||||
#[cfg_attr(not(bootstrap), allow(unnecessary_transmutes))]
|
||||
pub const fn to_bits(self) -> u32 {
|
||||
// SAFETY: `u32` is a plain old datatype so we can always transmute to it.
|
||||
unsafe { mem::transmute(self) }
|
||||
|
|
@ -1141,6 +1148,7 @@ impl f32 {
|
|||
#[rustc_const_stable(feature = "const_float_bits_conv", since = "1.83.0")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
#[cfg_attr(not(bootstrap), allow(unnecessary_transmutes))]
|
||||
pub const fn from_bits(v: u32) -> Self {
|
||||
// It turns out the safety issues with sNaN were overblown! Hooray!
|
||||
// SAFETY: `u32` is a plain old datatype so we can always transmute from it.
|
||||
|
|
@ -1515,8 +1523,9 @@ impl f32 {
|
|||
/// See [algebraic operators](primitive@f32#algebraic-operators) for more info.
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[rustc_const_unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[inline]
|
||||
pub fn algebraic_add(self, rhs: f32) -> f32 {
|
||||
pub const fn algebraic_add(self, rhs: f32) -> f32 {
|
||||
intrinsics::fadd_algebraic(self, rhs)
|
||||
}
|
||||
|
||||
|
|
@ -1525,8 +1534,9 @@ impl f32 {
|
|||
/// See [algebraic operators](primitive@f32#algebraic-operators) for more info.
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[rustc_const_unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[inline]
|
||||
pub fn algebraic_sub(self, rhs: f32) -> f32 {
|
||||
pub const fn algebraic_sub(self, rhs: f32) -> f32 {
|
||||
intrinsics::fsub_algebraic(self, rhs)
|
||||
}
|
||||
|
||||
|
|
@ -1535,8 +1545,9 @@ impl f32 {
|
|||
/// See [algebraic operators](primitive@f32#algebraic-operators) for more info.
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[rustc_const_unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[inline]
|
||||
pub fn algebraic_mul(self, rhs: f32) -> f32 {
|
||||
pub const fn algebraic_mul(self, rhs: f32) -> f32 {
|
||||
intrinsics::fmul_algebraic(self, rhs)
|
||||
}
|
||||
|
||||
|
|
@ -1545,8 +1556,9 @@ impl f32 {
|
|||
/// See [algebraic operators](primitive@f32#algebraic-operators) for more info.
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[rustc_const_unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[inline]
|
||||
pub fn algebraic_div(self, rhs: f32) -> f32 {
|
||||
pub const fn algebraic_div(self, rhs: f32) -> f32 {
|
||||
intrinsics::fdiv_algebraic(self, rhs)
|
||||
}
|
||||
|
||||
|
|
@ -1555,8 +1567,9 @@ impl f32 {
|
|||
/// See [algebraic operators](primitive@f32#algebraic-operators) for more info.
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[rustc_const_unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[inline]
|
||||
pub fn algebraic_rem(self, rhs: f32) -> f32 {
|
||||
pub const fn algebraic_rem(self, rhs: f32) -> f32 {
|
||||
intrinsics::frem_algebraic(self, rhs)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -442,16 +442,22 @@ impl f64 {
|
|||
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
|
||||
pub const MAX: f64 = 1.7976931348623157e+308_f64;
|
||||
|
||||
/// One greater than the minimum possible normal power of 2 exponent.
|
||||
/// One greater than the minimum possible *normal* power of 2 exponent
|
||||
/// for a significand bounded by 1 ≤ x < 2 (i.e. the IEEE definition).
|
||||
///
|
||||
/// If <i>x</i> = `MIN_EXP`, then normal numbers
|
||||
/// ≥ 0.5 × 2<sup><i>x</i></sup>.
|
||||
/// This corresponds to the exact minimum possible *normal* power of 2 exponent
|
||||
/// for a significand bounded by 0.5 ≤ x < 1 (i.e. the C definition).
|
||||
/// In other words, all normal numbers representable by this type are
|
||||
/// greater than or equal to 0.5 × 2<sup><i>MIN_EXP</i></sup>.
|
||||
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
|
||||
pub const MIN_EXP: i32 = -1021;
|
||||
/// Maximum possible power of 2 exponent.
|
||||
/// One greater than the maximum possible power of 2 exponent
|
||||
/// for a significand bounded by 1 ≤ x < 2 (i.e. the IEEE definition).
|
||||
///
|
||||
/// If <i>x</i> = `MAX_EXP`, then normal numbers
|
||||
/// < 1 × 2<sup><i>x</i></sup>.
|
||||
/// This corresponds to the exact maximum possible power of 2 exponent
|
||||
/// for a significand bounded by 0.5 ≤ x < 1 (i.e. the C definition).
|
||||
/// In other words, all numbers representable by this type are
|
||||
/// strictly less than 2<sup><i>MAX_EXP</i></sup>.
|
||||
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
|
||||
pub const MAX_EXP: i32 = 1024;
|
||||
|
||||
|
|
@ -718,8 +724,7 @@ impl f64 {
|
|||
pub const fn is_sign_negative(self) -> bool {
|
||||
// IEEE754 says: isSignMinus(x) is true if and only if x has negative sign. isSignMinus
|
||||
// applies to zeros and NaNs as well.
|
||||
// SAFETY: This is just transmuting to get the sign bit, it's fine.
|
||||
unsafe { mem::transmute::<f64, u64>(self) & Self::SIGN_MASK != 0 }
|
||||
self.to_bits() & Self::SIGN_MASK != 0
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
|
|
@ -1004,7 +1009,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.
|
||||
|
|
@ -1016,6 +1021,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 {
|
||||
|
|
@ -1094,6 +1100,7 @@ impl f64 {
|
|||
without modifying the original"]
|
||||
#[stable(feature = "float_bits_conv", since = "1.20.0")]
|
||||
#[rustc_const_stable(feature = "const_float_bits_conv", since = "1.83.0")]
|
||||
#[cfg_attr(not(bootstrap), allow(unnecessary_transmutes))]
|
||||
#[inline]
|
||||
pub const fn to_bits(self) -> u64 {
|
||||
// SAFETY: `u64` is a plain old datatype so we can always transmute to it.
|
||||
|
|
@ -1140,6 +1147,7 @@ impl f64 {
|
|||
#[rustc_const_stable(feature = "const_float_bits_conv", since = "1.83.0")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
#[cfg_attr(not(bootstrap), allow(unnecessary_transmutes))]
|
||||
pub const fn from_bits(v: u64) -> Self {
|
||||
// It turns out the safety issues with sNaN were overblown! Hooray!
|
||||
// SAFETY: `u64` is a plain old datatype so we can always transmute from it.
|
||||
|
|
@ -1514,8 +1522,9 @@ impl f64 {
|
|||
/// See [algebraic operators](primitive@f32#algebraic-operators) for more info.
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[rustc_const_unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[inline]
|
||||
pub fn algebraic_add(self, rhs: f64) -> f64 {
|
||||
pub const fn algebraic_add(self, rhs: f64) -> f64 {
|
||||
intrinsics::fadd_algebraic(self, rhs)
|
||||
}
|
||||
|
||||
|
|
@ -1524,8 +1533,9 @@ impl f64 {
|
|||
/// See [algebraic operators](primitive@f32#algebraic-operators) for more info.
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[rustc_const_unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[inline]
|
||||
pub fn algebraic_sub(self, rhs: f64) -> f64 {
|
||||
pub const fn algebraic_sub(self, rhs: f64) -> f64 {
|
||||
intrinsics::fsub_algebraic(self, rhs)
|
||||
}
|
||||
|
||||
|
|
@ -1534,8 +1544,9 @@ impl f64 {
|
|||
/// See [algebraic operators](primitive@f32#algebraic-operators) for more info.
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[rustc_const_unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[inline]
|
||||
pub fn algebraic_mul(self, rhs: f64) -> f64 {
|
||||
pub const fn algebraic_mul(self, rhs: f64) -> f64 {
|
||||
intrinsics::fmul_algebraic(self, rhs)
|
||||
}
|
||||
|
||||
|
|
@ -1544,8 +1555,9 @@ impl f64 {
|
|||
/// See [algebraic operators](primitive@f32#algebraic-operators) for more info.
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[rustc_const_unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[inline]
|
||||
pub fn algebraic_div(self, rhs: f64) -> f64 {
|
||||
pub const fn algebraic_div(self, rhs: f64) -> f64 {
|
||||
intrinsics::fdiv_algebraic(self, rhs)
|
||||
}
|
||||
|
||||
|
|
@ -1554,8 +1566,9 @@ impl f64 {
|
|||
/// See [algebraic operators](primitive@f32#algebraic-operators) for more info.
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[rustc_const_unstable(feature = "float_algebraic", issue = "136469")]
|
||||
#[inline]
|
||||
pub fn algebraic_rem(self, rhs: f64) -> f64 {
|
||||
pub const fn algebraic_rem(self, rhs: f64) -> f64 {
|
||||
intrinsics::frem_algebraic(self, rhs)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3675,6 +3675,7 @@ macro_rules! int_impl {
|
|||
/// ```
|
||||
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
|
||||
#[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
|
||||
#[cfg_attr(not(bootstrap), allow(unnecessary_transmutes))]
|
||||
// SAFETY: const sound because integers are plain old datatypes so we can always
|
||||
// transmute them to arrays of bytes
|
||||
#[must_use = "this returns the result of the operation, \
|
||||
|
|
@ -3778,6 +3779,7 @@ macro_rules! int_impl {
|
|||
/// ```
|
||||
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
|
||||
#[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
|
||||
#[cfg_attr(not(bootstrap), allow(unnecessary_transmutes))]
|
||||
#[must_use]
|
||||
// SAFETY: const sound because integers are plain old datatypes so we can always
|
||||
// transmute to them
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -3523,6 +3523,7 @@ macro_rules! uint_impl {
|
|||
#[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
|
||||
#[must_use = "this returns the result of the operation, \
|
||||
without modifying the original"]
|
||||
#[cfg_attr(not(bootstrap), allow(unnecessary_transmutes))]
|
||||
// SAFETY: const sound because integers are plain old datatypes so we can always
|
||||
// transmute them to arrays of bytes
|
||||
#[inline]
|
||||
|
|
@ -3624,6 +3625,7 @@ macro_rules! uint_impl {
|
|||
/// ```
|
||||
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
|
||||
#[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
|
||||
#[cfg_attr(not(bootstrap), allow(unnecessary_transmutes))]
|
||||
#[must_use]
|
||||
// SAFETY: const sound because integers are plain old datatypes so we can always
|
||||
// transmute to them
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue