/Users/lyon/j4p/src/sound/filterDesign/ComplexNumber.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:   ComplexNumber.java 
7     
8     
9    class ComplexNumber { 
10    
11       ComplexNumber(Root root) { 
12           real = -root.getReal(); 
13           imag = -root.getImag(); 
14       } 
15    
16       ComplexNumber(double d, double d1) { 
17           real = d; 
18           imag = d1; 
19       } 
20    
21       ComplexNumber(double d) { 
22           real = d; 
23           imag = 0.0D; 
24       } 
25    
26       ComplexNumber(ComplexNumber complexnumber, double d) { 
27           real = complexnumber.getReal(); 
28           imag = complexnumber.getImag(); 
29           gain = d; 
30       } 
31    
32       ComplexNumber(ComplexNumber complexnumber) { 
33           real = complexnumber.getReal(); 
34           imag = complexnumber.getImag(); 
35           gain = complexnumber.getGain(); 
36       } 
37    
38       ComplexNumber() { 
39           real = 0.0D; 
40           imag = 0.0D; 
41       } 
42    
43       public double getImag() { 
44           return imag; 
45       } 
46    
47       public double getReal() { 
48           return real; 
49       } 
50    
51       public double getGain() { 
52           return gain; 
53       } 
54    
55       public void setGain(double d) { 
56           gain = d; 
57       } 
58    
59       public void set(double d, double d1) { 
60           real = d; 
61           imag = d1; 
62       } 
63    
64       public void setImag(double d) { 
65           imag = d; 
66       } 
67    
68       public void setReal(double d) { 
69           real = d; 
70       } 
71    
72       public ComplexNumber add(ComplexNumber complexnumber) { 
73           return new ComplexNumber(real + complexnumber.getReal(), 
74                   imag + complexnumber.getImag()); 
75       } 
76    
77       public ComplexNumber sub(ComplexNumber complexnumber) { 
78           return new ComplexNumber(real - complexnumber.getReal(), 
79                   imag - complexnumber.getImag()); 
80       } 
81    
82       public ComplexNumber scale(double d) { 
83           return new ComplexNumber(real * d, imag * d); 
84       } 
85    
86       public boolean equals(ComplexNumber complexnumber) { 
87           return real == complexnumber.getReal() && 
88                   imag == complexnumber.getImag(); 
89       } 
90    
91       public ComplexNumber mul(ComplexNumber complexnumber) { 
92           return new ComplexNumber( 
93                   getReal() * complexnumber.getReal() - 
94                   getImag() * complexnumber.getImag(), 
95                   getReal() * complexnumber.getImag() + 
96                   getImag() * complexnumber.getReal()); 
97       } 
98    
99       public ComplexNumber div(ComplexNumber complexnumber) { 
100          ComplexNumber complexnumber1 = new ComplexNumber(this); 
101          div(complexnumber1, 
102                  complexnumber.getReal(), 
103                  complexnumber.getImag()); 
104          return complexnumber1; 
105      } 
106   
107      private static void div(ComplexNumber complexnumber, 
108                              double d, 
109                              double d1) { 
110          double d2; 
111          double d3; 
112          if (Math.abs(d) >= Math.abs(d1)) { 
113              double d4 = 1.0D / (d + d1 * (d1 / d)); 
114              d2 = 
115                      d4 * 
116                      (complexnumber.getReal() + 
117                      complexnumber.getImag() * (d1 / d)); 
118              d3 = 
119                      d4 * 
120                      (complexnumber.getImag() - 
121                      complexnumber.getReal() * (d1 / d)); 
122          } else { 
123              double d5 = 1.0D / (d * (d / d1) + d1); 
124              d2 = 
125                      d5 * 
126                      (complexnumber.getReal() * (d / d1) + 
127                      complexnumber.getImag()); 
128              d3 = 
129                      d5 * 
130                      (complexnumber.getImag() * (d / d1) - 
131                      complexnumber.getReal()); 
132          } 
133          complexnumber.setReal(d2); 
134          complexnumber.setImag(d3); 
135      } 
136   
137      public double abs() { 
138          return abs(real, imag); 
139      } 
140   
141      private static double abs(double d, double d1) { 
142          double d2 = Math.abs(d); 
143          double d3 = Math.abs(d1); 
144          if (d2 == 0.0D && d3 == 0.0D) 
145              return 0.0D; 
146          if (d2 >= d3) { 
147              double d4 = d1 / d; 
148              return d2 * Math.sqrt(1.0D + d4 * d4); 
149          } else { 
150              double d5 = d / d1; 
151              return d3 * Math.sqrt(1.0D + d5 * d5); 
152          } 
153      } 
154   
155      ComplexNumber sqrt() { 
156          double d1 = Math.sqrt(Math.sqrt(real * real + imag * imag)); 
157          double d; 
158          if (real >= 0.0D) 
159              d = Math.atan(imag / real) / 2D; 
160          else if (imag >= 0.0D) 
161              d = (Math.atan(imag / real) + 3.1415926535897931D) / 2D; 
162          else 
163              d = (Math.atan(imag / real) - 3.1415926535897931D) / 2D; 
164          double d2 = d1 * Math.cos(d); 
165          double d3 = d1 * Math.sin(d); 
166          return new ComplexNumber(d2, d3); 
167      } 
168   
169      double real; 
170      double imag; 
171      double gain; 
172  } 
173