qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 3/3] Add test suite for json marshalling


From: Jamie Lokier
Subject: Re: [Qemu-devel] [PATCH 3/3] Add test suite for json marshalling
Date: Mon, 16 Nov 2009 02:26:31 +0000
User-agent: Mutt/1.5.13 (2006-08-11)

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 via email to

[Prev in Thread] Current Thread [Next in Thread]