Merge branch 'master' into develop

Conflicts:
	src/complex.rs
This commit is contained in:
William Rieger 2015-09-04 18:56:40 -04:00
commit 50d89519a2
1 changed files with 16 additions and 19 deletions

View File

@ -81,6 +81,22 @@ impl<T: Clone + Float> Complex<T> {
pub fn norm(&self) -> T {
self.re.clone().hypot(self.im.clone())
}
/// Calculate the principal Arg of self.
#[inline]
pub fn arg(&self) -> T {
self.im.clone().atan2(self.re.clone())
}
/// Convert to polar form (r, theta), such that `self = r * exp(i
/// * theta)`
#[inline]
pub fn to_polar(&self) -> (T, T) {
(self.norm(), self.arg())
}
/// Convert a polar representation into a complex number.
#[inline]
pub fn from_polar(r: &T, theta: &T) -> Complex<T> {
Complex::new(*r * theta.cos(), *r * theta.sin())
}
/// Computes e^(self), where e is the base of the natural logarithm.
#[inline]
@ -153,25 +169,6 @@ impl<T: Clone + Float> Complex<T> {
}
}
impl<T: Clone + Float + Num> Complex<T> {
/// Calculate the principal Arg of self.
#[inline]
pub fn arg(&self) -> T {
self.im.clone().atan2(self.re.clone())
}
/// Convert to polar form (r, theta), such that `self = r * exp(i
/// * theta)`
#[inline]
pub fn to_polar(&self) -> (T, T) {
(self.norm(), self.arg())
}
/// Convert a polar representation into a complex number.
#[inline]
pub fn from_polar(r: &T, theta: &T) -> Complex<T> {
Complex::new(*r * theta.cos(), *r * theta.sin())
}
}
macro_rules! forward_val_val_binop {
(impl $imp:ident, $method:ident) => {
impl<T: Clone + Num> $imp<Complex<T>> for Complex<T> {