Package ucar.nc2.util

Class Misc


  • public class Misc
    extends Object
    Miscellaneous static routines.
    • Constructor Detail

      • Misc

        public Misc()
    • Method Detail

      • absoluteDifference

        public static float absoluteDifference​(float a,
                                               float b)
        The absolute difference between two floats, i.e. |a - b|.
      • absoluteDifference

        public static double absoluteDifference​(double a,
                                                double b)
        The absolute difference between two doubles, i.e. |a - b|.
      • relativeDifference

        public static float relativeDifference​(float a,
                                               float b)
        Returns the relative difference between two numbers, i.e. |a - b| / max(|a|, |b|).

        For cases where a == 0, b == 0, or a and b are extremely close, traditional relative difference calculation breaks down. So, in those instances, we compute the difference relative to Float.MIN_NORMAL, i.e. |a - b| / Float.MIN_NORMAL.

        Parameters:
        a - first number.
        b - second number.
        Returns:
        the relative difference.
        See Also:
        The Floating-Point Guide, Comparing Floating Point Numbers, 2012 Edition
      • nearlyEquals

        public static boolean nearlyEquals​(float a,
                                           float b)
        RelativeDifference is less than defaultMaxRelativeDiffFloat.
      • nearlyEquals

        public static boolean nearlyEquals​(float a,
                                           float b,
                                           float maxRelDiff)
        RelativeDifference is less than maxRelDiff.
      • nearlyEquals

        public static boolean nearlyEquals​(double a,
                                           double b,
                                           double maxRelDiff)
        RelativeDifference is less than maxRelDiff.
      • nearlyEqualsAbs

        public static boolean nearlyEqualsAbs​(float a,
                                              float b,
                                              float maxAbsDiff)
        AbsoluteDifference is less than maxAbsDiff.
      • nearlyEqualsAbs

        public static boolean nearlyEqualsAbs​(double a,
                                              double b,
                                              double maxAbsDiff)
        AbsoluteDifference is less than maxAbsDiff.
      • showBits

        public static String showBits​(byte[] bytes)
      • compare

        public static boolean compare​(byte[] raw1,
                                      byte[] raw2,
                                      Formatter f)
        For testing, use Truth.assertThat(raw1).isEqualTo(raw2)
      • compare

        public static boolean compare​(float[] raw1,
                                      float[] raw2,
                                      Formatter f)
        For testing, use Truth.assertThat(raw1).isEqualTo(raw2)
      • compare

        public static boolean compare​(int[] raw1,
                                      int[] raw2,
                                      Formatter f)
        For testing, use Truth.assertThat(raw1).isEqualTo(raw2)
      • showClassPath

        public static void showClassPath()