Changeset 66159 in webkit for trunk/JavaScriptCore/wtf/text/WTFString.cpp
- Timestamp:
- Aug 26, 2010, 5:38:54 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/text/WTFString.cpp
r66142 r66159 26 26 #include <stdarg.h> 27 27 #include <wtf/ASCIICType.h> 28 #include <wtf/ DecimalNumber.h>28 #include <wtf/text/CString.h> 29 29 #include <wtf/StringExtras.h> 30 30 #include <wtf/Vector.h> 31 #include <wtf/ text/CString.h>31 #include <wtf/dtoa.h> 32 32 #include <wtf/unicode/UTF8.h> 33 33 #include <wtf/unicode/Unicode.h> … … 948 948 } 949 949 950 static unsigned copyToString(const char* string, unsigned length, NumberToStringBuffer& buffer)951 {952 for (unsigned i = 0; i < length; ++i)953 buffer[i] = string[i];954 return length;955 }956 957 static NEVER_INLINE unsigned nanOrInfToString(double x, NumberToStringBuffer& buffer)958 {959 ASSERT(isnan(x) || isinf(x));960 if (isnan(x))961 return copyToString("NaN", 3, buffer);962 if (x < 0)963 return copyToString("-Infinity", 9, buffer);964 return copyToString("Infinity", 8, buffer);965 }966 967 // toString converts a number to a string without rounding. For values in the range968 // 1e-6 <= x < 1e+21 the result is formatted as a decimal, with values outside of969 // this range being formatted as an exponential.970 unsigned numberToString(double x, NumberToStringBuffer& buffer)971 {972 // Handle NaN and Infinity.973 if (UNLIKELY(isnan(x) || isinf(x)))974 return nanOrInfToString(x, buffer);975 976 // Convert to decimal, no rounding.977 DecimalNumber number(x);978 979 // Format as decimal or exponential, depending on the exponent.980 return number.exponent() >= -6 && number.exponent() < 21981 ? number.toStringDecimal(buffer)982 : number.toStringExponential(buffer);983 }984 985 950 } // namespace WTF 986 951
Note:
See TracChangeset
for help on using the changeset viewer.