All pastes #68435 Raw Edit

smsie

public text v1 · immutable
#68435 ·published 2006-06-21 16:54 UTC
rendered paste body
public 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));
	}