1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| /**
* Compare two float arrays for equality.
*
* @param a1 the first array to compare
* @param a2 the second array to compare
* @return true if a1 and a2 are both null, or if a2 is of the same length
* as a1, and for each 0 <= i < a1.length, a1[i] == a2[i]
*/
public static boolean equals(float[] a1, float[] a2)
{
// Quick test which saves comparing elements of the same array, and also
// catches the case that both are null.
if (a1 == a2)
return true;
if (null == a1 || null == a2)
return false;
// Must use Float.compare to take into account NaN, +-0.
// If they're the same length, test each element
if (a1.length == a2.length) {
int i = a1.length;
while (--i >= 0)
if (Float.compare(a1[i], a2[i]) != 0)
return false;
return true;
}
return false;
} |
Partager