/Users/lyon/j4p/src/sound/filterDesign/Complex.java

1    package sound.filterDesign; 
2     
3    // Decompiled by Jad v1.5.8c. Copyright 2001 Pavel Kouznetsov. 
4    // Jad home page: http://www.geocities.com/kpdus/jad.html 
5    // Decompiler options: packimports(3)  
6    // Source File Name:   Complex.java 
7     
8     
9    class Complex { 
10    
11       Complex(double d, double d1) { 
12           real = d; 
13           imag = d1; 
14           minimum = 1E-10D; 
15       } 
16    
17       Complex(double d) { 
18           real = d; 
19           imag = 0.0D; 
20           minimum = 1E-10D; 
21       } 
22    
23       Complex(Complex complex) { 
24           real = complex.getReal(); 
25           imag = complex.getImag(); 
26           minimum = 1E-10D; 
27       } 
28    
29       Complex(Complex complex, int i) { 
30           real = -complex.getReal(); 
31           imag = -complex.getImag(); 
32           minimum = 1E-10D; 
33       } 
34    
35       Complex() { 
36           real = 0.0D; 
37           imag = 0.0D; 
38           minimum = 1E-10D; 
39       } 
40    
41       Complex(Root root) { 
42           real = -root.getReal(); 
43           imag = -root.getImag(); 
44           minimum = 1E-10D; 
45       } 
46    
47       public double getImag() { 
48           return imag; 
49       } 
50    
51       public double getReal() { 
52           return real; 
53       } 
54    
55       public void set(double d, double d1) { 
56           real = d; 
57           imag = d1; 
58       } 
59    
60       public void setImag(double d) { 
61           imag = d; 
62       } 
63    
64       public void setReal(double d) { 
65           real = d; 
66       } 
67    
68       public Complex add(Complex complex) { 
69           return new Complex(real + complex.getReal(), 
70                   imag + complex.getImag()); 
71       } 
72    
73       public Complex sub(Complex complex) { 
74           return new Complex(real - complex.getReal(), 
75                   imag - complex.getImag()); 
76       } 
77    
78       public Complex scale(double d) { 
79           return new Complex(real * d, imag * d); 
80       } 
81    
82       public boolean equals(Complex complex) { 
83           return real == complex.getReal() && imag == complex.getImag(); 
84       } 
85    
86       public Complex mul(Complex complex) { 
87           return new Complex( 
88                   getReal() * complex.getReal() - 
89                   getImag() * complex.getImag(), 
90                   getReal() * complex.getImag() + 
91                   getImag() * complex.getReal()); 
92       } 
93    
94       public Complex mul(double d) { 
95           return scale(d); 
96       } 
97    
98       public Complex div(double d) { 
99           return scale(1.0D / d); 
100      } 
101   
102      public Complex div(Complex complex) { 
103          Complex complex1 = new Complex(this); 
104          div(complex1, complex.getReal(), complex.getImag()); 
105          return complex1; 
106      } 
107   
108      private static void div(Complex complex, double d, double d1) { 
109          double d2; 
110          double d3; 
111          if (Math.abs(d) >= Math.abs(d1)) { 
112              double d4 = 1.0D / (d + d1 * (d1 / d)); 
113              d2 = d4 * (complex.getReal() + complex.getImag() * (d1 / d)); 
114              d3 = d4 * (complex.getImag() - complex.getReal() * (d1 / d)); 
115          } else { 
116              double d5 = 1.0D / (d * (d / d1) + d1); 
117              d2 = d5 * (complex.getReal() * (d / d1) + complex.getImag()); 
118              d3 = d5 * (complex.getImag() * (d / d1) - complex.getReal()); 
119          } 
120          complex.setReal(d2); 
121          complex.setImag(d3); 
122      } 
123   
124      public double abs() { 
125          return abs(real, imag); 
126      } 
127   
128      private static double abs(double d, double d1) { 
129          double d2 = Math.abs(d); 
130          double d3 = Math.abs(d1); 
131          if (d2 == 0.0D && d3 == 0.0D) 
132              return 0.0D; 
133          if (d2 >= d3) { 
134              double d4 = d1 / d; 
135              return d2 * Math.sqrt(1.0D + d4 * d4); 
136          } else { 
137              double d5 = d / d1; 
138              return d3 * Math.sqrt(1.0D + d5 * d5); 
139          } 
140      } 
141   
142      public Complex sqrt() { 
143          double d1 = Math.sqrt(Math.sqrt(real * real + imag * imag)); 
144          double d; 
145          if (real >= 0.0D) 
146              d = Math.atan(imag / real) / 2D; 
147          else if (imag >= 0.0D) 
148              d = (Math.atan(imag / real) + 3.1415926535897931D) / 2D; 
149          else 
150              d = (Math.atan(imag / real) - 3.1415926535897931D) / 2D; 
151          double d2 = d1 * Math.cos(d); 
152          double d3 = d1 * Math.sin(d); 
153          return new Complex(d2, d3); 
154      } 
155   
156      public Complex conj() { 
157          return new Complex(real, -imag); 
158      } 
159   
160      public Complex neg() { 
161          return new Complex(-real, -imag); 
162      } 
163   
164      public Complex pow(int i) { 
165          double d = Math.atan(imag / real); 
166          if (imag == 0.0D) 
167              d = real <= 0.0D ? -3.1415926535897931D : 0.0D; 
168          if (real == 0.0D) 
169              d = imag <= 0.0D ? -1.5707963267948966D : 1.5707963267948966D; 
170          double d1 = Math.pow(abs(), i); 
171          return new Complex(d1 * Math.cos((double) i * d), 
172                  d1 * Math.sin((double) i * d)); 
173      } 
174   
175      public Complex exp(Complex complex) { 
176          double d = Math.exp(complex.getReal()); 
177          return new Complex(d * Math.cos(complex.getImag()), 
178                  d * Math.sin(complex.getImag())); 
179      } 
180   
181      public void setMinimum(double d) { 
182          minimum = d; 
183      } 
184   
185      public double getMinimum() { 
186          return minimum; 
187      } 
188   
189      public void cleanMe() { 
190          if (Math.abs(real) < minimum) 
191              real = 0.0D; 
192          if (Math.abs(imag) < minimum) 
193              imag = 0.0D; 
194      } 
195   
196      public String toString() { 
197          if (real == 0.0D) 
198              return imag + "i"; 
199          if (imag == 0.0D) 
200              return String.valueOf(real); 
201          if (imag > 0.0D) 
202              return real + "+" + imag + "i"; 
203          else 
204              return real + "" + imag + "i"; 
205      } 
206   
207      double real; 
208      double imag; 
209      double minimum; 
210  } 
211