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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 | 194 |
195 // Floor(-0.0) == 0.0 | 195 // Floor(-0.0) == 0.0 |
196 inline double Floor(double x) { | 196 inline double Floor(double x) { |
197 #if V8_CC_MSVC | 197 #if V8_CC_MSVC |
198 if (x == 0) return x; // Fix for issue 3477. | 198 if (x == 0) return x; // Fix for issue 3477. |
199 #endif | 199 #endif |
200 return std::floor(x); | 200 return std::floor(x); |
201 } | 201 } |
202 | 202 |
203 | 203 |
204 template <typename T> | |
205 bool SameValue(T x, T y) { | |
adamk
2015/07/14 18:26:58
Can you add a comment linking to:
http://www.ecma
bbudge
2015/07/14 20:26:24
Done.
| |
206 // SameValue(NaN, NaN) is true. | |
207 if (x != y) return std::isnan(x) && std::isnan(y); | |
208 // SameValue(0, -0) is false. | |
209 if (std::signbit(x) != std::signbit(y)) return false; | |
210 return true; | |
211 } | |
212 | |
213 | |
214 template <typename T> | |
215 bool SameValueZero(T x, T y) { | |
adamk
2015/07/14 18:26:58
And here linking to:
http://www.ecma-internationa
bbudge
2015/07/14 20:26:24
Done.
| |
216 if (x != y) return std::isnan(x) && std::isnan(y); | |
217 // SameValueZero doesn't distinguish between 0 and -0. | |
218 return true; | |
219 } | |
220 | |
221 | |
204 // TODO(svenpanne) Clean up the whole power-of-2 mess. | 222 // TODO(svenpanne) Clean up the whole power-of-2 mess. |
205 inline int32_t WhichPowerOf2Abs(int32_t x) { | 223 inline int32_t WhichPowerOf2Abs(int32_t x) { |
206 return (x == kMinInt) ? 31 : WhichPowerOf2(Abs(x)); | 224 return (x == kMinInt) ? 31 : WhichPowerOf2(Abs(x)); |
207 } | 225 } |
208 | 226 |
209 | 227 |
210 // Obtains the unsigned type corresponding to T | 228 // Obtains the unsigned type corresponding to T |
211 // available in C++11 as std::make_unsigned | 229 // available in C++11 as std::make_unsigned |
212 template<typename T> | 230 template<typename T> |
213 struct make_unsigned { | 231 struct make_unsigned { |
(...skipping 1534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1748 uint32_t* ptr = reinterpret_cast<uint32_t*>(p); | 1766 uint32_t* ptr = reinterpret_cast<uint32_t*>(p); |
1749 *ptr = c.u[0]; | 1767 *ptr = c.u[0]; |
1750 *(ptr + 1) = c.u[1]; | 1768 *(ptr + 1) = c.u[1]; |
1751 #endif // V8_TARGET_ARCH_MIPS | 1769 #endif // V8_TARGET_ARCH_MIPS |
1752 } | 1770 } |
1753 | 1771 |
1754 } // namespace internal | 1772 } // namespace internal |
1755 } // namespace v8 | 1773 } // namespace v8 |
1756 | 1774 |
1757 #endif // V8_UTILS_H_ | 1775 #endif // V8_UTILS_H_ |
OLD | NEW |