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)
        AbsoluteDifference 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.
      • showInts

        @Deprecated
        public static String showInts​(int[] inta)
        Deprecated.
        use Arrays.toString(arr)
      • showInts

        public static String showInts​(List<Integer> intList)
        Deprecated.
        use List.toString()
      • showInts

        public static void showInts​(int[] inta,
                                    Formatter f)
        Deprecated.
        use Arrays.toString(arr)
      • showBytes

        public static String showBytes​(byte[] buff)
        Deprecated.
        use Arrays.toString(arr)
      • showBytes

        public static void showBytes​(byte[] buff,
                                     Formatter f)
        Deprecated.
        use Arrays.toString(arr)
      • showBits

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

        public static boolean compare​(byte[] raw1,
                                      byte[] raw2,
                                      Formatter f)
      • compare

        public static boolean compare​(float[] raw1,
                                      float[] raw2,
                                      Formatter f)
      • compare

        public static boolean compare​(int[] raw1,
                                      int[] raw2,
                                      Formatter f)
      • compare

        @Deprecated
        public static int compare​(int x,
                                  int y)
        Deprecated.
        use Integer.compare(x, y)
      • compare

        @Deprecated
        public static int compare​(long x,
                                  long y)
        Deprecated.
        use Long.compare(x, y)
      • getSize

        @Deprecated
        public static int getSize​(Iterable ii)
        Deprecated.
        use Iterables.size(Iterable it)
      • getList

        @Deprecated
        public static List getList​(Iterable ii)
        Deprecated.
        use ImmutableList.copyOf(iterator) or Lists.newArrayList(iterator)