Auto merge of #128 - achanda:cfuncs, r=cuviper

Implement some more functions for the complex type
This commit is contained in:
Homu 2015-11-12 02:45:08 +09:00
commit 43bd642da5
1 changed files with 38 additions and 0 deletions

View File

@ -287,6 +287,24 @@ impl<T: Clone + Float> Complex<T> {
pub fn is_nan(self) -> bool {
self.re.is_nan() || self.im.is_nan()
}
/// Checks if the given complex number is infinite
#[inline]
pub fn is_infinite(self) -> bool {
!self.is_nan() && (self.re.is_infinite() || self.im.is_infinite())
}
/// Checks if the given complex number is finite
#[inline]
pub fn is_finite(self) -> bool {
self.re.is_finite() && self.im.is_finite()
}
/// Checks if the given complex number is normal
#[inline]
pub fn is_normal(self) -> bool {
self.re.is_normal() && self.im.is_normal()
}
}
macro_rules! forward_val_val_binop {
@ -939,4 +957,24 @@ mod test {
assert!(a.is_nan());
assert!(b.is_nan());
}
#[test]
fn test_is_infinite() {
let a = Complex::new(2f64, f64::INFINITY);
assert!(a.is_infinite());
}
#[test]
fn test_is_finite() {
assert!(_1_1i.is_finite())
}
#[test]
fn test_is_normal() {
let a = Complex::new(0f64, f64::NAN);
let b = Complex::new(2f64, f64::INFINITY);
assert!(!a.is_normal());
assert!(!b.is_normal());
assert!(_1_1i.is_normal());
}
}