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).
Both ComplexFloat and ComplexDouble classes contain wrong implementation of
arg()
.E.g.
must be replaced with
exp(ix) = cos(x) + i*sin(x)
.atan2(y, x) = arctan(y/x)
for non-zero x. So to getx = arg(exp(ix))
, you need to takeatan2(im(exp(ix)), re(exp(ix))) = atan2(sin(x), cos(x)) = arctan(tan(x)) = x
(for x in proper range).