jblas-project / jblas

Linear Algebra for Java
http://jblas.org
BSD 3-Clause "New" or "Revised" License
590 stars 149 forks source link

arg() function for complex numbers is wrong #36

Closed be9 closed 9 years ago

be9 commented 10 years ago

Both ComplexFloat and ComplexDouble classes contain wrong implementation of arg().

E.g.

    public float arg() {
        return (float) Math.atan2(r, i);
    }

must be replaced with

    public float arg() {
        return (float) Math.atan2(i, r);
    }

exp(ix) = cos(x) + i*sin(x). atan2(y, x) = arctan(y/x) for non-zero x. So to get x = arg(exp(ix)), you need to take atan2(im(exp(ix)), re(exp(ix))) = atan2(sin(x), cos(x)) = arctan(tan(x)) = x (for x in proper range).

mikiobraun commented 9 years ago

Hi be9,

after almost two years I finally get around to taking care of this.

Thanks for spotting and reporting it!

Best,

-M