Skip to content

Commit

Permalink
remove no-longer-needed abs_private
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Nov 12, 2024
1 parent 7d7c054 commit 2d3c08a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 51 deletions.
2 changes: 1 addition & 1 deletion library/core/src/fmt/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ macro_rules! impl_general_format {
($($t:ident)*) => {
$(impl GeneralFormat for $t {
fn already_rounded_value_should_use_exponential(&self) -> bool {
let abs = $t::abs_private(*self);
let abs = $t::abs(*self);
(abs != 0.0 && abs < 1e-4) || abs >= 1e+16
}
})*
Expand Down
18 changes: 4 additions & 14 deletions library/core/src/num/f128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,17 +284,6 @@ impl f128 {
self != self
}

// FIXME(#50145): `abs` is publicly unavailable in core due to
// concerns about portability, so this implementation is for
// private use internally.
#[inline]
pub(crate) const fn abs_private(self) -> f128 {
// SAFETY: This transmutation is fine just like in `to_bits`/`from_bits`.
unsafe {
mem::transmute::<u128, f128>(mem::transmute::<f128, u128>(self) & !Self::SIGN_MASK)
}
}

/// Returns `true` if this value is positive infinity or negative infinity, and
/// `false` otherwise.
///
Expand Down Expand Up @@ -344,10 +333,11 @@ impl f128 {
#[inline]
#[must_use]
#[unstable(feature = "f128", issue = "116909")]
#[rustc_allow_const_fn_unstable(const_float_methods)] // for `abs`
pub const fn is_finite(self) -> bool {
// There's no need to handle NaN separately: if self is NaN,
// the comparison is not true, exactly as desired.
self.abs_private() < Self::INFINITY
self.abs() < Self::INFINITY
}

/// Returns `true` if the number is [subnormal].
Expand Down Expand Up @@ -835,8 +825,8 @@ impl f128 {
const HI: f128 = f128::MAX / 2.;

let (a, b) = (self, other);
let abs_a = a.abs_private();
let abs_b = b.abs_private();
let abs_a = a.abs();
let abs_b = b.abs();

if abs_a <= HI && abs_b <= HI {
// Overflow is impossible
Expand Down
16 changes: 4 additions & 12 deletions library/core/src/num/f16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,6 @@ impl f16 {
self != self
}

// FIXMxE(#50145): `abs` is publicly unavailable in core due to
// concerns about portability, so this implementation is for
// private use internally.
#[inline]
pub(crate) const fn abs_private(self) -> f16 {
// SAFETY: This transmutation is fine just like in `to_bits`/`from_bits`.
unsafe { mem::transmute::<u16, f16>(mem::transmute::<f16, u16>(self) & !Self::SIGN_MASK) }
}

/// Returns `true` if this value is positive infinity or negative infinity, and
/// `false` otherwise.
///
Expand Down Expand Up @@ -334,10 +325,11 @@ impl f16 {
#[inline]
#[must_use]
#[unstable(feature = "f16", issue = "116909")]
#[rustc_allow_const_fn_unstable(const_float_methods)] // for `abs`
pub const fn is_finite(self) -> bool {
// There's no need to handle NaN separately: if self is NaN,
// the comparison is not true, exactly as desired.
self.abs_private() < Self::INFINITY
self.abs() < Self::INFINITY
}

/// Returns `true` if the number is [subnormal].
Expand Down Expand Up @@ -820,8 +812,8 @@ impl f16 {
const HI: f16 = f16::MAX / 2.;

let (a, b) = (self, other);
let abs_a = a.abs_private();
let abs_b = b.abs_private();
let abs_a = a.abs();
let abs_b = b.abs();

if abs_a <= HI && abs_b <= HI {
// Overflow is impossible
Expand Down
16 changes: 4 additions & 12 deletions library/core/src/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,15 +524,6 @@ impl f32 {
self != self
}

// FIXME(#50145): `abs` is publicly unavailable in core due to
// concerns about portability, so this implementation is for
// private use internally.
#[inline]
pub(crate) const fn abs_private(self) -> f32 {
// SAFETY: This transmutation is fine just like in `to_bits`/`from_bits`.
unsafe { mem::transmute::<u32, f32>(mem::transmute::<f32, u32>(self) & !Self::SIGN_MASK) }
}

/// Returns `true` if this value is positive infinity or negative infinity, and
/// `false` otherwise.
///
Expand Down Expand Up @@ -577,10 +568,11 @@ impl f32 {
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_float_classify", since = "1.83.0")]
#[inline]
#[rustc_allow_const_fn_unstable(const_float_methods)] // for `abs`
pub const fn is_finite(self) -> bool {
// There's no need to handle NaN separately: if self is NaN,
// the comparison is not true, exactly as desired.
self.abs_private() < Self::INFINITY
self.abs() < Self::INFINITY
}

/// Returns `true` if the number is [subnormal].
Expand Down Expand Up @@ -1020,8 +1012,8 @@ impl f32 {
const HI: f32 = f32::MAX / 2.;

let (a, b) = (self, other);
let abs_a = a.abs_private();
let abs_b = b.abs_private();
let abs_a = a.abs();
let abs_b = b.abs();

if abs_a <= HI && abs_b <= HI {
// Overflow is impossible
Expand Down
16 changes: 4 additions & 12 deletions library/core/src/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,15 +523,6 @@ impl f64 {
self != self
}

// FIXME(#50145): `abs` is publicly unavailable in core due to
// concerns about portability, so this implementation is for
// private use internally.
#[inline]
pub(crate) const fn abs_private(self) -> f64 {
// SAFETY: This transmutation is fine just like in `to_bits`/`from_bits`.
unsafe { mem::transmute::<u64, f64>(mem::transmute::<f64, u64>(self) & !Self::SIGN_MASK) }
}

/// Returns `true` if this value is positive infinity or negative infinity, and
/// `false` otherwise.
///
Expand Down Expand Up @@ -576,10 +567,11 @@ impl f64 {
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_float_classify", since = "1.83.0")]
#[inline]
#[rustc_allow_const_fn_unstable(const_float_methods)] // for `abs`
pub const fn is_finite(self) -> bool {
// There's no need to handle NaN separately: if self is NaN,
// the comparison is not true, exactly as desired.
self.abs_private() < Self::INFINITY
self.abs() < Self::INFINITY
}

/// Returns `true` if the number is [subnormal].
Expand Down Expand Up @@ -1023,8 +1015,8 @@ impl f64 {
const HI: f64 = f64::MAX / 2.;

let (a, b) = (self, other);
let abs_a = a.abs_private();
let abs_b = b.abs_private();
let abs_a = a.abs();
let abs_b = b.abs();

if abs_a <= HI && abs_b <= HI {
// Overflow is impossible
Expand Down

0 comments on commit 2d3c08a

Please sign in to comment.