Trait basic_dsp::ElementaryOps
source · [−]pub trait ElementaryOps<A, T, N, D>where
T: RealNumber,
N: NumberSpace,
D: Domain,
A: GetMetaData<T, N, D>,{
fn add(&mut self, summand: &A) -> Result<(), ErrorReason>;
fn sub(&mut self, subtrahend: &A) -> Result<(), ErrorReason>;
fn mul(&mut self, factor: &A) -> Result<(), ErrorReason>;
fn div(&mut self, divisor: &A) -> Result<(), ErrorReason>;
}
Expand description
Elementary algebra on types: addition, subtraction, multiplication and division
Required Methods
sourcefn add(&mut self, summand: &A) -> Result<(), ErrorReason>
fn add(&mut self, summand: &A) -> Result<(), ErrorReason>
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..]);
sourcefn sub(&mut self, subtrahend: &A) -> Result<(), ErrorReason>
fn sub(&mut self, subtrahend: &A) -> Result<(), ErrorReason>
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..]);
sourcefn mul(&mut self, factor: &A) -> Result<(), ErrorReason>
fn mul(&mut self, factor: &A) -> Result<(), ErrorReason>
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..]);
sourcefn div(&mut self, divisor: &A) -> Result<(), ErrorReason>
fn div(&mut self, divisor: &A) -> Result<(), ErrorReason>
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..]);