| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 int exponent = d.Exponent(); | 90 int exponent = d.Exponent(); |
| 91 if (exponent < 0) { | 91 if (exponent < 0) { |
| 92 if (exponent <= -Double::kSignificandSize) return 0; | 92 if (exponent <= -Double::kSignificandSize) return 0; |
| 93 return d.Sign() * static_cast<int32_t>(d.Significand() >> -exponent); | 93 return d.Sign() * static_cast<int32_t>(d.Significand() >> -exponent); |
| 94 } else { | 94 } else { |
| 95 if (exponent > 31) return 0; | 95 if (exponent > 31) return 0; |
| 96 return d.Sign() * static_cast<int32_t>(d.Significand() << exponent); | 96 return d.Sign() * static_cast<int32_t>(d.Significand() << exponent); |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 | 99 |
| 100 bool DoubleToSmiInteger(double value, int* smi_int_value) { |
| 101 if (IsMinusZero(value)) return false; |
| 102 int i = FastD2IChecked(value); |
| 103 if (value != i || !Smi::IsValid(i)) return false; |
| 104 *smi_int_value = i; |
| 105 return true; |
| 106 } |
| 100 | 107 |
| 101 bool IsSmiDouble(double value) { | 108 bool IsSmiDouble(double value) { |
| 102 return !IsMinusZero(value) && value >= Smi::kMinValue && | 109 return !IsMinusZero(value) && value >= Smi::kMinValue && |
| 103 value <= Smi::kMaxValue && value == FastI2D(FastD2I(value)); | 110 value <= Smi::kMaxValue && value == FastI2D(FastD2I(value)); |
| 104 } | 111 } |
| 105 | 112 |
| 106 | 113 |
| 107 bool IsInt32Double(double value) { | 114 bool IsInt32Double(double value) { |
| 108 return !IsMinusZero(value) && value >= kMinInt && value <= kMaxInt && | 115 return !IsMinusZero(value) && value >= kMinInt && value <= kMaxInt && |
| 109 value == FastI2D(FastD2I(value)); | 116 value == FastI2D(FastD2I(value)); |
| (...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 buffer[buffer_pos] = '\0'; | 766 buffer[buffer_pos] = '\0'; |
| 760 | 767 |
| 761 double converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent); | 768 double converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent); |
| 762 return (sign == NEGATIVE) ? -converted : converted; | 769 return (sign == NEGATIVE) ? -converted : converted; |
| 763 } | 770 } |
| 764 | 771 |
| 765 } // namespace internal | 772 } // namespace internal |
| 766 } // namespace v8 | 773 } // namespace v8 |
| 767 | 774 |
| 768 #endif // V8_CONVERSIONS_INL_H_ | 775 #endif // V8_CONVERSIONS_INL_H_ |
| OLD | NEW |