| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #ifndef V8_CONVERSIONS_INL_H_ | 28 #ifndef V8_CONVERSIONS_INL_H_ |
| 29 #define V8_CONVERSIONS_INL_H_ | 29 #define V8_CONVERSIONS_INL_H_ |
| 30 | 30 |
| 31 #include <limits.h> // Required for INT_MAX etc. | 31 #include <limits.h> // Required for INT_MAX etc. |
| 32 #include <math.h> | 32 #include <math.h> |
| 33 #include <float.h> // Required for DBL_MAX and on Win32 for finite() | 33 #include <float.h> // Required for DBL_MAX and on Win32 for finite() |
| 34 #include <stdarg.h> | 34 #include <stdarg.h> |
| 35 #include "globals.h" // Required for V8_INFINITY |
| 35 | 36 |
| 36 // ---------------------------------------------------------------------------- | 37 // ---------------------------------------------------------------------------- |
| 37 // Extra POSIX/ANSI functions for Win32/MSVC. | 38 // Extra POSIX/ANSI functions for Win32/MSVC. |
| 38 | 39 |
| 39 #include "conversions.h" | 40 #include "conversions.h" |
| 40 #include "strtod.h" | 41 #include "strtod.h" |
| 41 #include "platform.h" | 42 #include "platform.h" |
| 43 #include "double.h" |
| 42 | 44 |
| 43 namespace v8 { | 45 namespace v8 { |
| 44 namespace internal { | 46 namespace internal { |
| 45 | 47 |
| 46 static inline double JunkStringValue() { | 48 static inline double JunkStringValue() { |
| 47 return std::numeric_limits<double>::quiet_NaN(); | 49 return std::numeric_limits<double>::quiet_NaN(); |
| 48 } | 50 } |
| 49 | 51 |
| 50 | 52 |
| 51 // The fast double-to-unsigned-int conversion routine does not guarantee | 53 // The fast double-to-unsigned-int conversion routine does not guarantee |
| (...skipping 28 matching lines...) Expand all Loading... |
| 80 static inline double DoubleToInteger(double x) { | 82 static inline double DoubleToInteger(double x) { |
| 81 if (isnan(x)) return 0; | 83 if (isnan(x)) return 0; |
| 82 if (!isfinite(x) || x == 0) return x; | 84 if (!isfinite(x) || x == 0) return x; |
| 83 return (x >= 0) ? floor(x) : ceil(x); | 85 return (x >= 0) ? floor(x) : ceil(x); |
| 84 } | 86 } |
| 85 | 87 |
| 86 | 88 |
| 87 int32_t DoubleToInt32(double x) { | 89 int32_t DoubleToInt32(double x) { |
| 88 int32_t i = FastD2I(x); | 90 int32_t i = FastD2I(x); |
| 89 if (FastI2D(i) == x) return i; | 91 if (FastI2D(i) == x) return i; |
| 90 static const double two32 = 4294967296.0; | 92 Double d(x); |
| 91 static const double two31 = 2147483648.0; | 93 int exponent = d.Exponent(); |
| 92 if (!isfinite(x) || x == 0) return 0; | 94 if (exponent < 0) { |
| 93 if (x < 0 || x >= two32) x = modulo(x, two32); | 95 if (exponent <= -Double::kSignificandSize) return 0; |
| 94 x = (x >= 0) ? floor(x) : ceil(x) + two32; | 96 return d.Sign() * static_cast<int32_t>(d.Significand() >> -exponent); |
| 95 return (int32_t) ((x >= two31) ? x - two32 : x); | 97 } else { |
| 98 if (exponent > 31) return 0; |
| 99 return d.Sign() * static_cast<int32_t>(d.Significand() << exponent); |
| 100 } |
| 96 } | 101 } |
| 97 | 102 |
| 98 | 103 |
| 99 template <class Iterator, class EndMark> | 104 template <class Iterator, class EndMark> |
| 100 static bool SubStringEquals(Iterator* current, | 105 static bool SubStringEquals(Iterator* current, |
| 101 EndMark end, | 106 EndMark end, |
| 102 const char* substring) { | 107 const char* substring) { |
| 103 ASSERT(**current == *substring); | 108 ASSERT(**current == *substring); |
| 104 for (substring++; *substring != '\0'; substring++) { | 109 for (substring++; *substring != '\0'; substring++) { |
| 105 ++*current; | 110 ++*current; |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 ASSERT(buffer_pos < kBufferSize); | 660 ASSERT(buffer_pos < kBufferSize); |
| 656 buffer[buffer_pos] = '\0'; | 661 buffer[buffer_pos] = '\0'; |
| 657 | 662 |
| 658 double converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent); | 663 double converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent); |
| 659 return negative ? -converted : converted; | 664 return negative ? -converted : converted; |
| 660 } | 665 } |
| 661 | 666 |
| 662 } } // namespace v8::internal | 667 } } // namespace v8::internal |
| 663 | 668 |
| 664 #endif // V8_CONVERSIONS_INL_H_ | 669 #endif // V8_CONVERSIONS_INL_H_ |
| OLD | NEW |