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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 | 221 |
222 if (exponent == 0) { | 222 if (exponent == 0) { |
223 if (negative) { | 223 if (negative) { |
224 if (number == 0) return -0.0; | 224 if (number == 0) return -0.0; |
225 number = -number; | 225 number = -number; |
226 } | 226 } |
227 return static_cast<double>(number); | 227 return static_cast<double>(number); |
228 } | 228 } |
229 | 229 |
230 ASSERT(number != 0); | 230 ASSERT(number != 0); |
231 // The double could be constructed faster from number (mantissa), exponent | 231 return ldexp(static_cast<double>(negative ? -number : number), exponent); |
232 // and sign. Assuming it's a rare case more simple code is used. | |
233 return static_cast<double>(negative ? -number : number) * pow(2.0, exponent); | |
234 } | 232 } |
235 | 233 |
236 | 234 |
237 template <class Iterator, class EndMark> | 235 template <class Iterator, class EndMark> |
238 double InternalStringToInt(UnicodeCache* unicode_cache, | 236 double InternalStringToInt(UnicodeCache* unicode_cache, |
239 Iterator current, | 237 Iterator current, |
240 EndMark end, | 238 EndMark end, |
241 int radix) { | 239 int radix) { |
242 const bool allow_trailing_junk = true; | 240 const bool allow_trailing_junk = true; |
243 const double empty_string_val = JunkStringValue(); | 241 const double empty_string_val = JunkStringValue(); |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 ASSERT(buffer_pos < kBufferSize); | 659 ASSERT(buffer_pos < kBufferSize); |
662 buffer[buffer_pos] = '\0'; | 660 buffer[buffer_pos] = '\0'; |
663 | 661 |
664 double converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent); | 662 double converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent); |
665 return negative ? -converted : converted; | 663 return negative ? -converted : converted; |
666 } | 664 } |
667 | 665 |
668 } } // namespace v8::internal | 666 } } // namespace v8::internal |
669 | 667 |
670 #endif // V8_CONVERSIONS_INL_H_ | 668 #endif // V8_CONVERSIONS_INL_H_ |
OLD | NEW |