| 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_INL_H_ | 5 #ifndef V8_CONVERSIONS_INL_H_ |
| 6 #define V8_CONVERSIONS_INL_H_ | 6 #define V8_CONVERSIONS_INL_H_ |
| 7 | 7 |
| 8 #include <float.h> // Required for DBL_MAX and on Win32 for finite() | 8 #include <float.h> // Required for DBL_MAX and on Win32 for finite() |
| 9 #include <limits.h> // Required for INT_MAX etc. | 9 #include <limits.h> // Required for INT_MAX etc. |
| 10 #include <stdarg.h> | 10 #include <stdarg.h> |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 return !IsMinusZero(value) && value >= kMinInt && value <= kMaxInt && | 115 return !IsMinusZero(value) && value >= kMinInt && value <= kMaxInt && |
| 116 value == FastI2D(FastD2I(value)); | 116 value == FastI2D(FastD2I(value)); |
| 117 } | 117 } |
| 118 | 118 |
| 119 | 119 |
| 120 bool IsUint32Double(double value) { | 120 bool IsUint32Double(double value) { |
| 121 return !IsMinusZero(value) && value >= 0 && value <= kMaxUInt32 && | 121 return !IsMinusZero(value) && value >= 0 && value <= kMaxUInt32 && |
| 122 value == FastUI2D(FastD2UI(value)); | 122 value == FastUI2D(FastD2UI(value)); |
| 123 } | 123 } |
| 124 | 124 |
| 125 bool DoubleToUint32(double value, uint32_t* uint32_value) { |
| 126 if (IsMinusZero(value) || value < 0 || value > kMaxUInt32) { |
| 127 return false; |
| 128 } |
| 129 // TODO(leszeks): We maybe could be faster than FastD2UI here, since we only |
| 130 // care about the value being valid if the conversion is valid. |
| 131 uint32_t converted_value = FastD2UI(value); |
| 132 if (value == FastUI2D(converted_value)) { |
| 133 *uint32_value = converted_value; |
| 134 return true; |
| 135 } |
| 136 return false; |
| 137 } |
| 125 | 138 |
| 126 int32_t NumberToInt32(Object* number) { | 139 int32_t NumberToInt32(Object* number) { |
| 127 if (number->IsSmi()) return Smi::cast(number)->value(); | 140 if (number->IsSmi()) return Smi::cast(number)->value(); |
| 128 return DoubleToInt32(number->Number()); | 141 return DoubleToInt32(number->Number()); |
| 129 } | 142 } |
| 130 | 143 |
| 131 uint32_t NumberToUint32(Object* number) { | 144 uint32_t NumberToUint32(Object* number) { |
| 132 if (number->IsSmi()) return Smi::cast(number)->value(); | 145 if (number->IsSmi()) return Smi::cast(number)->value(); |
| 133 return DoubleToUint32(number->Number()); | 146 return DoubleToUint32(number->Number()); |
| 134 } | 147 } |
| (...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 buffer[buffer_pos] = '\0'; | 797 buffer[buffer_pos] = '\0'; |
| 785 | 798 |
| 786 double converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent); | 799 double converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent); |
| 787 return (sign == NEGATIVE) ? -converted : converted; | 800 return (sign == NEGATIVE) ? -converted : converted; |
| 788 } | 801 } |
| 789 | 802 |
| 790 } // namespace internal | 803 } // namespace internal |
| 791 } // namespace v8 | 804 } // namespace v8 |
| 792 | 805 |
| 793 #endif // V8_CONVERSIONS_INL_H_ | 806 #endif // V8_CONVERSIONS_INL_H_ |
| OLD | NEW |