Index: cc/base/math_util.h |
diff --git a/cc/base/math_util.h b/cc/base/math_util.h |
index a83ab4fdce34be03b56fd23ffe978262abbe69fb..93bca234c126e5c27f3cd2b3c0358418772b2e43 100644 |
--- a/cc/base/math_util.h |
+++ b/cc/base/math_util.h |
@@ -97,6 +97,18 @@ class CC_EXPORT MathUtil { |
return (d > 0.0) ? std::floor(d + 0.5) : std::ceil(d - 0.5); |
} |
+ // Rounds the given |value| to fixed precision. This makes amlost euqal |
vmpstr
2015/10/19 18:58:38
typo: amlost euqal -> almost equal
|
+ // floats (which differ by some threshold magnitude of floating point epsilon) |
+ // to be considered as same. |
+ // The |precision| should be >= 1 and |
+ // <= (std::numeric_limits<float>::digits10 - 1), i.e. 5, as floating point |
+ // precision of higher than that gives different values. For other |
+ // |precision|, this function returns the same |value|. |
+ // Examples: |
+ // RoundToFixedPrecision(7.33907556533813, 4) returns 7.339000225067138671875. |
+ // RoundToFixedPrecision(7.33907508850098, 4) returns 7.339000225067138671875. |
+ static float RoundToFixedPrecision(float value, int precision); |
+ |
// Returns true if rounded up value does not overflow, false otherwise. |
template <typename T> |
static bool VerifyRoundup(T n, T mul) { |