Package ucar.nc2.util
Class Misc
- java.lang.Object
-
- ucar.nc2.util.Misc
-
public class Misc extends Object
Miscellaneous static routines.
-
-
Field Summary
Fields Modifier and Type Field Description static double
defaultMaxRelativeDiffDouble
The default maximumrelative difference
that two doubles can have in order to be deemednearly equal
.static float
defaultMaxRelativeDiffFloat
The default maximumrelative difference
that two floats can have in order to be deemednearly equal
.static int
objectSize
Estimates object size in bytesstatic int
referenceSize
Estimates pointer size in bytes
-
Constructor Summary
Constructors Constructor Description Misc()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static double
absoluteDifference(double a, double b)
The absolute difference between two doubles, i.e.static float
absoluteDifference(float a, float b)
The absolute difference between two floats, i.e.static boolean
compare(byte[] raw1, byte[] raw2, Formatter f)
static boolean
compare(float[] raw1, float[] raw2, Formatter f)
static boolean
compare(int[] raw1, int[] raw2, Formatter f)
static int
compare(int x, int y)
Deprecated.use Integer.compare(x, y)static int
compare(long x, long y)
Deprecated.use Long.compare(x, y)static List
getList(Iterable ii)
Deprecated.use ImmutableList.copyOf(iterator) or Lists.newArrayList(iterator)static int
getSize(Iterable ii)
Deprecated.use Iterables.size(Iterable it)static boolean
nearlyEquals(double a, double b)
AbsoluteDifference is less thandefaultMaxRelativeDiffDouble
.static boolean
nearlyEquals(double a, double b, double maxRelDiff)
RelativeDifference is less than maxRelDiff.static boolean
nearlyEquals(float a, float b)
AbsoluteDifference is less thandefaultMaxRelativeDiffFloat
.static boolean
nearlyEquals(float a, float b, float maxRelDiff)
RelativeDifference is less than maxRelDiff.static boolean
nearlyEqualsAbs(double a, double b, double maxAbsDiff)
AbsoluteDifference is less than maxAbsDiff.static boolean
nearlyEqualsAbs(float a, float b, float maxAbsDiff)
AbsoluteDifference is less than maxAbsDiff.static double
relativeDifference(double a, double b)
Same asrelativeDifference(float, float)
, but for doubles.static float
relativeDifference(float a, float b)
Returns the relative difference between two numbers, i.e.static String
showBits(byte[] bytes)
static String
showBytes(byte[] buff)
Deprecated.use Arrays.toString(arr)static void
showBytes(byte[] buff, Formatter f)
Deprecated.use Arrays.toString(arr)static String
showInts(int[] inta)
Deprecated.use Arrays.toString(arr)static void
showInts(int[] inta, Formatter f)
Deprecated.use Arrays.toString(arr)static String
showInts(List<Integer> intList)
Deprecated.use List.toString()static String
stackTraceToString(StackTraceElement[] stackTrace)
Deprecated.do not use
-
-
-
Field Detail
-
referenceSize
public static final int referenceSize
Estimates pointer size in bytes- See Also:
- Constant Field Values
-
objectSize
public static final int objectSize
Estimates object size in bytes- See Also:
- Constant Field Values
-
defaultMaxRelativeDiffFloat
public static final float defaultMaxRelativeDiffFloat
The default maximumrelative difference
that two floats can have in order to be deemednearly equal
.- See Also:
- Constant Field Values
-
defaultMaxRelativeDiffDouble
public static final double defaultMaxRelativeDiffDouble
The default maximumrelative difference
that two doubles can have in order to be deemednearly equal
.- See Also:
- Constant Field Values
-
-
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
, ora
andb
are extremely close, traditional relative difference calculation breaks down. So, in those instances, we compute the difference relative toFloat.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
-
relativeDifference
public static double relativeDifference(double a, double b)
Same asrelativeDifference(float, float)
, but for doubles.
-
nearlyEquals
public static boolean nearlyEquals(float a, float b)
AbsoluteDifference is less thandefaultMaxRelativeDiffFloat
.
-
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)
AbsoluteDifference is less thandefaultMaxRelativeDiffDouble
.
-
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 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)
-
stackTraceToString
@Deprecated public static String stackTraceToString(StackTraceElement[] stackTrace)
Deprecated.do not use
-
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)
-
-