complex

Macro complex 

Source
macro_rules! complex {
    ($re:expr, $im:expr) => { ... };
}
Expand description

Creates a validated complex number from two f64 literals (real and imaginary parts).

This macro provides a concise syntax for creating ComplexNative64StrictFinite values. It accepts two arguments: the real part and the imaginary part.

§Panics

Panics if either the real or imaginary part is not finite (NaN, infinity) or is subnormal. For fallible conversion, use ComplexNative64StrictFinite::try_new_complex directly.

§Examples

use num_valid::complex;

let z1 = complex!(1.0, 2.0);   // 1 + 2i
let z2 = complex!(-3.0, 4.0);  // -3 + 4i
let z3 = complex!(0.0, -1.0);  // -i

// Euler's identity: e^(iπ) + 1 = 0
use std::f64::consts::PI;
use num_valid::functions::{Exp, Abs};

let i_pi = complex!(0.0, PI);
let e_to_i_pi = i_pi.exp();
let result = e_to_i_pi + complex!(1.0, 0.0);

assert!(result.abs().as_ref() < &1e-10); // Very close to zero

Creating unit vectors in the complex plane:

use num_valid::complex;

let unit_real = complex!(1.0, 0.0);      // Real axis
let unit_imag = complex!(0.0, 1.0);      // Imaginary axis
let unit_45deg = complex!(0.707, 0.707); // 45° angle