From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N9rIg-0002yz-Jz for qemu-devel@nongnu.org; Sun, 15 Nov 2009 21:26:42 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N9rIb-0002yP-Eu for qemu-devel@nongnu.org; Sun, 15 Nov 2009 21:26:41 -0500 Received: from [199.232.76.173] (port=42208 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N9rIb-0002yM-99 for qemu-devel@nongnu.org; Sun, 15 Nov 2009 21:26:37 -0500 Received: from mail2.shareable.org ([80.68.89.115]:47869) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1N9rIa-0005kU-RN for qemu-devel@nongnu.org; Sun, 15 Nov 2009 21:26:37 -0500 Date: Mon, 16 Nov 2009 02:26:31 +0000 From: Jamie Lokier Subject: Re: [Qemu-devel] [PATCH 3/3] Add test suite for json marshalling Message-ID: <20091116022631.GB9827@shareable.org> References: <1257967478-4847-1-git-send-email-aliguori@us.ibm.com> <1257967478-4847-3-git-send-email-aliguori@us.ibm.com> <20091113031431.GF19405@shareable.org> <4AFD67C4.9070100@codemonkey.ws> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4AFD67C4.9070100@codemonkey.ws> List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: Anthony Liguori , qemu-devel@nongnu.org, Luiz Capitulino Anthony Liguori wrote: > Jamie Lokier wrote: > >Anthony Liguori wrote: > > > >>After checking that we can demarshal, marshal again and compared to > >>the expected decoded value. This doesn't work so well for floats > >>because they cannot be accurately represented in decimal but we try > >>our best. > >> > > > >Good sprintf/scanf/strtod implementations do guarantee that what's > >printed and then parsed gets back the same floating point value, as > >long as you have printed sufficient decimal digits. > > > >I'm not sure if FLT_DIG/DLB_DIG are the right number of digits, > >though. Glibc's documentation of those is confusing and they might > >mean something a little different. > > > > Eh, I played around quite a bit and the results were disappointing. > > $ printf "%f\n" 43.32 > 43.320000 > $ printf "%0.32f\n" 43.32 > 43.31999999999999999972244424384371 True enough. I'm not sure how to ask for the minimum number of digits for unambiguous representation. Point still stands though: Try *parsing* both those outputs, and the double result is exactly the same in each case. $ printf '%0.32f\n' $(printf '%0.32f\n' 43.32) 43.31999999999999999972244424384371 So you can do this: unambiguous decimal text -> double -> same text and this: double -> unambiguous decimal text -> same double As long as "unambiguous decimal" was printed with enough digits. -- Jamie