]> git.lizzy.rs Git - rust.git/commitdiff
Rename and namespace `FPCategory`
authorTobias Bucher <tobiasbucher5991@gmail.com>
Mon, 22 Dec 2014 21:50:57 +0000 (22:50 +0100)
committerTobias Bucher <tobiasbucher5991@gmail.com>
Tue, 23 Dec 2014 12:42:09 +0000 (13:42 +0100)
Rename `FPCategory` to `FpCategory` and `Fp* to `*` in order to adhere to the
naming convention

This is a [breaking-change].

Existing code like this:
```
use std::num::{FPCategory, FPNaN};
```
should be adjusted to this:
```
use std::num::FpCategory as Fp
```

In the following code you can use the constants `Fp::Nan`, `Fp::Normal`, etc.

src/libcore/fmt/float.rs
src/libcore/num/f32.rs
src/libcore/num/f64.rs
src/libcore/num/mod.rs
src/libserialize/json.rs
src/libstd/num/f32.rs
src/libstd/num/f64.rs
src/libstd/num/mod.rs
src/libstd/num/strconv.rs

index 9ab450efd2272d86e61b469960adbf45cac6ae64..55a87973e0f5c2d7767182e80f727d9e4a11aa3d 100644 (file)
@@ -18,8 +18,8 @@
 use char::Char;
 use fmt;
 use iter::{range, DoubleEndedIteratorExt};
-use num::{Float, FPNaN, FPInfinite, ToPrimitive};
-use num::cast;
+use num::{cast, Float, ToPrimitive};
+use num::FpCategory as Fp;
 use ops::FnOnce;
 use result::Result::Ok;
 use slice::{mod, SliceExt};
@@ -109,11 +109,11 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
     let _1: T = Float::one();
 
     match num.classify() {
-        FPNaN => return f("NaN".as_bytes()),
-        FPInfinite if num > _0 => {
+        Fp::Nan => return f("NaN".as_bytes()),
+        Fp::Infinite if num > _0 => {
             return f("inf".as_bytes());
         }
-        FPInfinite if num < _0 => {
+        Fp::Infinite if num < _0 => {
             return f("-inf".as_bytes());
         }
         _ => {}
index add42a2ddce8441bc83331cd5f15702a033453ef..d8b22a085aa94da348aa26ead942c511cb1d335c 100644 (file)
@@ -18,7 +18,8 @@
 
 use intrinsics;
 use mem;
-use num::{Float, FPNormal, FPCategory, FPZero, FPSubnormal, FPInfinite, FPNaN};
+use num::Float;
+use num::FpCategory as Fp;
 use num::from_str_radix;
 use option::Option;
 
@@ -156,23 +157,23 @@ fn is_finite(self) -> bool {
     /// Returns `true` if the number is neither zero, infinite, subnormal or NaN.
     #[inline]
     fn is_normal(self) -> bool {
-        self.classify() == FPNormal
+        self.classify() == Fp::Normal
     }
 
     /// Returns the floating point category of the number. If only one property
     /// is going to be tested, it is generally faster to use the specific
     /// predicate instead.
-    fn classify(self) -> FPCategory {
+    fn classify(self) -> Fp {
         const EXP_MASK: u32 = 0x7f800000;
         const MAN_MASK: u32 = 0x007fffff;
 
         let bits: u32 = unsafe { mem::transmute(self) };
         match (bits & MAN_MASK, bits & EXP_MASK) {
-            (0, 0)        => FPZero,
-            (_, 0)        => FPSubnormal,
-            (0, EXP_MASK) => FPInfinite,
-            (_, EXP_MASK) => FPNaN,
-            _             => FPNormal,
+            (0, 0)        => Fp::Zero,
+            (_, 0)        => Fp::Subnormal,
+            (0, EXP_MASK) => Fp::Infinite,
+            (_, EXP_MASK) => Fp::Nan,
+            _             => Fp::Normal,
         }
     }
 
index 12c0771d0b936516e521f206457bcde3896023a3..a3f5c2df91fac8e839cdca30e7d6a4487c1c646e 100644 (file)
@@ -18,7 +18,8 @@
 
 use intrinsics;
 use mem;
-use num::{Float, FPNormal, FPCategory, FPZero, FPSubnormal, FPInfinite, FPNaN};
+use num::Float;
+use num::FpCategory as Fp;
 use num::from_str_radix;
 use option::Option;
 
@@ -164,23 +165,23 @@ fn is_finite(self) -> bool {
     /// Returns `true` if the number is neither zero, infinite, subnormal or NaN.
     #[inline]
     fn is_normal(self) -> bool {
-        self.classify() == FPNormal
+        self.classify() == Fp::Normal
     }
 
     /// Returns the floating point category of the number. If only one property
     /// is going to be tested, it is generally faster to use the specific
     /// predicate instead.
-    fn classify(self) -> FPCategory {
+    fn classify(self) -> Fp {
         const EXP_MASK: u64 = 0x7ff0000000000000;
         const MAN_MASK: u64 = 0x000fffffffffffff;
 
         let bits: u64 = unsafe { mem::transmute(self) };
         match (bits & MAN_MASK, bits & EXP_MASK) {
-            (0, 0)        => FPZero,
-            (_, 0)        => FPSubnormal,
-            (0, EXP_MASK) => FPInfinite,
-            (_, EXP_MASK) => FPNaN,
-            _             => FPNormal,
+            (0, 0)        => Fp::Zero,
+            (_, 0)        => Fp::Subnormal,
+            (0, EXP_MASK) => Fp::Infinite,
+            (_, EXP_MASK) => Fp::Nan,
+            _             => Fp::Normal,
         }
     }
 
index 60735879213d8cbfcfbe8e6e559178d1d2f1a07e..0d2ce4f60718f8faba2e1a961c3e0c9cf8dc2fae 100644 (file)
@@ -15,8 +15,6 @@
 #![stable]
 #![allow(missing_docs)]
 
-pub use self::FPCategory::*;
-
 use {int, i8, i16, i32, i64};
 use {uint, u8, u16, u32, u64};
 use {f32, f64};
@@ -1222,17 +1220,17 @@ fn from<N: ToPrimitive>(n: N) -> Option<$T> {
 /// Used for representing the classification of floating point numbers
 #[deriving(Copy, PartialEq, Show)]
 #[unstable = "may be renamed"]
-pub enum FPCategory {
+pub enum FpCategory {
     /// "Not a Number", often obtained by dividing by zero
-    FPNaN,
+    Nan,
     /// Positive or negative infinity
-    FPInfinite ,
+    Infinite ,
     /// Positive or negative zero
-    FPZero,
-    /// De-normalized floating point representation (less precise than `FPNormal`)
-    FPSubnormal,
+    Zero,
+    /// De-normalized floating point representation (less precise than `Normal`)
+    Subnormal,
     /// A regular floating point number
-    FPNormal,
+    Normal,
 }
 
 /// A built-in floating point number.
@@ -1277,7 +1275,7 @@ pub trait Float
     /// Returns true if this number is neither zero, infinite, denormal, or NaN.
     fn is_normal(self) -> bool;
     /// Returns the category that this number falls into.
-    fn classify(self) -> FPCategory;
+    fn classify(self) -> FpCategory;
 
     // FIXME (#5527): These should be associated constants
 
index 7df5590fb40e2e1e07c0b9a7b778d26038e13c5c..830d96fe172bcb5a8688006b24fd68f70d85ad2a 100644 (file)
 use std::collections::{HashMap, BTreeMap};
 use std::{char, f64, fmt, io, num, str};
 use std::mem::{swap, transmute};
-use std::num::{Float, FPNaN, FPInfinite, Int};
-use std::str::{FromStr};
+use std::num::{Float, Int};
+use std::num::FpCategory as Fp;
+use std::str::FromStr;
 use std::string;
 use std::ops;
 use unicode::str as unicode_str;
@@ -414,7 +415,7 @@ fn spaces(wr: &mut io::Writer, mut n: uint) -> Result<(), io::IoError> {
 
 fn fmt_number_or_null(v: f64) -> string::String {
     match v.classify() {
-        FPNaN | FPInfinite => string::String::from_str("null"),
+        Fp::Nan | Fp::Infinite => string::String::from_str("null"),
         _ if v.fract() != 0f64 => f64::to_str_digits(v, 6u),
         _ => f64::to_str_digits(v, 6u) + ".0",
     }
@@ -2332,7 +2333,7 @@ fn to_json(&self) -> Json { (*self as f64).to_json() }
 impl ToJson for f64 {
     fn to_json(&self) -> Json {
         match self.classify() {
-            FPNaN | FPInfinite => Json::Null,
+            Fp::Nan | Fp::Infinite => Json::Null,
             _                  => Json::F64(*self)
         }
     }
index 951627b26cad90b5ec8dd03ab53a59acc5bc1a28..1f76382ce8a41c153b5d6983e8f142a39d717c84 100644 (file)
@@ -351,6 +351,7 @@ pub fn to_str_exp_digits(num: f32, dig: uint, upper: bool) -> String {
 mod tests {
     use f32::*;
     use num::*;
+    use num::FpCategory as Fp;
 
     #[test]
     fn test_min_nan() {
@@ -620,14 +621,14 @@ fn test_classify() {
         let neg_inf: f32 = Float::neg_infinity();
         let zero: f32 = Float::zero();
         let neg_zero: f32 = Float::neg_zero();
-        assert_eq!(nan.classify(), FPNaN);
-        assert_eq!(inf.classify(), FPInfinite);
-        assert_eq!(neg_inf.classify(), FPInfinite);
-        assert_eq!(zero.classify(), FPZero);
-        assert_eq!(neg_zero.classify(), FPZero);
-        assert_eq!(1f32.classify(), FPNormal);
-        assert_eq!(1e-37f32.classify(), FPNormal);
-        assert_eq!(1e-38f32.classify(), FPSubnormal);
+        assert_eq!(nan.classify(), Fp::Nan);
+        assert_eq!(inf.classify(), Fp::Infinite);
+        assert_eq!(neg_inf.classify(), Fp::Infinite);
+        assert_eq!(zero.classify(), Fp::Zero);
+        assert_eq!(neg_zero.classify(), Fp::Zero);
+        assert_eq!(1f32.classify(), Fp::Normal);
+        assert_eq!(1e-37f32.classify(), Fp::Normal);
+        assert_eq!(1e-38f32.classify(), Fp::Subnormal);
     }
 
     #[test]
index 7cc94b9ebbbcb9b8b4f2937cd40e8e8a22843372..221ecf62c058d999a589e30f9c4c312a37f16892 100644 (file)
@@ -359,6 +359,7 @@ pub fn to_str_exp_digits(num: f64, dig: uint, upper: bool) -> String {
 mod tests {
     use f64::*;
     use num::*;
+    use num::FpCategory as Fp;
 
     #[test]
     fn test_min_nan() {
@@ -623,13 +624,13 @@ fn test_classify() {
         let neg_inf: f64 = Float::neg_infinity();
         let zero: f64 = Float::zero();
         let neg_zero: f64 = Float::neg_zero();
-        assert_eq!(nan.classify(), FPNaN);
-        assert_eq!(inf.classify(), FPInfinite);
-        assert_eq!(neg_inf.classify(), FPInfinite);
-        assert_eq!(zero.classify(), FPZero);
-        assert_eq!(neg_zero.classify(), FPZero);
-        assert_eq!(1e-307f64.classify(), FPNormal);
-        assert_eq!(1e-308f64.classify(), FPSubnormal);
+        assert_eq!(nan.classify(), Fp::Nan);
+        assert_eq!(inf.classify(), Fp::Infinite);
+        assert_eq!(neg_inf.classify(), Fp::Infinite);
+        assert_eq!(zero.classify(), Fp::Zero);
+        assert_eq!(neg_zero.classify(), Fp::Zero);
+        assert_eq!(1e-307f64.classify(), Fp::Normal);
+        assert_eq!(1e-308f64.classify(), Fp::Subnormal);
     }
 
     #[test]
index fdece4fbc0d9f3e57c9445ee00bec642d9ab1ad4..7c8763979bb36e3840491c1ce849f5439a44b41a 100644 (file)
@@ -31,8 +31,7 @@
 pub use core::num::{from_uint, from_u8, from_u16, from_u32, from_u64};
 pub use core::num::{from_f32, from_f64};
 pub use core::num::{FromStrRadix, from_str_radix};
-pub use core::num::{FPCategory, FPNaN, FPInfinite, FPZero, FPSubnormal};
-pub use core::num::{FPNormal, Float};
+pub use core::num::{FpCategory, Float};
 
 #[experimental = "may be removed or relocated"]
 pub mod strconv;
index d6331f3c718ac4c9d7b1aeaa1ba04893f593eb19..b1f4e5acb93f4d28119c24f2974e59ed2a5dbb2f 100644 (file)
@@ -17,7 +17,8 @@
 use self::SignFormat::*;
 
 use char::{mod, Char};
-use num::{mod, Int, Float, FPNaN, FPInfinite, ToPrimitive};
+use num::{mod, Int, Float, ToPrimitive};
+use num::FpCategory as Fp;
 use ops::FnMut;
 use slice::{SliceExt, CloneSliceExt};
 use str::StrExt;
@@ -199,14 +200,14 @@ pub fn float_to_str_bytes_common<T: Float>(
     let _1: T = Float::one();
 
     match num.classify() {
-        FPNaN => { return (b"NaN".to_vec(), true); }
-        FPInfinite if num > _0 => {
+        Fp::Nan => { return (b"NaN".to_vec(), true); }
+        Fp::Infinite if num > _0 => {
             return match sign {
                 SignAll => (b"+inf".to_vec(), true),
                 _       => (b"inf".to_vec(), true)
             };
         }
-        FPInfinite if num < _0 => {
+        Fp::Infinite if num < _0 => {
             return match sign {
                 SignNone => (b"inf".to_vec(), true),
                 _        => (b"-inf".to_vec(), true),