| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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_CONVERSIONS_H_ | 5 #ifndef V8_CONVERSIONS_H_ |
| 6 #define V8_CONVERSIONS_H_ | 6 #define V8_CONVERSIONS_H_ |
| 7 | 7 |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "src/checks.h" | 10 #include "src/checks.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 } | 34 } |
| 35 | 35 |
| 36 | 36 |
| 37 inline bool isBinaryDigit(int x) { | 37 inline bool isBinaryDigit(int x) { |
| 38 return x == '0' || x == '1'; | 38 return x == '0' || x == '1'; |
| 39 } | 39 } |
| 40 | 40 |
| 41 | 41 |
| 42 // The fast double-to-(unsigned-)int conversion routine does not guarantee | 42 // The fast double-to-(unsigned-)int conversion routine does not guarantee |
| 43 // rounding towards zero. | 43 // rounding towards zero. |
| 44 // For NaN and values outside the int range, return INT_MIN or INT_MAX. | 44 // If x is NaN, the result is INT_MIN. Otherwise the result is the argument x, |
| 45 // clamped to [INT_MIN, INT_MAX] and then rounded to an integer. |
| 45 inline int FastD2IChecked(double x) { | 46 inline int FastD2IChecked(double x) { |
| 46 if (!(x >= INT_MIN)) return INT_MIN; // Negation to catch NaNs. | 47 if (!(x >= INT_MIN)) return INT_MIN; // Negation to catch NaNs. |
| 47 if (x > INT_MAX) return INT_MAX; | 48 if (x > INT_MAX) return INT_MAX; |
| 48 return static_cast<int>(x); | 49 return static_cast<int>(x); |
| 49 } | 50 } |
| 50 | 51 |
| 51 | 52 |
| 52 // The fast double-to-(unsigned-)int conversion routine does not guarantee | 53 // The fast double-to-(unsigned-)int conversion routine does not guarantee |
| 53 // rounding towards zero. | 54 // rounding towards zero. |
| 54 // The result is unspecified if x is infinite or NaN, or if the rounded | 55 // The result is unspecified if x is infinite or NaN, or if the rounded |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 Object* number) { | 224 Object* number) { |
| 224 size_t result = 0; | 225 size_t result = 0; |
| 225 bool is_valid = TryNumberToSize(isolate, number, &result); | 226 bool is_valid = TryNumberToSize(isolate, number, &result); |
| 226 CHECK(is_valid); | 227 CHECK(is_valid); |
| 227 return result; | 228 return result; |
| 228 } | 229 } |
| 229 | 230 |
| 230 } } // namespace v8::internal | 231 } } // namespace v8::internal |
| 231 | 232 |
| 232 #endif // V8_CONVERSIONS_H_ | 233 #endif // V8_CONVERSIONS_H_ |
| OLD | NEW |