pub trait ComplexScalarMutateParts: ComplexScalarSetParts {
// Required methods
fn add_to_real_part(&mut self, c: &Self::RealType);
fn add_to_imaginary_part(&mut self, c: &Self::RealType);
fn multiply_real_part(&mut self, c: &Self::RealType);
fn multiply_imaginary_part(&mut self, c: &Self::RealType);
}
Expand description
Provides methods for in-place mutation of the components of a complex scalar.
This trait offers efficient, in-place operations to modify the real and imaginary parts of a complex number individually using a real scalar value. These methods are particularly useful in numerical algorithms that require adjusting specific components of a complex vector or matrix without allocating new complex numbers.
§Examples
use num_valid::{
ComplexNative64StrictFinite, RealNative64StrictFinite,
functions::{ComplexScalarGetParts, ComplexScalarMutateParts, ComplexScalarConstructors},
};
use try_create::TryNew;
let mut c = ComplexNative64StrictFinite::try_new_complex(3.0, 5.0).unwrap();
let real_addend = RealNative64StrictFinite::try_new(2.0).unwrap();
let real_multiplier = RealNative64StrictFinite::try_new(10.0).unwrap();
// Add 2.0 to the real part
c.add_to_real_part(&real_addend);
assert_eq!(c.real_part(), 5.0);
// Multiply the imaginary part by 10.0
c.multiply_imaginary_part(&real_multiplier);
assert_eq!(c.imag_part(), 50.0);
assert_eq!(c, ComplexNative64StrictFinite::try_new_complex(5.0, 50.0).unwrap());
Required Methods§
Sourcefn add_to_real_part(&mut self, c: &Self::RealType)
fn add_to_real_part(&mut self, c: &Self::RealType)
Add the value of the the real coefficient c
to real part of self
.
Sourcefn add_to_imaginary_part(&mut self, c: &Self::RealType)
fn add_to_imaginary_part(&mut self, c: &Self::RealType)
Add the value of the the real coefficient c
to imaginary part of self
.
Sourcefn multiply_real_part(&mut self, c: &Self::RealType)
fn multiply_real_part(&mut self, c: &Self::RealType)
Multiply the value of the real part by the real coefficient c
.
Sourcefn multiply_imaginary_part(&mut self, c: &Self::RealType)
fn multiply_imaginary_part(&mut self, c: &Self::RealType)
Multiply the value of the imaginary part by the real coefficient c
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl ComplexScalarMutateParts for Complex<f64>
Implement the ComplexScalarMutateParts
trait for the Complex<f64>
type.
impl ComplexScalarMutateParts for Complex<f64>
Implement the ComplexScalarMutateParts
trait for the Complex<f64>
type.
Source§fn add_to_real_part(&mut self, c: &f64)
fn add_to_real_part(&mut self, c: &f64)
Add the value of the the real coefficient c
to real part of self
.
§Panics
In debug builds, this will panic if the real part of self
is not finite after the addition.
This check is disabled in release builds for performance.
Source§fn add_to_imaginary_part(&mut self, c: &f64)
fn add_to_imaginary_part(&mut self, c: &f64)
Add the value of the the real coefficient c
to imaginary part of self
.
§Panics
In debug builds, this will panic if the imaginary part of self
is not finite after the addition.
This check is disabled in release builds for performance.
Source§fn multiply_real_part(&mut self, c: &f64)
fn multiply_real_part(&mut self, c: &f64)
Multiply the value of the real part by the real coefficient c
.
§Panics
In debug builds, this will panic if the real part of self
is not finite after the multiplication.
This check is disabled in release builds for performance.
Source§fn multiply_imaginary_part(&mut self, c: &f64)
fn multiply_imaginary_part(&mut self, c: &f64)
Multiply the value of the imaginary part by the real coefficient c
.
§Panics
In debug builds, this will panic if the imaginary part of self
is not finite after the multiplication.
This check is disabled in release builds for performance.
Implementors§
impl<K: NumKernel> ComplexScalarMutateParts for ComplexValidated<K>
Implement the ComplexScalarMutateParts
trait for the ComplexValidated
type.