Index: chrome/android/java/src/org/chromium/chrome/browser/util/MathUtils.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/util/MathUtils.java b/chrome/android/java/src/org/chromium/chrome/browser/util/MathUtils.java |
index 07ac76e1f36aabc00bc34b0f381f90daf50f87d2..77f90a7bed6b357111f9d65b895b6650d6ebdc41 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/util/MathUtils.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/util/MathUtils.java |
@@ -9,6 +9,9 @@ package org.chromium.chrome.browser.util; |
*/ |
public class MathUtils { |
+ /** A minimum difference to use when comparing floats for equality. */ |
+ public static final float EPSILON = 0.001f; |
+ |
private MathUtils() {} |
/** |
@@ -158,4 +161,14 @@ public class MathUtils { |
public static int compareLongs(long lhs, long rhs) { |
return lhs < rhs ? -1 : (lhs == rhs ? 0 : 1); |
} |
+ |
+ /** |
+ * Determine if two floats are equal. |
+ * @param f1 The first float to compare. |
+ * @param f2 The second float to compare. |
+ * @return True if the floats are equal. |
+ */ |
+ public static boolean areFloatsEqual(float f1, float f2) { |
+ return Math.abs(f1 - f2) < MathUtils.EPSILON; |
+ } |
} |