Ignore:
Timestamp:
Jul 3, 2011, 3:27:12 PM (14 years ago)
Author:
[email protected]
Message:

Reviewed by Sam Weinig.

https://bugs.webkit.org/show_bug.cgi?id=16652
Firefox and JavaScriptCore differ in Number.toString(integer)

Source/JavaScriptCore:

Our arbitrary radix (2..36) toString conversion is inaccurate.
This is partly because it uses doubles to perform math that requires
higher accuracy, and partly becasue it does not attempt to correctly
detect where to terminate, instead relying on a simple 'epsilon'.

  • runtime/NumberPrototype.cpp:

(JSC::decomposeDouble):

  • helper function to extract sign, exponent, mantissa from IEEE doubles.

(JSC::Uint16WithFraction::Uint16WithFraction):

  • helper class, u16int with infinite precision fraction, used to convert the fractional part of the number to a string.

(JSC::Uint16WithFraction::operator*=):

  • Multiply by a uint16.

(JSC::Uint16WithFraction::operator<):

  • Compare two Uint16WithFractions.

(JSC::Uint16WithFraction::floorAndSubtract):

  • Extract the integer portion of the number, and subtract it (clears the integer portion).

(JSC::Uint16WithFraction::comparePoint5):

  • Compare to 0.5.

(JSC::Uint16WithFraction::sumGreaterThanOne):

  • Passed a second Uint16WithFraction, returns true if the result of adding the two values would be greater than one.

(JSC::Uint16WithFraction::isNormalized):

  • Used by ASSERTs to consistency check internal representation.

(JSC::BigInteger::BigInteger):

  • helper class, unbounded integer value, used to convert the integer part of the number to a string.

(JSC::BigInteger::divide):

  • Divide this value through by a uint32.

(JSC::BigInteger::operator!):

  • test for zero.

(JSC::toStringWithRadix):

  • Performs number to string conversion, with the given radix (2..36).

(JSC::numberProtoFuncToString):

  • Changed to use toStringWithRadix.

Tools:

Added forwarding header.

  • DumpRenderTree/ForwardingHeaders/wtf/StdLibExtras.h: Added.

LayoutTests:

Our arbitrary radix (2..36) toString conversion is inaccurate.
This is partly because it uses doubles to perform math that requires
higher accuracy, and partly becasue it does not attempt to correctly
detect where to terminate, instead relying on a simple 'epsilon'.

  • fast/js/number-toString-expected.txt:
    • Update expected results from FAIL to PASS.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/wtf/MathExtras.h

    r89943 r90347  
    3232#include <limits>
    3333#include <stdlib.h>
     34#include <wtf/StdLibExtras.h>
    3435
    3536#if OS(SOLARIS)
     
    260261#endif
    261262
     263// decompose 'number' to its sign, exponent, and mantissa components.
     264// The result is interpreted as:
     265//     (sign ? -1 : 1) * pow(2, exponent) * (mantissa / (1 << 52))
     266inline void decomposeDouble(double number, bool& sign, int32_t& exponent, uint64_t& mantissa)
     267{
     268    ASSERT(isfinite(number));
     269
     270    sign = signbit(number);
     271
     272    uint64_t bits = WTF::bitwise_cast<uint64_t>(number);
     273    exponent = (static_cast<int32_t>(bits >> 52) & 0x7ff) - 0x3ff;
     274    mantissa = bits & 0xFFFFFFFFFFFFFull;
     275
     276    // Check for zero/denormal values; if so, adjust the exponent,
     277    // if not insert the implicit, omitted leading 1 bit.
     278    if (exponent == -0x3ff)
     279        exponent = mantissa ? -0x3fe : 0;
     280    else
     281        mantissa |= 0x10000000000000ull;
     282}
     283
    262284#endif // #ifndef WTF_MathExtras_h
Note: See TracChangeset for help on using the changeset viewer.