OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 const double maxIntAsDouble = std::numeric_limits<int>::max(); | 213 const double maxIntAsDouble = std::numeric_limits<int>::max(); |
214 return static_cast<int>(std::max(std::min(d, maxIntAsDouble), minIntAsDouble
)); | 214 return static_cast<int>(std::max(std::min(d, maxIntAsDouble), minIntAsDouble
)); |
215 } | 215 } |
216 | 216 |
217 inline int clampToPositiveInteger(double d) | 217 inline int clampToPositiveInteger(double d) |
218 { | 218 { |
219 const double maxIntAsDouble = std::numeric_limits<int>::max(); | 219 const double maxIntAsDouble = std::numeric_limits<int>::max(); |
220 return static_cast<int>(std::max<double>(std::min(d, maxIntAsDouble), 0)); | 220 return static_cast<int>(std::max<double>(std::min(d, maxIntAsDouble), 0)); |
221 } | 221 } |
222 | 222 |
223 inline int clampToInteger(float d) | 223 inline int clampToInteger(float x) |
224 { | 224 { |
225 const float minIntAsFloat = static_cast<float>(std::numeric_limits<int>::min
()); | 225 static const int s_intMax = std::numeric_limits<int>::max(); |
226 const float maxIntAsFloat = static_cast<float>(std::numeric_limits<int>::max
()); | 226 static const int s_intMin = std::numeric_limits<int>::min(); |
227 return static_cast<int>(std::max(std::min(d, maxIntAsFloat), minIntAsFloat))
; | 227 |
| 228 if (x >= static_cast<float>(s_intMax)) |
| 229 return s_intMax; |
| 230 if (x < static_cast<float>(s_intMin)) |
| 231 return s_intMin; |
| 232 return static_cast<int>(x); |
228 } | 233 } |
229 | 234 |
230 inline int clampToPositiveInteger(float d) | 235 inline int clampToPositiveInteger(float x) |
231 { | 236 { |
232 const float maxIntAsFloat = static_cast<float>(std::numeric_limits<int>::max
()); | 237 static const int s_intMax = std::numeric_limits<int>::max(); |
233 return static_cast<int>(std::max<float>(std::min(d, maxIntAsFloat), 0)); | 238 |
| 239 if (x >= static_cast<float>(s_intMax)) |
| 240 return s_intMax; |
| 241 if (x < 0) |
| 242 return 0; |
| 243 return static_cast<int>(x); |
234 } | 244 } |
235 | 245 |
236 inline int clampToInteger(unsigned value) | 246 inline int clampToInteger(unsigned value) |
237 { | 247 { |
238 return static_cast<int>(std::min(value, static_cast<unsigned>(std::numeric_l
imits<int>::max()))); | 248 return static_cast<int>(std::min(value, static_cast<unsigned>(std::numeric_l
imits<int>::max()))); |
239 } | 249 } |
240 | 250 |
241 #if !COMPILER(MSVC) && !(COMPILER(RVCT) && PLATFORM(BREWMP)) && !OS(SOLARIS) &&
!OS(SYMBIAN) | 251 #if !COMPILER(MSVC) && !(COMPILER(RVCT) && PLATFORM(BREWMP)) && !OS(SOLARIS) &&
!OS(SYMBIAN) |
242 using std::isfinite; | 252 using std::isfinite; |
243 using std::isinf; | 253 using std::isinf; |
244 using std::isnan; | 254 using std::isnan; |
245 using std::signbit; | 255 using std::signbit; |
246 #endif | 256 #endif |
247 | 257 |
248 #endif // #ifndef WTF_MathExtras_h | 258 #endif // #ifndef WTF_MathExtras_h |
OLD | NEW |