Skip to content

Commit

Permalink
Use assoc float consts instead of module level
Browse files Browse the repository at this point in the history
  • Loading branch information
faern committed Apr 20, 2020
1 parent 4ddf661 commit 6850e4a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/libcore/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ impl f32 {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn is_infinite(self) -> bool {
self.abs_private() == INFINITY
self.abs_private() == Self::INFINITY
}

/// Returns `true` if this number is neither infinite nor `NaN`.
Expand All @@ -287,7 +287,7 @@ impl f32 {
pub 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() < INFINITY
self.abs_private() < Self::INFINITY
}

/// Returns `true` if the number is neither zero, infinite,
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ impl f64 {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn is_infinite(self) -> bool {
self.abs_private() == INFINITY
self.abs_private() == Self::INFINITY
}

/// Returns `true` if this number is neither infinite nor `NaN`.
Expand All @@ -286,7 +286,7 @@ impl f64 {
pub 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() < INFINITY
self.abs_private() < Self::INFINITY
}

/// Returns `true` if the number is neither zero, infinite,
Expand Down
1 change: 0 additions & 1 deletion src/libcore/num/flt2dec/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use crate::num::dec2flt::rawfp::RawFloat;
use crate::num::FpCategory;
use crate::{f32, f64};

/// Decoded unsigned finite value, such that:
///
Expand Down
8 changes: 4 additions & 4 deletions src/libstd/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl f32 {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn signum(self) -> f32 {
if self.is_nan() { NAN } else { 1.0_f32.copysign(self) }
if self.is_nan() { Self::NAN } else { 1.0_f32.copysign(self) }
}

/// Returns a number composed of the magnitude of `self` and the sign of
Expand Down Expand Up @@ -832,8 +832,8 @@ impl f32 {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn asinh(self) -> f32 {
if self == NEG_INFINITY {
NEG_INFINITY
if self == Self::NEG_INFINITY {
Self::NEG_INFINITY
} else {
(self + ((self * self) + 1.0).sqrt()).ln().copysign(self)
}
Expand All @@ -855,7 +855,7 @@ impl f32 {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn acosh(self) -> f32 {
if self < 1.0 { crate::f32::NAN } else { (self + ((self * self) - 1.0).sqrt()).ln() }
if self < 1.0 { Self::NAN } else { (self + ((self * self) - 1.0).sqrt()).ln() }
}

/// Inverse hyperbolic tangent function.
Expand Down
14 changes: 7 additions & 7 deletions src/libstd/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl f64 {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn signum(self) -> f64 {
if self.is_nan() { NAN } else { 1.0_f64.copysign(self) }
if self.is_nan() { Self::NAN } else { 1.0_f64.copysign(self) }
}

/// Returns a number composed of the magnitude of `self` and the sign of
Expand Down Expand Up @@ -834,8 +834,8 @@ impl f64 {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn asinh(self) -> f64 {
if self == NEG_INFINITY {
NEG_INFINITY
if self == Self::NEG_INFINITY {
Self::NEG_INFINITY
} else {
(self + ((self * self) + 1.0).sqrt()).ln().copysign(self)
}
Expand All @@ -857,7 +857,7 @@ impl f64 {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn acosh(self) -> f64 {
if self < 1.0 { NAN } else { (self + ((self * self) - 1.0).sqrt()).ln() }
if self < 1.0 { Self::NAN } else { (self + ((self * self) - 1.0).sqrt()).ln() }
}

/// Inverse hyperbolic tangent function.
Expand Down Expand Up @@ -926,16 +926,16 @@ impl f64 {
if self > 0.0 {
log_fn(self)
} else if self == 0.0 {
NEG_INFINITY // log(0) = -Inf
Self::NEG_INFINITY // log(0) = -Inf
} else {
NAN // log(-n) = NaN
Self::NAN // log(-n) = NaN
}
} else if self.is_nan() {
self // log(NaN) = NaN
} else if self > 0.0 {
self // log(Inf) = Inf
} else {
NAN // log(-Inf) = NaN
Self::NAN // log(-Inf) = NaN
}
}
}
Expand Down

0 comments on commit 6850e4a

Please sign in to comment.