public class Misc extends Object
Modifier and Type | Field and Description |
---|---|
static double |
defaultMaxRelativeDiffDouble
The default maximum
relative difference that two doubles can have in
order to be deemed nearly equal . |
static float |
defaultMaxRelativeDiffFloat
The default maximum
relative difference that two floats can have in
order to be deemed nearly equal . |
static int |
objectSize |
static int |
referenceSize |
Constructor and Description |
---|
Misc() |
Modifier and Type | Method and Description |
---|---|
static double |
absoluteDifference(double a,
double b)
Same as
absoluteDifference(float, float) , but for doubles. |
static float |
absoluteDifference(float a,
float b)
Returns the absolute difference between two numbers, i.e.
|
static boolean |
compare(byte[] raw1,
byte[] raw2,
Formatter f) |
static void |
compare(float[] raw1,
float[] raw2,
Formatter f) |
static int |
compare(int x,
int y) |
static int |
compare(long x,
long y) |
static List |
getList(Iterable ii) |
static int |
getSize(Iterable ii) |
static boolean |
nearlyEquals(double a,
double b)
Returns the result of
nearlyEquals(double, double, double) , with defaultMaxRelativeDiffDouble . |
static boolean |
nearlyEquals(double a,
double b,
double maxRelDiff)
Same as
nearlyEquals(float, float, float) , but for doubles. |
static boolean |
nearlyEquals(float a,
float b)
Returns the result of
nearlyEquals(float, float, float) , with defaultMaxRelativeDiffFloat . |
static boolean |
nearlyEquals(float a,
float b,
float maxRelDiff)
Returns
true if a and b are nearly equal. |
static boolean |
nearlyEqualsAbs(double a,
double b,
double maxAbsDiff)
Same as
nearlyEqualsAbs(float, float, float) , but with doubles. |
static boolean |
nearlyEqualsAbs(float a,
float b,
float maxAbsDiff)
Check if two numbers are nearly equal with given absolute tolerance.
|
static double |
relativeDifference(double a,
double b)
Same as
relativeDifference(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) |
static void |
showBytes(byte[] buff,
Formatter f) |
static String |
showInts(int[] inta) |
static void |
showInts(int[] inta,
Formatter f) |
static String |
showInts(List<Integer> intList) |
static String |
stackTraceToString(StackTraceElement[] stackTrace) |
public static final int referenceSize
public static final int objectSize
public static final float defaultMaxRelativeDiffFloat
relative difference
that two floats can have in
order to be deemed nearly equal
.public static final double defaultMaxRelativeDiffDouble
relative difference
that two doubles can have in
order to be deemed nearly equal
.public static float absoluteDifference(float a, float b)
|a - b|
.a
- first number.b
- second number.public static double absoluteDifference(double a, double b)
absoluteDifference(float, float)
, but for doubles.public static float relativeDifference(float a, float b)
|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
.
a
- first number.b
- second number.public static double relativeDifference(double a, double b)
relativeDifference(float, float)
, but for doubles.public static boolean nearlyEquals(float a, float b)
nearlyEquals(float, float, float)
, with defaultMaxRelativeDiffFloat
.public static boolean nearlyEquals(float a, float b, float maxRelDiff)
true
if a
and b
are nearly equal. Specifically, it checks whether the
relative difference
of the two numbers is less than maxRelDiff
.a
- first number.b
- second number.maxRelDiff
- the maximum relative difference
the two numbers may have.true
if a
and b
are nearly equal.public static boolean nearlyEquals(double a, double b)
nearlyEquals(double, double, double)
, with defaultMaxRelativeDiffDouble
.public static boolean nearlyEquals(double a, double b, double maxRelDiff)
nearlyEquals(float, float, float)
, but for doubles.public static boolean nearlyEqualsAbs(float a, float b, float maxAbsDiff)
a
- first number.b
- second number.maxAbsDiff
- the maximum absolute difference
the two numbers may have.public static boolean nearlyEqualsAbs(double a, double b, double maxAbsDiff)
nearlyEqualsAbs(float, float, float)
, but with doubles.public static String showInts(int[] inta)
public static void showInts(int[] inta, Formatter f)
public static String showBytes(byte[] buff)
public static void showBytes(byte[] buff, Formatter f)
public static int getSize(Iterable ii)
public static String showBits(byte[] bytes)
public static boolean compare(byte[] raw1, byte[] raw2, Formatter f)
public static void compare(float[] raw1, float[] raw2, Formatter f)
public static int compare(int x, int y)
public static int compare(long x, long y)
public static String stackTraceToString(StackTraceElement[] stackTrace)