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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 | 203 |
204 | 204 |
205 // Floor(-0.0) == 0.0 | 205 // Floor(-0.0) == 0.0 |
206 inline double Floor(double x) { | 206 inline double Floor(double x) { |
207 #if V8_CC_MSVC | 207 #if V8_CC_MSVC |
208 if (x == 0) return x; // Fix for issue 3477. | 208 if (x == 0) return x; // Fix for issue 3477. |
209 #endif | 209 #endif |
210 return std::floor(x); | 210 return std::floor(x); |
211 } | 211 } |
212 | 212 |
| 213 inline double Pow(double x, double y) { |
| 214 #if (defined(__MINGW64_VERSION_MAJOR) && \ |
| 215 (!defined(__MINGW64_VERSION_RC) || __MINGW64_VERSION_RC < 1)) || \ |
| 216 defined(V8_OS_AIX) |
| 217 // MinGW64 and AIX have a custom implementation for pow. This handles certain |
| 218 // special cases that are different. |
| 219 if ((x == 0.0 || std::isinf(x)) && y != 0.0 && std::isfinite(y)) { |
| 220 double f; |
| 221 double result = ((x == 0.0) ^ (y > 0)) ? V8_INFINITY : 0; |
| 222 /* retain sign if odd integer exponent */ |
| 223 return ((std::modf(y, &f) == 0.0) && (static_cast<int64_t>(y) & 1)) |
| 224 ? copysign(result, x) |
| 225 : result; |
| 226 } |
| 227 |
| 228 if (x == 2.0) { |
| 229 int y_int = static_cast<int>(y); |
| 230 if (y == y_int) { |
| 231 return std::ldexp(1.0, y_int); |
| 232 } |
| 233 } |
| 234 #endif |
| 235 return std::pow(x, y); |
| 236 } |
213 | 237 |
214 // TODO(svenpanne) Clean up the whole power-of-2 mess. | 238 // TODO(svenpanne) Clean up the whole power-of-2 mess. |
215 inline int32_t WhichPowerOf2Abs(int32_t x) { | 239 inline int32_t WhichPowerOf2Abs(int32_t x) { |
216 return (x == kMinInt) ? 31 : WhichPowerOf2(Abs(x)); | 240 return (x == kMinInt) ? 31 : WhichPowerOf2(Abs(x)); |
217 } | 241 } |
218 | 242 |
219 | 243 |
220 // Obtains the unsigned type corresponding to T | 244 // Obtains the unsigned type corresponding to T |
221 // available in C++11 as std::make_unsigned | 245 // available in C++11 as std::make_unsigned |
222 template<typename T> | 246 template<typename T> |
(...skipping 1312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1535 } | 1559 } |
1536 | 1560 |
1537 static inline void WriteUnalignedUInt32(void* p, uint32_t value) { | 1561 static inline void WriteUnalignedUInt32(void* p, uint32_t value) { |
1538 WriteUnalignedValue(p, value); | 1562 WriteUnalignedValue(p, value); |
1539 } | 1563 } |
1540 | 1564 |
1541 } // namespace internal | 1565 } // namespace internal |
1542 } // namespace v8 | 1566 } // namespace v8 |
1543 | 1567 |
1544 #endif // V8_UTILS_H_ | 1568 #endif // V8_UTILS_H_ |
OLD | NEW |