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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 | 227 |
228 // Floor(-0.0) == 0.0 | 228 // Floor(-0.0) == 0.0 |
229 inline double Floor(double x) { | 229 inline double Floor(double x) { |
230 #if V8_CC_MSVC | 230 #if V8_CC_MSVC |
231 if (x == 0) return x; // Fix for issue 3477. | 231 if (x == 0) return x; // Fix for issue 3477. |
232 #endif | 232 #endif |
233 return std::floor(x); | 233 return std::floor(x); |
234 } | 234 } |
235 | 235 |
236 inline double Pow(double x, double y) { | 236 inline double Pow(double x, double y) { |
| 237 if (std::isnan(y) || ((x == 1 || x == -1) && std::isinf(y))) { |
| 238 return std::numeric_limits<double>::quiet_NaN(); |
| 239 } |
237 #if (defined(__MINGW64_VERSION_MAJOR) && \ | 240 #if (defined(__MINGW64_VERSION_MAJOR) && \ |
238 (!defined(__MINGW64_VERSION_RC) || __MINGW64_VERSION_RC < 1)) || \ | 241 (!defined(__MINGW64_VERSION_RC) || __MINGW64_VERSION_RC < 1)) || \ |
239 defined(V8_OS_AIX) | 242 defined(V8_OS_AIX) |
240 // MinGW64 and AIX have a custom implementation for pow. This handles certain | 243 // MinGW64 and AIX have a custom implementation for pow. This handles certain |
241 // special cases that are different. | 244 // special cases that are different. |
242 if ((x == 0.0 || std::isinf(x)) && y != 0.0 && std::isfinite(y)) { | 245 if ((x == 0.0 || std::isinf(x)) && y != 0.0 && std::isfinite(y)) { |
243 double f; | 246 double f; |
244 double result = ((x == 0.0) ^ (y > 0)) ? V8_INFINITY : 0; | 247 double result = ((x == 0.0) ^ (y > 0)) ? V8_INFINITY : 0; |
245 /* retain sign if odd integer exponent */ | 248 /* retain sign if odd integer exponent */ |
246 return ((std::modf(y, &f) == 0.0) && (static_cast<int64_t>(y) & 1)) | 249 return ((std::modf(y, &f) == 0.0) && (static_cast<int64_t>(y) & 1)) |
(...skipping 1340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1587 byte* dst = reinterpret_cast<byte*>(p); | 1590 byte* dst = reinterpret_cast<byte*>(p); |
1588 for (size_t i = 0; i < sizeof(V); i++) { | 1591 for (size_t i = 0; i < sizeof(V); i++) { |
1589 dst[i] = src[sizeof(V) - i - 1]; | 1592 dst[i] = src[sizeof(V) - i - 1]; |
1590 } | 1593 } |
1591 #endif // V8_TARGET_LITTLE_ENDIAN | 1594 #endif // V8_TARGET_LITTLE_ENDIAN |
1592 } | 1595 } |
1593 } // namespace internal | 1596 } // namespace internal |
1594 } // namespace v8 | 1597 } // namespace v8 |
1595 | 1598 |
1596 #endif // V8_UTILS_H_ | 1599 #endif // V8_UTILS_H_ |
OLD | NEW |