qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jamie Lokier <jamie@shareable.org>
To: Anthony Liguori <anthony@codemonkey.ws>
Cc: Anthony Liguori <aliguori@us.ibm.com>,
	qemu-devel@nongnu.org, Luiz Capitulino <lcapitulino@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 3/3] Add test suite for json marshalling
Date: Mon, 16 Nov 2009 02:26:31 +0000	[thread overview]
Message-ID: <20091116022631.GB9827@shareable.org> (raw)
In-Reply-To: <4AFD67C4.9070100@codemonkey.ws>

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

  reply	other threads:[~2009-11-16  2:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-11 19:24 [Qemu-devel] [PATCH 1/3] QDict: Introduce qdict_iter() Anthony Liguori
2009-11-11 19:24 ` [Qemu-devel] [PATCH 2/3] Provide marshalling mechanism for json Anthony Liguori
2009-11-11 19:24 ` [Qemu-devel] [PATCH 3/3] Add test suite for json marshalling Anthony Liguori
2009-11-13  3:14   ` Jamie Lokier
2009-11-13 14:05     ` Anthony Liguori
2009-11-16  2:26       ` Jamie Lokier [this message]
2009-11-18 10:48     ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091116022631.GB9827@shareable.org \
    --to=jamie@shareable.org \
    --cc=aliguori@us.ibm.com \
    --cc=anthony@codemonkey.ws \
    --cc=lcapitulino@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).