Ignore:
Timestamp:
Aug 27, 2010, 1:12:01 PM (15 years ago)
Author:
[email protected]
Message:

Bug 44745 - Number.toFixed/toExponential/toPrecision are inaccurate.

Reviewed by Oliver Hunt.

These methods should be using a version of dtoa that can generate results accurate
to the requested precision, whereas our version of dtoa is only currently able to
support producing results sufficiently accurate to distinguish the value from any
other IEEE-754 double precision number.

JavaScriptCore:

This change has no impact on benchmarks we track.

On microbenchmarks for these functions, this is a slight regression where a high
precision is requested (dtoa now need to iterate further to generate a a greater
number of digits), but with smaller precision values (hopefully more common) this
improves performance, since it reduced the accurate of result dtoa is required,
to produce, and removes the need to pre-round values before calling dtoa.

doubleToStringInJavaScriptFormat renamed to numberToString

doubleToStringInJavaScriptFormat renamed to numberToString

  • runtime/UString.cpp:

(JSC::UString::number):

doubleToStringInJavaScriptFormat renamed to numberToString

  • wtf/DecimalNumber.h:

(WTF::DecimalNumber::DecimalNumber):
(WTF::DecimalNumber::toStringDecimal):
(WTF::DecimalNumber::toStringExponential):

Remove all pre-rounding of values, instead call dtoa correctly.

  • wtf/dtoa.cpp:

(WTF::dtoa):

  • wtf/dtoa.h:

Reenable support for rounding to specific-figures/decimal-places in dtoa.
Modify to remove unbiased rounding, provide ECMA required away-from-zero.
Rewrite doubleToStringInJavaScriptFormat to use DecimalNumber, rename to
numberToString.

WebCore:

  • html/HTMLTreeBuilder.cpp:

(WebCore::serializeForNumberType):

doubleToStringInJavaScriptFormat renamed to numberToString.

LayoutTests:

Updating expected results, corrected errors in fast/js/kde/script-tests/Number.js
(corrected results confirmed with FireFox).

  • fast/js/kde/Number-expected.txt:
  • fast/js/kde/script-tests/Number.js:
  • fast/js/number-toExponential-expected.txt:
  • fast/js/number-tofixed-expected.txt:
  • fast/js/number-toprecision-expected.txt:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/UString.cpp

    r66159 r66245  
    2727#include "JSGlobalObjectFunctions.h"
    2828#include "Collector.h"
    29 #include "dtoa.h"
    3029#include "Identifier.h"
    3130#include "Operations.h"
     
    3736#include <wtf/ASCIICType.h>
    3837#include <wtf/Assertions.h>
     38#include <wtf/DecimalNumber.h>
    3939#include <wtf/MathExtras.h>
    4040#include <wtf/StringExtras.h>
     
    199199UString UString::number(double d)
    200200{
    201     DtoaBuffer buffer;
    202     unsigned length;
    203     doubleToStringInJavaScriptFormat(d, buffer, &length);
     201    NumberToStringBuffer buffer;
     202    unsigned length = numberToString(d, buffer);
    204203    return UString(buffer, length);
    205204}
Note: See TracChangeset for help on using the changeset viewer.