public static void assertRelativelyEquals(String msg,double expected,double actual,double relativeError){
  if (Double.isNaN(expected)) {
    Assert.assertTrue(msg,Double.isNaN(actual));
  }
 else   if (Double.isNaN(actual)) {
    Assert.assertTrue(msg,Double.isNaN(expected));
  }
 else   if (Double.isInfinite(actual) || Double.isInfinite(expected)) {
    Assert.assertEquals(expected,actual,relativeError);
  }
 else   if (expected == 0.0) {
    Assert.assertEquals(msg,actual,expected,relativeError);
  }
 else {
    double absError=FastMath.abs(expected) * relativeError;
    Assert.assertEquals(msg,expected,actual,absError);
  }
}

public static void assertRelativelyEquals ( String msg , double expected , double actual , double relativeError ) { if ( Double . isNaN ( expected ) ) { Assert . assertTrue ( msg , Double . isNaN ( actual ) ) ; } else if ( Double . isNaN ( actual ) ) { Assert . assertTrue ( msg , Double . isNaN ( expected ) ) ; } else if ( Double . isInfinite ( actual ) || Double . isInfinite ( expected ) ) { Assert . assertEquals ( expected , actual , relativeError ) ; } else if ( expected == 0.0 ) { Assert . assertEquals ( msg , actual , expected , relativeError ) ; } else { double absError = FastMath . abs ( expected ) * relativeError ; Assert . assertEquals ( msg , expected , actual , absError ) ; } }
verifies that the relative error in actual vs . expected is less than or equal to relativeerror . if expected is infinite or nan , actual must be the same ( nan or infinity of the same sign ) .
