Status: New
Owner: ----

New issue 3512 by [email protected]: Inconsistent printing of denormal floats
http://code.google.com/p/v8/issues/detail?id=3512

First, consider the following utility functions:

function _DoubleHi(f) {
    // Return the most significant 32 bits of a double float number.
    // This contains the sign, exponent, and 21 bits of the mantissa.
    var buf = new ArrayBuffer(8);
    (new Float64Array(buf))[0] = f;
    // Index 1 if the machine is little-endian.  Use index 0 for big-endian.
    var hi = (new Uint32Array(buf))[1];

    // Return as a signed integer
    return hi | 0;
}

function _DoubleLo(f) {
    // Return the least significant 32 bits of a double float number.
    // This contains the lower 32 bits of the mantissa.
    var buf = new ArrayBuffer(8);
    (new Float64Array(buf))[0] = f;
    // Index 1 if the machine is little-endian.  Use index 1 for big-endian.
    var lo = (new Uint32Array(buf))[0];

    return lo;
}

function _ConstructDouble(high, low)
{
    var buf = new ArrayBuffer(8);
    // This following is for a little-endian machine.  For a
    // big-endian machine reverse the indices.
    (new Uint32Array(buf))[1] = high;
    (new Uint32Array(buf))[0] = low;
    return new Float64Array(buf)[0];
}

function _DoubleBits(x)
{
    return [_DoubleHi(x), _DoubleLo(x)];
}

Then run _ConstructDouble(262271,558054906). JS prints this as

5.565382338080105e-309

However, _ConstructDouble(262271,558054906) is the exact rational number 4505782028811770/2^1076. If I use maxima to print this out using 32 digits of precision, I get:

bfloat(4505782028811770/2^1076); ->
5.5653802702119232229811010819437b-309

I would expect JS to print something closer to this value than what is actually printed. When JS reads the values produced by maxima, we get
_DoubleBits(5.5653802702119232229811010819437e-309) ->
[262271, 139513726]

It appears, however that JS has print/read consistency since

_DoubleBits(5.565382338080105e-309) ->
[262271, 558054906]

It's just that the printed value isn't quite what I would expect.


--
You received this message because this project is configured to send all issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to