Skip to content

Commit

Permalink
rollup merge of rust-lang#19758: tbu-/pr_fp_name
Browse files Browse the repository at this point in the history
This is a [breaking-change].
  • Loading branch information
brson committed Dec 12, 2014
2 parents f57d3b9 + 89af108 commit de97cbd
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 54 deletions.
8 changes: 4 additions & 4 deletions src/libcore/fmt/float.rs
Expand Up @@ -18,7 +18,7 @@ use char;
use char::Char;
use fmt;
use iter::{range, DoubleEndedIteratorExt};
use num::{Float, FPNaN, FPInfinite, ToPrimitive};
use num::{Float, FpNan, FpInfinite, ToPrimitive};
use num::cast;
use result::Result::Ok;
use slice::{mod, SlicePrelude};
Expand Down Expand Up @@ -106,11 +106,11 @@ pub fn float_to_str_bytes_common<T: Float, U>(
let _1: T = Float::one();

match num.classify() {
FPNaN => return f("NaN".as_bytes()),
FPInfinite if num > _0 => {
FpNan => return f("NaN".as_bytes()),
FpInfinite if num > _0 => {
return f("inf".as_bytes());
}
FPInfinite if num < _0 => {
FpInfinite if num < _0 => {
return f("-inf".as_bytes());
}
_ => {}
Expand Down
16 changes: 8 additions & 8 deletions src/libcore/num/f32.rs
Expand Up @@ -18,7 +18,7 @@

use intrinsics;
use mem;
use num::{Float, FPNormal, FPCategory, FPZero, FPSubnormal, FPInfinite, FPNaN};
use num::{Float, FpNormal, FpCategory, FpZero, FpSubnormal, FpInfinite, FpNan};
use num::from_str_radix;
use option::Option;

Expand Down Expand Up @@ -156,23 +156,23 @@ impl Float for f32 {
/// Returns `true` if the number is neither zero, infinite, subnormal or NaN.
#[inline]
fn is_normal(self) -> bool {
self.classify() == FPNormal
self.classify() == FpNormal
}

/// 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) -> FpCategory {
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) => FpZero,
(_, 0) => FpSubnormal,
(0, EXP_MASK) => FpInfinite,
(_, EXP_MASK) => FpNan,
_ => FpNormal,
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/libcore/num/f64.rs
Expand Up @@ -18,7 +18,7 @@

use intrinsics;
use mem;
use num::{Float, FPNormal, FPCategory, FPZero, FPSubnormal, FPInfinite, FPNaN};
use num::{Float, FpNormal, FpCategory, FpZero, FpSubnormal, FpInfinite, FpNan};
use num::from_str_radix;
use option::Option;

Expand Down Expand Up @@ -164,23 +164,23 @@ impl Float for f64 {
/// Returns `true` if the number is neither zero, infinite, subnormal or NaN.
#[inline]
fn is_normal(self) -> bool {
self.classify() == FPNormal
self.classify() == FpNormal
}

/// 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) -> FpCategory {
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) => FpZero,
(_, 0) => FpSubnormal,
(0, EXP_MASK) => FpInfinite,
(_, EXP_MASK) => FpNan,
_ => FpNormal,
}
}

Expand Down
20 changes: 10 additions & 10 deletions src/libcore/num/mod.rs
Expand Up @@ -15,7 +15,7 @@
#![stable]
#![allow(missing_docs)]

pub use self::FPCategory::*;
pub use self::FpCategory::*;

use {int, i8, i16, i32, i64};
use {uint, u8, u16, u32, u64};
Expand Down Expand Up @@ -1227,20 +1227,20 @@ impl_num_cast!(f64, to_f64)
/// Used for representing the classification of floating point numbers
#[deriving(PartialEq, Show)]
#[unstable = "may be renamed"]
pub enum FPCategory {
pub enum FpCategory {
/// "Not a Number", often obtained by dividing by zero
FPNaN,
FpNan,
/// Positive or negative infinity
FPInfinite ,
FpInfinite ,
/// Positive or negative zero
FPZero,
/// De-normalized floating point representation (less precise than `FPNormal`)
FPSubnormal,
FpZero,
/// De-normalized floating point representation (less precise than `FpNormal`)
FpSubnormal,
/// A regular floating point number
FPNormal,
FpNormal,
}

impl Copy for FPCategory {}
impl Copy for FpCategory {}

/// A built-in floating point number.
// FIXME(#5527): In a future version of Rust, many of these functions will
Expand Down Expand Up @@ -1284,7 +1284,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

Expand Down
6 changes: 3 additions & 3 deletions src/libserialize/json.rs
Expand Up @@ -201,7 +201,7 @@ use std;
use std::collections::{HashMap, TreeMap};
use std::{char, f64, fmt, io, num, str};
use std::mem::{swap, transmute};
use std::num::{Float, FPNaN, FPInfinite, Int};
use std::num::{Float, FpNan, FpInfinite, Int};
use std::str::{FromStr, ScalarValue};
use std::string;
use std::vec::Vec;
Expand Down Expand Up @@ -389,7 +389,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"),
FpNan | FpInfinite => string::String::from_str("null"),
_ if v.fract() != 0f64 => f64::to_str_digits(v, 6u),
_ => f64::to_str_digits(v, 6u) + ".0",
}
Expand Down Expand Up @@ -2293,7 +2293,7 @@ impl ToJson for f32 {
impl ToJson for f64 {
fn to_json(&self) -> Json {
match self.classify() {
FPNaN | FPInfinite => Json::Null,
FpNan | FpInfinite => Json::Null,
_ => Json::F64(*self)
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/libstd/num/f32.rs
Expand Up @@ -619,14 +619,14 @@ mod tests {
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(), 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);
}

#[test]
Expand Down
14 changes: 7 additions & 7 deletions src/libstd/num/f64.rs
Expand Up @@ -622,13 +622,13 @@ mod tests {
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(), 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);
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/num/mod.rs
Expand Up @@ -30,8 +30,8 @@ pub use core::num::{from_int, from_i8, from_i16, from_i32, from_i64};
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, FpNan, FpInfinite, FpZero, FpSubnormal};
pub use core::num::{FpNormal, Float};

#[experimental = "may be removed or relocated"]
pub mod strconv;
Expand Down
8 changes: 4 additions & 4 deletions src/libstd/num/strconv.rs
Expand Up @@ -20,7 +20,7 @@ use char;
use char::Char;
use kinds::Copy;
use num;
use num::{Int, Float, FPNaN, FPInfinite, ToPrimitive};
use num::{Int, Float, FpNan, FpInfinite, ToPrimitive};
use slice::{SlicePrelude, CloneSliceAllocPrelude};
use str::StrPrelude;
use string::String;
Expand Down Expand Up @@ -201,14 +201,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 => {
FpNan => { return (b"NaN".to_vec(), true); }
FpInfinite if num > _0 => {
return match sign {
SignAll => (b"+inf".to_vec(), true),
_ => (b"inf".to_vec(), true)
};
}
FPInfinite if num < _0 => {
FpInfinite if num < _0 => {
return match sign {
SignNone => (b"inf".to_vec(), true),
_ => (b"-inf".to_vec(), true),
Expand Down

0 comments on commit de97cbd

Please sign in to comment.