[Bug 24241] Adopt the ES6 "safe integer" range for (unsigned) long longs

https://www.w3.org/Bugs/Public/show_bug.cgi?id=24241

Tab Atkins Jr. <jackalmage@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jackalmage@gmail.com

--- Comment #1 from Tab Atkins Jr. <jackalmage@gmail.com> ---
To inline the reasoning:

2^53 is the endpoint of the contiguous representable integers.  However, it's
not *unambiguously* representable.  In particular, if an integral expression
would evaluate to 2^53 + 1, it'll get stored as 2^53.

This means that you can't be sure that your answer is exact just because it's
in the [-2^53, 2^53] range.  To be precise, something like this:

var c = a + b;
if(safe(a) && safe(b) && safe(c)) {
  // Definitely got the exact answer!
  return c;
} else {
  // Maybe got a slightly incorrect answer!
  throw "Whoops!";
}

...is buggy, because `var a=2^53, b=1, c=a+b;" passes the checks but gives the
wrong result.  You have to lop off one integer from each side of the range for
it to work correctly.

Since WebIDL's definition of long long int is the larger range, this means that
spec code that wants unambiguous integers has to specify an additional test,
which is wasteful.

It would be nice if WebIDL's definition of long long int was the "safe" range
instead.

-- 
You are receiving this mail because:
You are the QA Contact for the bug.

Received on Wednesday, 8 January 2014 20:54:55 UTC