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> |
| 11 #include <cmath> |
11 | 12 |
12 #include "include/v8.h" | 13 #include "include/v8.h" |
13 #include "src/allocation.h" | 14 #include "src/allocation.h" |
14 #include "src/base/logging.h" | 15 #include "src/base/logging.h" |
15 #include "src/base/macros.h" | 16 #include "src/base/macros.h" |
16 #include "src/base/platform/platform.h" | 17 #include "src/base/platform/platform.h" |
17 #include "src/globals.h" | 18 #include "src/globals.h" |
18 #include "src/list.h" | 19 #include "src/list.h" |
19 #include "src/vector.h" | 20 #include "src/vector.h" |
20 | 21 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 } | 134 } |
134 | 135 |
135 | 136 |
136 // Returns the absolute value of its argument. | 137 // Returns the absolute value of its argument. |
137 template <typename T> | 138 template <typename T> |
138 T Abs(T a) { | 139 T Abs(T a) { |
139 return a < 0 ? -a : a; | 140 return a < 0 ? -a : a; |
140 } | 141 } |
141 | 142 |
142 | 143 |
| 144 // Floor(-0.0) == 0.0 |
| 145 inline double Floor(double x) { |
| 146 #ifdef _MSC_VER |
| 147 if (x == 0) return x; // Fix for issue 3477. |
| 148 #endif |
| 149 return std::floor(x); |
| 150 } |
| 151 |
| 152 |
143 // TODO(svenpanne) Clean up the whole power-of-2 mess. | 153 // TODO(svenpanne) Clean up the whole power-of-2 mess. |
144 inline int32_t WhichPowerOf2Abs(int32_t x) { | 154 inline int32_t WhichPowerOf2Abs(int32_t x) { |
145 return (x == kMinInt) ? 31 : WhichPowerOf2(Abs(x)); | 155 return (x == kMinInt) ? 31 : WhichPowerOf2(Abs(x)); |
146 } | 156 } |
147 | 157 |
148 | 158 |
149 // Obtains the unsigned type corresponding to T | 159 // Obtains the unsigned type corresponding to T |
150 // available in C++11 as std::make_unsigned | 160 // available in C++11 as std::make_unsigned |
151 template<typename T> | 161 template<typename T> |
152 struct make_unsigned { | 162 struct make_unsigned { |
(...skipping 1368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1521 } | 1531 } |
1522 | 1532 |
1523 *index = result; | 1533 *index = result; |
1524 return true; | 1534 return true; |
1525 } | 1535 } |
1526 | 1536 |
1527 | 1537 |
1528 } } // namespace v8::internal | 1538 } } // namespace v8::internal |
1529 | 1539 |
1530 #endif // V8_UTILS_H_ | 1540 #endif // V8_UTILS_H_ |
OLD | NEW |