oxilean_std/complex/complex_nth_roots_group.rs
1//! # Complex - nth_roots_group Methods
2//!
3//! This module contains method implementations for `Complex`.
4//!
5//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
6
7use std::f64::consts::PI;
8
9use super::complex_type::Complex;
10
11impl Complex {
12 /// n-th roots of z: returns all n roots.
13 pub fn nth_roots(self, n: u32) -> Vec<Self> {
14 if n == 0 {
15 return vec![];
16 }
17 let (r, theta) = self.to_polar();
18 let r_n = r.powf(1.0 / n as f64);
19 (0..n)
20 .map(|k| {
21 let angle = (theta + 2.0 * PI * k as f64) / n as f64;
22 Self::from_polar(r_n, angle)
23 })
24 .collect()
25 }
26}