Fix rounding in FFT (fixes #2961) (#2962)

This commit is contained in:
leren1 2022-03-05 18:16:34 +01:00 committed by GitHub
parent 8bf74929e3
commit fe61eb2bdf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -142,8 +142,10 @@ public class FFT {
*/
public Complex divide(Complex z) {
Complex temp = new Complex();
temp.real = (this.real * z.real + this.img * z.img) / (z.abs() * z.abs());
temp.img = (this.img * z.real - this.real * z.img) / (z.abs() * z.abs());
double d = z.abs() * z.abs();
d = (double)Math.round(d * 1000000000d) / 1000000000d;
temp.real = (this.real * z.real + this.img * z.img) / (d);
temp.img = (this.img * z.real - this.real * z.img) / (d);
return temp;
}