From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:40037) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QOVm4-0007k3-Sk for qemu-devel@nongnu.org; Mon, 23 May 2011 10:06:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QOVm3-0002cH-M1 for qemu-devel@nongnu.org; Mon, 23 May 2011 10:06:24 -0400 Received: from mail-yi0-f45.google.com ([209.85.218.45]:38613) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QOVm3-0002cB-Jl for qemu-devel@nongnu.org; Mon, 23 May 2011 10:06:23 -0400 Received: by yib19 with SMTP id 19so2473886yib.4 for ; Mon, 23 May 2011 07:06:22 -0700 (PDT) Message-ID: <4DDA69DC.5050504@codemonkey.ws> Date: Mon, 23 May 2011 09:06:20 -0500 From: Anthony Liguori MIME-Version: 1.0 References: <20110520180331.GA21837@amd.home.annexia.org> <4DD6AEB9.6060506@codemonkey.ws> <20110523130411.GR24143@redhat.com> <4DDA620F.1090308@codemonkey.ws> <20110523134021.GT24143@redhat.com> <4DDA663F.30907@codemonkey.ws> <20110523110216.751853fc@doriath> In-Reply-To: <20110523110216.751853fc@doriath> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] qemu: json: Fix parsing of integers >= 0x8000000000000000 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Luiz Capitulino Cc: qemu-devel@nongnu.org, "Richard W.M. Jones" On 05/23/2011 09:02 AM, Luiz Capitulino wrote: > On Mon, 23 May 2011 08:50:55 -0500 > Anthony Liguori wrote: > >>>> The actual value of the alert will surprise you :-) >>>> >>>> Integers in Javascript are actually represented as doubles >>>> internally which means that integer constants are only accurate up >>>> to 52 bits. >>>> >>>> So really, we should cap integers at 32-bit :-/ >>>> >>>> Have I mentioned recently that I really dislike JSON... >>> >>> NB, I am distinguishing between JSON the generic specification and >>> JSON as implemented in web browsers. JSON the specification has *no* >>> limitation on integers. >> >> The spec has no notion of integers at all. Here's the relevant text. >> Note that the BNF only has a single entry point for numbers. It does >> not distinguish between integers and floating point numbers. Also, the >> only discussion of valid numbers is about whether the number can be >> represented as a rational number. I think the only way to read the spec >> here is that *all* numbers are meant to be represented as floating point >> numbers. > > Python json works just fine: > >>>> import json >>>> json.dumps(9223372036854775807) > '9223372036854775807' >>>> json.loads('9223372036854775807') > 9223372036854775807 Python integers use BigNumbers transparently when necessary. That's what happening here. There's a strong treatment of Python's behavior at http://deron.meranda.us/python/comparing_json_modules/numbers Regards, Anthony Liguori