ComplexScalar

Trait ComplexScalar 

Source
pub trait ComplexScalar:
    ComplexScalarMutateParts
    + Conjugate
    + Arg<Output = Self::RealType>
    + for<'a> Mul<&'a Self::RealType, Output = Self>
    + for<'a> MulAssign<&'a Self::RealType>
    + for<'a> Pow<&'a Self::RealType, Error = PowComplexBaseRealExponentErrors<Self::RawComplex>> {
    // Provided methods
    fn scale(self, c: &Self::RealType) -> Self { ... }
    fn scale_mut(&mut self, c: &Self::RealType) { ... }
}
Expand description

§Trait for complex scalar numbers

ComplexScalar is a specialized trait for complex number types that extends the core FpScalar functionality with complex-specific operations. It provides a unified interface for working with complex numbers across different validation policies and underlying representations.

§Design Philosophy

This trait bridges the gap between raw complex number operations and the validated complex number types in num-valid. It ensures that complex-specific operations like conjugation, argument calculation, and real-number scaling are available in a type-safe, validated context.

§Core Capabilities

The trait provides several key features:

  • Component manipulation: Through ComplexScalarMutateParts, allowing safe modification of real and imaginary parts
  • Conjugation: Via the functions::Conjugate trait for computing complex conjugates
  • Argument calculation: Through functions::Arg for computing the phase angle
  • Real scaling: Multiplication and assignment with real numbers
  • Power operations: Raising complex numbers to real exponents
  • Convenience methods: Like scale and scale_mut for efficient real-number scaling

§Type Relationships

Types implementing ComplexScalar must also implement FpScalar with Kind = scalar_kind::Complex, establishing them as complex number types within the num-valid type system.

§Usage Examples

§Basic Complex Operations

use num_valid::{ComplexNative64StrictFinite, RealNative64StrictFinite, ComplexScalar};
use num::Complex;
use try_create::TryNew;

let z = ComplexNative64StrictFinite::try_new(Complex::new(3.0, 4.0)).unwrap();
let factor = RealNative64StrictFinite::try_new(2.5).unwrap();

// Scale by a real number
let scaled = z.scale(&factor);
// Result: (7.5, 10.0)

§In-place Operations

use num_valid::{ComplexNative64StrictFinite, RealNative64StrictFinite, ComplexScalar};
use num::Complex;
use try_create::TryNew;

let mut z = ComplexNative64StrictFinite::try_new(Complex::new(1.0, 2.0)).unwrap();
let factor = RealNative64StrictFinite::try_new(3.0).unwrap();

z.scale_mut(&factor);
// z is now (3.0, 6.0)

§See Also

Provided Methods§

Source

fn scale(self, c: &Self::RealType) -> Self

Scale the complex number self by the real coefficient c.

This is equivalent to complex multiplication by a real number, scaling both the real and imaginary parts by the same factor.

§Examples
use num_valid::{ComplexNative64StrictFinite, RealNative64StrictFinite, ComplexScalar};
use num::Complex;
use try_create::TryNew;

let z = ComplexNative64StrictFinite::try_new(Complex::new(3.0, 4.0)).unwrap();
let factor = RealNative64StrictFinite::try_new(2.0).unwrap();

let scaled = z.scale(&factor);
// Result: (6.0, 8.0)
Source

fn scale_mut(&mut self, c: &Self::RealType)

Scale (in-place) the complex number self by the real coefficient c.

This modifies the complex number in place, scaling both components by the real factor.

§Examples
use num_valid::{ComplexNative64StrictFinite, RealNative64StrictFinite, ComplexScalar};
use num::Complex;
use try_create::TryNew;

let mut z = ComplexNative64StrictFinite::try_new(Complex::new(3.0, 4.0)).unwrap();
let factor = RealNative64StrictFinite::try_new(2.0).unwrap();

z.scale_mut(&factor);
// z is now (6.0, 8.0)

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 ComplexScalar for Complex<f64>

Implement the ComplexScalar trait for the Complex<f64> type.

Implementors§