cdm/src/main/java/ucar/nc2/util/Misc.java
public static float relativeDifference(float a, float b) {
    float absDiff = absoluteDifference(a, b);

    if (Float.compare(a, b) == 0) {  // Shortcut: handles infinities and NaNs.
      return 0;
    } else if (a == 0 || b == 0 || absDiff < Float.MIN_NORMAL) {
      return absDiff / Float.MIN_NORMAL;
    } else {
      float maxAbsValue = Math.max(Math.abs(a), Math.abs(b));
      return absDiff / maxAbsValue;
    }
  }
public static float relativeDifference(float a, float b) {
    float absDiff = absoluteDifference(a, b);

    if (Float.compare(a, b) == 0) {  // Shortcut: handles infinities and NaNs.
      return 0;
    } else if (a == 0 || b == 0 || absDiff < Float.MIN_NORMAL) {
      return absDiff / Float.MIN_NORMAL;
    } else {
      float maxAbsValue = Math.max(Math.abs(a), Math.abs(b));
      return absDiff / maxAbsValue;
    }
  }
Returns the relative difference between two numbers, i.e. {@code |a - b| / max(|a|, |b|)}.
<p>
For cases where {@code a == 0}, {@code b == 0}, or {@code a} and {@code b} are extremely close, traditional
relative difference calculation breaks down. So, in those instances, we compute the difference relative to
{@link Float#MIN_NORMAL}, i.e. {@code |a - b| / Float.MIN_NORMAL}.

@param a  first number.
@param b  second number.
@return   the relative difference.
@see <a href="http://floating-point-gui.de/errors/comparison/">The Floating-Point Guide</a>
@see <a href="https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/">
Comparing Floating Point Numbers, 2012 Edition</a>