about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2016-07-15 10:56:43 +0200
committerGitHub <noreply@github.com>2016-07-15 10:56:43 +0200
commit1544ebee28ddfefa4e184b3c3e6accb15e7b54b9 (patch)
tree0c40ed81204294942602946b1dc9d25ead1bd9b9 /src/libcore
parentca67437ec926be029719600af8dfaa800fc2f2ce (diff)
parent6b58baa5c896b64c010ca13a5c6865205475692a (diff)
downloadrust-1544ebee28ddfefa4e184b3c3e6accb15e7b54b9.tar.gz
rust-1544ebee28ddfefa4e184b3c3e6accb15e7b54b9.zip
Rollup merge of #34804 - GuillaumeGomez:fix_ret, r=steveklabnik
Add examples for FpCategory

Fixes #29364.

r? @steveklabnik
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/num/mod.rs29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs
index 7dd9ecedb56..fcdbde0d19f 100644
--- a/src/libcore/num/mod.rs
+++ b/src/libcore/num/mod.rs
@@ -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;
+/// 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,
 }