Skip to content

Commit

Permalink
Rename the NaN and is_NaN methods to lowercase.
Browse files Browse the repository at this point in the history
This is for consistency in naming conventions.

- ``std::num::Float::NaN()`` is changed to ``nan()``;
- ``std::num::Float.is_NaN()`` is changed to ``is_nan()``; and
- ``std::num::strconv::NumStrConv::NaN()`` is changed to ``nan()``.

Fixes #9319.
  • Loading branch information
chris-morgan committed Sep 19, 2013
1 parent 99ec14d commit d9874c0
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 138 deletions.
4 changes: 2 additions & 2 deletions src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pub fn check_arms(cx: &MatchCheckCtxt, arms: &[Arm]) {
Some(&DefStatic(did, false)) => {
let const_expr = lookup_const_by_id(cx.tcx, did).unwrap();
match eval_const_expr(cx.tcx, const_expr) {
const_float(f) if f.is_NaN() => true,
const_float(f) if f.is_nan() => true,
_ => false
}
}
Expand All @@ -136,7 +136,7 @@ pub fn check_arms(cx: &MatchCheckCtxt, arms: &[Arm]) {
do walk_pat(*pat) |p| {
if pat_matches_nan(p) {
cx.tcx.sess.span_warn(p.span, "unmatchable NaN in pattern, \
use the is_NaN method in a guard instead");
use the is_nan method in a guard instead");
}
true
};
Expand Down
72 changes: 36 additions & 36 deletions src/libstd/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ impl Orderable for f32 {
#[inline]
fn min(&self, other: &f32) -> f32 {
match () {
_ if self.is_NaN() => *self,
_ if other.is_NaN() => *other,
_ if self.is_nan() => *self,
_ if other.is_nan() => *other,
_ if *self < *other => *self,
_ => *other,
}
Expand All @@ -218,8 +218,8 @@ impl Orderable for f32 {
#[inline]
fn max(&self, other: &f32) -> f32 {
match () {
_ if self.is_NaN() => *self,
_ if other.is_NaN() => *other,
_ if self.is_nan() => *self,
_ if other.is_nan() => *other,
_ if *self > *other => *self,
_ => *other,
}
Expand All @@ -230,7 +230,7 @@ impl Orderable for f32 {
#[inline]
fn clamp(&self, mn: &f32, mx: &f32) -> f32 {
match () {
_ if self.is_NaN() => *self,
_ if self.is_nan() => *self,
_ if !(*self <= *mx) => *mx,
_ if !(*self >= *mn) => *mn,
_ => *self,
Expand Down Expand Up @@ -314,7 +314,7 @@ impl Signed for f32 {
///
#[inline]
fn signum(&self) -> f32 {
if self.is_NaN() { NaN } else { copysign(1.0, *self) }
if self.is_nan() { NaN } else { copysign(1.0, *self) }
}

/// Returns `true` if the number is positive, including `+0.0` and `infinity`
Expand Down Expand Up @@ -471,7 +471,7 @@ impl Hyperbolic for f32 {
#[inline]
fn acosh(&self) -> f32 {
match *self {
x if x < 1.0 => Float::NaN(),
x if x < 1.0 => Float::nan(),
x => (x + ((x * x) - 1.0).sqrt()).ln(),
}
}
Expand Down Expand Up @@ -593,7 +593,7 @@ impl Primitive for f32 {

impl Float for f32 {
#[inline]
fn NaN() -> f32 { 0.0 / 0.0 }
fn nan() -> f32 { 0.0 / 0.0 }

#[inline]
fn infinity() -> f32 { 1.0 / 0.0 }
Expand All @@ -606,7 +606,7 @@ impl Float for f32 {

/// Returns `true` if the number is NaN
#[inline]
fn is_NaN(&self) -> bool { *self != *self }
fn is_nan(&self) -> bool { *self != *self }

/// Returns `true` if the number is infinite
#[inline]
Expand All @@ -617,7 +617,7 @@ impl Float for f32 {
/// Returns `true` if the number is neither infinite or NaN
#[inline]
fn is_finite(&self) -> bool {
!(self.is_NaN() || self.is_infinite())
!(self.is_nan() || self.is_infinite())
}

/// Returns `true` if the number is neither zero, infinite, subnormal or NaN
Expand Down Expand Up @@ -949,10 +949,10 @@ mod tests {
assert_eq!(8f32.clamp(&2f32, &4f32), 4f32);
assert_eq!(3f32.clamp(&2f32, &4f32), 3f32);

let nan: f32 = Float::NaN();
assert!(3f32.clamp(&nan, &4f32).is_NaN());
assert!(3f32.clamp(&2f32, &nan).is_NaN());
assert!(nan.clamp(&2f32, &4f32).is_NaN());
let nan: f32 = Float::nan();
assert!(3f32.clamp(&nan, &4f32).is_nan());
assert!(3f32.clamp(&2f32, &nan).is_nan());
assert!(nan.clamp(&2f32, &4f32).is_nan());
}

#[test]
Expand Down Expand Up @@ -1032,25 +1032,25 @@ mod tests {

let inf: f32 = Float::infinity();
let neg_inf: f32 = Float::neg_infinity();
let nan: f32 = Float::NaN();
let nan: f32 = Float::nan();
assert_eq!(inf.asinh(), inf);
assert_eq!(neg_inf.asinh(), neg_inf);
assert!(nan.asinh().is_NaN());
assert!(nan.asinh().is_nan());
assert_approx_eq!(2.0f32.asinh(), 1.443635475178810342493276740273105f32);
assert_approx_eq!((-2.0f32).asinh(), -1.443635475178810342493276740273105f32);
}

#[test]
fn test_acosh() {
assert_eq!(1.0f32.acosh(), 0.0f32);
assert!(0.999f32.acosh().is_NaN());
assert!(0.999f32.acosh().is_nan());

let inf: f32 = Float::infinity();
let neg_inf: f32 = Float::neg_infinity();
let nan: f32 = Float::NaN();
let nan: f32 = Float::nan();
assert_eq!(inf.acosh(), inf);
assert!(neg_inf.acosh().is_NaN());
assert!(nan.acosh().is_NaN());
assert!(neg_inf.acosh().is_nan());
assert!(nan.acosh().is_nan());
assert_approx_eq!(2.0f32.acosh(), 1.31695789692481670862504634730796844f32);
assert_approx_eq!(3.0f32.acosh(), 1.76274717403908605046521864995958461f32);
}
Expand All @@ -1065,15 +1065,15 @@ mod tests {
assert_eq!(1.0f32.atanh(), inf32);
assert_eq!((-1.0f32).atanh(), neg_inf32);

assert!(2f64.atanh().atanh().is_NaN());
assert!((-2f64).atanh().atanh().is_NaN());
assert!(2f64.atanh().atanh().is_nan());
assert!((-2f64).atanh().atanh().is_nan());

let inf64: f32 = Float::infinity();
let neg_inf64: f32 = Float::neg_infinity();
let nan32: f32 = Float::NaN();
assert!(inf64.atanh().is_NaN());
assert!(neg_inf64.atanh().is_NaN());
assert!(nan32.atanh().is_NaN());
let nan32: f32 = Float::nan();
assert!(inf64.atanh().is_nan());
assert!(neg_inf64.atanh().is_nan());
assert!(nan32.atanh().is_nan());

assert_approx_eq!(0.5f32.atanh(), 0.54930614433405484569762261846126285f32);
assert_approx_eq!((-0.5f32).atanh(), -0.54930614433405484569762261846126285f32);
Expand Down Expand Up @@ -1125,7 +1125,7 @@ mod tests {
assert_eq!((-1f32).abs(), 1f32);
assert_eq!(neg_infinity.abs(), infinity);
assert_eq!((1f32/neg_infinity).abs(), 0f32);
assert!(NaN.abs().is_NaN());
assert!(NaN.abs().is_nan());
}

#[test]
Expand All @@ -1142,8 +1142,8 @@ mod tests {

#[test] #[ignore(cfg(windows))] // FIXME #8663
fn test_abs_sub_nowin() {
assert!(NaN.abs_sub(&-1f32).is_NaN());
assert!(1f32.abs_sub(&NaN).is_NaN());
assert!(NaN.abs_sub(&-1f32).is_nan());
assert!(1f32.abs_sub(&NaN).is_nan());
}

#[test]
Expand All @@ -1155,7 +1155,7 @@ mod tests {
assert_eq!((-1f32).signum(), -1f32);
assert_eq!(neg_infinity.signum(), -1f32);
assert_eq!((1f32/neg_infinity).signum(), -1f32);
assert!(NaN.signum().is_NaN());
assert!(NaN.signum().is_nan());
}

#[test]
Expand Down Expand Up @@ -1200,7 +1200,7 @@ mod tests {

#[test]
fn test_is_normal() {
let nan: f32 = Float::NaN();
let nan: f32 = Float::nan();
let inf: f32 = Float::infinity();
let neg_inf: f32 = Float::neg_infinity();
let zero: f32 = Zero::zero();
Expand All @@ -1217,7 +1217,7 @@ mod tests {

#[test]
fn test_classify() {
let nan: f32 = Float::NaN();
let nan: f32 = Float::nan();
let inf: f32 = Float::infinity();
let neg_inf: f32 = Float::neg_infinity();
let zero: f32 = Zero::zero();
Expand Down Expand Up @@ -1246,10 +1246,10 @@ mod tests {

let inf: f32 = Float::infinity();
let neg_inf: f32 = Float::neg_infinity();
let nan: f32 = Float::NaN();
let nan: f32 = Float::nan();
assert_eq!(Float::ldexp(inf, -123), inf);
assert_eq!(Float::ldexp(neg_inf, -123), neg_inf);
assert!(Float::ldexp(nan, -123).is_NaN());
assert!(Float::ldexp(nan, -123).is_nan());
}

#[test]
Expand All @@ -1273,9 +1273,9 @@ mod tests {
fn test_frexp_nowin() {
let inf: f32 = Float::infinity();
let neg_inf: f32 = Float::neg_infinity();
let nan: f32 = Float::NaN();
let nan: f32 = Float::nan();
assert_eq!(match inf.frexp() { (x, _) => x }, inf)
assert_eq!(match neg_inf.frexp() { (x, _) => x }, neg_inf)
assert!(match nan.frexp() { (x, _) => x.is_NaN() })
assert!(match nan.frexp() { (x, _) => x.is_nan() })
}
}
Loading

5 comments on commit d9874c0

@bors
Copy link
Contributor

@bors bors commented on d9874c0 Sep 20, 2013

Choose a reason for hiding this comment

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

saw approval from brson
at chris-morgan@d9874c0

@bors
Copy link
Contributor

@bors bors commented on d9874c0 Sep 20, 2013

Choose a reason for hiding this comment

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

merging chris-morgan/rust/lowercase-nan-methods = d9874c0 into auto

@bors
Copy link
Contributor

@bors bors commented on d9874c0 Sep 20, 2013

Choose a reason for hiding this comment

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

chris-morgan/rust/lowercase-nan-methods = d9874c0 merged ok, testing candidate = ccb80ab

@bors
Copy link
Contributor

@bors bors commented on d9874c0 Sep 20, 2013

@bors
Copy link
Contributor

@bors bors commented on d9874c0 Sep 20, 2013

Choose a reason for hiding this comment

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

fast-forwarding master to auto = ccb80ab

Please sign in to comment.