Hoverbear/rust-rosetta — pull request #202 by pfalabella (2014-08-16 13:21:31+00:00)
Title: implemented Roots of unity

Added roots of unity.

I wanted to do what @Ryman did in https://github.com/Ryman/rust-rosetta/commit/dfa44277b6f1b04592b8301c275e12f4531fb739 but when I tried to return directly the iterator I got in trouble with lifetimes, so I had to collect results in a vector.

i.e. I would have liked to write this (in case someone else can fix it):
http://is.gd/EidM34

```rust
extern crate num;
use num::complex::{Complex, Complex32};
use std::f32::consts;
use std::iter::{Range, Map};

type RootsIterator<'a> = Map<'a, uint, Complex32, Range>;

fn main() {
let degree = 3u;

for root in roots_of_unity(degree) {
println!("{}", root);
}
}

fn roots_of_unity<'a>(degree: uint) -> RootsIterator<'a> {
range(0, degree).map(|el|
Complex::::from_polar(&1f32, &(2. * consts::PI * (el as f32) / (degree as f32))))
}
```