Ignore:
Timestamp:
Jul 4, 2011, 7:59:02 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

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