Changeset 77045 in webkit for trunk/Source/JavaScriptCore/wtf/MathExtras.h
- Timestamp:
- Jan 28, 2011, 9:02:31 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/wtf/MathExtras.h
r74147 r77045 27 27 #define WTF_MathExtras_h 28 28 29 #include <algorithm> 29 30 #include <cmath> 30 31 #include <float.h> 32 #include <limits> 31 33 #include <stdlib.h> 32 34 … … 206 208 inline float grad2rad(float g) { return g * piFloat / 200.0f; } 207 209 210 inline int clampToInteger(double d) 211 { 212 const double minIntAsDouble = std::numeric_limits<int>::min(); 213 const double maxIntAsDouble = std::numeric_limits<int>::max(); 214 return static_cast<int>(std::max(std::min(d, maxIntAsDouble), minIntAsDouble)); 215 } 216 217 inline int clampToPositiveInteger(double d) 218 { 219 const double maxIntAsDouble = std::numeric_limits<int>::max(); 220 return static_cast<int>(std::max<double>(std::min(d, maxIntAsDouble), 0)); 221 } 222 223 inline int clampToInteger(float d) 224 { 225 const float minIntAsFloat = std::numeric_limits<int>::min(); 226 const float maxIntAsFloat = std::numeric_limits<int>::max(); 227 return static_cast<int>(std::max(std::min(d, maxIntAsFloat), minIntAsFloat)); 228 } 229 230 inline int clampToPositiveInteger(float d) 231 { 232 const float maxIntAsFloat = std::numeric_limits<int>::max(); 233 return static_cast<int>(std::max<float>(std::min(d, maxIntAsFloat), 0)); 234 } 235 208 236 #if !COMPILER(MSVC) && !COMPILER(WINSCW) && !(COMPILER(RVCT) && (OS(SYMBIAN) || PLATFORM(BREWMP))) 209 237 using std::isfinite;
Note:
See TracChangeset
for help on using the changeset viewer.