| 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 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 | 346 |
| 347 template<typename T> inline T defaultMaximumForClamp() { return std::numeric_lim
its<T>::max(); } | 347 template<typename T> inline T defaultMaximumForClamp() { return std::numeric_lim
its<T>::max(); } |
| 348 // This basically reimplements C++11's std::numeric_limits<T>::lowest(). | 348 // This basically reimplements C++11's std::numeric_limits<T>::lowest(). |
| 349 template<typename T> inline T defaultMinimumForClamp() { return std::numeric_lim
its<T>::min(); } | 349 template<typename T> inline T defaultMinimumForClamp() { return std::numeric_lim
its<T>::min(); } |
| 350 template<> inline float defaultMinimumForClamp<float>() { return -std::numeric_l
imits<float>::max(); } | 350 template<> inline float defaultMinimumForClamp<float>() { return -std::numeric_l
imits<float>::max(); } |
| 351 template<> inline double defaultMinimumForClamp<double>() { return -std::numeric
_limits<double>::max(); } | 351 template<> inline double defaultMinimumForClamp<double>() { return -std::numeric
_limits<double>::max(); } |
| 352 | 352 |
| 353 // And, finally, the actual function for people to call. | 353 // And, finally, the actual function for people to call. |
| 354 template<typename LimitType, typename ValueType> inline LimitType clampTo(ValueT
ype value, LimitType min = defaultMinimumForClamp<LimitType>(), LimitType max =
defaultMaximumForClamp<LimitType>()) | 354 template<typename LimitType, typename ValueType> inline LimitType clampTo(ValueT
ype value, LimitType min = defaultMinimumForClamp<LimitType>(), LimitType max =
defaultMaximumForClamp<LimitType>()) |
| 355 { | 355 { |
| 356 // FIXME: Uncomment this after fixing all callsites which violate it. | 356 ASSERT(!std::isnan(static_cast<double>(value))); |
| 357 // ASSERT(!std::isnan(static_cast<double>(value))); | |
| 358 ASSERT(min <= max); // This also ensures |min| and |max| aren't NaN. | 357 ASSERT(min <= max); // This also ensures |min| and |max| aren't NaN. |
| 359 return ClampToHelper<LimitType, ValueType>::clampTo(value, min, max); | 358 return ClampToHelper<LimitType, ValueType>::clampTo(value, min, max); |
| 360 } | 359 } |
| 361 | 360 |
| 362 inline bool isWithinIntRange(float x) | 361 inline bool isWithinIntRange(float x) |
| 363 { | 362 { |
| 364 return x > static_cast<float>(std::numeric_limits<int>::min()) && x < static
_cast<float>(std::numeric_limits<int>::max()); | 363 return x > static_cast<float>(std::numeric_limits<int>::min()) && x < static
_cast<float>(std::numeric_limits<int>::max()); |
| 365 } | 364 } |
| 366 | 365 |
| 367 static size_t greatestCommonDivisor(size_t a, size_t b) | 366 static size_t greatestCommonDivisor(size_t a, size_t b) |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 if (i >> 2) | 420 if (i >> 2) |
| 422 log2 += 2, i >>= 2; | 421 log2 += 2, i >>= 2; |
| 423 if (i >> 1) | 422 if (i >> 1) |
| 424 log2 += 1; | 423 log2 += 1; |
| 425 return log2; | 424 return log2; |
| 426 } | 425 } |
| 427 | 426 |
| 428 } // namespace WTF | 427 } // namespace WTF |
| 429 | 428 |
| 430 #endif // #ifndef WTF_MathExtras_h | 429 #endif // #ifndef WTF_MathExtras_h |
| OLD | NEW |