| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_UTILS_H_ | 5 #ifndef V8_UTILS_H_ |
| 6 #define V8_UTILS_H_ | 6 #define V8_UTILS_H_ |
| 7 | 7 |
| 8 #include <limits.h> | 8 #include <limits.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 return a < b ? b : a; | 193 return a < b ? b : a; |
| 194 } | 194 } |
| 195 | 195 |
| 196 | 196 |
| 197 // Returns the minimum of the two parameters. | 197 // Returns the minimum of the two parameters. |
| 198 template <typename T> | 198 template <typename T> |
| 199 T Min(T a, T b) { | 199 T Min(T a, T b) { |
| 200 return a < b ? a : b; | 200 return a < b ? a : b; |
| 201 } | 201 } |
| 202 | 202 |
| 203 // Returns the maximum of the two parameters according to JavaScript semantics. |
| 204 template <typename T> |
| 205 T JSMax(T x, T y) { |
| 206 if (std::isnan(x)) return x; |
| 207 if (std::isnan(y)) return y; |
| 208 if (std::signbit(x) < std::signbit(y)) return x; |
| 209 return x > y ? x : y; |
| 210 } |
| 211 |
| 212 // Returns the maximum of the two parameters according to JavaScript semantics. |
| 213 template <typename T> |
| 214 T JSMin(T x, T y) { |
| 215 if (std::isnan(x)) return x; |
| 216 if (std::isnan(y)) return y; |
| 217 if (std::signbit(x) < std::signbit(y)) return y; |
| 218 return x > y ? y : x; |
| 219 } |
| 203 | 220 |
| 204 // Returns the absolute value of its argument. | 221 // Returns the absolute value of its argument. |
| 205 template <typename T> | 222 template <typename T> |
| 206 T Abs(T a) { | 223 T Abs(T a) { |
| 207 return a < 0 ? -a : a; | 224 return a < 0 ? -a : a; |
| 208 } | 225 } |
| 209 | 226 |
| 210 | 227 |
| 211 // Floor(-0.0) == 0.0 | 228 // Floor(-0.0) == 0.0 |
| 212 inline double Floor(double x) { | 229 inline double Floor(double x) { |
| (...skipping 1357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1570 byte* dst = reinterpret_cast<byte*>(p); | 1587 byte* dst = reinterpret_cast<byte*>(p); |
| 1571 for (size_t i = 0; i < sizeof(V); i++) { | 1588 for (size_t i = 0; i < sizeof(V); i++) { |
| 1572 dst[i] = src[sizeof(V) - i - 1]; | 1589 dst[i] = src[sizeof(V) - i - 1]; |
| 1573 } | 1590 } |
| 1574 #endif // V8_TARGET_LITTLE_ENDIAN | 1591 #endif // V8_TARGET_LITTLE_ENDIAN |
| 1575 } | 1592 } |
| 1576 } // namespace internal | 1593 } // namespace internal |
| 1577 } // namespace v8 | 1594 } // namespace v8 |
| 1578 | 1595 |
| 1579 #endif // V8_UTILS_H_ | 1596 #endif // V8_UTILS_H_ |
| OLD | NEW |