Trait basic_dsp_vector::ElementaryOps
[−]
[src]
pub trait ElementaryOps<A> { fn add(&mut self, summand: &A) -> VoidResult; fn sub(&mut self, subtrahend: &A) -> VoidResult; fn mul(&mut self, factor: &A) -> VoidResult; fn div(&mut self, divisor: &A) -> VoidResult; }
Elementary algebra on types: addition, subtraction, multiplication and division
Required Methods
fn add(&mut self, summand: &A) -> VoidResult
Calculates the sum of self + summand
. It consumes self and returns the result.
Failures
TransRes may report the following ErrorReason
members:
VectorsMustHaveTheSameSize
:self
andsummand
must have the same sizeVectorMetaDataMustAgree
:self
andsummand
must be in the same domain and number space
Example
use basic_dsp_vector::*; let mut vector1 = vec!(1.0, 2.0).to_real_time_vec(); let vector2 = vec!(10.0, 11.0).to_real_time_vec(); vector1.add(&vector2).expect("Ignoring error handling in examples"); assert_eq!([11.0, 13.0], vector1[0..]);
fn sub(&mut self, subtrahend: &A) -> VoidResult
Calculates the difference of self - subtrahend
. It consumes self and returns the result.
Failures
TransRes may report the following ErrorReason
members:
VectorsMustHaveTheSameSize
:self
andsubtrahend
must have the same sizeVectorMetaDataMustAgree
:self
andsubtrahend
must be in the same domain and number space
Example
use basic_dsp_vector::*; let mut vector1 = vec!(1.0, 2.0).to_real_time_vec(); let vector2 = vec!(10.0, 11.0).to_real_time_vec(); vector1.sub(&vector2).expect("Ignoring error handling in examples"); assert_eq!([-9.0, -9.0], vector1[0..]);
fn mul(&mut self, factor: &A) -> VoidResult
Calculates the product of self * factor
. It consumes self and returns the result.
Failures
TransRes may report the following ErrorReason
members:
VectorsMustHaveTheSameSize
:self
andfactor
must have the same sizeVectorMetaDataMustAgree
:self
andfactor
must be in the same domain and number space
Example
use basic_dsp_vector::*; let mut vector1 = vec!(1.0, 2.0).to_real_time_vec(); let vector2 = vec!(10.0, 11.0).to_real_time_vec(); vector1.mul(&vector2).expect("Ignoring error handling in examples"); assert_eq!([10.0, 22.0], vector1[0..]);
fn div(&mut self, divisor: &A) -> VoidResult
Calculates the quotient of self / summand
. It consumes self and returns the result.
Failures
TransRes may report the following ErrorReason
members:
VectorsMustHaveTheSameSize
:self
anddivisor
must have the same sizeVectorMetaDataMustAgree
:self
anddivisor
must be in the same domain and number space
Example
use basic_dsp_vector::*; let mut vector1 = vec!(10.0, 22.0).to_real_time_vec(); let vector2 = vec!(2.0, 11.0).to_real_time_vec(); vector1.div(&vector2).expect("Ignoring error handling in examples"); assert_eq!([5.0, 2.0], vector1[0..]);
Implementors
impl<T, N, D> ElementaryOps<Identifier<T, N, D>> for Identifier<T, N, D> where T: RealNumber, N: NumberSpace, D: Domain
impl<S, T, N, D> ElementaryOps<DspVec<S, T, N, D>> for DspVec<S, T, N, D> where S: ToSliceMut<T>, T: RealNumber, N: NumberSpace, D: Domain