Skip to content

Make Float::classify matching more clear for f64 and f32 #6439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions src/libcore/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,10 +578,7 @@ impl Float for f32 {
/// Returns `true` if the number is neither zero, infinite, subnormal or NaN
#[inline(always)]
fn is_normal(&self) -> bool {
match self.classify() {
FPNormal => true,
_ => false,
}
self.classify() == FPNormal
}

/// Returns the floating point category of the number. If only one property is going to
Expand All @@ -591,14 +588,14 @@ impl Float for f32 {
static MAN_MASK: u32 = 0x007fffff;

match (
unsafe { ::cast::transmute::<f32,u32>(*self) } & MAN_MASK,
unsafe { ::cast::transmute::<f32,u32>(*self) } & EXP_MASK,
unsafe { ::cast::transmute::<f32,u32>(*self) } & MAN_MASK
) {
(EXP_MASK, 0) => FPInfinite,
(EXP_MASK, _) => FPNaN,
(exp, _) if exp != 0 => FPNormal,
_ if self.is_zero() => FPZero,
_ => FPSubnormal,
(0, 0) => FPZero,
(_, 0) => FPSubnormal,
(0, EXP_MASK) => FPInfinite,
(_, EXP_MASK) => FPNaN,
_ => FPNormal,
}
}

Expand Down
17 changes: 7 additions & 10 deletions src/libcore/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,10 +621,7 @@ impl Float for f64 {
/// Returns `true` if the number is neither zero, infinite, subnormal or NaN
#[inline(always)]
fn is_normal(&self) -> bool {
match self.classify() {
FPNormal => true,
_ => false,
}
self.classify() == FPNormal
}

/// Returns the floating point category of the number. If only one property is going to
Expand All @@ -634,14 +631,14 @@ impl Float for f64 {
static MAN_MASK: u64 = 0x000fffffffffffff;

match (
unsafe { ::cast::transmute::<f64,u64>(*self) } & MAN_MASK,
unsafe { ::cast::transmute::<f64,u64>(*self) } & EXP_MASK,
unsafe { ::cast::transmute::<f64,u64>(*self) } & MAN_MASK
) {
(EXP_MASK, 0) => FPInfinite,
(EXP_MASK, _) => FPNaN,
(exp, _) if exp != 0 => FPNormal,
_ if self.is_zero() => FPZero,
_ => FPSubnormal,
(0, 0) => FPZero,
(_, 0) => FPSubnormal,
(0, EXP_MASK) => FPInfinite,
(_, EXP_MASK) => FPNaN,
_ => FPNormal,
}
}

Expand Down