/** * Returns the sine of this complex number. * @return the sine. */ public Cfloat sin() { return sin(this); }
/** * Returns the hyperbolic sine of a complex number. * @param x a complex number. * @return the hyperbolic sine. */ public static Cfloat sinh(Cfloat x) { return new Cfloat(sinh(x.r)*cos(x.i),cosh(x.r)*sin(x.i)); }
/** * Returns the cosine of a complex number. * @param x a complex number. * @return the cosine. */ public static Cfloat cos(Cfloat x) { return new Cfloat(cos(x.r)*cosh(x.i),-sin(x.r)*sinh(x.i)); }
void apply(float[] cx, 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.sin(ct); cy[ir] = ce.r; cy[ii] = ce.i; } } void apply(double[] cx, double[] cy) {
/** * Returns the hyperbolic cosine of a complex number. * @param x a complex number. * @return the hyperbolic cosine. */ public static Cfloat cosh(Cfloat x) { return new Cfloat(cosh(x.r)*cos(x.i),sinh(x.r)*sin(x.i)); }
/** * 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 sine of a complex number. * @param x a complex number. * @return the sine. */ public static Cfloat sin(Cfloat x) { return new Cfloat(sin(x.r)*cosh(x.i),cos(x.r)*sinh(x.i)); }
/** * Returns the complex number (r*cos(a),r*sin(a)). * @param r the polar radius. * @param a the polar angle. * @return the complex number. */ public static Cfloat polar(float r, float a) { return new Cfloat(r*cos(a),r*sin(a)); }
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))); }