Skip to content

Proposal: Complex helper constructors #78

Open
@ElectricCoffee

Description

@ElectricCoffee

I have a simple request based on an actual use-case that I needed: helper functions to create reals and imaginaries directly.

impl<T: Clone + Num> Complex<T> {
  fn re(re: T) -> Complex<T> {
    Complex::new(re, T::zero())
  }

  fn im(im: T) -> Complex<T> {
    Complex::new(T::zero(), im)
  }
}

With these two constructors we'd be able to simply write Complex::im(2.0) instead of Complex::new(0.0, 2.0), which would make it slightly more ergonomic for the cases where you know for a fact you don't need one of the parts right away, but do need a Complex number.

Similarly (or alternatively) a set of conversion functions from a scalar Num to a complex one would be nice too, so we can write 2.0.to_im() to achieve the same or a similar result.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions