oxilean_std/complex/complex_norm_sq_group.rs
1//! # Complex - norm_sq_group Methods
2//!
3//! This module contains method implementations for `Complex`.
4//!
5//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
6
7use super::complex_type::Complex;
8
9impl Complex {
10 /// Modulus squared: |z|² = re² + im².
11 pub fn norm_sq(self) -> f64 {
12 self.re * self.re + self.im * self.im
13 }
14 /// Modulus: |z|.
15 pub fn abs(self) -> f64 {
16 self.norm_sq().sqrt()
17 }
18 /// Division: z/w = z * conj(w) / |w|².
19 pub fn div(self, other: Self) -> Option<Self> {
20 let denom = other.norm_sq();
21 if denom < f64::EPSILON {
22 return None;
23 }
24 Some(self.mul(other.conj()).scale(1.0 / denom))
25 }
26}