public static void cpow(float[] cx, Cfloat ca, float[] cy) { Cfloat ct = new Cfloat(); int n1 = cx.length/2; for (int ir=0,ii=1,nn=2*n1; ir<nn; ir+=2,ii+=2) { ct.r = cx[ir]; ct.i = cx[ii]; Cfloat ce = Cfloat.pow(ct,ca); cy[ir] = ce.r; cy[ii] = ce.i; } } public static void cpow(float[][] cx, Cfloat ca, float[][] cy) {
public void test() { Cfloat a = new Cfloat(FLT_PI,FLT_E); Cfloat b = new Cfloat(FLT_E,FLT_PI); assertEquals(a,sub(add(a,b),b)); assertEquals(a,div(mul(a,b),b)); assertEquals(a,conj(conj(a))); assertEquals(a,polar(abs(a),arg(a))); assertEquals(a,exp(log(a))); assertEquals(a,pow(sqrt(a),2.0f)); assertEquals(pow(a,b),exp(b.times(log(a)))); assertEquals(pow(a,b),exp(b.times(log(a)))); assertEquals(sin(FLT_I.times(a)), FLT_I.times(sinh(a))); assertEquals(cos(FLT_I.times(a)),cosh(a)); assertEquals(tan(FLT_I.times(a)), FLT_I.times(tanh(a))); }
/** * Returns the square root of a complex number. * @param x a complex number. * @return the square root. */ public static Cfloat sqrt(Cfloat x) { if (x.r==0.0f) { float t = sqrt(0.5f*abs(x.i)); return new Cfloat(t,(x.i<0.0f)?-t:t); } else { float t = sqrt(2.0f*(abs(x)+abs(x.r))); float u = 0.5f*t; return (x.r>0.0f) ? new Cfloat(u,x.i/t) : new Cfloat(abs(x.i)/t,(x.i<0.0f)?-u:u); } }
/** * Returns the hyperbolic tangent of a complex number. * @param x a complex number. * @return the hyperbolic tangent. */ public static Cfloat tanh(Cfloat x) { return sinh(x).overEquals(cosh(x)); }
/** * Returns the tangent of a complex number. * @param x a complex number. * @return the tangent. */ public static Cfloat tan(Cfloat x) { return sin(x).overEquals(cos(x)); }
/** * Returns the sum z + x, where z is this complex number. * @param x a real number. * @return z + x. */ public Cfloat plus(float x) { return new Cfloat(this).plusEquals(x); }