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 DoubleToUint32IfEqualToSelf(double value, uint32_t* uint32_value) { |
| 126 if (value < 0) return false; |
| 127 // TODO(leszeks): We maybe could be faster than FastD2UI here, since we only |
| 128 // care about the value being valid if the conversion is valid. |
| 129 uint32_t converted_value = FastD2UI(value); |
| 130 if (FastUI2D(converted_value) == value) { |
| 131 *uint32_value = converted_value; |
| 132 return true; |
| 133 } |
| 134 return false; |
| 135 } |
125 | 136 |
126 int32_t NumberToInt32(Object* number) { | 137 int32_t NumberToInt32(Object* number) { |
127 if (number->IsSmi()) return Smi::cast(number)->value(); | 138 if (number->IsSmi()) return Smi::cast(number)->value(); |
128 return DoubleToInt32(number->Number()); | 139 return DoubleToInt32(number->Number()); |
129 } | 140 } |
130 | 141 |
131 uint32_t NumberToUint32(Object* number) { | 142 uint32_t NumberToUint32(Object* number) { |
132 if (number->IsSmi()) return Smi::cast(number)->value(); | 143 if (number->IsSmi()) return Smi::cast(number)->value(); |
133 return DoubleToUint32(number->Number()); | 144 return DoubleToUint32(number->Number()); |
134 } | 145 } |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 buffer[buffer_pos] = '\0'; | 795 buffer[buffer_pos] = '\0'; |
785 | 796 |
786 double converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent); | 797 double converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent); |
787 return (sign == NEGATIVE) ? -converted : converted; | 798 return (sign == NEGATIVE) ? -converted : converted; |
788 } | 799 } |
789 | 800 |
790 } // namespace internal | 801 } // namespace internal |
791 } // namespace v8 | 802 } // namespace v8 |
792 | 803 |
793 #endif // V8_CONVERSIONS_INL_H_ | 804 #endif // V8_CONVERSIONS_INL_H_ |
OLD | NEW |