pub trait Conjugate: Sized {
// Required method
fn conjugate(self) -> Self;
}
Expand description
Trait for computing the complex conjugate of a number.
The complex conjugate of a complex number is obtained by changing the sign of its imaginary part.
§Example
use num_valid::functions::Conjugate;
use num::Complex;
use try_create::TryNew;
// Example with Complex<f64>
let z = Complex::new(1.0, -2.0);
let z_conjugate = z.conjugate();
println!("Conjugate: {}", z_conjugate); // Output: Conjugate: 1+2i
assert_eq!(z_conjugate, Complex::new(1.0, 2.0));
// Example with ComplexRugStrictFinite<53> (when the `rug` feature is enabled)
#[cfg(feature = "rug")]
{
use rug::Float;
use num_valid::ComplexRugStrictFinite;
const PRECISION: u32 = 53;
let z = ComplexRugStrictFinite::<PRECISION>::try_new(
rug::Complex::with_val(PRECISION,
(Float::with_val(PRECISION, 1.0),Float::with_val(PRECISION, -2.0)),
)).unwrap();
let z_conjugate = z.conjugate();
println!("Conjugate: {}", z_conjugate);
assert_eq!(
z_conjugate,
ComplexRugStrictFinite::<PRECISION>::try_new(
rug::Complex::with_val(PRECISION,
(Float::with_val(PRECISION, 1.0),Float::with_val(PRECISION, 2.0)),
)).unwrap()
);
}
Required Methods§
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.