Java Utililty Methods Float Number Equal

List of utility methods to do Float Number Equal

Description

The list of methods to do Float Number Equal are organized into topic(s).

Method

booleanareFloatsEqual(float f1, float f2)
used to compare two floats which are tested for having (almost) the same value
return areFloatsEqual(f1, f2, 0.001F);
booleanareFloatsEqual(float f1, float f2)
are Floats Equal
return (Math.abs(f1 - f2) < 0.0000001);
booleanareFloatsEqual(Float one, Float two)
Checks if two floats are equal - handles nulls
boolean nullDiff = one == null ^ two == null;
boolean valueDiff = one != null && two != null && !one.equals(two);
return !nullDiff && !valueDiff;
booleanequal(float val1, float val2)
Checks if two floats are equal based on identity.
return Float.floatToIntBits(val1) == Float.floatToIntBits(val2);
booleanequals(float f1, float f2)
equals
return Math.abs(f1 - f2) < 0.0000001f;
booleanfloatEqual(float a, float b, float epsilon)
float Equal
return (Math.abs(a - b) < epsilon);
booleanfloatEqual(float f1, float f2)
Returns whether the two specified float value are equal.
float absDiff = Math.abs(f1 - f2);
return absDiff < FP_EQUALITY_THRESHOLD;
booleanfloatEquals(float a, float b)
Implements the semantics of Float#equals(Object) for two primitive floats.
return Float.floatToIntBits(a) == Float.floatToIntBits(b);
booleanfloatEquals(float x, float y)
float Equals
return Math.abs(x - y) < DELTA;