rendered paste bodypublic boolean equals(Complex c, int precision) {
precision-=(int)(Math.log(re)/Math.log(10)+1);
System.out.println("DEBUG:: subtraction is: "+(Math.log(re)/Math.log(10)+1));
System.out.println("DEBUG:: precision is: "+precision);
if (Math.abs(re - c.getRe()) > Math.pow(10, -precision))
return false;
if (Math.abs(im - c.getIm()) > Math.pow(10, -precision))
return false;
return true;
}
// JUnit test:
public void testEquals2(){
Complex a=new Complex(1.9999, -1.9999);
Complex b=new Complex(1.9998, -1.9998);
assertTrue(a.equals(b, 2));
assertTrue(a.equals(b, 3));
assertFalse(a.equals(b, 4));
}