No Tribble At All
From Huben's Wiki
Line 7: | Line 7: | ||
a + b = (a<sub>real</sub> + b<sub>real</sub>) + (a<sub>imag</sub> + b<sub>imag</sub>) | a + b = (a<sub>real</sub> + b<sub>real</sub>) + (a<sub>imag</sub> + b<sub>imag</sub>) | ||
− | a * b = (a<sub>real</sub> * b<sub>real</sub> - a<sub>imag</sub> | + | a * b = (a<sub>real</sub> * b<sub>real</sub> - a<sub>imag</sub> * b<sub>imag</sub>) + (a<sub>real</sub> * b<sub>imag</sub> + a<sub>imag</sub> * b<sub>real</sub>) |
+ | |||
+ | b. conjugate = b<sub>real</sub> - b<sub>imag</sub> | ||
a / b = (a * b.conjugate) / (b * b.conjugate) // note that b * b.conjugate is a real number, not complex. | a / b = (a * b.conjugate) / (b * b.conjugate) // note that b * b.conjugate is a real number, not complex. | ||
Line 45: | Line 47: | ||
{ | { | ||
// Complex c1 = new Complex(); | // Complex c1 = new Complex(); | ||
− | |||
− | |||
− | |||
− | |||
// implement toString before proceding further | // implement toString before proceding further | ||
// System.out.println(c1); // 0.0+0.0i | // System.out.println(c1); // 0.0+0.0i | ||
+ | // Complex c2 = new Complex(3); | ||
// System.out.println(c2); // 3.0+0.0i | // System.out.println(c2); // 3.0+0.0i | ||
+ | // Complex c3 = new Complex(-2, -5.5); | ||
// System.out.println(c3); // -2.0-5.5i | // System.out.println(c3); // -2.0-5.5i | ||
+ | // Complex c4 = new Complex(2, 3); | ||
// System.out.println(c4); // 2.0+3.0i | // System.out.println(c4); // 2.0+3.0i | ||
+ | // Complex c5 = new Complex(c4); | ||
// System.out.println(c5); // 2.0+3.0i | // System.out.println(c5); // 2.0+3.0i | ||
// System.out.println(c3.getReal()); // -2.0 | // System.out.println(c3.getReal()); // -2.0 |