| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 #include <stdarg.h> | |
| 6 #include <cmath> | 5 #include <cmath> |
| 6 #include <cstdarg> |
| 7 #include <limits> |
| 7 | 8 |
| 8 #include "src/v8.h" | 9 #include "src/v8.h" |
| 9 | 10 |
| 10 #include "src/bignum.h" | 11 #include "src/bignum.h" |
| 11 #include "src/cached-powers.h" | 12 #include "src/cached-powers.h" |
| 12 #include "src/double.h" | 13 #include "src/double.h" |
| 13 #include "src/globals.h" | 14 #include "src/globals.h" |
| 14 #include "src/strtod.h" | 15 #include "src/strtod.h" |
| 15 #include "src/utils.h" | 16 #include "src/utils.h" |
| 16 | 17 |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 // Returns the correct double for the buffer*10^exponent. | 346 // Returns the correct double for the buffer*10^exponent. |
| 346 // The variable guess should be a close guess that is either the correct double | 347 // The variable guess should be a close guess that is either the correct double |
| 347 // or its lower neighbor (the nearest double less than the correct one). | 348 // or its lower neighbor (the nearest double less than the correct one). |
| 348 // Preconditions: | 349 // Preconditions: |
| 349 // buffer.length() + exponent <= kMaxDecimalPower + 1 | 350 // buffer.length() + exponent <= kMaxDecimalPower + 1 |
| 350 // buffer.length() + exponent > kMinDecimalPower | 351 // buffer.length() + exponent > kMinDecimalPower |
| 351 // buffer.length() <= kMaxDecimalSignificantDigits | 352 // buffer.length() <= kMaxDecimalSignificantDigits |
| 352 static double BignumStrtod(Vector<const char> buffer, | 353 static double BignumStrtod(Vector<const char> buffer, |
| 353 int exponent, | 354 int exponent, |
| 354 double guess) { | 355 double guess) { |
| 355 if (guess == V8_INFINITY) { | 356 if (guess == std::numeric_limits<double>::infinity()) { |
| 356 return guess; | 357 return guess; |
| 357 } | 358 } |
| 358 | 359 |
| 359 DiyFp upper_boundary = Double(guess).UpperBoundary(); | 360 DiyFp upper_boundary = Double(guess).UpperBoundary(); |
| 360 | 361 |
| 361 DCHECK(buffer.length() + exponent <= kMaxDecimalPower + 1); | 362 DCHECK(buffer.length() + exponent <= kMaxDecimalPower + 1); |
| 362 DCHECK(buffer.length() + exponent > kMinDecimalPower); | 363 DCHECK(buffer.length() + exponent > kMinDecimalPower); |
| 363 DCHECK(buffer.length() <= kMaxSignificantDecimalDigits); | 364 DCHECK(buffer.length() <= kMaxSignificantDecimalDigits); |
| 364 // Make sure that the Bignum will be able to hold all our numbers. | 365 // Make sure that the Bignum will be able to hold all our numbers. |
| 365 // Our Bignum implementation has a separate field for exponents. Shifts will | 366 // Our Bignum implementation has a separate field for exponents. Shifts will |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 if (trimmed.length() == 0) return 0.0; | 402 if (trimmed.length() == 0) return 0.0; |
| 402 if (trimmed.length() > kMaxSignificantDecimalDigits) { | 403 if (trimmed.length() > kMaxSignificantDecimalDigits) { |
| 403 char significant_buffer[kMaxSignificantDecimalDigits]; | 404 char significant_buffer[kMaxSignificantDecimalDigits]; |
| 404 int significant_exponent; | 405 int significant_exponent; |
| 405 TrimToMaxSignificantDigits(trimmed, exponent, | 406 TrimToMaxSignificantDigits(trimmed, exponent, |
| 406 significant_buffer, &significant_exponent); | 407 significant_buffer, &significant_exponent); |
| 407 return Strtod(Vector<const char>(significant_buffer, | 408 return Strtod(Vector<const char>(significant_buffer, |
| 408 kMaxSignificantDecimalDigits), | 409 kMaxSignificantDecimalDigits), |
| 409 significant_exponent); | 410 significant_exponent); |
| 410 } | 411 } |
| 411 if (exponent + trimmed.length() - 1 >= kMaxDecimalPower) return V8_INFINITY; | 412 if (exponent + trimmed.length() - 1 >= kMaxDecimalPower) { |
| 413 return std::numeric_limits<double>::infinity(); |
| 414 } |
| 412 if (exponent + trimmed.length() <= kMinDecimalPower) return 0.0; | 415 if (exponent + trimmed.length() <= kMinDecimalPower) return 0.0; |
| 413 | 416 |
| 414 double guess; | 417 double guess; |
| 415 if (DoubleStrtod(trimmed, exponent, &guess) || | 418 if (DoubleStrtod(trimmed, exponent, &guess) || |
| 416 DiyFpStrtod(trimmed, exponent, &guess)) { | 419 DiyFpStrtod(trimmed, exponent, &guess)) { |
| 417 return guess; | 420 return guess; |
| 418 } | 421 } |
| 419 return BignumStrtod(trimmed, exponent, guess); | 422 return BignumStrtod(trimmed, exponent, guess); |
| 420 } | 423 } |
| 421 | 424 |
| 422 } } // namespace v8::internal | 425 } } // namespace v8::internal |
| OLD | NEW |