diff options
author | Steve Block <steveblock@google.com> | 2010-08-27 11:02:25 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2010-09-02 17:17:20 +0100 |
commit | e8b154fd68f9b33be40a3590e58347f353835f5c (patch) | |
tree | 0733ce26384183245aaa5656af26c653636fe6c1 /JavaScriptCore/wtf/text/WTFString.cpp | |
parent | da56157816334089526a7a115a85fd85a6e9a1dc (diff) | |
download | external_webkit-e8b154fd68f9b33be40a3590e58347f353835f5c.zip external_webkit-e8b154fd68f9b33be40a3590e58347f353835f5c.tar.gz external_webkit-e8b154fd68f9b33be40a3590e58347f353835f5c.tar.bz2 |
Merge WebKit at r66079 : Initial merge by git
Change-Id: Ie2e1440fb9d487d24e52c247342c076fecaecac7
Diffstat (limited to 'JavaScriptCore/wtf/text/WTFString.cpp')
-rw-r--r-- | JavaScriptCore/wtf/text/WTFString.cpp | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/JavaScriptCore/wtf/text/WTFString.cpp b/JavaScriptCore/wtf/text/WTFString.cpp index 7d44d21..bbff576 100644 --- a/JavaScriptCore/wtf/text/WTFString.cpp +++ b/JavaScriptCore/wtf/text/WTFString.cpp @@ -25,10 +25,10 @@ #include <limits> #include <stdarg.h> #include <wtf/ASCIICType.h> -#include <wtf/text/CString.h> +#include <wtf/DecimalNumber.h> #include <wtf/StringExtras.h> #include <wtf/Vector.h> -#include <wtf/dtoa.h> +#include <wtf/text/CString.h> #include <wtf/unicode/UTF8.h> #include <wtf/unicode/Unicode.h> @@ -947,6 +947,41 @@ float charactersToFloat(const UChar* data, size_t length, bool* ok) return static_cast<float>(charactersToDouble(data, length, ok)); } +static unsigned copyToString(const char* string, unsigned length, NumberToStringBuffer& buffer) +{ + for (unsigned i = 0; i < length; ++i) + buffer[i] = string[i]; + return length; +} + +static NEVER_INLINE unsigned nanOrInfToString(double x, NumberToStringBuffer& buffer) +{ + ASSERT(isnan(x) || isinf(x)); + if (isnan(x)) + return copyToString("NaN", 3, buffer); + if (x < 0) + return copyToString("-Infinity", 9, buffer); + return copyToString("Infinity", 8, buffer); +} + +// toString converts a number to a string without rounding. For values in the range +// 1e-6 <= x < 1e+21 the result is formatted as a decimal, with values outside of +// this range being formatted as an exponential. +unsigned numberToString(double x, NumberToStringBuffer& buffer) +{ + // Handle NaN and Infinity. + if (UNLIKELY(isnan(x) || isinf(x))) + return nanOrInfToString(x, buffer); + + // Convert to decimal, no rounding. + DecimalNumber number(x); + + // Format as decimal or exponential, depending on the exponent. + return number.exponent() >= -6 && number.exponent() < 21 + ? number.toStringDecimal(buffer) + : number.toStringExponential(buffer); +} + } // namespace WTF #ifndef NDEBUG |