diff options
author | Ben Murdoch <benm@google.com> | 2011-07-13 10:14:36 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2011-07-13 11:03:14 +0100 |
commit | d0147a863b872ecaa451ab0dce2a348760e99e2c (patch) | |
tree | b4819830b7ab03f384ed8ab83734ac0f46193263 /Source/JavaScriptCore/wtf | |
parent | 65b45b34343dc5d5b9dbeda52e9de428e146c8f7 (diff) | |
download | external_webkit-d0147a863b872ecaa451ab0dce2a348760e99e2c.zip external_webkit-d0147a863b872ecaa451ab0dce2a348760e99e2c.tar.gz external_webkit-d0147a863b872ecaa451ab0dce2a348760e99e2c.tar.bz2 |
Merge WebKit at branches/chromium/742 r89068: Initial merge by Git.
Take us to top of Chrome 12 release branch (12.0.742.130)
Change-Id: I4408a97e343a118cf4a1bb9d71367bcc2c16ae48
Diffstat (limited to 'Source/JavaScriptCore/wtf')
-rw-r--r-- | Source/JavaScriptCore/wtf/MathExtras.h | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/Source/JavaScriptCore/wtf/MathExtras.h b/Source/JavaScriptCore/wtf/MathExtras.h index fac187c..f1b13a5 100644 --- a/Source/JavaScriptCore/wtf/MathExtras.h +++ b/Source/JavaScriptCore/wtf/MathExtras.h @@ -220,17 +220,27 @@ inline int clampToPositiveInteger(double d) return static_cast<int>(std::max<double>(std::min(d, maxIntAsDouble), 0)); } -inline int clampToInteger(float d) +inline int clampToInteger(float x) { - const float minIntAsFloat = static_cast<float>(std::numeric_limits<int>::min()); - const float maxIntAsFloat = static_cast<float>(std::numeric_limits<int>::max()); - return static_cast<int>(std::max(std::min(d, maxIntAsFloat), minIntAsFloat)); + static const int s_intMax = std::numeric_limits<int>::max(); + static const int s_intMin = std::numeric_limits<int>::min(); + + if (x >= static_cast<float>(s_intMax)) + return s_intMax; + if (x < static_cast<float>(s_intMin)) + return s_intMin; + return static_cast<int>(x); } -inline int clampToPositiveInteger(float d) +inline int clampToPositiveInteger(float x) { - const float maxIntAsFloat = static_cast<float>(std::numeric_limits<int>::max()); - return static_cast<int>(std::max<float>(std::min(d, maxIntAsFloat), 0)); + static const int s_intMax = std::numeric_limits<int>::max(); + + if (x >= static_cast<float>(s_intMax)) + return s_intMax; + if (x < 0) + return 0; + return static_cast<int>(x); } inline int clampToInteger(unsigned value) |