Package ucar.nc2.util
Class Misc
java.lang.Object
ucar.nc2.util.Misc
Miscellaneous static routines.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleThe default maximumrelative differencethat two doubles can have in order to be deemednearly equal.static final floatThe default maximumrelative differencethat two floats can have in order to be deemednearly equal.static final intEstimates object size in bytesstatic final intEstimates pointer size in bytes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic doubleabsoluteDifference(double a, double b) The absolute difference between two doubles, i.e.static floatabsoluteDifference(float a, float b) The absolute difference between two floats, i.e.static booleanstatic booleanstatic booleanstatic intcompare(int x, int y) Deprecated.use Integer.compare(x, y)static intcompare(long x, long y) Deprecated.use Long.compare(x, y)static ListDeprecated.use ImmutableList.copyOf(iterator) or Lists.newArrayList(iterator)static intDeprecated.use Iterables.size(Iterable it)static booleannearlyEquals(double a, double b) AbsoluteDifference is less thandefaultMaxRelativeDiffDouble.static booleannearlyEquals(double a, double b, double maxRelDiff) RelativeDifference is less than maxRelDiff.static booleannearlyEquals(float a, float b) AbsoluteDifference is less thandefaultMaxRelativeDiffFloat.static booleannearlyEquals(float a, float b, float maxRelDiff) RelativeDifference is less than maxRelDiff.static booleannearlyEqualsAbs(double a, double b, double maxAbsDiff) AbsoluteDifference is less than maxAbsDiff.static booleannearlyEqualsAbs(float a, float b, float maxAbsDiff) AbsoluteDifference is less than maxAbsDiff.static doublerelativeDifference(double a, double b) Same asrelativeDifference(float, float), but for doubles.static floatrelativeDifference(float a, float b) Returns the relative difference between two numbers, i.e.static StringshowBits(byte[] bytes) static StringshowBytes(byte[] buff) Deprecated.use Arrays.toString(arr)static voidDeprecated.use Arrays.toString(arr)static StringshowInts(int[] inta) Deprecated.use Arrays.toString(arr)static voidDeprecated.use Arrays.toString(arr)static StringDeprecated.use List.toString()static StringstackTraceToString(StackTraceElement[] stackTrace) Deprecated.do not use
-
Field Details
-
referenceSize
public static final int referenceSizeEstimates pointer size in bytes- See Also:
-
objectSize
public static final int objectSizeEstimates object size in bytes- See Also:
-
defaultMaxRelativeDiffFloat
public static final float defaultMaxRelativeDiffFloatThe default maximumrelative differencethat two floats can have in order to be deemednearly equal.- See Also:
-
defaultMaxRelativeDiffDouble
public static final double defaultMaxRelativeDiffDoubleThe default maximumrelative differencethat two doubles can have in order to be deemednearly equal.- See Also:
-
-
Constructor Details
-
Misc
public Misc()
-
-
Method Details
-
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, oraandbare 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:
-
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.use Arrays.toString(arr) -
showInts
Deprecated.use List.toString() -
showInts
Deprecated.use Arrays.toString(arr) -
showBytes
Deprecated.use Arrays.toString(arr) -
showBytes
Deprecated.use Arrays.toString(arr) -
showBits
-
compare
-
compare
-
compare
-
compare
Deprecated.use Integer.compare(x, y) -
compare
Deprecated.use Long.compare(x, y) -
stackTraceToString
Deprecated.do not use -
getSize
Deprecated.use Iterables.size(Iterable it) -
getList
Deprecated.use ImmutableList.copyOf(iterator) or Lists.newArrayList(iterator)
-