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
Estimates object size in bytes
|
static int |
referenceSize
Estimates pointer size in bytes
|
Constructor and Description |
---|
Misc() |
Modifier and Type | Method and 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 boolean |
nearlyEquals(double a,
double b)
RelativeDifference is less than
defaultMaxRelativeDiffDouble . |
static boolean |
nearlyEquals(double a,
double b,
double maxRelDiff)
RelativeDifference is less than maxRelDiff.
|
static boolean |
nearlyEquals(float a,
float b)
RelativeDifference is less than
defaultMaxRelativeDiffFloat . |
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 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) |
public static final double defaultMaxRelativeDiffDouble
relative difference
that two doubles can have in
order to be deemed nearly equal
.public static final float defaultMaxRelativeDiffFloat
relative difference
that two floats can have in
order to be deemed nearly equal
.public static final int objectSize
public static final int referenceSize
public static double absoluteDifference(double a, double b)
|a - b|
.public static float absoluteDifference(float a, float b)
|a - b|
.public static boolean compare(byte[] raw1, byte[] raw2, Formatter f)
public static boolean compare(float[] raw1, float[] raw2, Formatter f)
public static boolean compare(int[] raw1, int[] raw2, Formatter f)
public static boolean nearlyEquals(double a, double b)
defaultMaxRelativeDiffDouble
.public static boolean nearlyEquals(double a, double b, double maxRelDiff)
public static boolean nearlyEquals(float a, float b)
defaultMaxRelativeDiffFloat
.public static boolean nearlyEquals(float a, float b, float maxRelDiff)
public static boolean nearlyEqualsAbs(double a, double b, double maxAbsDiff)
public static boolean nearlyEqualsAbs(float a, float b, float maxAbsDiff)
public static double relativeDifference(double a, double b)
relativeDifference(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 String showBits(byte[] bytes)