Skip to content

Commit 96a3c7c

Browse files
committed
auto merge of #19758 : tbu-/rust/pr_fp_name, r=alexcrichton
This is a [breaking-change].
2 parents d10642e + 16f01cc commit 96a3c7c

File tree

9 files changed

+59
-56
lines changed

9 files changed

+59
-56
lines changed

src/libcore/fmt/float.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use char;
1818
use char::Char;
1919
use fmt;
2020
use iter::{range, DoubleEndedIteratorExt};
21-
use num::{Float, FPNaN, FPInfinite, ToPrimitive};
22-
use num::cast;
21+
use num::{cast, Float, ToPrimitive};
22+
use num::FpCategory as Fp;
2323
use ops::FnOnce;
2424
use result::Result::Ok;
2525
use slice::{mod, SliceExt};
@@ -109,11 +109,11 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
109109
let _1: T = Float::one();
110110

111111
match num.classify() {
112-
FPNaN => return f("NaN".as_bytes()),
113-
FPInfinite if num > _0 => {
112+
Fp::Nan => return f("NaN".as_bytes()),
113+
Fp::Infinite if num > _0 => {
114114
return f("inf".as_bytes());
115115
}
116-
FPInfinite if num < _0 => {
116+
Fp::Infinite if num < _0 => {
117117
return f("-inf".as_bytes());
118118
}
119119
_ => {}

src/libcore/num/f32.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919
use intrinsics;
2020
use mem;
21-
use num::{Float, FPNormal, FPCategory, FPZero, FPSubnormal, FPInfinite, FPNaN};
21+
use num::Float;
22+
use num::FpCategory as Fp;
2223
use num::from_str_radix;
2324
use option::Option;
2425

@@ -156,23 +157,23 @@ impl Float for f32 {
156157
/// Returns `true` if the number is neither zero, infinite, subnormal or NaN.
157158
#[inline]
158159
fn is_normal(self) -> bool {
159-
self.classify() == FPNormal
160+
self.classify() == Fp::Normal
160161
}
161162

162163
/// Returns the floating point category of the number. If only one property
163164
/// is going to be tested, it is generally faster to use the specific
164165
/// predicate instead.
165-
fn classify(self) -> FPCategory {
166+
fn classify(self) -> Fp {
166167
const EXP_MASK: u32 = 0x7f800000;
167168
const MAN_MASK: u32 = 0x007fffff;
168169

169170
let bits: u32 = unsafe { mem::transmute(self) };
170171
match (bits & MAN_MASK, bits & EXP_MASK) {
171-
(0, 0) => FPZero,
172-
(_, 0) => FPSubnormal,
173-
(0, EXP_MASK) => FPInfinite,
174-
(_, EXP_MASK) => FPNaN,
175-
_ => FPNormal,
172+
(0, 0) => Fp::Zero,
173+
(_, 0) => Fp::Subnormal,
174+
(0, EXP_MASK) => Fp::Infinite,
175+
(_, EXP_MASK) => Fp::Nan,
176+
_ => Fp::Normal,
176177
}
177178
}
178179

src/libcore/num/f64.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919
use intrinsics;
2020
use mem;
21-
use num::{Float, FPNormal, FPCategory, FPZero, FPSubnormal, FPInfinite, FPNaN};
21+
use num::Float;
22+
use num::FpCategory as Fp;
2223
use num::from_str_radix;
2324
use option::Option;
2425

@@ -164,23 +165,23 @@ impl Float for f64 {
164165
/// Returns `true` if the number is neither zero, infinite, subnormal or NaN.
165166
#[inline]
166167
fn is_normal(self) -> bool {
167-
self.classify() == FPNormal
168+
self.classify() == Fp::Normal
168169
}
169170

170171
/// Returns the floating point category of the number. If only one property
171172
/// is going to be tested, it is generally faster to use the specific
172173
/// predicate instead.
173-
fn classify(self) -> FPCategory {
174+
fn classify(self) -> Fp {
174175
const EXP_MASK: u64 = 0x7ff0000000000000;
175176
const MAN_MASK: u64 = 0x000fffffffffffff;
176177

177178
let bits: u64 = unsafe { mem::transmute(self) };
178179
match (bits & MAN_MASK, bits & EXP_MASK) {
179-
(0, 0) => FPZero,
180-
(_, 0) => FPSubnormal,
181-
(0, EXP_MASK) => FPInfinite,
182-
(_, EXP_MASK) => FPNaN,
183-
_ => FPNormal,
180+
(0, 0) => Fp::Zero,
181+
(_, 0) => Fp::Subnormal,
182+
(0, EXP_MASK) => Fp::Infinite,
183+
(_, EXP_MASK) => Fp::Nan,
184+
_ => Fp::Normal,
184185
}
185186
}
186187

src/libcore/num/mod.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#![stable]
1616
#![allow(missing_docs)]
1717

18-
pub use self::FPCategory::*;
19-
2018
use {int, i8, i16, i32, i64};
2119
use {uint, u8, u16, u32, u64};
2220
use {f32, f64};
@@ -1222,17 +1220,17 @@ impl_num_cast! { f64, to_f64 }
12221220
/// Used for representing the classification of floating point numbers
12231221
#[deriving(Copy, PartialEq, Show)]
12241222
#[unstable = "may be renamed"]
1225-
pub enum FPCategory {
1223+
pub enum FpCategory {
12261224
/// "Not a Number", often obtained by dividing by zero
1227-
FPNaN,
1225+
Nan,
12281226
/// Positive or negative infinity
1229-
FPInfinite ,
1227+
Infinite ,
12301228
/// Positive or negative zero
1231-
FPZero,
1232-
/// De-normalized floating point representation (less precise than `FPNormal`)
1233-
FPSubnormal,
1229+
Zero,
1230+
/// De-normalized floating point representation (less precise than `Normal`)
1231+
Subnormal,
12341232
/// A regular floating point number
1235-
FPNormal,
1233+
Normal,
12361234
}
12371235

12381236
/// A built-in floating point number.
@@ -1277,7 +1275,7 @@ pub trait Float
12771275
/// Returns true if this number is neither zero, infinite, denormal, or NaN.
12781276
fn is_normal(self) -> bool;
12791277
/// Returns the category that this number falls into.
1280-
fn classify(self) -> FPCategory;
1278+
fn classify(self) -> FpCategory;
12811279

12821280
// FIXME (#5527): These should be associated constants
12831281

src/libserialize/json.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,9 @@ use std;
201201
use std::collections::{HashMap, BTreeMap};
202202
use std::{char, f64, fmt, io, num, str};
203203
use std::mem::{swap, transmute};
204-
use std::num::{Float, FPNaN, FPInfinite, Int};
205-
use std::str::{FromStr};
204+
use std::num::{Float, Int};
205+
use std::num::FpCategory as Fp;
206+
use std::str::FromStr;
206207
use std::string;
207208
use std::ops;
208209
use unicode::str as unicode_str;
@@ -414,7 +415,7 @@ fn spaces(wr: &mut io::Writer, mut n: uint) -> Result<(), io::IoError> {
414415

415416
fn fmt_number_or_null(v: f64) -> string::String {
416417
match v.classify() {
417-
FPNaN | FPInfinite => string::String::from_str("null"),
418+
Fp::Nan | Fp::Infinite => string::String::from_str("null"),
418419
_ if v.fract() != 0f64 => f64::to_str_digits(v, 6u),
419420
_ => f64::to_str_digits(v, 6u) + ".0",
420421
}
@@ -2332,7 +2333,7 @@ impl ToJson for f32 {
23322333
impl ToJson for f64 {
23332334
fn to_json(&self) -> Json {
23342335
match self.classify() {
2335-
FPNaN | FPInfinite => Json::Null,
2336+
Fp::Nan | Fp::Infinite => Json::Null,
23362337
_ => Json::F64(*self)
23372338
}
23382339
}

src/libstd/num/f32.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ pub fn to_str_exp_digits(num: f32, dig: uint, upper: bool) -> String {
351351
mod tests {
352352
use f32::*;
353353
use num::*;
354+
use num::FpCategory as Fp;
354355

355356
#[test]
356357
fn test_min_nan() {
@@ -620,14 +621,14 @@ mod tests {
620621
let neg_inf: f32 = Float::neg_infinity();
621622
let zero: f32 = Float::zero();
622623
let neg_zero: f32 = Float::neg_zero();
623-
assert_eq!(nan.classify(), FPNaN);
624-
assert_eq!(inf.classify(), FPInfinite);
625-
assert_eq!(neg_inf.classify(), FPInfinite);
626-
assert_eq!(zero.classify(), FPZero);
627-
assert_eq!(neg_zero.classify(), FPZero);
628-
assert_eq!(1f32.classify(), FPNormal);
629-
assert_eq!(1e-37f32.classify(), FPNormal);
630-
assert_eq!(1e-38f32.classify(), FPSubnormal);
624+
assert_eq!(nan.classify(), Fp::Nan);
625+
assert_eq!(inf.classify(), Fp::Infinite);
626+
assert_eq!(neg_inf.classify(), Fp::Infinite);
627+
assert_eq!(zero.classify(), Fp::Zero);
628+
assert_eq!(neg_zero.classify(), Fp::Zero);
629+
assert_eq!(1f32.classify(), Fp::Normal);
630+
assert_eq!(1e-37f32.classify(), Fp::Normal);
631+
assert_eq!(1e-38f32.classify(), Fp::Subnormal);
631632
}
632633

633634
#[test]

src/libstd/num/f64.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ pub fn to_str_exp_digits(num: f64, dig: uint, upper: bool) -> String {
359359
mod tests {
360360
use f64::*;
361361
use num::*;
362+
use num::FpCategory as Fp;
362363

363364
#[test]
364365
fn test_min_nan() {
@@ -623,13 +624,13 @@ mod tests {
623624
let neg_inf: f64 = Float::neg_infinity();
624625
let zero: f64 = Float::zero();
625626
let neg_zero: f64 = Float::neg_zero();
626-
assert_eq!(nan.classify(), FPNaN);
627-
assert_eq!(inf.classify(), FPInfinite);
628-
assert_eq!(neg_inf.classify(), FPInfinite);
629-
assert_eq!(zero.classify(), FPZero);
630-
assert_eq!(neg_zero.classify(), FPZero);
631-
assert_eq!(1e-307f64.classify(), FPNormal);
632-
assert_eq!(1e-308f64.classify(), FPSubnormal);
627+
assert_eq!(nan.classify(), Fp::Nan);
628+
assert_eq!(inf.classify(), Fp::Infinite);
629+
assert_eq!(neg_inf.classify(), Fp::Infinite);
630+
assert_eq!(zero.classify(), Fp::Zero);
631+
assert_eq!(neg_zero.classify(), Fp::Zero);
632+
assert_eq!(1e-307f64.classify(), Fp::Normal);
633+
assert_eq!(1e-308f64.classify(), Fp::Subnormal);
633634
}
634635

635636
#[test]

src/libstd/num/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ pub use core::num::{from_int, from_i8, from_i16, from_i32, from_i64};
3131
pub use core::num::{from_uint, from_u8, from_u16, from_u32, from_u64};
3232
pub use core::num::{from_f32, from_f64};
3333
pub use core::num::{FromStrRadix, from_str_radix};
34-
pub use core::num::{FPCategory, FPNaN, FPInfinite, FPZero, FPSubnormal};
35-
pub use core::num::{FPNormal, Float};
34+
pub use core::num::{FpCategory, Float};
3635

3736
#[experimental = "may be removed or relocated"]
3837
pub mod strconv;

src/libstd/num/strconv.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ use self::SignificantDigits::*;
1717
use self::SignFormat::*;
1818

1919
use char::{mod, Char};
20-
use num::{mod, Int, Float, FPNaN, FPInfinite, ToPrimitive};
20+
use num::{mod, Int, Float, ToPrimitive};
21+
use num::FpCategory as Fp;
2122
use ops::FnMut;
2223
use slice::{SliceExt, CloneSliceExt};
2324
use str::StrExt;
@@ -199,14 +200,14 @@ pub fn float_to_str_bytes_common<T: Float>(
199200
let _1: T = Float::one();
200201

201202
match num.classify() {
202-
FPNaN => { return (b"NaN".to_vec(), true); }
203-
FPInfinite if num > _0 => {
203+
Fp::Nan => { return (b"NaN".to_vec(), true); }
204+
Fp::Infinite if num > _0 => {
204205
return match sign {
205206
SignAll => (b"+inf".to_vec(), true),
206207
_ => (b"inf".to_vec(), true)
207208
};
208209
}
209-
FPInfinite if num < _0 => {
210+
Fp::Infinite if num < _0 => {
210211
return match sign {
211212
SignNone => (b"inf".to_vec(), true),
212213
_ => (b"-inf".to_vec(), true),

0 commit comments

Comments
 (0)