rust-num / num-complex

Complex numbers for Rust
Apache License 2.0
232 stars 50 forks source link

Add Complex::powi and assorted Pow impls #56

Closed cuviper closed 5 years ago

cuviper commented 5 years ago

Closes #18.

cuviper commented 5 years ago

The CI failure is legit, I neglected no-std support.

However, this is annoying, because adding blanket T: Float impls gated on a feature is technically a breaking change! Actually, that makes this PR a breaking change already, because someone could technically have this for their own custom F type already:

impl Pow<F> for Complex<F> {
    type Output = Complex<F>;

    fn pow(self, exp: F) -> Self::Output {
        // ...
    }
}

The blanket powc should be OK though (with std), because a third party can't write this:

impl Pow<Complex<F>> for Complex<F> {
    type Output = Complex<F>;

    fn pow(self, exp: Self) -> Self::Output {
        //...
    }
}
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
  --> src/lib.rs:35:1
   |
35 | impl Pow<Complex<F>> for Complex<F> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
   |
   = note: the impl does not reference only types defined in this crate
   = note: define and implement a trait or new type instead
cuviper commented 5 years ago

bors r+

bors[bot] commented 5 years ago

Build succeeded