W3C home > Mailing lists > Public > public-script-coord@w3.org > January to March 2012

Re: Conversion of ES Number to WebIDL long long and unsigned long long should not throw by default

From: Sigbjorn Finne <sigbjorn.finne@gmail.com>
Date: Mon, 13 Feb 2012 09:34:19 +0100
Message-ID: <CAAO+_-AEd9BhXPNZZnWVizYB1yDh9Yggq_xF1Wy567mGjfcA+w@mail.gmail.com>
To: Boris Zbarsky <bzbarsky@mit.edu>
Cc: "public-script-coord@w3.org" <public-script-coord@w3.org>
On Wed, Feb 8, 2012 at 5:28 AM, Boris Zbarsky <bzbarsky@mit.edu> wrote:

> The current WebIDL algorithm for long long says:
>
>  Set x to sign(x) * floor(abs(x)).
>  Set x to x modulo 2^64.
>  If x is greater than or equal to 2^63, then set x to x - 2^64.
>  If x < -(2^53 - 1) or x > 2^53 - 1, then throw a TypeError.
>
> This makes no sense.  The justification is something about how your x
> might have lost precision and so you may not be hitting the 64-bit int you
> "wanted"... but in that case the check-and-throw should be done before
> reduction mod 2^64.  Doing it after just means the result is somewhat
> random once your double is greater than 2^64.
>

The purpose of the third step is to adjust sign, I'd say. See the
definition of modulo in the ES spec (preserves sign of the divisor) +
compare the above to ToInt32()'s definition.

--sof
Received on Monday, 13 February 2012 08:35:05 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 8 May 2013 19:30:05 UTC