spaces.cc
string-search.cc
string-stream.cc
+ strtod.cc
stub-cache.cc
token.cc
top.cc
#include "dtoa.h"
#include "factory.h"
#include "scanner.h"
+#include "strtod.h"
namespace v8 {
namespace internal {
}
-extern "C" double gay_strtod(const char* s00, const char** se);
-
// Maximum number of significant digits in decimal representation.
// The longest possible double in decimal representation is
// (2^53 - 1) * 2 ^ -1074 that is (2 ^ 53 - 1) * 5 ^ 1074 / 10 ^ 1074
}
ASSERT(buffer_pos < kBufferSize);
- buffer[buffer_pos++] = '\0';
- return sign ? -gay_strtod(buffer, NULL) : gay_strtod(buffer, NULL);
+ buffer[buffer_pos] = '\0';
+ Vector<char> buffer_vector(buffer, buffer_pos);
+ return sign ? -strtod(buffer_vector, NULL) : strtod(buffer_vector, NULL);
}
// The following code causes accumulating rounding error for numbers greater
++current;
if (!AdvanceToNonspace(¤t, end)) return JUNK_STRING_VALUE;
} else if (*current == '-') {
- buffer[buffer_pos++] = '-';
++current;
if (!AdvanceToNonspace(¤t, end)) return JUNK_STRING_VALUE;
sign = true;
return JUNK_STRING_VALUE;
}
- ASSERT(buffer_pos == 0 || buffer[0] == '-');
- return buffer_pos > 0 ? -V8_INFINITY : V8_INFINITY;
+ ASSERT(buffer_pos == 0);
+ return sign ? -V8_INFINITY : V8_INFINITY;
}
bool leading_zero = false;
return JUNK_STRING_VALUE; // "0x".
}
- bool sign = (buffer_pos > 0 && buffer[0] == '-');
return InternalStringToIntDouble<4>(current,
end,
sign,
}
if (*current == '.') {
+ if (octal && !allow_trailing_junk) return JUNK_STRING_VALUE;
+ if (octal) goto parsing_done;
+
++current;
if (current == end) {
if (significant_digits == 0 && !leading_zero) {
}
}
- ASSERT(buffer_pos < kBufferSize);
- buffer[buffer_pos++] = '.';
+ // We don't emit a '.', but adjust the exponent instead.
fractional_part = true;
- // There is the fractional part.
+ // There is a fractional part.
while (*current >= '0' && *current <= '9') {
if (significant_digits < kMaxSignificantDigits) {
ASSERT(buffer_pos < kBufferSize);
buffer[buffer_pos++] = static_cast<char>(*current);
significant_digits++;
+ exponent--;
} else {
// Ignore insignificant digits in the fractional part.
nonzero_digit_dropped = nonzero_digit_dropped || *current != '0';
exponent += insignificant_digits;
if (octal) {
- bool sign = buffer[0] == '-';
- int start_pos = (sign ? 1 : 0);
-
- return InternalStringToIntDouble<3>(buffer + start_pos,
+ return InternalStringToIntDouble<3>(buffer,
buffer + buffer_pos,
sign,
allow_trailing_junk);
}
if (nonzero_digit_dropped) {
- if (insignificant_digits) buffer[buffer_pos++] = '.';
buffer[buffer_pos++] = '1';
- }
-
- // If the number has no more than kMaxDigitsInInt digits and doesn't have
- // fractional part it could be parsed faster (without checks for
- // spaces, overflow, etc.).
- const int kMaxDigitsInInt = 9 * sizeof(int) / 4; // NOLINT
-
- if (exponent != 0) {
- ASSERT(buffer_pos < kBufferSize);
- buffer[buffer_pos++] = 'e';
- if (exponent < 0) {
- ASSERT(buffer_pos < kBufferSize);
- buffer[buffer_pos++] = '-';
- exponent = -exponent;
- }
-
- // The minimal/maximal double is +/-1.7e-308. Given that
- // the buffer contains at most 773 (kMaxSignificantDigits + 1) the
- // minimal possible exponent is hence -(308 + 773)=-1081.
- // Since leading zeros are removed the maximal exponent cannot exceed 308.
- // If the following test triggers the result will be +/-infinity or +/-0.
- if (exponent > 9999) exponent = 9999;
-
- const int exp_digits = 4;
- for (int i = 0; i < exp_digits; i++) {
- buffer[buffer_pos + exp_digits - 1 - i] = '0' + exponent % 10;
- exponent /= 10;
- }
- ASSERT(exponent == 0);
- buffer_pos += exp_digits;
- } else if (!fractional_part && significant_digits <= kMaxDigitsInInt) {
- if (significant_digits == 0) return SignedZero(sign);
- ASSERT(buffer_pos > 0);
- int num = 0;
- int start_pos = (buffer[0] == '-' ? 1 : 0);
- for (int i = start_pos; i < buffer_pos; i++) {
- ASSERT(buffer[i] >= '0' && buffer[i] <= '9');
- num = 10 * num + (buffer[i] - '0');
- }
- return static_cast<double>(start_pos == 0 ? num : -num);
+ exponent--;
}
ASSERT(buffer_pos < kBufferSize);
buffer[buffer_pos] = '\0';
- return gay_strtod(buffer, NULL);
+ double converted = strtod(Vector<char>(buffer, buffer_pos), exponent);
+ return sign? -converted: converted;
}
+
double StringToDouble(String* str, int flags, double empty_string_val) {
StringShape shape(str);
if (shape.IsSequentialAscii()) {
--- /dev/null
+// Copyright 2010 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include <stdarg.h>
+#include <limits.h>
+
+#include "v8.h"
+
+#include "strtod.h"
+// #include "cached-powers.h"
+
+namespace v8 {
+namespace internal {
+
+extern "C" double gay_strtod(const char* s00, const char** se);
+
+double strtod(Vector<char> buffer, int exponent) {
+ char gay_buffer[1024];
+ buffer.start()[buffer.length()] = '\0';
+ snprintf(gay_buffer, 1024, "%se%d", buffer.start(), exponent);
+ return gay_strtod(gay_buffer, NULL);
+}
+
+} } // namespace v8::internal
--- /dev/null
+// Copyright 2010 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef V8_STRTOD_H_
+#define V8_STRTOD_H_
+
+namespace v8 {
+namespace internal {
+
+// The buffer must only contain digits in the range [0-9]. It must not
+// contain a dot or a sign. It must not start with '0', and must not be empty.
+double strtod(Vector<char> buffer, int exponent);
+
+} } // namespace v8::internal
+
+#endif // V8_STRTOD_H_
\ No newline at end of file
'../../src/string-search.h',
'../../src/string-stream.cc',
'../../src/string-stream.h',
+ '../../src/strtod.cc',
+ '../../src/strtod.h',
'../../src/stub-cache.cc',
'../../src/stub-cache.h',
'../../src/token.cc',