Auto merge of #114 - achanda:is_nan, r=hauleth
Implement is_nan for the complex type Also run the associated test
This commit is contained in:
commit
d9b72a3366
|
@ -281,6 +281,12 @@ impl<T: Clone + Float> Complex<T> {
|
||||||
}
|
}
|
||||||
((one + self).ln() - (one - self).ln()) / two
|
((one + self).ln() - (one - self).ln()) / two
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Checks if the given complex number is NaN
|
||||||
|
#[inline]
|
||||||
|
pub fn is_nan(self) -> bool {
|
||||||
|
self.re.is_nan() || self.im.is_nan()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! forward_val_val_binop {
|
macro_rules! forward_val_val_binop {
|
||||||
|
@ -514,11 +520,9 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic]
|
|
||||||
#[ignore]
|
|
||||||
fn test_inv_zero() {
|
fn test_inv_zero() {
|
||||||
// FIXME #5736: should this really fail, or just NaN?
|
// FIXME #20: should this really fail, or just NaN?
|
||||||
_0_0i.inv();
|
assert!(_0_0i.inv().is_nan());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -920,4 +924,19 @@ mod test {
|
||||||
assert!(::hash(&b) != ::hash(&c));
|
assert!(::hash(&b) != ::hash(&c));
|
||||||
assert!(::hash(&c) != ::hash(&a));
|
assert!(::hash(&c) != ::hash(&a));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_is_nan() {
|
||||||
|
assert!(!_1_1i.is_nan());
|
||||||
|
let a = Complex::new(f64::NAN, f64::NAN);
|
||||||
|
assert!(a.is_nan());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_is_nan_special_cases() {
|
||||||
|
let a = Complex::new(0f64, f64::NAN);
|
||||||
|
let b = Complex::new(f64::NAN, 0f64);
|
||||||
|
assert!(a.is_nan());
|
||||||
|
assert!(b.is_nan());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue