Skip to main content

Complex

Struct Complex 

Source
pub struct Complex { /* private fields */ }
Expand description

Nombre complexe en virgule flottante simple précision.

Représenté sous forme cartésienne re + im·i.

§Invariants

Aucun invariant fort n’est imposé : NaN et Infinity sont autorisés (ils se propagent naturellement comme en IEEE 754).

Implementations§

Source§

impl Complex

Source

pub const ZERO: Self

Le zéro complexe 0 + 0i.

Source

pub const ONE: Self

L’unité réelle 1 + 0i.

Source

pub const I: Self

L’unité imaginaire 0 + 1i.

Source

pub const fn new(re: f32, im: f32) -> Self

Crée un nouveau nombre complexe re + im·i.

use embedded_complex_f32::Complex;
let z = Complex::new(1.0, -2.0);
assert_eq!(z.re(), 1.0);
assert_eq!(z.im(), -2.0);
Source

pub const fn re(self) -> f32

Partie réelle.

Source

pub const fn im(self) -> f32

Partie imaginaire.

Source

pub fn is_nan(self) -> bool

Retourne true si l’un des composants est NaN.

Source

pub fn is_infinite(self) -> bool

Retourne true si l’un des composants est infini.

Source

pub fn is_finite(self) -> bool

Retourne true si les deux composants sont finis.

Source§

impl Complex

Source

pub fn conj(self) -> Self

Conjugué : re - im·i.

use embedded_complex_f32::Complex;
let z = Complex::new(3.0, -4.0);
assert_eq!(z.conj(), Complex::new(3.0, 4.0));
Source

pub fn norm(self) -> f32

Norme (module) : √(re² + im²).

Utilise embedded_f32_sqrt::sqrt aucune dépendance C requise.

use embedded_complex_f32::Complex;
let z = Complex::new(3.0, 4.0);
assert!((z.norm() - 5.0).abs() < 1e-4);
Source

pub fn norm_sq(self) -> f32

Carré de la norme : re² + im² (évite la racine carrée).

use embedded_complex_f32::Complex;
let z = Complex::new(3.0, 4.0);
assert!((z.norm_sq() - 25.0).abs() < 1e-4);
Source

pub fn checked_div(self, rhs: Self) -> Result<Self, ComplexError>

Division vérifiée — retourne Err(ComplexError::DivisionByZero) si |rhs| == 0.

use embedded_complex_f32::{Complex, ComplexError};
let z = Complex::new(1.0, 0.0);
assert_eq!(z.checked_div(Complex::ZERO), Err(ComplexError::DivisionByZero));
Source

pub fn inv(self) -> Result<Self, ComplexError>

Inverse : 1 / self.

Retourne Err(ComplexError::DivisionByZero) si |self| == 0.

use embedded_complex_f32::Complex;
let r = Complex::new(4.0, 0.0).inv().unwrap();
assert!((r.re() - 0.25).abs() < 1e-5);
Source

pub fn csqrt(self) -> Result<Self, ComplexError>

Racine carrée complexe.

Pour z = r·e^{iθ}, retourne √r · e^{iθ/2} via les identités trigonométriques demi-angle sans libm, sans appel trig approché.

use embedded_complex_f32::Complex;
let z = Complex::new(3.0, 4.0);
let s = z.csqrt().unwrap();
let back = s * s;
assert!((back.re() - 3.0).abs() < 1e-4);
assert!((back.im() - 4.0).abs() < 1e-4);
Source

pub fn powi(self, n: i32) -> Result<Self, ComplexError>

Puissance entière self^n par exponentiation rapide.

n peut être négatif (utilise inv si n < 0).

use embedded_complex_f32::Complex;
// i⁴ = 1
let r = Complex::I.powi(4).unwrap();
assert!((r.re() - 1.0).abs() < 1e-5);

Trait Implementations§

Source§

impl Add<f32> for Complex

Source§

type Output = Complex

The resulting type after applying the + operator.
Source§

fn add(self, rhs: f32) -> Self

Performs the + operation. Read more
Source§

impl Add for Complex

Source§

type Output = Complex

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self

Performs the + operation. Read more
Source§

impl AddAssign for Complex

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl Clone for Complex

Source§

fn clone(&self) -> Complex

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Complex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Complex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Div<f32> for Complex

Source§

type Output = Complex

The resulting type after applying the / operator.
Source§

fn div(self, rhs: f32) -> Self

Performs the / operation. Read more
Source§

impl Div for Complex

Division via conjugué : (a+bi)/(c+di) = [(a+bi)(c−di)] / (c²+d²).

Retourne NaN + NaN·i si |rhs| == 0. Préférez Complex::checked_div pour une gestion explicite de l’erreur.

Source§

type Output = Complex

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Self

Performs the / operation. Read more
Source§

impl DivAssign for Complex

Source§

fn div_assign(&mut self, rhs: Self)

Performs the /= operation. Read more
Source§

impl From<(f32, f32)> for Complex

Source§

fn from((re, im): (f32, f32)) -> Self

Converts to this type from the input type.
Source§

impl From<Complex> for (f32, f32)

Source§

fn from(z: Complex) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for Complex

Source§

fn from(x: f32) -> Self

Embed un scalaire réel comme x + 0i.

Source§

impl Mul<f32> for Complex

Source§

type Output = Complex

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f32) -> Self

Performs the * operation. Read more
Source§

impl Mul for Complex

(a+bi)(c+di) = (ac−bd) + (ad+bc)i

Source§

type Output = Complex

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self

Performs the * operation. Read more
Source§

impl MulAssign for Complex

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl Neg for Complex

Source§

type Output = Complex

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl PartialEq for Complex

Source§

fn eq(&self, other: &Complex) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Sub<f32> for Complex

Source§

type Output = Complex

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: f32) -> Self

Performs the - operation. Read more
Source§

impl Sub for Complex

Source§

type Output = Complex

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self

Performs the - operation. Read more
Source§

impl SubAssign for Complex

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl Copy for Complex

Source§

impl StructuralPartialEq for Complex

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.