Skip to content
Merged
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
29 changes: 24 additions & 5 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2308,26 +2308,45 @@ impl usize {
///
/// [`f32::classify()`]: ../../std/primitive.f32.html#method.classify
/// [`f64::classify()`]: ../../std/primitive.f64.html#method.classify
///
/// # Examples
///
/// ```
/// use std::num::FpCategory;
/// use std::f32;
///
/// let num = 12.4_f32;
/// let inf = f32::INFINITY;
/// let zero = 0f32;
/// let sub: f32 = 0.000000000000000000000000000000000000011754942;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d much rather you used something like 1.1754942e-38 instead, as it is much more readable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right. Didn't think to this solution. Thanks!

/// let nan = f32::NAN;
///
/// assert_eq!(num.classify(), FpCategory::Normal);
/// assert_eq!(inf.classify(), FpCategory::Infinite);
/// assert_eq!(zero.classify(), FpCategory::Zero);
/// assert_eq!(nan.classify(), FpCategory::Nan);
/// assert_eq!(sub.classify(), FpCategory::Subnormal);
/// ```
#[derive(Copy, Clone, PartialEq, Debug)]
#[stable(feature = "rust1", since = "1.0.0")]
pub enum FpCategory {
/// "Not a Number", often obtained by dividing by zero
/// "Not a Number", often obtained by dividing by zero.
#[stable(feature = "rust1", since = "1.0.0")]
Nan,

/// Positive or negative infinity
/// Positive or negative infinity.
#[stable(feature = "rust1", since = "1.0.0")]
Infinite ,

/// Positive or negative zero
/// Positive or negative zero.
#[stable(feature = "rust1", since = "1.0.0")]
Zero,

/// De-normalized floating point representation (less precise than `Normal`)
/// De-normalized floating point representation (less precise than `Normal`).
#[stable(feature = "rust1", since = "1.0.0")]
Subnormal,

/// A regular floating point number
/// A regular floating point number.
#[stable(feature = "rust1", since = "1.0.0")]
Normal,
}
Expand Down